Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class Jetpack { |
||
26 | public $xmlrpc_server = null; |
||
27 | |||
28 | private $xmlrpc_verification = null; |
||
29 | |||
30 | public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA'] |
||
31 | |||
32 | /** |
||
33 | * @var array The handles of styles that are concatenated into jetpack.css |
||
34 | */ |
||
35 | public $concatenated_style_handles = array( |
||
36 | 'jetpack-carousel', |
||
37 | 'grunion.css', |
||
38 | 'the-neverending-homepage', |
||
39 | 'jetpack_likes', |
||
40 | 'jetpack_related-posts', |
||
41 | 'sharedaddy', |
||
42 | 'jetpack-slideshow', |
||
43 | 'presentations', |
||
44 | 'jetpack-subscriptions', |
||
45 | 'jetpack-responsive-videos-style', |
||
46 | 'jetpack-social-menu', |
||
47 | 'tiled-gallery', |
||
48 | 'jetpack_display_posts_widget', |
||
49 | 'gravatar-profile-widget', |
||
50 | 'goodreads-widget', |
||
51 | 'jetpack_social_media_icons_widget', |
||
52 | 'jetpack-top-posts-widget', |
||
53 | 'jetpack_image_widget', |
||
54 | 'jetpack-my-community-widget', |
||
55 | ); |
||
56 | |||
57 | public $plugins_to_deactivate = array( |
||
58 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
59 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
60 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
61 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
62 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
63 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
64 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
65 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
66 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
67 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
68 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
69 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
70 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
71 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
72 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
73 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
74 | ); |
||
75 | |||
76 | static $capability_translations = array( |
||
|
|||
77 | 'administrator' => 'manage_options', |
||
78 | 'editor' => 'edit_others_posts', |
||
79 | 'author' => 'publish_posts', |
||
80 | 'contributor' => 'edit_posts', |
||
81 | 'subscriber' => 'read', |
||
82 | ); |
||
83 | |||
84 | /** |
||
85 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
86 | * if the plugins are active. Used by filter_default_modules |
||
87 | * |
||
88 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
89 | * change `module-slug` and add this to your plugin: |
||
90 | * |
||
91 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
92 | * function my_jetpack_get_default_modules( $modules ) { |
||
93 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
94 | * } |
||
95 | * |
||
96 | * @var array |
||
97 | */ |
||
98 | private $conflicting_plugins = array( |
||
99 | 'comments' => array( |
||
100 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
101 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
102 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
103 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
104 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
105 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
106 | ), |
||
107 | 'contact-form' => array( |
||
108 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
109 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
110 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
111 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
112 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
113 | ), |
||
114 | 'minileven' => array( |
||
115 | 'WPtouch' => 'wptouch/wptouch.php', |
||
116 | ), |
||
117 | 'latex' => array( |
||
118 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
119 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
120 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
121 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
122 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
123 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
124 | ), |
||
125 | 'protect' => array( |
||
126 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
127 | 'Captcha' => 'captcha/captcha.php', |
||
128 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
129 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
130 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
131 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
132 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
133 | 'Security-protection' => 'security-protection/security-protection.php', |
||
134 | 'Login Security' => 'login-security/login-security.php', |
||
135 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
136 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
137 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
138 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
139 | ), |
||
140 | 'random-redirect' => array( |
||
141 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
142 | ), |
||
143 | 'related-posts' => array( |
||
144 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
145 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
146 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
147 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
148 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
149 | 'outbrain' => 'outbrain/outbrain.php', |
||
150 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
151 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
152 | ), |
||
153 | 'sharedaddy' => array( |
||
154 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
155 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
156 | 'ShareThis' => 'share-this/sharethis.php', |
||
157 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
158 | ), |
||
159 | 'seo-tools' => array( |
||
160 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
161 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
162 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
163 | ), |
||
164 | 'verification-tools' => array( |
||
165 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
166 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
167 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
168 | ), |
||
169 | 'widget-visibility' => array( |
||
170 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
171 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
172 | ), |
||
173 | 'sitemaps' => array( |
||
174 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
175 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
176 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
177 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
178 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
179 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
180 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
181 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
182 | 'Sitemap' => 'sitemap/sitemap.php', |
||
183 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
184 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
185 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
186 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
187 | ), |
||
188 | ); |
||
189 | |||
190 | /** |
||
191 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
192 | * |
||
193 | * Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate |
||
194 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
195 | * |
||
196 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
197 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
198 | */ |
||
199 | private $open_graph_conflicting_plugins = array( |
||
200 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
201 | // 2 Click Social Media Buttons |
||
202 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
203 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
204 | 'autodescription/autodescription.php', // The SEO Framework |
||
205 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
206 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
207 | // Open Graph Meta Tags by Heateor |
||
208 | 'facebook/facebook.php', // Facebook (official plugin) |
||
209 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
210 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
211 | // Facebook Featured Image & OG Meta Tags |
||
212 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
213 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
214 | // Facebook Open Graph Meta Tags for WordPress |
||
215 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
216 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
217 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
218 | // Fedmich's Facebook Open Graph Meta |
||
219 | 'header-footer/plugin.php', // Header and Footer |
||
220 | 'network-publisher/networkpub.php', // Network Publisher |
||
221 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
222 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
223 | // NextScripts SNAP |
||
224 | 'og-tags/og-tags.php', // OG Tags |
||
225 | 'opengraph/opengraph.php', // Open Graph |
||
226 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
227 | // Open Graph Protocol Framework |
||
228 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
229 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
230 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
231 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
232 | 'sharepress/sharepress.php', // SharePress |
||
233 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
234 | 'social-discussions/social-discussions.php', // Social Discussions |
||
235 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
236 | 'socialize/socialize.php', // Socialize |
||
237 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
238 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
239 | // Tweet, Like, Google +1 and Share |
||
240 | 'wordbooker/wordbooker.php', // Wordbooker |
||
241 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
242 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
243 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
244 | // WP Facebook Like Send & Open Graph Meta |
||
245 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
246 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
247 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
248 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
249 | ); |
||
250 | |||
251 | /** |
||
252 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
253 | */ |
||
254 | private $twitter_cards_conflicting_plugins = array( |
||
255 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
256 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
257 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
258 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
259 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
260 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
261 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
262 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
263 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
264 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
265 | ); |
||
266 | |||
267 | /** |
||
268 | * Message to display in admin_notice |
||
269 | * @var string |
||
270 | */ |
||
271 | public $message = ''; |
||
272 | |||
273 | /** |
||
274 | * Error to display in admin_notice |
||
275 | * @var string |
||
276 | */ |
||
277 | public $error = ''; |
||
278 | |||
279 | /** |
||
280 | * Modules that need more privacy description. |
||
281 | * @var string |
||
282 | */ |
||
283 | public $privacy_checks = ''; |
||
284 | |||
285 | /** |
||
286 | * Stats to record once the page loads |
||
287 | * |
||
288 | * @var array |
||
289 | */ |
||
290 | public $stats = array(); |
||
291 | |||
292 | /** |
||
293 | * Jetpack_Sync object |
||
294 | */ |
||
295 | public $sync; |
||
296 | |||
297 | /** |
||
298 | * Verified data for JSON authorization request |
||
299 | */ |
||
300 | public $json_api_authorization_request = array(); |
||
301 | |||
302 | /** |
||
303 | * Holds the singleton instance of this class |
||
304 | * @since 2.3.3 |
||
305 | * @var Jetpack |
||
306 | */ |
||
307 | static $instance = false; |
||
308 | |||
309 | /** |
||
310 | * Singleton |
||
311 | * @static |
||
312 | */ |
||
313 | public static function init() { |
||
314 | if ( ! self::$instance ) { |
||
315 | self::$instance = new Jetpack; |
||
316 | |||
317 | self::$instance->plugin_upgrade(); |
||
318 | } |
||
319 | |||
320 | return self::$instance; |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Must never be called statically |
||
325 | */ |
||
326 | function plugin_upgrade() { |
||
327 | if ( Jetpack::is_active() ) { |
||
328 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
329 | if ( JETPACK__VERSION != $version ) { |
||
330 | |||
331 | // Check which active modules actually exist and remove others from active_modules list |
||
332 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
333 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
334 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
335 | Jetpack::update_active_modules( $modules ); |
||
336 | } |
||
337 | |||
338 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
339 | |||
340 | // Upgrade to 4.3.0 |
||
341 | if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) { |
||
342 | Jetpack_Options::delete_option( 'identity_crisis_whitelist' ); |
||
343 | } |
||
344 | |||
345 | Jetpack::maybe_set_version_option(); |
||
346 | } |
||
347 | } |
||
348 | } |
||
349 | |||
350 | static function activate_manage( ) { |
||
351 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
352 | self::activate_module( 'manage', false, false ); |
||
353 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
354 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
355 | } |
||
356 | } |
||
357 | |||
358 | static function update_active_modules( $modules ) { |
||
359 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
360 | |||
361 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $modules ) ); |
||
362 | |||
363 | if ( is_array( $modules ) && is_array( $current_modules ) ) { |
||
364 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
365 | foreach( $new_active_modules as $module ) { |
||
366 | /** |
||
367 | * Fires when a specific module is activated. |
||
368 | * |
||
369 | * @since 1.9.0 |
||
370 | * |
||
371 | * @param string $module Module slug. |
||
372 | * @param boolean $success whether the module was activated. @since 4.2 |
||
373 | */ |
||
374 | do_action( 'jetpack_activate_module', $module, $success ); |
||
375 | |||
376 | /** |
||
377 | * Fires when a module is activated. |
||
378 | * The dynamic part of the filter, $module, is the module slug. |
||
379 | * |
||
380 | * @since 1.9.0 |
||
381 | * |
||
382 | * @param string $module Module slug. |
||
383 | */ |
||
384 | do_action( "jetpack_activate_module_$module", $module ); |
||
385 | } |
||
386 | |||
387 | $new_deactive_modules = array_diff( $current_modules, $modules ); |
||
388 | foreach( $new_deactive_modules as $module ) { |
||
389 | /** |
||
390 | * Fired after a module has been deactivated. |
||
391 | * |
||
392 | * @since 4.2.0 |
||
393 | * |
||
394 | * @param string $module Module slug. |
||
395 | * @param boolean $success whether the module was deactivated. |
||
396 | */ |
||
397 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
398 | /** |
||
399 | * Fires when a module is deactivated. |
||
400 | * The dynamic part of the filter, $module, is the module slug. |
||
401 | * |
||
402 | * @since 1.9.0 |
||
403 | * |
||
404 | * @param string $module Module slug. |
||
405 | */ |
||
406 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
407 | } |
||
408 | } |
||
409 | |||
410 | return $success; |
||
411 | } |
||
412 | |||
413 | static function delete_active_modules() { |
||
414 | self::update_active_modules( array() ); |
||
415 | } |
||
416 | |||
417 | /** |
||
418 | * Constructor. Initializes WordPress hooks |
||
419 | */ |
||
420 | private function __construct() { |
||
421 | /* |
||
422 | * Check for and alert any deprecated hooks |
||
423 | */ |
||
424 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
425 | |||
426 | |||
427 | /* |
||
428 | * Load things that should only be in Network Admin. |
||
429 | * |
||
430 | * For now blow away everything else until a more full |
||
431 | * understanding of what is needed at the network level is |
||
432 | * available |
||
433 | */ |
||
434 | if( is_multisite() ) { |
||
435 | Jetpack_Network::init(); |
||
436 | } |
||
437 | |||
438 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
439 | |||
440 | // Unlink user before deleting the user from .com |
||
441 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
442 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
443 | |||
444 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
445 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
446 | |||
447 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
448 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
449 | |||
450 | $this->require_jetpack_authentication(); |
||
451 | |||
452 | if ( Jetpack::is_active() ) { |
||
453 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
454 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
455 | |||
456 | $signed = $this->verify_xml_rpc_signature(); |
||
457 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
458 | // The actual API methods. |
||
459 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
460 | } else { |
||
461 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
462 | // active Jetpack connection, so that additional users can link their account. |
||
463 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
464 | } |
||
465 | } else { |
||
466 | // The bootstrap API methods. |
||
467 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
468 | } |
||
469 | |||
470 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
471 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
472 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
473 | $this->require_jetpack_authentication(); |
||
474 | $this->add_remote_request_handlers(); |
||
475 | } else { |
||
476 | if ( Jetpack::is_active() ) { |
||
477 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
478 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
479 | } |
||
480 | } |
||
481 | |||
482 | if ( Jetpack::is_active() ) { |
||
483 | Jetpack_Heartbeat::init(); |
||
484 | } |
||
485 | |||
486 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
487 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
488 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
489 | } |
||
490 | |||
491 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
492 | |||
493 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
494 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
495 | |||
496 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
497 | |||
498 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
499 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
500 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
501 | |||
502 | // returns HTTPS support status |
||
503 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
504 | |||
505 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
506 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
507 | |||
508 | // JITM AJAX callback function |
||
509 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
510 | |||
511 | // Universal ajax callback for all tracking events triggered via js |
||
512 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
513 | |||
514 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
515 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
516 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
517 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
518 | |||
519 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
520 | |||
521 | /** |
||
522 | * These actions run checks to load additional files. |
||
523 | * They check for external files or plugins, so they need to run as late as possible. |
||
524 | */ |
||
525 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
526 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
527 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
528 | |||
529 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
530 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
531 | |||
532 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
533 | |||
534 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
535 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
536 | |||
537 | // A filter to control all just in time messages |
||
538 | add_filter( 'jetpack_just_in_time_msgs', '__return_true' ); |
||
539 | |||
540 | /** |
||
541 | * This is the hack to concatinate all css files into one. |
||
542 | * For description and reasoning see the implode_frontend_css method |
||
543 | * |
||
544 | * Super late priority so we catch all the registered styles |
||
545 | */ |
||
546 | if( !is_admin() ) { |
||
547 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
548 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
549 | } |
||
550 | } |
||
551 | |||
552 | function jetpack_admin_ajax_tracks_callback() { |
||
553 | // Check for nonce |
||
554 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
555 | wp_die( 'Permissions check failed.' ); |
||
556 | } |
||
557 | |||
558 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
559 | wp_die( 'No valid event name or type.' ); |
||
560 | } |
||
561 | |||
562 | $tracks_data = array(); |
||
563 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
564 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
565 | } |
||
566 | |||
567 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
568 | wp_send_json_success(); |
||
569 | wp_die(); |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * The callback for the JITM ajax requests. |
||
574 | */ |
||
575 | function jetpack_jitm_ajax_callback() { |
||
632 | |||
633 | /** |
||
634 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
635 | */ |
||
636 | function __destruct() { |
||
641 | |||
642 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
708 | |||
709 | function require_jetpack_authentication() { |
||
710 | // Don't let anyone authenticate |
||
711 | $_COOKIE = array(); |
||
712 | remove_all_filters( 'authenticate' ); |
||
713 | remove_all_actions( 'wp_login_failed' ); |
||
714 | |||
715 | if ( Jetpack::is_active() ) { |
||
716 | // Allow Jetpack authentication |
||
717 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
718 | } |
||
719 | } |
||
720 | |||
721 | /** |
||
722 | * Load language files |
||
723 | * @action plugins_loaded |
||
724 | */ |
||
725 | public static function plugin_textdomain() { |
||
726 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
727 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
728 | } |
||
729 | |||
730 | /** |
||
731 | * Register assets for use in various modules and the Jetpack admin page. |
||
732 | * |
||
733 | * @uses wp_script_is, wp_register_script, plugins_url |
||
734 | * @action wp_loaded |
||
735 | * @return null |
||
736 | */ |
||
737 | public function register_assets() { |
||
738 | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
||
739 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
740 | } |
||
741 | |||
742 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
743 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
744 | } |
||
745 | |||
746 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
747 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
748 | } |
||
749 | |||
750 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
751 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
752 | } |
||
753 | |||
754 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
755 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
756 | |||
757 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
758 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
759 | if ( ! is_numeric( $fb_app_id ) ) { |
||
760 | $fb_app_id = ''; |
||
761 | } |
||
762 | wp_localize_script( |
||
763 | 'jetpack-facebook-embed', |
||
764 | 'jpfbembed', |
||
765 | array( |
||
766 | 'appid' => $fb_app_id, |
||
767 | 'locale' => $this->get_locale(), |
||
768 | ) |
||
769 | ); |
||
770 | } |
||
771 | |||
772 | /** |
||
773 | * As jetpack_register_genericons is by default fired off a hook, |
||
774 | * the hook may have already fired by this point. |
||
775 | * So, let's just trigger it manually. |
||
776 | */ |
||
777 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
778 | jetpack_register_genericons(); |
||
779 | |||
780 | /** |
||
781 | * Register the social logos |
||
782 | */ |
||
783 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
784 | jetpack_register_social_logos(); |
||
785 | |||
786 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
787 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
788 | } |
||
789 | |||
790 | /** |
||
791 | * Guess locale from language code. |
||
792 | * |
||
793 | * @param string $lang Language code. |
||
794 | * @return string|bool |
||
795 | */ |
||
796 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
797 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
798 | return 'en_US'; |
||
799 | } |
||
800 | |||
801 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
802 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
803 | return false; |
||
804 | } |
||
805 | |||
806 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
807 | } |
||
808 | |||
809 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
810 | // WP.com: get_locale() returns 'it' |
||
811 | $locale = GP_Locales::by_slug( $lang ); |
||
812 | } else { |
||
813 | // Jetpack: get_locale() returns 'it_IT'; |
||
814 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
815 | } |
||
816 | |||
817 | if ( ! $locale ) { |
||
818 | return false; |
||
819 | } |
||
820 | |||
821 | if ( empty( $locale->facebook_locale ) ) { |
||
822 | if ( empty( $locale->wp_locale ) ) { |
||
823 | return false; |
||
824 | } else { |
||
825 | // Facebook SDK is smart enough to fall back to en_US if a |
||
826 | // locale isn't supported. Since supported Facebook locales |
||
827 | // can fall out of sync, we'll attempt to use the known |
||
828 | // wp_locale value and rely on said fallback. |
||
829 | return $locale->wp_locale; |
||
830 | } |
||
831 | } |
||
832 | |||
833 | return $locale->facebook_locale; |
||
834 | } |
||
835 | |||
836 | /** |
||
837 | * Get the locale. |
||
838 | * |
||
839 | * @return string|bool |
||
840 | */ |
||
841 | function get_locale() { |
||
850 | |||
851 | /** |
||
852 | * Device Pixels support |
||
853 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
854 | */ |
||
855 | function devicepx() { |
||
860 | |||
861 | /** |
||
862 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
863 | * @param bool $option |
||
864 | * @return string |
||
865 | */ |
||
866 | public function jetpack_main_network_site_option( $option ) { |
||
869 | /** |
||
870 | * Network Name. |
||
871 | */ |
||
872 | static function network_name( $option = null ) { |
||
876 | /** |
||
877 | * Does the network allow new user and site registrations. |
||
878 | * @return string |
||
879 | */ |
||
880 | static function network_allow_new_registrations( $option = null ) { |
||
883 | /** |
||
884 | * Does the network allow admins to add new users. |
||
885 | * @return boolian |
||
886 | */ |
||
887 | static function network_add_new_users( $option = null ) { |
||
890 | /** |
||
891 | * File upload psace left per site in MB. |
||
892 | * -1 means NO LIMIT. |
||
893 | * @return number |
||
894 | */ |
||
895 | static function network_site_upload_space( $option = null ) { |
||
899 | |||
900 | /** |
||
901 | * Network allowed file types. |
||
902 | * @return string |
||
903 | */ |
||
904 | static function network_upload_file_types( $option = null ) { |
||
907 | |||
908 | /** |
||
909 | * Maximum file upload size set by the network. |
||
910 | * @return number |
||
911 | */ |
||
912 | static function network_max_upload_file_size( $option = null ) { |
||
916 | |||
917 | /** |
||
918 | * Lets us know if a site allows admins to manage the network. |
||
919 | * @return array |
||
920 | */ |
||
921 | static function network_enable_administration_menus( $option = null ) { |
||
924 | |||
925 | /** |
||
926 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
927 | * jetpack_other_linked_admins transient. |
||
928 | * |
||
929 | * @since 4.3.2 |
||
930 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
931 | * |
||
932 | * @param int $user_id The user ID whose role changed. |
||
933 | * @param string $role The new role. |
||
934 | * @param array $old_roles An array of the user's previous roles. |
||
935 | */ |
||
936 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
937 | if ( 'administrator' == $role |
||
938 | || ( is_array( $old_roles ) && in_array( 'administrator', $old_roles ) ) |
||
939 | || is_null( $old_roles ) |
||
940 | ) { |
||
941 | delete_transient( 'jetpack_other_linked_admins' ); |
||
942 | } |
||
943 | } |
||
944 | |||
945 | /** |
||
946 | * Checks to see if there are any other users available to become primary |
||
947 | * Users must both: |
||
948 | * - Be linked to wpcom |
||
949 | * - Be an admin |
||
950 | * |
||
951 | * @return mixed False if no other users are linked, Int if there are. |
||
952 | */ |
||
953 | static function get_other_linked_admins() { |
||
954 | $other_linked_users = get_transient( 'jetpack_other_linked_admins' ); |
||
955 | |||
956 | if ( false === $other_linked_users ) { |
||
957 | $admins = get_users( array( 'role' => 'administrator' ) ); |
||
958 | if ( count( $admins ) > 1 ) { |
||
959 | $available = array(); |
||
960 | foreach ( $admins as $admin ) { |
||
961 | if ( Jetpack::is_user_connected( $admin->ID ) ) { |
||
962 | $available[] = $admin->ID; |
||
963 | } |
||
964 | } |
||
965 | |||
966 | $count_connected_admins = count( $available ); |
||
967 | if ( count( $available ) > 1 ) { |
||
968 | $other_linked_users = $count_connected_admins; |
||
969 | } else { |
||
970 | $other_linked_users = 0; |
||
971 | } |
||
972 | } else { |
||
973 | $other_linked_users = 0; |
||
974 | } |
||
975 | |||
976 | set_transient( 'jetpack_other_linked_admins', $other_linked_users, HOUR_IN_SECONDS ); |
||
977 | } |
||
978 | |||
979 | return ( 0 === $other_linked_users ) ? false : $other_linked_users; |
||
980 | } |
||
981 | |||
982 | /** |
||
983 | * Return whether we are dealing with a multi network setup or not. |
||
984 | * The reason we are type casting this is because we want to avoid the situation where |
||
985 | * the result is false since when is_main_network_option return false it cases |
||
986 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
987 | * database which could be set to anything as opposed to what this function returns. |
||
988 | * @param bool $option |
||
989 | * |
||
990 | * @return boolean |
||
991 | */ |
||
992 | public function is_main_network_option( $option ) { |
||
993 | // return '1' or '' |
||
994 | return (string) (bool) Jetpack::is_multi_network(); |
||
995 | } |
||
996 | |||
997 | /** |
||
998 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
999 | * |
||
1000 | * @param string $option |
||
1001 | * @return boolean |
||
1002 | */ |
||
1003 | public function is_multisite( $option ) { |
||
1004 | return (string) (bool) is_multisite(); |
||
1005 | } |
||
1006 | |||
1007 | /** |
||
1008 | * Implemented since there is no core is multi network function |
||
1009 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
1010 | * |
||
1011 | * @since 3.3 |
||
1012 | * @return boolean |
||
1013 | */ |
||
1014 | public static function is_multi_network() { |
||
1015 | global $wpdb; |
||
1016 | |||
1017 | // if we don't have a multi site setup no need to do any more |
||
1018 | if ( ! is_multisite() ) { |
||
1019 | return false; |
||
1020 | } |
||
1021 | |||
1022 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
1023 | if ( $num_sites > 1 ) { |
||
1024 | return true; |
||
1025 | } else { |
||
1026 | return false; |
||
1027 | } |
||
1028 | } |
||
1029 | |||
1030 | /** |
||
1031 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1032 | * @return null |
||
1033 | */ |
||
1034 | function update_jetpack_main_network_site_option() { |
||
1035 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1036 | } |
||
1037 | /** |
||
1038 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1039 | * |
||
1040 | */ |
||
1041 | function update_jetpack_network_settings() { |
||
1042 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1043 | // Only sync this info for the main network site. |
||
1044 | } |
||
1045 | |||
1046 | /** |
||
1047 | * Get back if the current site is single user site. |
||
1048 | * |
||
1049 | * @return bool |
||
1050 | */ |
||
1051 | public static function is_single_user_site() { |
||
1052 | global $wpdb; |
||
1053 | |||
1054 | View Code Duplication | if ( false === ( $some_users = get_transient( 'jetpack_is_single_user' ) ) ) { |
|
1055 | $some_users = $wpdb->get_var( "SELECT COUNT(*) FROM (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' LIMIT 2) AS someusers" ); |
||
1056 | set_transient( 'jetpack_is_single_user', (int) $some_users, 12 * HOUR_IN_SECONDS ); |
||
1057 | } |
||
1058 | return 1 === (int) $some_users; |
||
1059 | } |
||
1060 | |||
1061 | /** |
||
1062 | * Returns true if the site has file write access false otherwise. |
||
1063 | * @return string ( '1' | '0' ) |
||
1064 | **/ |
||
1065 | public static function file_system_write_access() { |
||
1066 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
||
1067 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
||
1068 | } |
||
1069 | |||
1070 | require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
||
1071 | |||
1072 | $filesystem_method = get_filesystem_method(); |
||
1073 | if ( $filesystem_method === 'direct' ) { |
||
1074 | return 1; |
||
1075 | } |
||
1076 | |||
1077 | ob_start(); |
||
1078 | $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
||
1079 | ob_end_clean(); |
||
1080 | if ( $filesystem_credentials_are_stored ) { |
||
1081 | return 1; |
||
1082 | } |
||
1083 | return 0; |
||
1084 | } |
||
1085 | |||
1086 | /** |
||
1087 | * Finds out if a site is using a version control system. |
||
1088 | * @return string ( '1' | '0' ) |
||
1089 | **/ |
||
1090 | public static function is_version_controlled() { |
||
1091 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); |
||
1092 | return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); |
||
1093 | } |
||
1094 | |||
1095 | /** |
||
1096 | * Determines whether the current theme supports featured images or not. |
||
1097 | * @return string ( '1' | '0' ) |
||
1098 | */ |
||
1099 | public static function featured_images_enabled() { |
||
1100 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1101 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
1102 | } |
||
1103 | |||
1104 | /** |
||
1105 | * jetpack_updates is saved in the following schema: |
||
1106 | * |
||
1107 | * array ( |
||
1108 | * 'plugins' => (int) Number of plugin updates available. |
||
1109 | * 'themes' => (int) Number of theme updates available. |
||
1110 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1111 | * 'translations' => (int) Number of translation updates available. |
||
1112 | * 'total' => (int) Total of all available updates. |
||
1113 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1114 | * ) |
||
1115 | * @return array |
||
1116 | */ |
||
1117 | public static function get_updates() { |
||
1118 | $update_data = wp_get_update_data(); |
||
1119 | |||
1120 | // Stores the individual update counts as well as the total count. |
||
1121 | if ( isset( $update_data['counts'] ) ) { |
||
1122 | $updates = $update_data['counts']; |
||
1123 | } |
||
1124 | |||
1125 | // If we need to update WordPress core, let's find the latest version number. |
||
1126 | View Code Duplication | if ( ! empty( $updates['wordpress'] ) ) { |
|
1127 | $cur = get_preferred_from_update_core(); |
||
1128 | if ( isset( $cur->response ) && 'upgrade' === $cur->response ) { |
||
1129 | $updates['wp_update_version'] = $cur->current; |
||
1130 | } |
||
1131 | } |
||
1132 | return isset( $updates ) ? $updates : array(); |
||
1133 | } |
||
1134 | |||
1135 | public static function get_update_details() { |
||
1136 | $update_details = array( |
||
1137 | 'update_core' => get_site_transient( 'update_core' ), |
||
1138 | 'update_plugins' => get_site_transient( 'update_plugins' ), |
||
1139 | 'update_themes' => get_site_transient( 'update_themes' ), |
||
1140 | ); |
||
1141 | return $update_details; |
||
1142 | } |
||
1143 | |||
1144 | public static function refresh_update_data() { |
||
1145 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1146 | |||
1147 | } |
||
1148 | |||
1149 | public static function refresh_theme_data() { |
||
1150 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1151 | } |
||
1152 | |||
1153 | /** |
||
1154 | * Is Jetpack active? |
||
1155 | */ |
||
1156 | public static function is_active() { |
||
1159 | |||
1160 | /** |
||
1161 | * Get the plan that this Jetpack site is currently using |
||
1162 | * |
||
1163 | * @uses get_transient() |
||
1164 | * @uses set_transient() |
||
1165 | * @uses Jetpack_Options::get_option() |
||
1166 | * @uses Jetpack_Client::wpcom_json_api_request_as_blog() |
||
1167 | * @uses is_wp_error() |
||
1168 | * |
||
1169 | * @access public |
||
1170 | * @static |
||
1171 | * |
||
1172 | * @return array|boolean |
||
1173 | */ |
||
1174 | public static function get_active_plan() { |
||
1175 | // Check cache for stale results |
||
1176 | $plan = get_transient( 'jetpack_active_plan' ); |
||
1177 | |||
1178 | if ( ! $plan ) { |
||
1179 | // Make the API request for site data |
||
1180 | $request = sprintf( '/sites/%d', Jetpack_Options::get_option( 'id' ) ); |
||
1181 | $result = Jetpack_Client::wpcom_json_api_request_as_blog( $request, '1.1' ); |
||
1182 | |||
1183 | // Bail if there is an error |
||
1184 | if ( is_wp_error( $result ) ) { |
||
1185 | return array( 'supports' => array() ); |
||
1186 | } |
||
1187 | |||
1188 | // Decode response and extract the plan data |
||
1189 | $response = json_decode( $result['body'], true ); |
||
1190 | $plan = (array) $response['plan']; |
||
1191 | |||
1192 | // Cache the results for 10 minutes since this makes an API request on each call |
||
1193 | set_transient( 'jetpack_active_plan', $plan, 3600 ); |
||
1194 | } |
||
1195 | |||
1196 | // Add in an array of supported features |
||
1197 | $plan['supports'] = array(); |
||
1198 | |||
1199 | $premium_plans = array( |
||
1200 | 'jetpack_premium', |
||
1201 | 'jetpack_premium_monthly', |
||
1202 | 'jetpack_business', |
||
1203 | 'jetpack_business_monthly', |
||
1204 | ); |
||
1205 | |||
1206 | // If a site has a premium plan, add in supports details. |
||
1207 | if ( in_array( $plan['product_slug'], $premium_plans ) ) { |
||
1208 | $plan['supports'][] = 'videopress'; |
||
1209 | $plan['supports'][] = 'akismet'; |
||
1210 | $plan['supports'][] = 'vaultpress'; |
||
1211 | } |
||
1212 | |||
1213 | return $plan; |
||
1214 | } |
||
1215 | |||
1216 | /** |
||
1217 | * Is Jetpack in development (offline) mode? |
||
1218 | */ |
||
1219 | public static function is_development_mode() { |
||
1220 | $development_mode = false; |
||
1221 | |||
1222 | if ( defined( 'JETPACK_DEV_DEBUG' ) ) { |
||
1223 | $development_mode = JETPACK_DEV_DEBUG; |
||
1224 | } |
||
1225 | |||
1226 | elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
1227 | $development_mode = true; |
||
1228 | } |
||
1229 | /** |
||
1230 | * Filters Jetpack's development mode. |
||
1231 | * |
||
1232 | * @see https://jetpack.com/support/development-mode/ |
||
1233 | * |
||
1234 | * @since 2.2.1 |
||
1235 | * |
||
1236 | * @param bool $development_mode Is Jetpack's development mode active. |
||
1237 | */ |
||
1238 | return apply_filters( 'jetpack_development_mode', $development_mode ); |
||
1239 | } |
||
1240 | |||
1241 | /** |
||
1242 | * Get Jetpack development mode notice text and notice class. |
||
1243 | * |
||
1244 | * Mirrors the checks made in Jetpack::is_development_mode |
||
1245 | * |
||
1246 | */ |
||
1247 | public static function show_development_mode_notice() { |
||
1248 | if ( Jetpack::is_development_mode() ) { |
||
1249 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
1250 | $notice = sprintf( |
||
1251 | /* translators: %s is a URL */ |
||
1252 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), |
||
1253 | 'https://jetpack.com/support/development-mode/' |
||
1254 | ); |
||
1255 | } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
1256 | $notice = sprintf( |
||
1257 | /* translators: %s is a URL */ |
||
1258 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), |
||
1259 | 'https://jetpack.com/support/development-mode/' |
||
1260 | ); |
||
1261 | } else { |
||
1262 | $notice = sprintf( |
||
1263 | /* translators: %s is a URL */ |
||
1264 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), |
||
1265 | 'https://jetpack.com/support/development-mode/' |
||
1266 | ); |
||
1267 | } |
||
1268 | |||
1269 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1270 | } |
||
1271 | |||
1272 | // Throw up a notice if using a development version and as for feedback. |
||
1273 | if ( Jetpack::is_development_version() ) { |
||
1274 | /* translators: %s is a URL */ |
||
1275 | $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.com/contact-support/beta-group/' ); |
||
1276 | |||
1277 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1278 | } |
||
1279 | // Throw up a notice if using staging mode |
||
1280 | if ( Jetpack::is_staging_site() ) { |
||
1281 | /* translators: %s is a URL */ |
||
1282 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); |
||
1283 | |||
1284 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1285 | } |
||
1286 | } |
||
1287 | |||
1288 | /** |
||
1289 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1290 | */ |
||
1291 | public static function is_development_version() { |
||
1292 | /** |
||
1293 | * Allows filtering whether this is a development version of Jetpack. |
||
1294 | * |
||
1295 | * This filter is especially useful for tests. |
||
1296 | * |
||
1297 | * @since 4.3.0 |
||
1298 | * |
||
1299 | * @param bool $development_version Is this a develoment version of Jetpack? |
||
1300 | */ |
||
1301 | return (bool) apply_filters( |
||
1302 | 'jetpack_development_version', |
||
1303 | ! preg_match( '/^\d+(\.\d+)+$/', Jetpack_Constants::get_constant( 'JETPACK__VERSION' ) ) |
||
1304 | ); |
||
1305 | } |
||
1306 | |||
1307 | /** |
||
1308 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1309 | */ |
||
1310 | public static function is_user_connected( $user_id = false ) { |
||
1311 | $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); |
||
1312 | if ( ! $user_id ) { |
||
1313 | return false; |
||
1314 | } |
||
1315 | |||
1316 | return (bool) Jetpack_Data::get_access_token( $user_id ); |
||
1317 | } |
||
1318 | |||
1319 | /** |
||
1320 | * Get the wpcom user data of the current|specified connected user. |
||
1321 | */ |
||
1322 | public static function get_connected_user_data( $user_id = null ) { |
||
1323 | if ( ! $user_id ) { |
||
1324 | $user_id = get_current_user_id(); |
||
1325 | } |
||
1326 | |||
1327 | $transient_key = "jetpack_connected_user_data_$user_id"; |
||
1328 | |||
1329 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
||
1330 | return $cached_user_data; |
||
1331 | } |
||
1332 | |||
1333 | Jetpack::load_xml_rpc_client(); |
||
1334 | $xml = new Jetpack_IXR_Client( array( |
||
1335 | 'user_id' => $user_id, |
||
1336 | ) ); |
||
1337 | $xml->query( 'wpcom.getUser' ); |
||
1338 | if ( ! $xml->isError() ) { |
||
1339 | $user_data = $xml->getResponse(); |
||
1340 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
||
1341 | return $user_data; |
||
1342 | } |
||
1343 | |||
1344 | return false; |
||
1345 | } |
||
1346 | |||
1347 | /** |
||
1348 | * Get the wpcom email of the current|specified connected user. |
||
1349 | */ |
||
1350 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
1351 | if ( ! $user_id ) { |
||
1352 | $user_id = get_current_user_id(); |
||
1353 | } |
||
1354 | Jetpack::load_xml_rpc_client(); |
||
1355 | $xml = new Jetpack_IXR_Client( array( |
||
1356 | 'user_id' => $user_id, |
||
1357 | ) ); |
||
1358 | $xml->query( 'wpcom.getUserEmail' ); |
||
1359 | if ( ! $xml->isError() ) { |
||
1360 | return $xml->getResponse(); |
||
1361 | } |
||
1362 | return false; |
||
1363 | } |
||
1364 | |||
1365 | /** |
||
1366 | * Get the wpcom email of the master user. |
||
1367 | */ |
||
1368 | public static function get_master_user_email() { |
||
1369 | $master_user_id = Jetpack_Options::get_option( 'master_user' ); |
||
1370 | if ( $master_user_id ) { |
||
1371 | return self::get_connected_user_email( $master_user_id ); |
||
1372 | } |
||
1373 | return ''; |
||
1374 | } |
||
1375 | |||
1376 | function current_user_is_connection_owner() { |
||
1377 | $user_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
1378 | return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && get_current_user_id() === $user_token->external_user_id; |
||
1379 | } |
||
1380 | |||
1381 | /** |
||
1382 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
1383 | */ |
||
1384 | function extra_oembed_providers() { |
||
1385 | // Cloudup: https://dev.cloudup.com/#oembed |
||
1386 | wp_oembed_add_provider( 'https://cloudup.com/*' , 'https://cloudup.com/oembed' ); |
||
1387 | wp_oembed_add_provider( 'https://me.sh/*', 'https://me.sh/oembed?format=json' ); |
||
1388 | wp_oembed_add_provider( '#https?://(www\.)?gfycat\.com/.*#i', 'https://api.gfycat.com/v1/oembed', true ); |
||
1389 | wp_oembed_add_provider( '#https?://[^.]+\.(wistia\.com|wi\.st)/(medias|embed)/.*#', 'https://fast.wistia.com/oembed', true ); |
||
1390 | wp_oembed_add_provider( '#https?://sketchfab\.com/.*#i', 'https://sketchfab.com/oembed', true ); |
||
1391 | } |
||
1392 | |||
1393 | /** |
||
1394 | * Synchronize connected user role changes |
||
1395 | */ |
||
1396 | function user_role_change( $user_id ) { |
||
1397 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Users::user_role_change()' ); |
||
1398 | Jetpack_Sync_Users::user_role_change( $user_id ); |
||
1399 | } |
||
1400 | |||
1401 | /** |
||
1402 | * Loads the currently active modules. |
||
1403 | */ |
||
1404 | public static function load_modules() { |
||
1488 | |||
1489 | /** |
||
1490 | * Check if Jetpack's REST API compat file should be included |
||
1491 | * @action plugins_loaded |
||
1492 | * @return null |
||
1493 | */ |
||
1494 | public function check_rest_api_compat() { |
||
1510 | |||
1511 | /** |
||
1512 | * Gets all plugins currently active in values, regardless of whether they're |
||
1513 | * traditionally activated or network activated. |
||
1514 | * |
||
1515 | * @todo Store the result in core's object cache maybe? |
||
1516 | */ |
||
1517 | public static function get_active_plugins() { |
||
1533 | |||
1534 | /** |
||
1535 | * Gets and parses additional plugin data to send with the heartbeat data |
||
1536 | * |
||
1537 | * @since 3.8.1 |
||
1538 | * |
||
1539 | * @return array Array of plugin data |
||
1540 | */ |
||
1541 | public static function get_parsed_plugin_data() { |
||
1542 | if ( ! function_exists( 'get_plugins' ) ) { |
||
1543 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
1544 | } |
||
1545 | /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
||
1546 | $all_plugins = apply_filters( 'all_plugins', get_plugins() ); |
||
1547 | $active_plugins = Jetpack::get_active_plugins(); |
||
1548 | |||
1549 | $plugins = array(); |
||
1550 | foreach ( $all_plugins as $path => $plugin_data ) { |
||
1551 | $plugins[ $path ] = array( |
||
1552 | 'is_active' => in_array( $path, $active_plugins ), |
||
1553 | 'file' => $path, |
||
1554 | 'name' => $plugin_data['Name'], |
||
1555 | 'version' => $plugin_data['Version'], |
||
1556 | 'author' => $plugin_data['Author'], |
||
1557 | ); |
||
1558 | } |
||
1559 | |||
1560 | return $plugins; |
||
1561 | } |
||
1562 | |||
1563 | /** |
||
1564 | * Gets and parses theme data to send with the heartbeat data |
||
1565 | * |
||
1566 | * @since 3.8.1 |
||
1567 | * |
||
1568 | * @return array Array of theme data |
||
1569 | */ |
||
1570 | public static function get_parsed_theme_data() { |
||
1592 | |||
1593 | /** |
||
1594 | * Checks whether a specific plugin is active. |
||
1595 | * |
||
1596 | * We don't want to store these in a static variable, in case |
||
1597 | * there are switch_to_blog() calls involved. |
||
1598 | */ |
||
1599 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
1602 | |||
1603 | /** |
||
1604 | * Check if Jetpack's Open Graph tags should be used. |
||
1605 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
1606 | * |
||
1607 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
1608 | * @action plugins_loaded |
||
1609 | * @return null |
||
1610 | */ |
||
1611 | public function check_open_graph() { |
||
1638 | |||
1639 | /** |
||
1640 | * Check if Jetpack's Twitter tags should be used. |
||
1641 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
1642 | * |
||
1643 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
1644 | * @action plugins_loaded |
||
1645 | * @return null |
||
1646 | */ |
||
1647 | public function check_twitter_tags() { |
||
1671 | |||
1672 | /** |
||
1673 | * Allows plugins to submit security reports. |
||
1674 | * |
||
1675 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
1676 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
1677 | * @param array $args See definitions above |
||
1678 | */ |
||
1679 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
1680 | _deprecated_function( __FUNCTION__, 'jetpack-4.2', null ); |
||
1681 | } |
||
1682 | |||
1683 | /* Jetpack Options API */ |
||
1684 | |||
1685 | public static function get_option_names( $type = 'compact' ) { |
||
1686 | return Jetpack_Options::get_option_names( $type ); |
||
1687 | } |
||
1688 | |||
1689 | /** |
||
1690 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
1691 | * |
||
1692 | * @param string $name Option name |
||
1693 | * @param mixed $default (optional) |
||
1694 | */ |
||
1695 | public static function get_option( $name, $default = false ) { |
||
1696 | return Jetpack_Options::get_option( $name, $default ); |
||
1697 | } |
||
1698 | |||
1699 | /** |
||
1700 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
1701 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
1702 | * $name must be a registered option name. |
||
1703 | */ |
||
1704 | public static function create_nonce( $name ) { |
||
1705 | $secret = wp_generate_password( 32, false ) . ':' . wp_generate_password( 32, false ) . ':' . ( time() + 600 ); |
||
1706 | |||
1707 | Jetpack_Options::update_option( $name, $secret ); |
||
1708 | @list( $secret_1, $secret_2, $eol ) = explode( ':', Jetpack_Options::get_option( $name ) ); |
||
1709 | if ( empty( $secret_1 ) || empty( $secret_2 ) || $eol < time() ) |
||
1710 | return new Jetpack_Error( 'missing_secrets' ); |
||
1711 | |||
1712 | return array( |
||
1713 | 'secret_1' => $secret_1, |
||
1714 | 'secret_2' => $secret_2, |
||
1715 | 'eol' => $eol, |
||
1716 | ); |
||
1717 | } |
||
1718 | |||
1719 | /** |
||
1720 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
1721 | * |
||
1722 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
1723 | * @param string $name Option name |
||
1724 | * @param mixed $value Option value |
||
1725 | */ |
||
1726 | public static function update_option( $name, $value ) { |
||
1727 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::update_option()' ); |
||
1728 | return Jetpack_Options::update_option( $name, $value ); |
||
1729 | } |
||
1730 | |||
1731 | /** |
||
1732 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
1733 | * |
||
1734 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
1735 | * @param array $array array( option name => option value, ... ) |
||
1736 | */ |
||
1737 | public static function update_options( $array ) { |
||
1738 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::update_options()' ); |
||
1739 | return Jetpack_Options::update_options( $array ); |
||
1740 | } |
||
1741 | |||
1742 | /** |
||
1743 | * Deletes the given option. May be passed multiple option names as an array. |
||
1744 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
1745 | * |
||
1746 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
1747 | * @param string|array $names |
||
1748 | */ |
||
1749 | public static function delete_option( $names ) { |
||
1750 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::delete_option()' ); |
||
1751 | return Jetpack_Options::delete_option( $names ); |
||
1752 | } |
||
1753 | |||
1754 | /** |
||
1755 | * Enters a user token into the user_tokens option |
||
1756 | * |
||
1757 | * @param int $user_id |
||
1758 | * @param string $token |
||
1759 | * return bool |
||
1760 | */ |
||
1761 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
1762 | // not designed for concurrent updates |
||
1763 | $user_tokens = Jetpack_Options::get_option( 'user_tokens' ); |
||
1764 | if ( ! is_array( $user_tokens ) ) |
||
1765 | $user_tokens = array(); |
||
1766 | $user_tokens[$user_id] = $token; |
||
1767 | if ( $is_master_user ) { |
||
1768 | $master_user = $user_id; |
||
1769 | $options = compact( 'user_tokens', 'master_user' ); |
||
1770 | } else { |
||
1771 | $options = compact( 'user_tokens' ); |
||
1772 | } |
||
1773 | return Jetpack_Options::update_options( $options ); |
||
1774 | } |
||
1775 | |||
1776 | /** |
||
1777 | * Returns an array of all PHP files in the specified absolute path. |
||
1778 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
1779 | * |
||
1780 | * @param string $absolute_path The absolute path of the directory to search. |
||
1781 | * @return array Array of absolute paths to the PHP files. |
||
1782 | */ |
||
1783 | public static function glob_php( $absolute_path ) { |
||
1784 | if ( function_exists( 'glob' ) ) { |
||
1785 | return glob( "$absolute_path/*.php" ); |
||
1786 | } |
||
1787 | |||
1788 | $absolute_path = untrailingslashit( $absolute_path ); |
||
1789 | $files = array(); |
||
1790 | if ( ! $dir = @opendir( $absolute_path ) ) { |
||
1791 | return $files; |
||
1792 | } |
||
1793 | |||
1794 | while ( false !== $file = readdir( $dir ) ) { |
||
1795 | if ( '.' == substr( $file, 0, 1 ) || '.php' != substr( $file, -4 ) ) { |
||
1796 | continue; |
||
1797 | } |
||
1798 | |||
1799 | $file = "$absolute_path/$file"; |
||
1800 | |||
1801 | if ( ! is_file( $file ) ) { |
||
1802 | continue; |
||
1803 | } |
||
1804 | |||
1805 | $files[] = $file; |
||
1806 | } |
||
1807 | |||
1808 | closedir( $dir ); |
||
1809 | |||
1810 | return $files; |
||
1811 | } |
||
1812 | |||
1813 | public static function activate_new_modules( $redirect = false ) { |
||
1814 | if ( ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) { |
||
1815 | return; |
||
1816 | } |
||
1817 | |||
1818 | $jetpack_old_version = Jetpack_Options::get_option( 'version' ); // [sic] |
||
1819 | View Code Duplication | if ( ! $jetpack_old_version ) { |
|
1820 | $jetpack_old_version = $version = $old_version = '1.1:' . time(); |
||
1821 | /** This action is documented in class.jetpack.php */ |
||
1822 | do_action( 'updating_jetpack_version', $version, false ); |
||
1823 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
1824 | } |
||
1825 | |||
1826 | list( $jetpack_version ) = explode( ':', $jetpack_old_version ); // [sic] |
||
1827 | |||
1828 | if ( version_compare( JETPACK__VERSION, $jetpack_version, '<=' ) ) { |
||
1829 | return; |
||
1830 | } |
||
1831 | |||
1832 | $active_modules = Jetpack::get_active_modules(); |
||
1833 | $reactivate_modules = array(); |
||
1834 | foreach ( $active_modules as $active_module ) { |
||
1835 | $module = Jetpack::get_module( $active_module ); |
||
1836 | if ( ! isset( $module['changed'] ) ) { |
||
1837 | continue; |
||
1838 | } |
||
1839 | |||
1840 | if ( version_compare( $module['changed'], $jetpack_version, '<=' ) ) { |
||
1841 | continue; |
||
1842 | } |
||
1843 | |||
1844 | $reactivate_modules[] = $active_module; |
||
1845 | Jetpack::deactivate_module( $active_module ); |
||
1846 | } |
||
1847 | |||
1848 | $new_version = JETPACK__VERSION . ':' . time(); |
||
1849 | /** This action is documented in class.jetpack.php */ |
||
1850 | do_action( 'updating_jetpack_version', $new_version, $jetpack_old_version ); |
||
1851 | Jetpack_Options::update_options( |
||
1852 | array( |
||
1853 | 'version' => $new_version, |
||
1854 | 'old_version' => $jetpack_old_version, |
||
1855 | ) |
||
1856 | ); |
||
1857 | |||
1858 | Jetpack::state( 'message', 'modules_activated' ); |
||
1859 | Jetpack::activate_default_modules( $jetpack_version, JETPACK__VERSION, $reactivate_modules ); |
||
1860 | |||
1861 | if ( $redirect ) { |
||
1862 | $page = 'jetpack'; // make sure we redirect to either settings or the jetpack page |
||
1863 | if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'jetpack', 'jetpack_modules' ) ) ) { |
||
1864 | $page = $_GET['page']; |
||
1865 | } |
||
1866 | |||
1867 | wp_safe_redirect( Jetpack::admin_url( 'page=' . $page ) ); |
||
1868 | exit; |
||
1869 | } |
||
1870 | } |
||
1871 | |||
1872 | /** |
||
1873 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
1874 | * Make sure to tuck away module "library" files in a sub-directory. |
||
1875 | */ |
||
1876 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
1877 | static $modules = null; |
||
1878 | |||
1879 | if ( ! isset( $modules ) ) { |
||
1880 | $available_modules_option = Jetpack_Options::get_option( 'available_modules', array() ); |
||
1881 | // Use the cache if we're on the front-end and it's available... |
||
1882 | if ( ! is_admin() && ! empty( $available_modules_option[ JETPACK__VERSION ] ) ) { |
||
1883 | $modules = $available_modules_option[ JETPACK__VERSION ]; |
||
1884 | } else { |
||
1885 | $files = Jetpack::glob_php( JETPACK__PLUGIN_DIR . 'modules' ); |
||
1886 | |||
1887 | $modules = array(); |
||
1888 | |||
1889 | foreach ( $files as $file ) { |
||
1890 | if ( ! $headers = Jetpack::get_module( $file ) ) { |
||
1891 | continue; |
||
1892 | } |
||
1893 | |||
1894 | $modules[ Jetpack::get_module_slug( $file ) ] = $headers['introduced']; |
||
1895 | } |
||
1896 | |||
1897 | Jetpack_Options::update_option( 'available_modules', array( |
||
1898 | JETPACK__VERSION => $modules, |
||
1899 | ) ); |
||
1900 | } |
||
1901 | } |
||
1902 | |||
1903 | /** |
||
1904 | * Filters the array of modules available to be activated. |
||
1905 | * |
||
1906 | * @since 2.4.0 |
||
1907 | * |
||
1908 | * @param array $modules Array of available modules. |
||
1909 | * @param string $min_version Minimum version number required to use modules. |
||
1910 | * @param string $max_version Maximum version number required to use modules. |
||
1911 | */ |
||
1912 | $mods = apply_filters( 'jetpack_get_available_modules', $modules, $min_version, $max_version ); |
||
1913 | |||
1914 | if ( ! $min_version && ! $max_version ) { |
||
1915 | return array_keys( $mods ); |
||
1916 | } |
||
1917 | |||
1918 | $r = array(); |
||
1919 | foreach ( $mods as $slug => $introduced ) { |
||
1920 | if ( $min_version && version_compare( $min_version, $introduced, '>=' ) ) { |
||
1921 | continue; |
||
1922 | } |
||
1923 | |||
1924 | if ( $max_version && version_compare( $max_version, $introduced, '<' ) ) { |
||
1925 | continue; |
||
1926 | } |
||
1927 | |||
1928 | $r[] = $slug; |
||
1929 | } |
||
1930 | |||
1931 | return $r; |
||
1932 | } |
||
1933 | |||
1934 | /** |
||
1935 | * Default modules loaded on activation. |
||
1936 | */ |
||
1937 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
1938 | $return = array(); |
||
1939 | |||
1940 | foreach ( Jetpack::get_available_modules( $min_version, $max_version ) as $module ) { |
||
1941 | $module_data = Jetpack::get_module( $module ); |
||
1942 | |||
1943 | switch ( strtolower( $module_data['auto_activate'] ) ) { |
||
1944 | case 'yes' : |
||
1945 | $return[] = $module; |
||
1946 | break; |
||
1947 | case 'public' : |
||
1948 | if ( Jetpack_Options::get_option( 'public' ) ) { |
||
1949 | $return[] = $module; |
||
1950 | } |
||
1951 | break; |
||
1952 | case 'no' : |
||
1953 | default : |
||
1954 | break; |
||
1955 | } |
||
1956 | } |
||
1957 | /** |
||
1958 | * Filters the array of default modules. |
||
1959 | * |
||
1960 | * @since 2.5.0 |
||
1961 | * |
||
1962 | * @param array $return Array of default modules. |
||
1963 | * @param string $min_version Minimum version number required to use modules. |
||
1964 | * @param string $max_version Maximum version number required to use modules. |
||
1965 | */ |
||
1966 | return apply_filters( 'jetpack_get_default_modules', $return, $min_version, $max_version ); |
||
1967 | } |
||
1968 | |||
1969 | /** |
||
1970 | * Checks activated modules during auto-activation to determine |
||
1971 | * if any of those modules are being deprecated. If so, close |
||
1972 | * them out, and add any replacement modules. |
||
1973 | * |
||
1974 | * Runs at priority 99 by default. |
||
1975 | * |
||
1976 | * This is run late, so that it can still activate a module if |
||
1977 | * the new module is a replacement for another that the user |
||
1978 | * currently has active, even if something at the normal priority |
||
1979 | * would kibosh everything. |
||
1980 | * |
||
1981 | * @since 2.6 |
||
1982 | * @uses jetpack_get_default_modules filter |
||
1983 | * @param array $modules |
||
1984 | * @return array |
||
1985 | */ |
||
1986 | function handle_deprecated_modules( $modules ) { |
||
1987 | $deprecated_modules = array( |
||
1988 | 'debug' => null, // Closed out and moved to ./class.jetpack-debugger.php |
||
1989 | 'wpcc' => 'sso', // Closed out in 2.6 -- SSO provides the same functionality. |
||
1990 | 'gplus-authorship' => null, // Closed out in 3.2 -- Google dropped support. |
||
1991 | ); |
||
1992 | |||
1993 | // Don't activate SSO if they never completed activating WPCC. |
||
1994 | if ( Jetpack::is_module_active( 'wpcc' ) ) { |
||
1995 | $wpcc_options = Jetpack_Options::get_option( 'wpcc_options' ); |
||
1996 | if ( empty( $wpcc_options ) || empty( $wpcc_options['client_id'] ) || empty( $wpcc_options['client_id'] ) ) { |
||
1997 | $deprecated_modules['wpcc'] = null; |
||
1998 | } |
||
1999 | } |
||
2000 | |||
2001 | foreach ( $deprecated_modules as $module => $replacement ) { |
||
2002 | if ( Jetpack::is_module_active( $module ) ) { |
||
2003 | self::deactivate_module( $module ); |
||
2004 | if ( $replacement ) { |
||
2005 | $modules[] = $replacement; |
||
2006 | } |
||
2007 | } |
||
2008 | } |
||
2009 | |||
2010 | return array_unique( $modules ); |
||
2011 | } |
||
2012 | |||
2013 | /** |
||
2014 | * Checks activated plugins during auto-activation to determine |
||
2015 | * if any of those plugins are in the list with a corresponding module |
||
2016 | * that is not compatible with the plugin. The module will not be allowed |
||
2017 | * to auto-activate. |
||
2018 | * |
||
2019 | * @since 2.6 |
||
2020 | * @uses jetpack_get_default_modules filter |
||
2021 | * @param array $modules |
||
2022 | * @return array |
||
2023 | */ |
||
2024 | function filter_default_modules( $modules ) { |
||
2025 | |||
2026 | $active_plugins = self::get_active_plugins(); |
||
2027 | |||
2028 | if ( ! empty( $active_plugins ) ) { |
||
2029 | |||
2030 | // For each module we'd like to auto-activate... |
||
2031 | foreach ( $modules as $key => $module ) { |
||
2032 | // If there are potential conflicts for it... |
||
2033 | if ( ! empty( $this->conflicting_plugins[ $module ] ) ) { |
||
2034 | // For each potential conflict... |
||
2035 | foreach ( $this->conflicting_plugins[ $module ] as $title => $plugin ) { |
||
2036 | // If that conflicting plugin is active... |
||
2037 | if ( in_array( $plugin, $active_plugins ) ) { |
||
2038 | // Remove that item from being auto-activated. |
||
2039 | unset( $modules[ $key ] ); |
||
2040 | } |
||
2041 | } |
||
2042 | } |
||
2043 | } |
||
2044 | } |
||
2045 | |||
2046 | return $modules; |
||
2047 | } |
||
2048 | |||
2049 | /** |
||
2050 | * Extract a module's slug from its full path. |
||
2051 | */ |
||
2052 | public static function get_module_slug( $file ) { |
||
2053 | return str_replace( '.php', '', basename( $file ) ); |
||
2054 | } |
||
2055 | |||
2056 | /** |
||
2057 | * Generate a module's path from its slug. |
||
2058 | */ |
||
2059 | public static function get_module_path( $slug ) { |
||
2060 | return JETPACK__PLUGIN_DIR . "modules/$slug.php"; |
||
2061 | } |
||
2062 | |||
2063 | /** |
||
2064 | * Load module data from module file. Headers differ from WordPress |
||
2065 | * plugin headers to avoid them being identified as standalone |
||
2066 | * plugins on the WordPress plugins page. |
||
2067 | */ |
||
2068 | public static function get_module( $module ) { |
||
2069 | $headers = array( |
||
2070 | 'name' => 'Module Name', |
||
2071 | 'description' => 'Module Description', |
||
2072 | 'jumpstart_desc' => 'Jumpstart Description', |
||
2073 | 'sort' => 'Sort Order', |
||
2074 | 'recommendation_order' => 'Recommendation Order', |
||
2075 | 'introduced' => 'First Introduced', |
||
2076 | 'changed' => 'Major Changes In', |
||
2077 | 'deactivate' => 'Deactivate', |
||
2078 | 'free' => 'Free', |
||
2079 | 'requires_connection' => 'Requires Connection', |
||
2080 | 'auto_activate' => 'Auto Activate', |
||
2081 | 'module_tags' => 'Module Tags', |
||
2082 | 'feature' => 'Feature', |
||
2083 | 'additional_search_queries' => 'Additional Search Queries', |
||
2084 | ); |
||
2085 | |||
2086 | $file = Jetpack::get_module_path( Jetpack::get_module_slug( $module ) ); |
||
2087 | |||
2088 | $mod = Jetpack::get_file_data( $file, $headers ); |
||
2089 | if ( empty( $mod['name'] ) ) { |
||
2090 | return false; |
||
2091 | } |
||
2092 | |||
2093 | $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort']; |
||
2094 | $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order']; |
||
2095 | $mod['deactivate'] = empty( $mod['deactivate'] ); |
||
2096 | $mod['free'] = empty( $mod['free'] ); |
||
2097 | $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' == $mod['requires_connection'] ) ? false : true; |
||
2098 | |||
2099 | if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ) ) ) { |
||
2100 | $mod['auto_activate'] = 'No'; |
||
2101 | } else { |
||
2102 | $mod['auto_activate'] = (string) $mod['auto_activate']; |
||
2103 | } |
||
2104 | |||
2105 | if ( $mod['module_tags'] ) { |
||
2106 | $mod['module_tags'] = explode( ',', $mod['module_tags'] ); |
||
2107 | $mod['module_tags'] = array_map( 'trim', $mod['module_tags'] ); |
||
2108 | $mod['module_tags'] = array_map( array( __CLASS__, 'translate_module_tag' ), $mod['module_tags'] ); |
||
2109 | } else { |
||
2110 | $mod['module_tags'] = array( self::translate_module_tag( 'Other' ) ); |
||
2111 | } |
||
2112 | |||
2113 | if ( $mod['feature'] ) { |
||
2114 | $mod['feature'] = explode( ',', $mod['feature'] ); |
||
2115 | $mod['feature'] = array_map( 'trim', $mod['feature'] ); |
||
2116 | } else { |
||
2117 | $mod['feature'] = array( self::translate_module_tag( 'Other' ) ); |
||
2118 | } |
||
2119 | |||
2120 | /** |
||
2121 | * Filters the feature array on a module. |
||
2122 | * |
||
2123 | * This filter allows you to control where each module is filtered: Recommended, |
||
2124 | * Jumpstart, and the default "Other" listing. |
||
2125 | * |
||
2126 | * @since 3.5.0 |
||
2127 | * |
||
2128 | * @param array $mod['feature'] The areas to feature this module: |
||
2129 | * 'Jumpstart' adds to the "Jumpstart" option to activate many modules at once. |
||
2130 | * 'Recommended' shows on the main Jetpack admin screen. |
||
2131 | * 'Other' should be the default if no other value is in the array. |
||
2132 | * @param string $module The slug of the module, e.g. sharedaddy. |
||
2133 | * @param array $mod All the currently assembled module data. |
||
2134 | */ |
||
2135 | $mod['feature'] = apply_filters( 'jetpack_module_feature', $mod['feature'], $module, $mod ); |
||
2136 | |||
2137 | /** |
||
2138 | * Filter the returned data about a module. |
||
2139 | * |
||
2140 | * This filter allows overriding any info about Jetpack modules. It is dangerous, |
||
2141 | * so please be careful. |
||
2142 | * |
||
2143 | * @since 3.6.0 |
||
2144 | * |
||
2145 | * @param array $mod The details of the requested module. |
||
2146 | * @param string $module The slug of the module, e.g. sharedaddy |
||
2147 | * @param string $file The path to the module source file. |
||
2148 | */ |
||
2149 | return apply_filters( 'jetpack_get_module', $mod, $module, $file ); |
||
2150 | } |
||
2151 | |||
2152 | /** |
||
2153 | * Like core's get_file_data implementation, but caches the result. |
||
2154 | */ |
||
2155 | public static function get_file_data( $file, $headers ) { |
||
2156 | //Get just the filename from $file (i.e. exclude full path) so that a consistent hash is generated |
||
2157 | $file_name = basename( $file ); |
||
2158 | $file_data_option = Jetpack_Options::get_option( 'file_data', array() ); |
||
2159 | $key = md5( $file_name . serialize( $headers ) ); |
||
2160 | $refresh_cache = is_admin() && isset( $_GET['page'] ) && 'jetpack' === substr( $_GET['page'], 0, 7 ); |
||
2161 | |||
2162 | // If we don't need to refresh the cache, and already have the value, short-circuit! |
||
2163 | if ( ! $refresh_cache && isset( $file_data_option[ JETPACK__VERSION ][ $key ] ) ) { |
||
2164 | return $file_data_option[ JETPACK__VERSION ][ $key ]; |
||
2165 | } |
||
2166 | |||
2167 | $data = get_file_data( $file, $headers ); |
||
2168 | |||
2169 | // Strip out any old Jetpack versions that are cluttering the option. |
||
2170 | $file_data_option = array_intersect_key( (array) $file_data_option, array( JETPACK__VERSION => null ) ); |
||
2171 | $file_data_option[ JETPACK__VERSION ][ $key ] = $data; |
||
2172 | Jetpack_Options::update_option( 'file_data', $file_data_option ); |
||
2173 | |||
2174 | return $data; |
||
2175 | } |
||
2176 | |||
2177 | /** |
||
2178 | * Return translated module tag. |
||
2179 | * |
||
2180 | * @param string $tag Tag as it appears in each module heading. |
||
2181 | * |
||
2182 | * @return mixed |
||
2183 | */ |
||
2184 | public static function translate_module_tag( $tag ) { |
||
2185 | return jetpack_get_module_i18n_tag( $tag ); |
||
2186 | } |
||
2187 | |||
2188 | /** |
||
2189 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2190 | * |
||
2191 | * @since 3.9.2 |
||
2192 | * |
||
2193 | * @param array $modules |
||
2194 | * |
||
2195 | * @return string|void |
||
2196 | */ |
||
2197 | public static function get_translated_modules( $modules ) { |
||
2198 | foreach ( $modules as $index => $module ) { |
||
2199 | $i18n_module = jetpack_get_module_i18n( $module['module'] ); |
||
2200 | if ( isset( $module['name'] ) ) { |
||
2201 | $modules[ $index ]['name'] = $i18n_module['name']; |
||
2202 | } |
||
2203 | if ( isset( $module['description'] ) ) { |
||
2204 | $modules[ $index ]['description'] = $i18n_module['description']; |
||
2205 | $modules[ $index ]['short_description'] = $i18n_module['description']; |
||
2206 | } |
||
2207 | } |
||
2208 | return $modules; |
||
2209 | } |
||
2210 | |||
2211 | /** |
||
2212 | * Get a list of activated modules as an array of module slugs. |
||
2213 | */ |
||
2214 | public static function get_active_modules() { |
||
2215 | $active = Jetpack_Options::get_option( 'active_modules' ); |
||
2216 | |||
2217 | if ( ! is_array( $active ) ) { |
||
2218 | $active = array(); |
||
2219 | } |
||
2220 | |||
2221 | if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) { |
||
2222 | $active[] = 'vaultpress'; |
||
2223 | } else { |
||
2224 | $active = array_diff( $active, array( 'vaultpress' ) ); |
||
2225 | } |
||
2226 | |||
2227 | // Get the current site plan |
||
2228 | $plan = Jetpack::get_active_plan(); |
||
2229 | |||
2230 | // If this plan supports videopress, force activate module |
||
2231 | if ( in_array( 'videopress', $plan['supports'] ) ) { |
||
2232 | $active[] = 'videopress'; |
||
2233 | } else { |
||
2234 | $active = array_diff( $active, array( 'videopress' ) ); |
||
2235 | } |
||
2236 | |||
2237 | //If protect is active on the main site of a multisite, it should be active on all sites. |
||
2238 | if ( ! in_array( 'protect', $active ) && is_multisite() && get_site_option( 'jetpack_protect_active' ) ) { |
||
2239 | $active[] = 'protect'; |
||
2240 | } |
||
2241 | |||
2242 | return array_unique( $active ); |
||
2243 | } |
||
2244 | |||
2245 | /** |
||
2246 | * Check whether or not a Jetpack module is active. |
||
2247 | * |
||
2248 | * @param string $module The slug of a Jetpack module. |
||
2249 | * @return bool |
||
2250 | * |
||
2251 | * @static |
||
2252 | */ |
||
2253 | public static function is_module_active( $module ) { |
||
2254 | return in_array( $module, self::get_active_modules() ); |
||
2255 | } |
||
2256 | |||
2257 | public static function is_module( $module ) { |
||
2258 | return ! empty( $module ) && ! validate_file( $module, Jetpack::get_available_modules() ); |
||
2259 | } |
||
2260 | |||
2261 | /** |
||
2262 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2263 | * |
||
2264 | * @param bool $catch True to start catching, False to stop. |
||
2265 | * |
||
2266 | * @static |
||
2267 | */ |
||
2268 | public static function catch_errors( $catch ) { |
||
2269 | static $display_errors, $error_reporting; |
||
2270 | |||
2271 | if ( $catch ) { |
||
2272 | $display_errors = @ini_set( 'display_errors', 1 ); |
||
2273 | $error_reporting = @error_reporting( E_ALL ); |
||
2274 | add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
2275 | } else { |
||
2276 | @ini_set( 'display_errors', $display_errors ); |
||
2277 | @error_reporting( $error_reporting ); |
||
2278 | remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
2279 | } |
||
2280 | } |
||
2281 | |||
2282 | /** |
||
2283 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2284 | */ |
||
2285 | public static function catch_errors_on_shutdown() { |
||
2286 | Jetpack::state( 'php_errors', ob_get_clean() ); |
||
2287 | } |
||
2288 | |||
2289 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
2290 | $jetpack = Jetpack::init(); |
||
2291 | |||
2292 | $modules = Jetpack::get_default_modules( $min_version, $max_version ); |
||
2293 | $modules = array_merge( $other_modules, $modules ); |
||
2294 | |||
2295 | // Look for standalone plugins and disable if active. |
||
2296 | |||
2297 | $to_deactivate = array(); |
||
2298 | foreach ( $modules as $module ) { |
||
2299 | if ( isset( $jetpack->plugins_to_deactivate[$module] ) ) { |
||
2300 | $to_deactivate[$module] = $jetpack->plugins_to_deactivate[$module]; |
||
2301 | } |
||
2302 | } |
||
2303 | |||
2304 | $deactivated = array(); |
||
2305 | foreach ( $to_deactivate as $module => $deactivate_me ) { |
||
2306 | list( $probable_file, $probable_title ) = $deactivate_me; |
||
2307 | if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) { |
||
2308 | $deactivated[] = $module; |
||
2309 | } |
||
2310 | } |
||
2311 | |||
2312 | if ( $deactivated && $redirect ) { |
||
2313 | Jetpack::state( 'deactivated_plugins', join( ',', $deactivated ) ); |
||
2314 | |||
2315 | $url = add_query_arg( |
||
2316 | array( |
||
2317 | 'action' => 'activate_default_modules', |
||
2318 | '_wpnonce' => wp_create_nonce( 'activate_default_modules' ), |
||
2319 | ), |
||
2320 | add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), Jetpack::admin_url( 'page=jetpack' ) ) |
||
2321 | ); |
||
2322 | wp_safe_redirect( $url ); |
||
2323 | exit; |
||
2324 | } |
||
2325 | |||
2326 | /** |
||
2327 | * Fires before default modules are activated. |
||
2328 | * |
||
2329 | * @since 1.9.0 |
||
2330 | * |
||
2331 | * @param string $min_version Minimum version number required to use modules. |
||
2332 | * @param string $max_version Maximum version number required to use modules. |
||
2333 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
2334 | */ |
||
2335 | do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
2336 | |||
2337 | // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating |
||
2338 | Jetpack::restate(); |
||
2339 | Jetpack::catch_errors( true ); |
||
2340 | |||
2341 | $active = Jetpack::get_active_modules(); |
||
2342 | |||
2343 | foreach ( $modules as $module ) { |
||
2344 | if ( did_action( "jetpack_module_loaded_$module" ) ) { |
||
2345 | $active[] = $module; |
||
2346 | self::update_active_modules( $active ); |
||
2347 | continue; |
||
2348 | } |
||
2349 | |||
2350 | if ( in_array( $module, $active ) ) { |
||
2351 | $module_info = Jetpack::get_module( $module ); |
||
2352 | if ( ! $module_info['deactivate'] ) { |
||
2353 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
2354 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
2355 | $active_state = explode( ',', $active_state ); |
||
2356 | } else { |
||
2357 | $active_state = array(); |
||
2358 | } |
||
2359 | $active_state[] = $module; |
||
2360 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
2361 | } |
||
2362 | continue; |
||
2363 | } |
||
2364 | |||
2365 | $file = Jetpack::get_module_path( $module ); |
||
2366 | if ( ! file_exists( $file ) ) { |
||
2367 | continue; |
||
2368 | } |
||
2369 | |||
2370 | // we'll override this later if the plugin can be included without fatal error |
||
2371 | if ( $redirect ) { |
||
2372 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
2373 | } |
||
2374 | Jetpack::state( 'error', 'module_activation_failed' ); |
||
2375 | Jetpack::state( 'module', $module ); |
||
2376 | ob_start(); |
||
2377 | require $file; |
||
2378 | |||
2379 | $active[] = $module; |
||
2380 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
2381 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
2382 | $active_state = explode( ',', $active_state ); |
||
2383 | } else { |
||
2384 | $active_state = array(); |
||
2385 | } |
||
2386 | $active_state[] = $module; |
||
2387 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
2388 | Jetpack::update_active_modules( $active ); |
||
2389 | |||
2390 | ob_end_clean(); |
||
2391 | } |
||
2392 | Jetpack::state( 'error', false ); |
||
2393 | Jetpack::state( 'module', false ); |
||
2394 | Jetpack::catch_errors( false ); |
||
2395 | /** |
||
2396 | * Fires when default modules are activated. |
||
2397 | * |
||
2398 | * @since 1.9.0 |
||
2399 | * |
||
2400 | * @param string $min_version Minimum version number required to use modules. |
||
2401 | * @param string $max_version Maximum version number required to use modules. |
||
2402 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
2403 | */ |
||
2404 | do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
2405 | } |
||
2406 | |||
2407 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
2408 | /** |
||
2409 | * Fires before a module is activated. |
||
2410 | * |
||
2411 | * @since 2.6.0 |
||
2412 | * |
||
2413 | * @param string $module Module slug. |
||
2414 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
2415 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
2416 | */ |
||
2417 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
2418 | |||
2419 | $jetpack = Jetpack::init(); |
||
2420 | |||
2421 | if ( ! strlen( $module ) ) |
||
2422 | return false; |
||
2423 | |||
2424 | if ( ! Jetpack::is_module( $module ) ) |
||
2425 | return false; |
||
2426 | |||
2427 | // If it's already active, then don't do it again |
||
2428 | $active = Jetpack::get_active_modules(); |
||
2429 | foreach ( $active as $act ) { |
||
2430 | if ( $act == $module ) |
||
2431 | return true; |
||
2432 | } |
||
2433 | |||
2434 | $module_data = Jetpack::get_module( $module ); |
||
2435 | |||
2436 | if ( ! Jetpack::is_active() ) { |
||
2437 | if ( !Jetpack::is_development_mode() ) |
||
2438 | return false; |
||
2439 | |||
2440 | // If we're not connected but in development mode, make sure the module doesn't require a connection |
||
2441 | if ( Jetpack::is_development_mode() && $module_data['requires_connection'] ) |
||
2442 | return false; |
||
2443 | } |
||
2444 | |||
2445 | // Check and see if the old plugin is active |
||
2446 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
2447 | // Deactivate the old plugin |
||
2448 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
2449 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
2450 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
2451 | Jetpack::state( 'deactivated_plugins', $module ); |
||
2452 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
2453 | exit; |
||
2454 | } |
||
2455 | } |
||
2456 | |||
2457 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
2458 | Jetpack::state( 'module', $module ); |
||
2459 | Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
2460 | |||
2461 | Jetpack::catch_errors( true ); |
||
2462 | ob_start(); |
||
2463 | require Jetpack::get_module_path( $module ); |
||
2464 | /** This action is documented in class.jetpack.php */ |
||
2465 | do_action( 'jetpack_activate_module', $module ); |
||
2466 | $active[] = $module; |
||
2467 | Jetpack::update_active_modules( $active ); |
||
2468 | |||
2469 | Jetpack::state( 'error', false ); // the override |
||
2470 | ob_end_clean(); |
||
2471 | Jetpack::catch_errors( false ); |
||
2472 | |||
2473 | // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. |
||
2474 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
2475 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
2476 | |||
2477 | //Jump start is being dismissed send data to MC Stats |
||
2478 | $jetpack->stat( 'jumpstart', 'manual,'.$module ); |
||
2479 | |||
2480 | $jetpack->do_stats( 'server_side' ); |
||
2481 | } |
||
2482 | |||
2483 | if ( $redirect ) { |
||
2484 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
2485 | } |
||
2486 | if ( $exit ) { |
||
2487 | exit; |
||
2488 | } |
||
2489 | return true; |
||
2490 | } |
||
2491 | |||
2492 | function activate_module_actions( $module ) { |
||
2493 | _deprecated_function( __METHOD__, 'jeptack-4.2' ); |
||
2494 | } |
||
2495 | |||
2496 | public static function deactivate_module( $module ) { |
||
2497 | /** |
||
2498 | * Fires when a module is deactivated. |
||
2499 | * |
||
2500 | * @since 1.9.0 |
||
2501 | * |
||
2502 | * @param string $module Module slug. |
||
2503 | */ |
||
2504 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
2505 | |||
2506 | $jetpack = Jetpack::init(); |
||
2507 | |||
2508 | $active = Jetpack::get_active_modules(); |
||
2509 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
2510 | |||
2511 | // A flag for Jump Start so it's not shown again. |
||
2512 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
2513 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
2514 | |||
2515 | //Jump start is being dismissed send data to MC Stats |
||
2516 | $jetpack->stat( 'jumpstart', 'manual,deactivated-'.$module ); |
||
2517 | |||
2518 | $jetpack->do_stats( 'server_side' ); |
||
2519 | } |
||
2520 | |||
2521 | return self::update_active_modules( $new ); |
||
2522 | } |
||
2523 | |||
2524 | public static function enable_module_configurable( $module ) { |
||
2525 | $module = Jetpack::get_module_slug( $module ); |
||
2526 | add_filter( 'jetpack_module_configurable_' . $module, '__return_true' ); |
||
2527 | } |
||
2528 | |||
2529 | public static function module_configuration_url( $module ) { |
||
2530 | $module = Jetpack::get_module_slug( $module ); |
||
2531 | return Jetpack::admin_url( array( 'page' => 'jetpack', 'configure' => $module ) ); |
||
2532 | } |
||
2533 | |||
2534 | public static function module_configuration_load( $module, $method ) { |
||
2535 | $module = Jetpack::get_module_slug( $module ); |
||
2536 | add_action( 'jetpack_module_configuration_load_' . $module, $method ); |
||
2537 | } |
||
2538 | |||
2539 | public static function module_configuration_head( $module, $method ) { |
||
2540 | $module = Jetpack::get_module_slug( $module ); |
||
2541 | add_action( 'jetpack_module_configuration_head_' . $module, $method ); |
||
2542 | } |
||
2543 | |||
2544 | public static function module_configuration_screen( $module, $method ) { |
||
2545 | $module = Jetpack::get_module_slug( $module ); |
||
2546 | add_action( 'jetpack_module_configuration_screen_' . $module, $method ); |
||
2547 | } |
||
2548 | |||
2549 | public static function module_configuration_activation_screen( $module, $method ) { |
||
2550 | $module = Jetpack::get_module_slug( $module ); |
||
2551 | add_action( 'display_activate_module_setting_' . $module, $method ); |
||
2552 | } |
||
2553 | |||
2554 | /* Installation */ |
||
2555 | |||
2556 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
2557 | ?> |
||
2558 | <!doctype html> |
||
2559 | <html> |
||
2560 | <head> |
||
2561 | <meta charset="<?php bloginfo( 'charset' ); ?>"> |
||
2562 | <style> |
||
2563 | * { |
||
2564 | text-align: center; |
||
2565 | margin: 0; |
||
2566 | padding: 0; |
||
2567 | font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; |
||
2568 | } |
||
2569 | p { |
||
2570 | margin-top: 1em; |
||
2571 | font-size: 18px; |
||
2572 | } |
||
2573 | </style> |
||
2574 | <body> |
||
2575 | <p><?php echo esc_html( $message ); ?></p> |
||
2576 | </body> |
||
2577 | </html> |
||
2578 | <?php |
||
2579 | if ( $deactivate ) { |
||
2580 | $plugins = get_option( 'active_plugins' ); |
||
2581 | $jetpack = plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ); |
||
2582 | $update = false; |
||
2583 | foreach ( $plugins as $i => $plugin ) { |
||
2584 | if ( $plugin === $jetpack ) { |
||
2585 | $plugins[$i] = false; |
||
2586 | $update = true; |
||
2587 | } |
||
2588 | } |
||
2589 | |||
2590 | if ( $update ) { |
||
2591 | update_option( 'active_plugins', array_filter( $plugins ) ); |
||
2592 | } |
||
2593 | } |
||
2594 | exit; |
||
2595 | } |
||
2596 | |||
2597 | /** |
||
2598 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
2599 | * @static |
||
2600 | */ |
||
2601 | public static function plugin_activation( $network_wide ) { |
||
2602 | Jetpack_Options::update_option( 'activated', 1 ); |
||
2603 | |||
2604 | if ( version_compare( $GLOBALS['wp_version'], JETPACK__MINIMUM_WP_VERSION, '<' ) ) { |
||
2605 | Jetpack::bail_on_activation( sprintf( __( 'Jetpack requires WordPress version %s or later.', 'jetpack' ), JETPACK__MINIMUM_WP_VERSION ) ); |
||
2606 | } |
||
2607 | |||
2608 | if ( $network_wide ) |
||
2609 | Jetpack::state( 'network_nag', true ); |
||
2610 | |||
2611 | Jetpack::plugin_initialize(); |
||
2612 | } |
||
2613 | /** |
||
2614 | * Runs before bumping version numbers up to a new version |
||
2615 | * @param (string) $version Version:timestamp |
||
2616 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
2617 | * @return null [description] |
||
2618 | */ |
||
2619 | public static function do_version_bump( $version, $old_version ) { |
||
2620 | |||
2621 | if ( ! $old_version ) { // For new sites |
||
2622 | // Setting up jetpack manage |
||
2623 | Jetpack::activate_manage(); |
||
2624 | } |
||
2625 | } |
||
2626 | |||
2627 | /** |
||
2628 | * Sets the internal version number and activation state. |
||
2629 | * @static |
||
2630 | */ |
||
2631 | public static function plugin_initialize() { |
||
2632 | if ( ! Jetpack_Options::get_option( 'activated' ) ) { |
||
2633 | Jetpack_Options::update_option( 'activated', 2 ); |
||
2634 | } |
||
2635 | |||
2636 | View Code Duplication | if ( ! Jetpack_Options::get_option( 'version' ) ) { |
|
2637 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
2638 | /** This action is documented in class.jetpack.php */ |
||
2639 | do_action( 'updating_jetpack_version', $version, false ); |
||
2640 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
2641 | } |
||
2642 | |||
2643 | Jetpack::load_modules(); |
||
2644 | |||
2645 | Jetpack_Options::delete_option( 'do_activate' ); |
||
2646 | } |
||
2647 | |||
2648 | /** |
||
2649 | * Removes all connection options |
||
2650 | * @static |
||
2651 | */ |
||
2652 | public static function plugin_deactivation( ) { |
||
2653 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
||
2654 | if( is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
2655 | Jetpack_Network::init()->deactivate(); |
||
2656 | } else { |
||
2657 | Jetpack::disconnect( false ); |
||
2658 | //Jetpack_Heartbeat::init()->deactivate(); |
||
2659 | } |
||
2660 | } |
||
2661 | |||
2662 | /** |
||
2663 | * Disconnects from the Jetpack servers. |
||
2664 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
2665 | * @static |
||
2666 | */ |
||
2667 | public static function disconnect( $update_activated_state = true ) { |
||
2668 | wp_clear_scheduled_hook( 'jetpack_clean_nonces' ); |
||
2669 | Jetpack::clean_nonces( true ); |
||
2670 | |||
2671 | // If the site is in an IDC because sync is not allowed, |
||
2672 | // let's make sure to not disconnect the production site. |
||
2673 | if ( ! self::validate_sync_error_idc_option() ) { |
||
2674 | Jetpack::load_xml_rpc_client(); |
||
2675 | $xml = new Jetpack_IXR_Client(); |
||
2676 | $xml->query( 'jetpack.deregister' ); |
||
2677 | } |
||
2678 | |||
2679 | Jetpack_Options::delete_option( |
||
2680 | array( |
||
2681 | 'register', |
||
2682 | 'blog_token', |
||
2683 | 'user_token', |
||
2684 | 'user_tokens', |
||
2685 | 'master_user', |
||
2686 | 'time_diff', |
||
2687 | 'fallback_no_verify_ssl_certs', |
||
2688 | ) |
||
2689 | ); |
||
2690 | |||
2691 | Jetpack_IDC::clear_all_idc_options(); |
||
2692 | |||
2693 | if ( $update_activated_state ) { |
||
2694 | Jetpack_Options::update_option( 'activated', 4 ); |
||
2695 | } |
||
2696 | |||
2697 | if ( $jetpack_unique_connection = Jetpack_Options::get_option( 'unique_connection' ) ) { |
||
2698 | // Check then record unique disconnection if site has never been disconnected previously |
||
2699 | if ( - 1 == $jetpack_unique_connection['disconnected'] ) { |
||
2700 | $jetpack_unique_connection['disconnected'] = 1; |
||
2701 | } else { |
||
2702 | if ( 0 == $jetpack_unique_connection['disconnected'] ) { |
||
2703 | //track unique disconnect |
||
2704 | $jetpack = Jetpack::init(); |
||
2705 | |||
2706 | $jetpack->stat( 'connections', 'unique-disconnect' ); |
||
2707 | $jetpack->do_stats( 'server_side' ); |
||
2708 | } |
||
2709 | // increment number of times disconnected |
||
2710 | $jetpack_unique_connection['disconnected'] += 1; |
||
2711 | } |
||
2712 | |||
2713 | Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection ); |
||
2714 | } |
||
2715 | |||
2716 | // Delete all the sync related data. Since it could be taking up space. |
||
2717 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; |
||
2718 | Jetpack_Sync_Sender::get_instance()->uninstall(); |
||
2719 | |||
2720 | // Disable the Heartbeat cron |
||
2721 | Jetpack_Heartbeat::init()->deactivate(); |
||
2722 | } |
||
2723 | |||
2724 | /** |
||
2725 | * Unlinks the current user from the linked WordPress.com user |
||
2726 | */ |
||
2727 | public static function unlink_user( $user_id = null ) { |
||
2728 | if ( ! $tokens = Jetpack_Options::get_option( 'user_tokens' ) ) |
||
2729 | return false; |
||
2730 | |||
2731 | $user_id = empty( $user_id ) ? get_current_user_id() : intval( $user_id ); |
||
2732 | |||
2733 | if ( Jetpack_Options::get_option( 'master_user' ) == $user_id ) |
||
2734 | return false; |
||
2735 | |||
2736 | if ( ! isset( $tokens[ $user_id ] ) ) |
||
2737 | return false; |
||
2738 | |||
2739 | Jetpack::load_xml_rpc_client(); |
||
2740 | $xml = new Jetpack_IXR_Client( compact( 'user_id' ) ); |
||
2741 | $xml->query( 'jetpack.unlink_user', $user_id ); |
||
2742 | |||
2743 | unset( $tokens[ $user_id ] ); |
||
2744 | |||
2745 | Jetpack_Options::update_option( 'user_tokens', $tokens ); |
||
2746 | |||
2747 | /** |
||
2748 | * Fires after the current user has been unlinked from WordPress.com. |
||
2749 | * |
||
2750 | * @since 4.1.0 |
||
2751 | * |
||
2752 | * @param int $user_id The current user's ID. |
||
2753 | */ |
||
2754 | do_action( 'jetpack_unlinked_user', $user_id ); |
||
2755 | |||
2756 | return true; |
||
2757 | } |
||
2758 | |||
2759 | /** |
||
2760 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
2761 | */ |
||
2762 | public static function try_registration() { |
||
2763 | // Let's get some testing in beta versions and such. |
||
2764 | if ( self::is_development_version() && defined( 'PHP_URL_HOST' ) ) { |
||
2765 | // Before attempting to connect, let's make sure that the domains are viable. |
||
2766 | $domains_to_check = array_unique( array( |
||
2767 | 'siteurl' => parse_url( get_site_url(), PHP_URL_HOST ), |
||
2768 | 'homeurl' => parse_url( get_home_url(), PHP_URL_HOST ), |
||
2769 | ) ); |
||
2770 | foreach ( $domains_to_check as $domain ) { |
||
2771 | $result = Jetpack_Data::is_usable_domain( $domain ); |
||
2772 | if ( is_wp_error( $result ) ) { |
||
2773 | return $result; |
||
2774 | } |
||
2775 | } |
||
2776 | } |
||
2777 | |||
2778 | $result = Jetpack::register(); |
||
2779 | |||
2780 | // If there was an error with registration and the site was not registered, record this so we can show a message. |
||
2781 | if ( ! $result || is_wp_error( $result ) ) { |
||
2782 | return $result; |
||
2783 | } else { |
||
2784 | return true; |
||
2785 | } |
||
2786 | } |
||
2787 | |||
2788 | /** |
||
2789 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
2790 | * |
||
2791 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
2792 | */ |
||
2793 | public static function log( $code, $data = null ) { |
||
2794 | // only grab the latest 200 entries |
||
2795 | $log = array_slice( Jetpack_Options::get_option( 'log', array() ), -199, 199 ); |
||
2796 | |||
2797 | // Append our event to the log |
||
2798 | $log_entry = array( |
||
2799 | 'time' => time(), |
||
2800 | 'user_id' => get_current_user_id(), |
||
2801 | 'blog_id' => Jetpack_Options::get_option( 'id' ), |
||
2802 | 'code' => $code, |
||
2803 | ); |
||
2804 | // Don't bother storing it unless we've got some. |
||
2805 | if ( ! is_null( $data ) ) { |
||
2806 | $log_entry['data'] = $data; |
||
2807 | } |
||
2808 | $log[] = $log_entry; |
||
2809 | |||
2810 | // Try add_option first, to make sure it's not autoloaded. |
||
2811 | // @todo: Add an add_option method to Jetpack_Options |
||
2812 | if ( ! add_option( 'jetpack_log', $log, null, 'no' ) ) { |
||
2813 | Jetpack_Options::update_option( 'log', $log ); |
||
2814 | } |
||
2815 | |||
2816 | /** |
||
2817 | * Fires when Jetpack logs an internal event. |
||
2818 | * |
||
2819 | * @since 3.0.0 |
||
2820 | * |
||
2821 | * @param array $log_entry { |
||
2822 | * Array of details about the log entry. |
||
2823 | * |
||
2824 | * @param string time Time of the event. |
||
2825 | * @param int user_id ID of the user who trigerred the event. |
||
2826 | * @param int blog_id Jetpack Blog ID. |
||
2827 | * @param string code Unique name for the event. |
||
2828 | * @param string data Data about the event. |
||
2829 | * } |
||
2830 | */ |
||
2831 | do_action( 'jetpack_log_entry', $log_entry ); |
||
2832 | } |
||
2833 | |||
2834 | /** |
||
2835 | * Get the internal event log. |
||
2836 | * |
||
2837 | * @param $event (string) - only return the specific log events |
||
2838 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
2839 | * |
||
2840 | * @return array of log events || WP_Error for invalid params |
||
2841 | */ |
||
2842 | public static function get_log( $event = false, $num = false ) { |
||
2843 | if ( $event && ! is_string( $event ) ) { |
||
2844 | return new WP_Error( __( 'First param must be string or empty', 'jetpack' ) ); |
||
2845 | } |
||
2846 | |||
2847 | if ( $num && ! is_numeric( $num ) ) { |
||
2848 | return new WP_Error( __( 'Second param must be numeric or empty', 'jetpack' ) ); |
||
2849 | } |
||
2850 | |||
2851 | $entire_log = Jetpack_Options::get_option( 'log', array() ); |
||
2852 | |||
2853 | // If nothing set - act as it did before, otherwise let's start customizing the output |
||
2854 | if ( ! $num && ! $event ) { |
||
2855 | return $entire_log; |
||
2856 | } else { |
||
2857 | $entire_log = array_reverse( $entire_log ); |
||
2858 | } |
||
2859 | |||
2860 | $custom_log_output = array(); |
||
2861 | |||
2862 | if ( $event ) { |
||
2863 | foreach ( $entire_log as $log_event ) { |
||
2864 | if ( $event == $log_event[ 'code' ] ) { |
||
2865 | $custom_log_output[] = $log_event; |
||
2866 | } |
||
2867 | } |
||
2868 | } else { |
||
2869 | $custom_log_output = $entire_log; |
||
2870 | } |
||
2871 | |||
2872 | if ( $num ) { |
||
2873 | $custom_log_output = array_slice( $custom_log_output, 0, $num ); |
||
2874 | } |
||
2875 | |||
2876 | return $custom_log_output; |
||
2877 | } |
||
2878 | |||
2879 | /** |
||
2880 | * Log modification of important settings. |
||
2881 | */ |
||
2882 | public static function log_settings_change( $option, $old_value, $value ) { |
||
2883 | switch( $option ) { |
||
2884 | case 'jetpack_sync_non_public_post_stati': |
||
2885 | self::log( $option, $value ); |
||
2886 | break; |
||
2887 | } |
||
2888 | } |
||
2889 | |||
2890 | /** |
||
2891 | * Return stat data for WPCOM sync |
||
2892 | */ |
||
2893 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
2894 | $data = Jetpack_Heartbeat::generate_stats_array(); |
||
2895 | |||
2896 | if ( $extended ) { |
||
2897 | $additional_data = self::get_additional_stat_data(); |
||
2898 | $data = array_merge( $data, $additional_data ); |
||
2899 | } |
||
2900 | |||
2901 | if ( $encode ) { |
||
2902 | return json_encode( $data ); |
||
2903 | } |
||
2904 | |||
2905 | return $data; |
||
2906 | } |
||
2907 | |||
2908 | /** |
||
2909 | * Get additional stat data to sync to WPCOM |
||
2910 | */ |
||
2911 | public static function get_additional_stat_data( $prefix = '' ) { |
||
2912 | $return["{$prefix}themes"] = Jetpack::get_parsed_theme_data(); |
||
2913 | $return["{$prefix}plugins-extra"] = Jetpack::get_parsed_plugin_data(); |
||
2914 | $return["{$prefix}users"] = (int) Jetpack::get_site_user_count(); |
||
2915 | $return["{$prefix}site-count"] = 0; |
||
2916 | |||
2917 | if ( function_exists( 'get_blog_count' ) ) { |
||
2918 | $return["{$prefix}site-count"] = get_blog_count(); |
||
2919 | } |
||
2920 | return $return; |
||
2921 | } |
||
2922 | |||
2923 | private static function get_site_user_count() { |
||
2924 | global $wpdb; |
||
2925 | |||
2926 | if ( function_exists( 'wp_is_large_network' ) ) { |
||
2927 | if ( wp_is_large_network( 'users' ) ) { |
||
2928 | return -1; // Not a real value but should tell us that we are dealing with a large network. |
||
2929 | } |
||
2930 | } |
||
2931 | View Code Duplication | if ( false === ( $user_count = get_transient( 'jetpack_site_user_count' ) ) ) { |
|
2932 | // It wasn't there, so regenerate the data and save the transient |
||
2933 | $user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities'" ); |
||
2934 | set_transient( 'jetpack_site_user_count', $user_count, DAY_IN_SECONDS ); |
||
2935 | } |
||
2936 | return $user_count; |
||
2937 | } |
||
2938 | |||
2939 | /* Admin Pages */ |
||
2940 | |||
2941 | function admin_init() { |
||
2942 | // If the plugin is not connected, display a connect message. |
||
2943 | if ( |
||
2944 | // the plugin was auto-activated and needs its candy |
||
2945 | Jetpack_Options::get_option_and_ensure_autoload( 'do_activate', '0' ) |
||
2946 | || |
||
2947 | // the plugin is active, but was never activated. Probably came from a site-wide network activation |
||
2948 | ! Jetpack_Options::get_option( 'activated' ) |
||
2949 | ) { |
||
2950 | Jetpack::plugin_initialize(); |
||
2951 | } |
||
2952 | |||
2953 | if ( ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) { |
||
2954 | if ( 4 != Jetpack_Options::get_option( 'activated' ) ) { |
||
2955 | Jetpack_Connection_Banner::init(); |
||
2956 | } |
||
2957 | } elseif ( false === Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ) ) { |
||
2958 | // Upgrade: 1.1 -> 1.1.1 |
||
2959 | // Check and see if host can verify the Jetpack servers' SSL certificate |
||
2960 | $args = array(); |
||
2961 | Jetpack_Client::_wp_remote_request( |
||
2962 | Jetpack::fix_url_for_bad_hosts( Jetpack::api_url( 'test' ) ), |
||
2963 | $args, |
||
2964 | true |
||
2965 | ); |
||
2966 | } else if ( $this->can_display_jetpack_manage_notice() && ! Jetpack_Options::get_option( 'dismissed_manage_banner' ) ) { |
||
2967 | // Show the notice on the Dashboard only for now |
||
2968 | add_action( 'load-index.php', array( $this, 'prepare_manage_jetpack_notice' ) ); |
||
2969 | } |
||
2970 | |||
2971 | if ( current_user_can( 'manage_options' ) && 'AUTO' == JETPACK_CLIENT__HTTPS && ! self::permit_ssl() ) { |
||
2972 | add_action( 'jetpack_notices', array( $this, 'alert_auto_ssl_fail' ) ); |
||
2973 | } |
||
2974 | |||
2975 | add_action( 'load-plugins.php', array( $this, 'intercept_plugin_error_scrape_init' ) ); |
||
2976 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
||
2977 | add_filter( 'plugin_action_links_' . plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ), array( $this, 'plugin_action_links' ) ); |
||
2978 | |||
2979 | if ( Jetpack::is_active() || Jetpack::is_development_mode() ) { |
||
2980 | // Artificially throw errors in certain whitelisted cases during plugin activation |
||
2981 | add_action( 'activate_plugin', array( $this, 'throw_error_on_activate_plugin' ) ); |
||
2982 | } |
||
2983 | |||
2984 | // Jetpack Manage Activation Screen from .com |
||
2985 | Jetpack::module_configuration_activation_screen( 'manage', array( $this, 'manage_activate_screen' ) ); |
||
2986 | |||
2987 | // Add custom column in wp-admin/users.php to show whether user is linked. |
||
2988 | add_filter( 'manage_users_columns', array( $this, 'jetpack_icon_user_connected' ) ); |
||
2989 | add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_user_connected_icon' ), 10, 3 ); |
||
2990 | add_action( 'admin_print_styles', array( $this, 'jetpack_user_col_style' ) ); |
||
2991 | } |
||
2992 | |||
2993 | function admin_body_class( $admin_body_class = '' ) { |
||
2994 | $classes = explode( ' ', trim( $admin_body_class ) ); |
||
2995 | |||
2996 | $classes[] = self::is_active() ? 'jetpack-connected' : 'jetpack-disconnected'; |
||
2997 | |||
2998 | $admin_body_class = implode( ' ', array_unique( $classes ) ); |
||
2999 | return " $admin_body_class "; |
||
3000 | } |
||
3001 | |||
3002 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
3003 | return $admin_body_class . ' jetpack-pagestyles '; |
||
3004 | } |
||
3005 | |||
3006 | /** |
||
3007 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
3008 | * |
||
3009 | * @return null |
||
3010 | */ |
||
3011 | function prepare_manage_jetpack_notice() { |
||
3012 | |||
3013 | add_action( 'admin_print_styles', array( $this, 'admin_banner_styles' ) ); |
||
3014 | add_action( 'admin_notices', array( $this, 'admin_jetpack_manage_notice' ) ); |
||
3015 | } |
||
3016 | |||
3017 | function manage_activate_screen() { |
||
3018 | include ( JETPACK__PLUGIN_DIR . 'modules/manage/activate-admin.php' ); |
||
3019 | } |
||
3020 | /** |
||
3021 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
3022 | * This function artificially throws errors for such cases (whitelisted). |
||
3023 | * |
||
3024 | * @param string $plugin The activated plugin. |
||
3025 | */ |
||
3026 | function throw_error_on_activate_plugin( $plugin ) { |
||
3027 | $active_modules = Jetpack::get_active_modules(); |
||
3028 | |||
3029 | // The Shortlinks module and the Stats plugin conflict, but won't cause errors on activation because of some function_exists() checks. |
||
3030 | if ( function_exists( 'stats_get_api_key' ) && in_array( 'shortlinks', $active_modules ) ) { |
||
3031 | $throw = false; |
||
3032 | |||
3033 | // Try and make sure it really was the stats plugin |
||
3034 | if ( ! class_exists( 'ReflectionFunction' ) ) { |
||
3035 | if ( 'stats.php' == basename( $plugin ) ) { |
||
3036 | $throw = true; |
||
3037 | } |
||
3038 | } else { |
||
3039 | $reflection = new ReflectionFunction( 'stats_get_api_key' ); |
||
3040 | if ( basename( $plugin ) == basename( $reflection->getFileName() ) ) { |
||
3041 | $throw = true; |
||
3042 | } |
||
3043 | } |
||
3044 | |||
3045 | if ( $throw ) { |
||
3046 | trigger_error( sprintf( __( 'Jetpack contains the most recent version of the old “%1$s” plugin.', 'jetpack' ), 'WordPress.com Stats' ), E_USER_ERROR ); |
||
3047 | } |
||
3048 | } |
||
3049 | } |
||
3050 | |||
3051 | function intercept_plugin_error_scrape_init() { |
||
3052 | add_action( 'check_admin_referer', array( $this, 'intercept_plugin_error_scrape' ), 10, 2 ); |
||
3053 | } |
||
3054 | |||
3055 | function intercept_plugin_error_scrape( $action, $result ) { |
||
3056 | if ( ! $result ) { |
||
3057 | return; |
||
3058 | } |
||
3059 | |||
3060 | foreach ( $this->plugins_to_deactivate as $deactivate_me ) { |
||
3061 | if ( "plugin-activation-error_{$deactivate_me[0]}" == $action ) { |
||
3062 | Jetpack::bail_on_activation( sprintf( __( 'Jetpack contains the most recent version of the old “%1$s” plugin.', 'jetpack' ), $deactivate_me[1] ), false ); |
||
3063 | } |
||
3064 | } |
||
3065 | } |
||
3066 | |||
3067 | function add_remote_request_handlers() { |
||
3068 | add_action( 'wp_ajax_nopriv_jetpack_upload_file', array( $this, 'remote_request_handlers' ) ); |
||
3069 | } |
||
3070 | |||
3071 | function remote_request_handlers() { |
||
3072 | switch ( current_filter() ) { |
||
3073 | case 'wp_ajax_nopriv_jetpack_upload_file' : |
||
3074 | $response = $this->upload_handler(); |
||
3075 | break; |
||
3076 | default : |
||
3077 | $response = new Jetpack_Error( 'unknown_handler', 'Unknown Handler', 400 ); |
||
3078 | break; |
||
3079 | } |
||
3080 | |||
3081 | if ( ! $response ) { |
||
3082 | $response = new Jetpack_Error( 'unknown_error', 'Unknown Error', 400 ); |
||
3083 | } |
||
3084 | |||
3085 | if ( is_wp_error( $response ) ) { |
||
3086 | $status_code = $response->get_error_data(); |
||
3087 | $error = $response->get_error_code(); |
||
3088 | $error_description = $response->get_error_message(); |
||
3089 | |||
3090 | if ( ! is_int( $status_code ) ) { |
||
3091 | $status_code = 400; |
||
3092 | } |
||
3093 | |||
3094 | status_header( $status_code ); |
||
3095 | die( json_encode( (object) compact( 'error', 'error_description' ) ) ); |
||
3096 | } |
||
3097 | |||
3098 | status_header( 200 ); |
||
3099 | if ( true === $response ) { |
||
3100 | exit; |
||
3101 | } |
||
3102 | |||
3103 | die( json_encode( (object) $response ) ); |
||
3104 | } |
||
3105 | |||
3106 | function upload_handler() { |
||
3107 | if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { |
||
3108 | return new Jetpack_Error( 405, get_status_header_desc( 405 ), 405 ); |
||
3109 | } |
||
3110 | |||
3111 | $user = wp_authenticate( '', '' ); |
||
3112 | if ( ! $user || is_wp_error( $user ) ) { |
||
3113 | return new Jetpack_Error( 403, get_status_header_desc( 403 ), 403 ); |
||
3114 | } |
||
3115 | |||
3116 | wp_set_current_user( $user->ID ); |
||
3117 | |||
3118 | if ( ! current_user_can( 'upload_files' ) ) { |
||
3119 | return new Jetpack_Error( 'cannot_upload_files', 'User does not have permission to upload files', 403 ); |
||
3120 | } |
||
3121 | |||
3122 | if ( empty( $_FILES ) ) { |
||
3123 | return new Jetpack_Error( 'no_files_uploaded', 'No files were uploaded: nothing to process', 400 ); |
||
3124 | } |
||
3125 | |||
3126 | foreach ( array_keys( $_FILES ) as $files_key ) { |
||
3127 | if ( ! isset( $_POST["_jetpack_file_hmac_{$files_key}"] ) ) { |
||
3128 | return new Jetpack_Error( 'missing_hmac', 'An HMAC for one or more files is missing', 400 ); |
||
3129 | } |
||
3130 | } |
||
3131 | |||
3132 | $media_keys = array_keys( $_FILES['media'] ); |
||
3133 | |||
3134 | $token = Jetpack_Data::get_access_token( get_current_user_id() ); |
||
3135 | if ( ! $token || is_wp_error( $token ) ) { |
||
3136 | return new Jetpack_Error( 'unknown_token', 'Unknown Jetpack token', 403 ); |
||
3137 | } |
||
3138 | |||
3139 | $uploaded_files = array(); |
||
3140 | $global_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; |
||
3141 | unset( $GLOBALS['post'] ); |
||
3142 | foreach ( $_FILES['media']['name'] as $index => $name ) { |
||
3143 | $file = array(); |
||
3144 | foreach ( $media_keys as $media_key ) { |
||
3145 | $file[$media_key] = $_FILES['media'][$media_key][$index]; |
||
3146 | } |
||
3147 | |||
3148 | list( $hmac_provided, $salt ) = explode( ':', $_POST['_jetpack_file_hmac_media'][$index] ); |
||
3149 | |||
3150 | $hmac_file = hash_hmac_file( 'sha1', $file['tmp_name'], $salt . $token->secret ); |
||
3151 | if ( $hmac_provided !== $hmac_file ) { |
||
3152 | $uploaded_files[$index] = (object) array( 'error' => 'invalid_hmac', 'error_description' => 'The corresponding HMAC for this file does not match' ); |
||
3153 | continue; |
||
3154 | } |
||
3155 | |||
3156 | $_FILES['.jetpack.upload.'] = $file; |
||
3157 | $post_id = isset( $_POST['post_id'][$index] ) ? absint( $_POST['post_id'][$index] ) : 0; |
||
3158 | if ( ! current_user_can( 'edit_post', $post_id ) ) { |
||
3159 | $post_id = 0; |
||
3160 | } |
||
3161 | $attachment_id = media_handle_upload( |
||
3162 | '.jetpack.upload.', |
||
3163 | $post_id, |
||
3164 | array(), |
||
3165 | array( |
||
3166 | 'action' => 'jetpack_upload_file', |
||
3167 | ) |
||
3168 | ); |
||
3169 | |||
3170 | if ( ! $attachment_id ) { |
||
3171 | $uploaded_files[$index] = (object) array( 'error' => 'unknown', 'error_description' => 'An unknown problem occurred processing the upload on the Jetpack site' ); |
||
3172 | } elseif ( is_wp_error( $attachment_id ) ) { |
||
3173 | $uploaded_files[$index] = (object) array( 'error' => 'attachment_' . $attachment_id->get_error_code(), 'error_description' => $attachment_id->get_error_message() ); |
||
3174 | } else { |
||
3175 | $attachment = get_post( $attachment_id ); |
||
3176 | $uploaded_files[$index] = (object) array( |
||
3177 | 'id' => (string) $attachment_id, |
||
3178 | 'file' => $attachment->post_title, |
||
3179 | 'url' => wp_get_attachment_url( $attachment_id ), |
||
3180 | 'type' => $attachment->post_mime_type, |
||
3181 | 'meta' => wp_get_attachment_metadata( $attachment_id ), |
||
3182 | ); |
||
3183 | // Zip files uploads are not supported unless they are done for installation purposed |
||
3184 | // lets delete them in case something goes wrong in this whole process |
||
3185 | if ( 'application/zip' === $attachment->post_mime_type ) { |
||
3186 | // Schedule a cleanup for 2 hours from now in case of failed install. |
||
3187 | wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $attachment_id ) ); |
||
3188 | } |
||
3189 | } |
||
3190 | } |
||
3191 | if ( ! is_null( $global_post ) ) { |
||
3192 | $GLOBALS['post'] = $global_post; |
||
3193 | } |
||
3194 | |||
3195 | return $uploaded_files; |
||
3196 | } |
||
3197 | |||
3198 | /** |
||
3199 | * Add help to the Jetpack page |
||
3200 | * |
||
3201 | * @since Jetpack (1.2.3) |
||
3202 | * @return false if not the Jetpack page |
||
3203 | */ |
||
3204 | function admin_help() { |
||
3245 | |||
3246 | function admin_menu_css() { |
||
3249 | |||
3250 | function admin_menu_order() { |
||
3253 | |||
3254 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
3269 | |||
3270 | function admin_head() { |
||
3275 | |||
3276 | function admin_banner_styles() { |
||
3277 | $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
3278 | |||
3279 | View Code Duplication | if ( ! wp_style_is( 'jetpack-dops-style' ) ) { |
|
3280 | wp_register_style( |
||
3281 | 'jetpack-dops-style', |
||
3282 | plugins_url( '_inc/build/admin.dops-style.css', JETPACK__PLUGIN_FILE ), |
||
3283 | array(), |
||
3284 | JETPACK__VERSION |
||
3285 | ); |
||
3286 | } |
||
3287 | |||
3288 | wp_enqueue_style( |
||
3289 | 'jetpack', |
||
3290 | plugins_url( "css/jetpack-banners{$min}.css", JETPACK__PLUGIN_FILE ), |
||
3291 | array( 'jetpack-dops-style' ), |
||
3292 | JETPACK__VERSION . '-20121016' |
||
3293 | ); |
||
3294 | wp_style_add_data( 'jetpack', 'rtl', 'replace' ); |
||
3295 | wp_style_add_data( 'jetpack', 'suffix', $min ); |
||
3296 | } |
||
3297 | |||
3298 | function plugin_action_links( $actions ) { |
||
3313 | |||
3314 | /** |
||
3315 | * This is the first banner |
||
3316 | * It should be visible only to user that can update the option |
||
3317 | * Are not connected |
||
3318 | * |
||
3319 | * @return null |
||
3320 | */ |
||
3321 | function admin_jetpack_manage_notice() { |
||
3322 | $screen = get_current_screen(); |
||
3323 | |||
3324 | // Don't show the connect notice on the jetpack settings page. |
||
3325 | if ( ! in_array( $screen->base, array( 'dashboard' ) ) || $screen->is_network || $screen->action ) { |
||
3326 | return; |
||
3327 | } |
||
3328 | |||
3329 | $opt_out_url = $this->opt_out_jetpack_manage_url(); |
||
3330 | $opt_in_url = $this->opt_in_jetpack_manage_url(); |
||
3331 | /** |
||
3332 | * I think it would be great to have different wordsing depending on where you are |
||
3333 | * for example if we show the notice on dashboard and a different one if we show it on Plugins screen |
||
3334 | * etc.. |
||
3335 | */ |
||
3336 | |||
3337 | ?> |
||
3338 | <div id="message" class="updated jp-banner"> |
||
3339 | <a href="<?php echo esc_url( $opt_out_url ); ?>" class="notice-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>"></a> |
||
3340 | <div class="jp-banner__description-container"> |
||
3341 | <h2 class="jp-banner__header"><?php esc_html_e( 'Jetpack Centralized Site Management', 'jetpack' ); ?></h2> |
||
3342 | <p class="jp-banner__description"><?php printf( __( 'Manage multiple Jetpack enabled sites from one single dashboard at wordpress.com. Allows all existing, connected Administrators to modify your site.', 'jetpack' ), 'https://jetpack.com/support/site-management' ); ?></p> |
||
3343 | <p class="jp-banner__button-container"> |
||
3344 | <a href="<?php echo esc_url( $opt_in_url ); ?>" class="button button-primary" id="wpcom-connect"><?php _e( 'Activate Jetpack Manage', 'jetpack' ); ?></a> |
||
3345 | <a href="https://jetpack.com/support/site-management" class="button" target="_blank" title="<?php esc_attr_e( 'Learn more about Jetpack Manage on Jetpack.com', 'jetpack' ); ?>"><?php _e( 'Learn more', 'jetpack' ); ?></a> |
||
3346 | </p> |
||
3347 | </div> |
||
3348 | </div> |
||
3349 | <?php |
||
3350 | } |
||
3351 | |||
3352 | /** |
||
3353 | * Returns the url that the user clicks to remove the notice for the big banner |
||
3354 | * @return (string) |
||
3355 | */ |
||
3356 | function opt_out_jetpack_manage_url() { |
||
3360 | /** |
||
3361 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
3362 | * @return (string) |
||
3363 | */ |
||
3364 | function opt_in_jetpack_manage_url() { |
||
3367 | |||
3368 | function opt_in_jetpack_manage_notice() { |
||
3378 | /** |
||
3379 | * Determines whether to show the notice of not true = display notice |
||
3380 | * @return (bool) |
||
3381 | */ |
||
3382 | function can_display_jetpack_manage_notice() { |
||
3404 | |||
3405 | /* |
||
3406 | * Registration flow: |
||
3407 | * 1 - ::admin_page_load() action=register |
||
3408 | * 2 - ::try_registration() |
||
3409 | * 3 - ::register() |
||
3410 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
3411 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
3412 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
3413 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
3414 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
3415 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
3416 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
3417 | * jetpack_id, jetpack_secret, jetpack_public |
||
3418 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
3419 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
3420 | * 5 - user logs in with WP.com account |
||
3421 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
3422 | * - Jetpack_Client_Server::authorize() |
||
3423 | * - Jetpack_Client_Server::get_token() |
||
3424 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
3425 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
3426 | * - which responds with access_token, token_type, scope |
||
3427 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
3428 | * - Jetpack::activate_default_modules() |
||
3429 | * - Deactivates deprecated plugins |
||
3430 | * - Activates all default modules |
||
3431 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
3432 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
3433 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
3434 | * Done! |
||
3435 | */ |
||
3436 | |||
3437 | /** |
||
3438 | * Handles the page load events for the Jetpack admin page |
||
3439 | */ |
||
3440 | function admin_page_load() { |
||
3441 | $error = false; |
||
3442 | |||
3443 | // Make sure we have the right body class to hook stylings for subpages off of. |
||
3444 | add_filter( 'admin_body_class', array( __CLASS__, 'add_jetpack_pagestyles' ) ); |
||
3445 | |||
3446 | if ( ! empty( $_GET['jetpack_restate'] ) ) { |
||
3447 | // Should only be used in intermediate redirects to preserve state across redirects |
||
3448 | Jetpack::restate(); |
||
3449 | } |
||
3450 | |||
3451 | if ( isset( $_GET['connect_url_redirect'] ) ) { |
||
3452 | // User clicked in the iframe to link their accounts |
||
3453 | if ( ! Jetpack::is_user_connected() ) { |
||
3454 | $connect_url = $this->build_connect_url( true, false, 'iframe' ); |
||
3455 | if ( isset( $_GET['notes_iframe'] ) ) |
||
3456 | $connect_url .= '¬es_iframe'; |
||
3457 | wp_redirect( $connect_url ); |
||
3458 | exit; |
||
3459 | } else { |
||
3460 | if ( ! isset( $_GET['calypso_env'] ) ) { |
||
3461 | Jetpack::state( 'message', 'already_authorized' ); |
||
3462 | wp_safe_redirect( Jetpack::admin_url() ); |
||
3463 | } else { |
||
3464 | $connect_url = $this->build_connect_url( true, false, 'iframe' ); |
||
3465 | $connect_url .= '&already_authorized=true'; |
||
3466 | wp_redirect( $connect_url ); |
||
3467 | } |
||
3468 | } |
||
3469 | } |
||
3470 | |||
3471 | |||
3472 | if ( isset( $_GET['action'] ) ) { |
||
3473 | switch ( $_GET['action'] ) { |
||
3474 | case 'authorize': |
||
3475 | if ( Jetpack::is_active() && Jetpack::is_user_connected() ) { |
||
3476 | Jetpack::state( 'message', 'already_authorized' ); |
||
3477 | wp_safe_redirect( Jetpack::admin_url() ); |
||
3478 | exit; |
||
3479 | } |
||
3480 | Jetpack::log( 'authorize' ); |
||
3481 | $client_server = new Jetpack_Client_Server; |
||
3482 | $client_server->client_authorize(); |
||
3483 | exit; |
||
3484 | case 'register' : |
||
3485 | if ( ! current_user_can( 'jetpack_connect' ) ) { |
||
3486 | $error = 'cheatin'; |
||
3487 | break; |
||
3488 | } |
||
3489 | check_admin_referer( 'jetpack-register' ); |
||
3490 | Jetpack::log( 'register' ); |
||
3491 | Jetpack::maybe_set_version_option(); |
||
3492 | $registered = Jetpack::try_registration(); |
||
3493 | if ( is_wp_error( $registered ) ) { |
||
3494 | $error = $registered->get_error_code(); |
||
3495 | Jetpack::state( 'error', $error ); |
||
3496 | Jetpack::state( 'error', $registered->get_error_message() ); |
||
3497 | break; |
||
3498 | } |
||
3499 | |||
3500 | $from = isset( $_GET['from'] ) ? $_GET['from'] : false; |
||
3501 | |||
3502 | wp_redirect( $this->build_connect_url( true, false, $from ) ); |
||
3503 | exit; |
||
3666 | |||
3667 | function admin_notices() { |
||
3764 | |||
3765 | /** |
||
3766 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
3767 | */ |
||
3768 | function stat( $group, $detail ) { |
||
3773 | |||
3774 | /** |
||
3775 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
3776 | */ |
||
3777 | function do_stats( $method = '' ) { |
||
3792 | |||
3793 | /** |
||
3794 | * Runs stats code for a one-off, server-side. |
||
3795 | * |
||
3796 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
3797 | * |
||
3798 | * @return bool If it worked. |
||
3799 | */ |
||
3800 | static function do_server_side_stat( $args ) { |
||
3810 | |||
3811 | /** |
||
3812 | * Builds the stats url. |
||
3813 | * |
||
3814 | * @param $args array|string The arguments to append to the URL. |
||
3815 | * |
||
3816 | * @return string The URL to be pinged. |
||
3817 | */ |
||
3818 | static function build_stats_url( $args ) { |
||
3838 | |||
3839 | static function translate_current_user_to_role() { |
||
3848 | |||
3849 | static function translate_role_to_cap( $role ) { |
||
3856 | |||
3857 | static function sign_role( $role ) { |
||
3869 | |||
3870 | |||
3871 | /** |
||
3872 | * Builds a URL to the Jetpack connection auth page |
||
3873 | * |
||
3874 | * @since 3.9.5 |
||
3875 | * |
||
3876 | * @param bool $raw If true, URL will not be escaped. |
||
3877 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
3878 | * If string, will be a custom redirect. |
||
3879 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
3880 | * |
||
3881 | * @return string Connect URL |
||
3882 | */ |
||
3883 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
3967 | |||
3968 | function build_reconnect_url( $raw = false ) { |
||
3972 | |||
3973 | public static function admin_url( $args = null ) { |
||
3978 | |||
3979 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
3983 | |||
3984 | function dismiss_jetpack_notice() { |
||
4058 | |||
4059 | function debugger_page() { |
||
4067 | |||
4068 | public static function admin_screen_configure_module( $module_id ) { |
||
4120 | |||
4121 | /** |
||
4122 | * Display link to activate the module to see the settings screen. |
||
4123 | * @param string $module_id |
||
4124 | * @return null |
||
4125 | */ |
||
4126 | public static function display_activate_module_link( $module_id ) { |
||
4178 | |||
4179 | public static function sort_modules( $a, $b ) { |
||
4185 | |||
4186 | function ajax_recheck_ssl() { |
||
4194 | |||
4195 | /* Client API */ |
||
4196 | |||
4197 | /** |
||
4198 | * Returns the requested Jetpack API URL |
||
4199 | * |
||
4200 | * @return string |
||
4201 | */ |
||
4202 | public static function api_url( $relative_url ) { |
||
4205 | |||
4206 | /** |
||
4207 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
4208 | */ |
||
4209 | public static function fix_url_for_bad_hosts( $url ) { |
||
4225 | |||
4226 | /** |
||
4227 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
4228 | * |
||
4229 | * @since 2.3.3 |
||
4230 | * @return boolean |
||
4231 | */ |
||
4232 | public static function permit_ssl( $force_recheck = false ) { |
||
4274 | |||
4275 | /* |
||
4276 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
4277 | */ |
||
4278 | public function alert_auto_ssl_fail() { |
||
4327 | |||
4328 | /** |
||
4329 | * Returns the Jetpack XML-RPC API |
||
4330 | * |
||
4331 | * @return string |
||
4332 | */ |
||
4333 | public static function xmlrpc_api_url() { |
||
4337 | |||
4338 | /** |
||
4339 | * Creates two secret tokens and the end of life timestamp for them. |
||
4340 | * |
||
4341 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
4342 | * |
||
4343 | * @since 2.6 |
||
4344 | * @return array |
||
4345 | */ |
||
4346 | public function generate_secrets( $action, $exp = 600 ) { |
||
4354 | |||
4355 | /** |
||
4356 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
4357 | * |
||
4358 | * Based on local php max_execution_time in php.ini |
||
4359 | * |
||
4360 | * @since 2.6 |
||
4361 | * @return int |
||
4362 | **/ |
||
4363 | public function get_remote_query_timeout_limit() { |
||
4369 | |||
4370 | |||
4371 | /** |
||
4372 | * Takes the response from the Jetpack register new site endpoint and |
||
4373 | * verifies it worked properly. |
||
4374 | * |
||
4375 | * @since 2.6 |
||
4376 | * @return true or Jetpack_Error |
||
4377 | **/ |
||
4378 | public function validate_remote_register_response( $response ) { |
||
4413 | /** |
||
4414 | * @return bool|WP_Error |
||
4415 | */ |
||
4416 | public static function register() { |
||
4513 | |||
4514 | /** |
||
4515 | * If the db version is showing something other that what we've got now, bump it to current. |
||
4516 | * |
||
4517 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
4518 | */ |
||
4519 | public static function maybe_set_version_option() { |
||
4533 | |||
4534 | /* Client Server API */ |
||
4535 | |||
4536 | /** |
||
4537 | * Loads the Jetpack XML-RPC client |
||
4538 | */ |
||
4539 | public static function load_xml_rpc_client() { |
||
4543 | |||
4544 | function verify_xml_rpc_signature() { |
||
4642 | |||
4643 | /** |
||
4644 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
4645 | */ |
||
4646 | function authenticate_jetpack( $user, $username, $password ) { |
||
4669 | |||
4670 | function add_nonce( $timestamp, $nonce ) { |
||
4708 | |||
4709 | /** |
||
4710 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
4711 | * Capture it here so we can verify the signature later. |
||
4712 | */ |
||
4713 | function xmlrpc_methods( $methods ) { |
||
4717 | |||
4718 | function public_xmlrpc_methods( $methods ) { |
||
4724 | |||
4725 | function jetpack_getOptions( $args ) { |
||
4765 | |||
4766 | function xmlrpc_options( $options ) { |
||
4784 | |||
4785 | public static function clean_nonces( $all = false ) { |
||
4806 | |||
4807 | /** |
||
4808 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
4809 | * SET: state( $key, $value ); |
||
4810 | * GET: $value = state( $key ); |
||
4811 | * |
||
4812 | * @param string $key |
||
4813 | * @param string $value |
||
4814 | * @param bool $restate private |
||
4815 | */ |
||
4816 | public static function state( $key = null, $value = null, $restate = false ) { |
||
4866 | |||
4867 | public static function restate() { |
||
4870 | |||
4871 | public static function check_privacy( $file ) { |
||
4906 | |||
4907 | /** |
||
4908 | * Helper method for multicall XMLRPC. |
||
4909 | */ |
||
4910 | public static function xmlrpc_async_call() { |
||
4952 | |||
4953 | public static function staticize_subdomain( $url ) { |
||
4988 | |||
4989 | /* JSON API Authorization */ |
||
4990 | |||
4991 | /** |
||
4992 | * Handles the login action for Authorizing the JSON API |
||
4993 | */ |
||
4994 | function login_form_json_api_authorization() { |
||
5003 | |||
5004 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
5005 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
5018 | |||
5019 | // Make sure the POSTed request is handled by the same action |
||
5020 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
5024 | |||
5025 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
5026 | function store_json_api_authorization_token( $user_login, $user ) { |
||
5032 | |||
5033 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
5034 | function allow_wpcom_public_api_domain( $domains ) { |
||
5038 | |||
5039 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
5040 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
5052 | |||
5053 | // Verifies the request by checking the signature |
||
5054 | function verify_json_api_authorization_request() { |
||
5133 | |||
5134 | function login_message_json_api_authorization( $message ) { |
||
5140 | |||
5141 | /** |
||
5142 | * Get $content_width, but with a <s>twist</s> filter. |
||
5143 | */ |
||
5144 | public static function get_content_width() { |
||
5155 | |||
5156 | /** |
||
5157 | * Centralize the function here until it gets added to core. |
||
5158 | * |
||
5159 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
5160 | * @param int $size Size of the avatar image |
||
5161 | * @param string $default URL to a default image to use if no avatar is available |
||
5162 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
5163 | * |
||
5164 | * @return array First element is the URL, second is the class. |
||
5165 | */ |
||
5166 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
5194 | |||
5195 | /** |
||
5196 | * Pings the WordPress.com Mirror Site for the specified options. |
||
5197 | * |
||
5198 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
5199 | * |
||
5200 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
5201 | */ |
||
5202 | public function get_cloud_site_options( $option_names ) { |
||
5218 | |||
5219 | /** |
||
5220 | * Checks if the site is currently in an identity crisis. |
||
5221 | * |
||
5222 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
5223 | */ |
||
5224 | public static function check_identity_crisis() { |
||
5231 | |||
5232 | /** |
||
5233 | * Checks whether the home and siteurl specifically are whitelisted |
||
5234 | * Written so that we don't have re-check $key and $value params every time |
||
5235 | * we want to check if this site is whitelisted, for example in footer.php |
||
5236 | * |
||
5237 | * @since 3.8.0 |
||
5238 | * @return bool True = already whitelisted False = not whitelisted |
||
5239 | */ |
||
5240 | public static function is_staging_site() { |
||
5299 | |||
5300 | /** |
||
5301 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
5302 | * |
||
5303 | * @return bool |
||
5304 | */ |
||
5305 | public static function validate_sync_error_idc_option() { |
||
5349 | |||
5350 | /** |
||
5351 | * Normalizes a url by doing three things: |
||
5352 | * - Strips protocol |
||
5353 | * - Strips www |
||
5354 | * - Adds a trailing slash |
||
5355 | * |
||
5356 | * @since 4.4.0 |
||
5357 | * @param string $url |
||
5358 | * @return WP_Error|string |
||
5359 | */ |
||
5360 | public static function normalize_url_protocol_agnostic( $url ) { |
||
5370 | |||
5371 | /** |
||
5372 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
5373 | * |
||
5374 | * @since 4.4.0 |
||
5375 | * |
||
5376 | * @param array $response |
||
5377 | * @return array Array of the local urls, wpcom urls, and error code |
||
5378 | */ |
||
5379 | public static function get_sync_error_idc_option( $response = array() ) { |
||
5403 | |||
5404 | /** |
||
5405 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
5406 | * If set to true, the site will be put into staging mode. |
||
5407 | * |
||
5408 | * @since 4.3.2 |
||
5409 | * @return bool |
||
5410 | */ |
||
5411 | public static function sync_idc_optin() { |
||
5429 | |||
5430 | /** |
||
5431 | * Maybe Use a .min.css stylesheet, maybe not. |
||
5432 | * |
||
5433 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
5434 | */ |
||
5435 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
5470 | |||
5471 | /** |
||
5472 | * Maybe inlines a stylesheet. |
||
5473 | * |
||
5474 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
5475 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
5476 | * |
||
5477 | * Attached to `style_loader_tag` filter. |
||
5478 | * |
||
5479 | * @param string $tag The tag that would link to the external asset. |
||
5480 | * @param string $handle The registered handle of the script in question. |
||
5481 | * |
||
5482 | * @return string |
||
5483 | */ |
||
5484 | public static function maybe_inline_style( $tag, $handle ) { |
||
5534 | |||
5535 | /** |
||
5536 | * Loads a view file from the views |
||
5537 | * |
||
5538 | * Data passed in with the $data parameter will be available in the |
||
5539 | * template file as $data['value'] |
||
5540 | * |
||
5541 | * @param string $template - Template file to load |
||
5542 | * @param array $data - Any data to pass along to the template |
||
5543 | * @return boolean - If template file was found |
||
5544 | **/ |
||
5545 | public function load_view( $template, $data = array() ) { |
||
5556 | |||
5557 | /** |
||
5558 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
5559 | */ |
||
5560 | public function deprecated_hooks() { |
||
5604 | |||
5605 | /** |
||
5606 | * Converts any url in a stylesheet, to the correct absolute url. |
||
5607 | * |
||
5608 | * Considerations: |
||
5609 | * - Normal, relative URLs `feh.png` |
||
5610 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
5611 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
5612 | * - Absolute URLs `http://domain.com/feh.png` |
||
5613 | * - Domain root relative URLs `/feh.png` |
||
5614 | * |
||
5615 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
5616 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
5617 | * |
||
5618 | * @return mixed|string |
||
5619 | */ |
||
5620 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
5664 | |||
5665 | /** |
||
5666 | * This methods removes all of the registered css files on the front end |
||
5667 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
5668 | * all the files into one file. |
||
5669 | * |
||
5670 | * Pros: |
||
5671 | * - Uses only ONE css asset connection instead of 15 |
||
5672 | * - Saves a minimum of 56k |
||
5673 | * - Reduces server load |
||
5674 | * - Reduces time to first painted byte |
||
5675 | * |
||
5676 | * Cons: |
||
5677 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
5678 | * should not cause any issues with themes. |
||
5679 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
5680 | * jetpack_implode_frontend_css filter for a workaround |
||
5681 | * |
||
5682 | * For some situations developers may wish to disable css imploding and |
||
5683 | * instead operate in legacy mode where each file loads seperately and |
||
5684 | * can be edited individually or dequeued. This can be accomplished with |
||
5685 | * the following line: |
||
5686 | * |
||
5687 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
5688 | * |
||
5689 | * @since 3.2 |
||
5690 | **/ |
||
5691 | public function implode_frontend_css( $travis_test = false ) { |
||
5743 | |||
5744 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
5754 | |||
5755 | /* |
||
5756 | * Check the heartbeat data |
||
5757 | * |
||
5758 | * Organizes the heartbeat data by severity. For example, if the site |
||
5759 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
5760 | * |
||
5761 | * Data will be added to "caution" array, if it either: |
||
5762 | * - Out of date Jetpack version |
||
5763 | * - Out of date WP version |
||
5764 | * - Out of date PHP version |
||
5765 | * |
||
5766 | * $return array $filtered_data |
||
5767 | */ |
||
5768 | public static function jetpack_check_heartbeat_data() { |
||
5821 | |||
5822 | |||
5823 | /* |
||
5824 | * This method is used to organize all options that can be reset |
||
5825 | * without disconnecting Jetpack. |
||
5826 | * |
||
5827 | * It is used in class.jetpack-cli.php to reset options |
||
5828 | * |
||
5829 | * @return array of options to delete. |
||
5830 | */ |
||
5831 | public static function get_jetpack_options_for_reset() { |
||
5898 | |||
5899 | /** |
||
5900 | * Check if an option of a Jetpack module has been updated. |
||
5901 | * |
||
5902 | * If any module option has been updated before Jump Start has been dismissed, |
||
5903 | * update the 'jumpstart' option so we can hide Jump Start. |
||
5904 | * |
||
5905 | * @param string $option_name |
||
5906 | * |
||
5907 | * @return bool |
||
5908 | */ |
||
5909 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
5930 | |||
5931 | /* |
||
5932 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
5933 | * so we can bring them directly to their site in calypso. |
||
5934 | * |
||
5935 | * @param string | url |
||
5936 | * @return string | url without the guff |
||
5937 | */ |
||
5938 | public static function build_raw_urls( $url ) { |
||
5944 | |||
5945 | /** |
||
5946 | * Stores and prints out domains to prefetch for page speed optimization. |
||
5947 | * |
||
5948 | * @param mixed $new_urls |
||
5949 | */ |
||
5950 | public static function dns_prefetch( $new_urls = null ) { |
||
5967 | |||
5968 | public function wp_dashboard_setup() { |
||
5996 | |||
5997 | /** |
||
5998 | * @param mixed $result Value for the user's option |
||
5999 | * @return mixed |
||
6000 | */ |
||
6001 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
6026 | |||
6027 | public static function dashboard_widget() { |
||
6035 | |||
6036 | public static function dashboard_widget_footer() { |
||
6069 | |||
6070 | public function dashboard_widget_connect_to_wpcom() { |
||
6092 | |||
6093 | /** |
||
6094 | * Return string containing the Jetpack logo. |
||
6095 | * |
||
6096 | * @since 3.9.0 |
||
6097 | * |
||
6098 | * @return string |
||
6099 | */ |
||
6100 | public static function get_jp_emblem() { |
||
6103 | |||
6104 | /* |
||
6105 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
6106 | */ |
||
6107 | function jetpack_icon_user_connected( $columns ) { |
||
6111 | |||
6112 | /* |
||
6113 | * Show Jetpack icon if the user is linked. |
||
6114 | */ |
||
6115 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
6127 | |||
6128 | /* |
||
6129 | * Style the Jetpack user column |
||
6130 | */ |
||
6131 | function jetpack_user_col_style() { |
||
6144 | } |
||
6145 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.