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 | 'tiled-gallery', |
||
46 | 'widget-conditions', |
||
47 | 'jetpack_display_posts_widget', |
||
48 | 'gravatar-profile-widget', |
||
49 | 'widget-grid-and-list', |
||
50 | 'jetpack-widgets', |
||
51 | 'goodreads-widget', |
||
52 | 'jetpack_social_media_icons_widget', |
||
53 | ); |
||
54 | |||
55 | public $plugins_to_deactivate = array( |
||
56 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
57 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
58 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
59 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
60 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
61 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
62 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
63 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
64 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
65 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
66 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
67 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
68 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
69 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
70 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
71 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
72 | ); |
||
73 | |||
74 | static $capability_translations = array( |
||
|
|||
75 | 'administrator' => 'manage_options', |
||
76 | 'editor' => 'edit_others_posts', |
||
77 | 'author' => 'publish_posts', |
||
78 | 'contributor' => 'edit_posts', |
||
79 | 'subscriber' => 'read', |
||
80 | ); |
||
81 | |||
82 | /** |
||
83 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
84 | * if the plugins are active. Used by filter_default_modules |
||
85 | * |
||
86 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
87 | * change `module-slug` and add this to your plugin: |
||
88 | * |
||
89 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
90 | * function my_jetpack_get_default_modules( $modules ) { |
||
91 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
92 | * } |
||
93 | * |
||
94 | * @var array |
||
95 | */ |
||
96 | private $conflicting_plugins = array( |
||
97 | 'comments' => array( |
||
98 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
99 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
100 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
101 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
102 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
103 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
104 | ), |
||
105 | 'contact-form' => array( |
||
106 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
107 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
108 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
109 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
110 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
111 | ), |
||
112 | 'minileven' => array( |
||
113 | 'WPtouch' => 'wptouch/wptouch.php', |
||
114 | ), |
||
115 | 'latex' => array( |
||
116 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
117 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
118 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
119 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
120 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
121 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
122 | ), |
||
123 | 'protect' => array( |
||
124 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
125 | 'Captcha' => 'captcha/captcha.php', |
||
126 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
127 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
128 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
129 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
130 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
131 | 'Security-protection' => 'security-protection/security-protection.php', |
||
132 | 'Login Security' => 'login-security/login-security.php', |
||
133 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
134 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
135 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
136 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
137 | ), |
||
138 | 'random-redirect' => array( |
||
139 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
140 | ), |
||
141 | 'related-posts' => array( |
||
142 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
143 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
144 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
145 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
146 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
147 | 'outbrain' => 'outbrain/outbrain.php', |
||
148 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
149 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
150 | ), |
||
151 | 'sharedaddy' => array( |
||
152 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
153 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
154 | 'ShareThis' => 'share-this/sharethis.php', |
||
155 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
156 | ), |
||
157 | 'verification-tools' => array( |
||
158 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
159 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
160 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
161 | ), |
||
162 | 'widget-visibility' => array( |
||
163 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
164 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
165 | ), |
||
166 | 'sitemaps' => array( |
||
167 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
168 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
169 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
170 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
171 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
172 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
173 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
174 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
175 | 'Sitemap' => 'sitemap/sitemap.php', |
||
176 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
177 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
178 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
179 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
180 | ), |
||
181 | ); |
||
182 | |||
183 | /** |
||
184 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
185 | * |
||
186 | * Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate |
||
187 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
188 | * |
||
189 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
190 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
191 | */ |
||
192 | private $open_graph_conflicting_plugins = array( |
||
193 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
194 | // 2 Click Social Media Buttons |
||
195 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
196 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
197 | 'autodescription/autodescription.php', // The SEO Framework |
||
198 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
199 | 'facebook/facebook.php', // Facebook (official plugin) |
||
200 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
201 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
202 | // Facebook Featured Image & OG Meta Tags |
||
203 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
204 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
205 | // Facebook Open Graph Meta Tags for WordPress |
||
206 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
207 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
208 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
209 | // Fedmich's Facebook Open Graph Meta |
||
210 | 'header-footer/plugin.php', // Header and Footer |
||
211 | 'network-publisher/networkpub.php', // Network Publisher |
||
212 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
213 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
214 | // NextScripts SNAP |
||
215 | 'opengraph/opengraph.php', // Open Graph |
||
216 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
217 | // Open Graph Protocol Framework |
||
218 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
219 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
220 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
221 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
222 | 'sharepress/sharepress.php', // SharePress |
||
223 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
224 | 'social-discussions/social-discussions.php', // Social Discussions |
||
225 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
226 | 'socialize/socialize.php', // Socialize |
||
227 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
228 | // Tweet, Like, Google +1 and Share |
||
229 | 'wordbooker/wordbooker.php', // Wordbooker |
||
230 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
231 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
232 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
233 | // WP Facebook Like Send & Open Graph Meta |
||
234 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
235 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
236 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
237 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
238 | ); |
||
239 | |||
240 | /** |
||
241 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
242 | */ |
||
243 | private $twitter_cards_conflicting_plugins = array( |
||
244 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
245 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
246 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
247 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
248 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
249 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
250 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
251 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
252 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
253 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
254 | ); |
||
255 | |||
256 | /** |
||
257 | * Message to display in admin_notice |
||
258 | * @var string |
||
259 | */ |
||
260 | public $message = ''; |
||
261 | |||
262 | /** |
||
263 | * Error to display in admin_notice |
||
264 | * @var string |
||
265 | */ |
||
266 | public $error = ''; |
||
267 | |||
268 | /** |
||
269 | * Modules that need more privacy description. |
||
270 | * @var string |
||
271 | */ |
||
272 | public $privacy_checks = ''; |
||
273 | |||
274 | /** |
||
275 | * Stats to record once the page loads |
||
276 | * |
||
277 | * @var array |
||
278 | */ |
||
279 | public $stats = array(); |
||
280 | |||
281 | /** |
||
282 | * Jetpack_Sync object |
||
283 | */ |
||
284 | public $sync; |
||
285 | |||
286 | /** |
||
287 | * Verified data for JSON authorization request |
||
288 | */ |
||
289 | public $json_api_authorization_request = array(); |
||
290 | |||
291 | /** |
||
292 | * Holds the singleton instance of this class |
||
293 | * @since 2.3.3 |
||
294 | * @var Jetpack |
||
295 | */ |
||
296 | static $instance = false; |
||
297 | |||
298 | /** |
||
299 | * Singleton |
||
300 | * @static |
||
301 | */ |
||
302 | public static function init() { |
||
303 | if ( ! self::$instance ) { |
||
304 | self::$instance = new Jetpack; |
||
305 | |||
306 | self::$instance->plugin_upgrade(); |
||
307 | } |
||
308 | |||
309 | return self::$instance; |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Must never be called statically |
||
314 | */ |
||
315 | function plugin_upgrade() { |
||
316 | if ( Jetpack::is_active() ) { |
||
317 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
318 | if ( JETPACK__VERSION != $version ) { |
||
319 | |||
320 | // Check which active modules actually exist and remove others from active_modules list |
||
321 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
322 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
323 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
324 | Jetpack::update_active_modules( $modules ); |
||
325 | } |
||
326 | |||
327 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
328 | Jetpack::maybe_set_version_option(); |
||
329 | } |
||
330 | } |
||
331 | } |
||
332 | |||
333 | static function activate_manage( ) { |
||
334 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
335 | self::activate_module( 'manage', false, false ); |
||
336 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
337 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
338 | } |
||
339 | } |
||
340 | |||
341 | static function update_active_modules( $modules ) { |
||
342 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
343 | |||
344 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $modules ) ); |
||
345 | |||
346 | if ( is_array( $modules ) && is_array( $current_modules ) ) { |
||
347 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
348 | foreach( $new_active_modules as $module ) { |
||
349 | /** |
||
350 | * Fires when a specific module is activated. |
||
351 | * |
||
352 | * @since 1.9.0 |
||
353 | * |
||
354 | * @param string $module Module slug. |
||
355 | * @param boolean $success whether the module was activated. @since 4.2 |
||
356 | */ |
||
357 | do_action( 'jetpack_activate_module', $module, $success ); |
||
358 | |||
359 | /** |
||
360 | * Fires when a module is activated. |
||
361 | * The dynamic part of the filter, $module, is the module slug. |
||
362 | * |
||
363 | * @since 1.9.0 |
||
364 | * |
||
365 | * @param string $module Module slug. |
||
366 | */ |
||
367 | do_action( "jetpack_activate_module_$module", $module ); |
||
368 | } |
||
369 | |||
370 | $new_deactive_modules = array_diff( $current_modules, $modules ); |
||
371 | foreach( $new_deactive_modules as $module ) { |
||
372 | /** |
||
373 | * Fired after a module has been deactivated. |
||
374 | * |
||
375 | * @since 4.2.0 |
||
376 | * |
||
377 | * @param string $module Module slug. |
||
378 | * @param boolean $success whether the module was deactivated. |
||
379 | */ |
||
380 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
381 | /** |
||
382 | * Fires when a module is deactivated. |
||
383 | * The dynamic part of the filter, $module, is the module slug. |
||
384 | * |
||
385 | * @since 1.9.0 |
||
386 | * |
||
387 | * @param string $module Module slug. |
||
388 | */ |
||
389 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
390 | } |
||
391 | } |
||
392 | |||
393 | return $success; |
||
394 | } |
||
395 | |||
396 | static function delete_active_modules() { |
||
397 | self::update_active_modules( array() ); |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * Constructor. Initializes WordPress hooks |
||
402 | */ |
||
403 | private function __construct() { |
||
404 | /* |
||
405 | * Check for and alert any deprecated hooks |
||
406 | */ |
||
407 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
408 | |||
409 | |||
410 | /* |
||
411 | * Load things that should only be in Network Admin. |
||
412 | * |
||
413 | * For now blow away everything else until a more full |
||
414 | * understanding of what is needed at the network level is |
||
415 | * available |
||
416 | */ |
||
417 | if( is_multisite() ) { |
||
418 | Jetpack_Network::init(); |
||
419 | } |
||
420 | |||
421 | // Unlink user before deleting the user from .com |
||
422 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
423 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
424 | |||
425 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
426 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
427 | |||
428 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
429 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
430 | |||
431 | $this->require_jetpack_authentication(); |
||
432 | |||
433 | if ( Jetpack::is_active() ) { |
||
434 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
435 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
436 | |||
437 | $signed = $this->verify_xml_rpc_signature(); |
||
438 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
439 | // The actual API methods. |
||
440 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
441 | } else { |
||
442 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
443 | // active Jetpack connection, so that additional users can link their account. |
||
444 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
445 | } |
||
446 | } else { |
||
447 | // The bootstrap API methods. |
||
448 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
449 | } |
||
450 | |||
451 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
452 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
453 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
454 | $this->require_jetpack_authentication(); |
||
455 | $this->add_remote_request_handlers(); |
||
456 | } else { |
||
457 | if ( Jetpack::is_active() ) { |
||
458 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
459 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
460 | } |
||
461 | } |
||
462 | |||
463 | if ( Jetpack::is_active() ) { |
||
464 | Jetpack_Heartbeat::init(); |
||
465 | } |
||
466 | |||
467 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
468 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
469 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
470 | } |
||
471 | |||
472 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
473 | |||
474 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
475 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
476 | |||
477 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
478 | |||
479 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
480 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
481 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
482 | |||
483 | // returns HTTPS support status |
||
484 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
485 | |||
486 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
487 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
488 | |||
489 | // Identity Crisis AJAX callback function |
||
490 | add_action( 'wp_ajax_jetpack_resolve_identity_crisis', array( $this, 'resolve_identity_crisis_ajax_callback' ) ); |
||
491 | |||
492 | // JITM AJAX callback function |
||
493 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
494 | |||
495 | add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) ); |
||
496 | add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) ); |
||
497 | |||
498 | // Universal ajax callback for all tracking events triggered via js |
||
499 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
500 | |||
501 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
502 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
503 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
504 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
505 | |||
506 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
507 | |||
508 | /** |
||
509 | * These actions run checks to load additional files. |
||
510 | * They check for external files or plugins, so they need to run as late as possible. |
||
511 | */ |
||
512 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
513 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
514 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
515 | |||
516 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
517 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
518 | |||
519 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
520 | |||
521 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
522 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
523 | |||
524 | // A filter to control all just in time messages |
||
525 | add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); |
||
526 | |||
527 | /** |
||
528 | * This is the hack to concatinate all css files into one. |
||
529 | * For description and reasoning see the implode_frontend_css method |
||
530 | * |
||
531 | * Super late priority so we catch all the registered styles |
||
532 | */ |
||
533 | if( !is_admin() ) { |
||
534 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
535 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
536 | } |
||
537 | |||
538 | } |
||
539 | |||
540 | function jetpack_admin_ajax_tracks_callback() { |
||
541 | // Check for nonce |
||
542 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
543 | wp_die( 'Permissions check failed.' ); |
||
544 | } |
||
545 | |||
546 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
547 | wp_die( 'No valid event name or type.' ); |
||
548 | } |
||
549 | |||
550 | $tracks_data = array(); |
||
551 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
552 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
553 | } |
||
554 | |||
555 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
556 | wp_send_json_success(); |
||
557 | wp_die(); |
||
558 | } |
||
559 | |||
560 | function jetpack_admin_ajax_callback() { |
||
561 | // Check for nonce |
||
562 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) || ! current_user_can( 'jetpack_manage_modules' ) ) { |
|
563 | wp_die( 'permissions check failed' ); |
||
564 | } |
||
565 | |||
566 | if ( isset( $_REQUEST['toggleModule'] ) && 'nux-toggle-module' == $_REQUEST['toggleModule'] ) { |
||
567 | $slug = $_REQUEST['thisModuleSlug']; |
||
568 | |||
569 | if ( ! in_array( $slug, Jetpack::get_available_modules() ) ) { |
||
570 | wp_die( 'That is not a Jetpack module slug' ); |
||
571 | } |
||
572 | |||
573 | if ( Jetpack::is_module_active( $slug ) ) { |
||
574 | Jetpack::deactivate_module( $slug ); |
||
575 | } else { |
||
576 | Jetpack::activate_module( $slug, false, false ); |
||
577 | } |
||
578 | |||
579 | $modules = Jetpack_Admin::init()->get_modules(); |
||
580 | echo json_encode( $modules[ $slug ] ); |
||
581 | |||
582 | exit; |
||
583 | } |
||
584 | |||
585 | wp_die(); |
||
586 | } |
||
587 | |||
588 | /* |
||
589 | * Sometimes we need to refresh the data, |
||
590 | * especially if the page is visited via a 'history' |
||
591 | * event like back/forward |
||
592 | */ |
||
593 | function jetpack_admin_ajax_refresh_data() { |
||
594 | // Check for nonce |
||
595 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) ) { |
|
596 | wp_die( 'permissions check failed' ); |
||
597 | } |
||
598 | |||
599 | if ( isset( $_REQUEST['refreshData'] ) && 'refresh' == $_REQUEST['refreshData'] ) { |
||
600 | $modules = Jetpack_Admin::init()->get_modules(); |
||
601 | echo json_encode( $modules ); |
||
602 | exit; |
||
603 | } |
||
604 | |||
605 | wp_die(); |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * The callback for the JITM ajax requests. |
||
610 | */ |
||
611 | function jetpack_jitm_ajax_callback() { |
||
612 | // Check for nonce |
||
613 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
614 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
615 | } |
||
616 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
617 | $module_slug = $_REQUEST['jitmModule']; |
||
618 | Jetpack::log( 'activate', $module_slug ); |
||
619 | Jetpack::activate_module( $module_slug, false, false ); |
||
620 | Jetpack::state( 'message', 'no_message' ); |
||
621 | |||
622 | //A Jetpack module is being activated through a JITM, track it |
||
623 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
624 | $this->do_stats( 'server_side' ); |
||
625 | |||
626 | wp_send_json_success(); |
||
627 | } |
||
628 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
629 | // get the hide_jitm options array |
||
630 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
631 | $module_slug = $_REQUEST['jitmModule']; |
||
632 | |||
633 | if( ! $jetpack_hide_jitm ) { |
||
634 | $jetpack_hide_jitm = array( |
||
635 | $module_slug => 'hide' |
||
636 | ); |
||
637 | } else { |
||
638 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
639 | } |
||
640 | |||
641 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
642 | |||
643 | //jitm is being dismissed forever, track it |
||
644 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
645 | $this->do_stats( 'server_side' ); |
||
646 | |||
647 | wp_send_json_success(); |
||
648 | } |
||
649 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
650 | $module_slug = $_REQUEST['jitmModule']; |
||
651 | |||
652 | // User went to WordPress.com, track this |
||
653 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
654 | $this->do_stats( 'server_side' ); |
||
655 | |||
656 | wp_send_json_success(); |
||
657 | } |
||
658 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
659 | $track = $_REQUEST['jitmModule']; |
||
660 | |||
661 | // User is viewing JITM, track it. |
||
662 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
663 | $this->do_stats( 'server_side' ); |
||
664 | |||
665 | wp_send_json_success(); |
||
666 | } |
||
667 | } |
||
668 | |||
669 | /** |
||
670 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
671 | */ |
||
672 | function __destruct() { |
||
673 | if ( ! empty( $this->stats ) ) { |
||
674 | $this->do_stats( 'server_side' ); |
||
675 | } |
||
676 | } |
||
677 | |||
678 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
679 | switch( $cap ) { |
||
680 | case 'jetpack_connect' : |
||
681 | case 'jetpack_reconnect' : |
||
682 | if ( Jetpack::is_development_mode() ) { |
||
683 | $caps = array( 'do_not_allow' ); |
||
684 | break; |
||
685 | } |
||
686 | /** |
||
687 | * Pass through. If it's not development mode, these should match disconnect. |
||
688 | * Let users disconnect if it's development mode, just in case things glitch. |
||
689 | */ |
||
690 | case 'jetpack_disconnect' : |
||
691 | /** |
||
692 | * In multisite, can individual site admins manage their own connection? |
||
693 | * |
||
694 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
695 | */ |
||
696 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
697 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
698 | /** |
||
699 | * We need to update the option name -- it's terribly unclear which |
||
700 | * direction the override goes. |
||
701 | * |
||
702 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
703 | */ |
||
704 | $caps = array( 'do_not_allow' ); |
||
705 | break; |
||
706 | } |
||
707 | } |
||
708 | |||
709 | $caps = array( 'manage_options' ); |
||
710 | break; |
||
711 | case 'jetpack_manage_modules' : |
||
712 | case 'jetpack_activate_modules' : |
||
713 | case 'jetpack_deactivate_modules' : |
||
714 | $caps = array( 'manage_options' ); |
||
715 | break; |
||
716 | case 'jetpack_configure_modules' : |
||
717 | $caps = array( 'manage_options' ); |
||
718 | break; |
||
719 | case 'jetpack_network_admin_page': |
||
720 | case 'jetpack_network_settings_page': |
||
721 | $caps = array( 'manage_network_plugins' ); |
||
722 | break; |
||
723 | case 'jetpack_network_sites_page': |
||
724 | $caps = array( 'manage_sites' ); |
||
725 | break; |
||
726 | case 'jetpack_admin_page' : |
||
727 | if ( Jetpack::is_development_mode() ) { |
||
728 | $caps = array( 'manage_options' ); |
||
729 | break; |
||
730 | } else { |
||
731 | $caps = array( 'read' ); |
||
732 | } |
||
733 | break; |
||
734 | case 'jetpack_connect_user' : |
||
735 | if ( Jetpack::is_development_mode() ) { |
||
736 | $caps = array( 'do_not_allow' ); |
||
737 | break; |
||
738 | } |
||
739 | $caps = array( 'read' ); |
||
740 | break; |
||
741 | } |
||
742 | return $caps; |
||
743 | } |
||
744 | |||
745 | function require_jetpack_authentication() { |
||
746 | // Don't let anyone authenticate |
||
747 | $_COOKIE = array(); |
||
748 | remove_all_filters( 'authenticate' ); |
||
749 | |||
750 | /** |
||
751 | * For the moment, remove Limit Login Attempts if its xmlrpc for Jetpack. |
||
752 | * If Limit Login Attempts is installed as a mu-plugin, it can occasionally |
||
753 | * generate false-positives. |
||
754 | */ |
||
755 | remove_filter( 'wp_login_failed', 'limit_login_failed' ); |
||
756 | |||
757 | if ( Jetpack::is_active() ) { |
||
758 | // Allow Jetpack authentication |
||
759 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
760 | } |
||
761 | } |
||
762 | |||
763 | /** |
||
764 | * Load language files |
||
765 | * @action plugins_loaded |
||
766 | */ |
||
767 | public static function plugin_textdomain() { |
||
768 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
769 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
770 | } |
||
771 | |||
772 | /** |
||
773 | * Register assets for use in various modules and the Jetpack admin page. |
||
774 | * |
||
775 | * @uses wp_script_is, wp_register_script, plugins_url |
||
776 | * @action wp_loaded |
||
777 | * @return null |
||
778 | */ |
||
779 | public function register_assets() { |
||
780 | View Code Duplication | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
|
781 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
782 | } |
||
783 | |||
784 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
785 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
786 | } |
||
787 | |||
788 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
789 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
790 | } |
||
791 | |||
792 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
793 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
794 | } |
||
795 | |||
796 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
797 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
798 | |||
799 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
800 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
801 | if ( ! is_numeric( $fb_app_id ) ) { |
||
802 | $fb_app_id = ''; |
||
803 | } |
||
804 | wp_localize_script( |
||
805 | 'jetpack-facebook-embed', |
||
806 | 'jpfbembed', |
||
807 | array( |
||
808 | 'appid' => $fb_app_id, |
||
809 | 'locale' => $this->get_locale(), |
||
810 | ) |
||
811 | ); |
||
812 | } |
||
813 | |||
814 | /** |
||
815 | * As jetpack_register_genericons is by default fired off a hook, |
||
816 | * the hook may have already fired by this point. |
||
817 | * So, let's just trigger it manually. |
||
818 | */ |
||
819 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
820 | jetpack_register_genericons(); |
||
821 | |||
822 | /** |
||
823 | * Register the social logos |
||
824 | */ |
||
825 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
826 | jetpack_register_social_logos(); |
||
827 | |||
828 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
829 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
830 | } |
||
831 | |||
832 | /** |
||
833 | * Guess locale from language code. |
||
834 | * |
||
835 | * @param string $lang Language code. |
||
836 | * @return string|bool |
||
837 | */ |
||
838 | function guess_locale_from_lang( $lang ) { |
||
839 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
840 | return 'en_US'; |
||
841 | } |
||
842 | |||
843 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
844 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
845 | return false; |
||
846 | } |
||
847 | |||
848 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
849 | } |
||
850 | |||
851 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
852 | // WP.com: get_locale() returns 'it' |
||
853 | $locale = GP_Locales::by_slug( $lang ); |
||
854 | } else { |
||
855 | // Jetpack: get_locale() returns 'it_IT'; |
||
856 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
857 | } |
||
858 | |||
859 | if ( ! $locale ) { |
||
860 | return false; |
||
861 | } |
||
862 | |||
863 | if ( empty( $locale->facebook_locale ) ) { |
||
864 | if ( empty( $locale->wp_locale ) ) { |
||
865 | return false; |
||
866 | } else { |
||
867 | // Facebook SDK is smart enough to fall back to en_US if a |
||
868 | // locale isn't supported. Since supported Facebook locales |
||
869 | // can fall out of sync, we'll attempt to use the known |
||
870 | // wp_locale value and rely on said fallback. |
||
871 | return $locale->wp_locale; |
||
872 | } |
||
873 | } |
||
874 | |||
875 | return $locale->facebook_locale; |
||
876 | } |
||
877 | |||
878 | /** |
||
879 | * Get the locale. |
||
880 | * |
||
881 | * @return string|bool |
||
882 | */ |
||
883 | function get_locale() { |
||
884 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
885 | |||
886 | if ( ! $locale ) { |
||
887 | $locale = 'en_US'; |
||
888 | } |
||
889 | |||
890 | return $locale; |
||
891 | } |
||
892 | |||
893 | /** |
||
894 | * Device Pixels support |
||
895 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
896 | */ |
||
897 | function devicepx() { |
||
898 | if ( Jetpack::is_active() ) { |
||
899 | wp_enqueue_script( 'devicepx', set_url_scheme( 'http://s0.wp.com/wp-content/js/devicepx-jetpack.js' ), array(), gmdate( 'oW' ), true ); |
||
900 | } |
||
901 | } |
||
902 | |||
903 | /** |
||
904 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
905 | * @param bool $option |
||
906 | * @return string |
||
907 | */ |
||
908 | public function jetpack_main_network_site_option( $option ) { |
||
909 | return network_site_url(); |
||
910 | } |
||
911 | /** |
||
912 | * Network Name. |
||
913 | */ |
||
914 | static function network_name( $option = null ) { |
||
915 | global $current_site; |
||
916 | return $current_site->site_name; |
||
917 | } |
||
918 | /** |
||
919 | * Does the network allow new user and site registrations. |
||
920 | * @return string |
||
921 | */ |
||
922 | static function network_allow_new_registrations( $option = null ) { |
||
923 | return ( in_array( get_site_option( 'registration' ), array('none', 'user', 'blog', 'all' ) ) ? get_site_option( 'registration') : 'none' ); |
||
924 | } |
||
925 | /** |
||
926 | * Does the network allow admins to add new users. |
||
927 | * @return boolian |
||
928 | */ |
||
929 | static function network_add_new_users( $option = null ) { |
||
930 | return (bool) get_site_option( 'add_new_users' ); |
||
931 | } |
||
932 | /** |
||
933 | * File upload psace left per site in MB. |
||
934 | * -1 means NO LIMIT. |
||
935 | * @return number |
||
936 | */ |
||
937 | static function network_site_upload_space( $option = null ) { |
||
938 | // value in MB |
||
939 | return ( get_site_option( 'upload_space_check_disabled' ) ? -1 : get_space_allowed() ); |
||
940 | } |
||
941 | |||
942 | /** |
||
943 | * Network allowed file types. |
||
944 | * @return string |
||
945 | */ |
||
946 | static function network_upload_file_types( $option = null ) { |
||
947 | return get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ); |
||
948 | } |
||
949 | |||
950 | /** |
||
951 | * Maximum file upload size set by the network. |
||
952 | * @return number |
||
953 | */ |
||
954 | static function network_max_upload_file_size( $option = null ) { |
||
955 | // value in KB |
||
956 | return get_site_option( 'fileupload_maxk', 300 ); |
||
957 | } |
||
958 | |||
959 | /** |
||
960 | * Lets us know if a site allows admins to manage the network. |
||
961 | * @return array |
||
962 | */ |
||
963 | static function network_enable_administration_menus( $option = null ) { |
||
964 | return get_site_option( 'menu_items' ); |
||
965 | } |
||
966 | |||
967 | /** |
||
968 | * Return whether we are dealing with a multi network setup or not. |
||
969 | * The reason we are type casting this is because we want to avoid the situation where |
||
970 | * the result is false since when is_main_network_option return false it cases |
||
971 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
972 | * database which could be set to anything as opposed to what this function returns. |
||
973 | * @param bool $option |
||
974 | * |
||
975 | * @return boolean |
||
976 | */ |
||
977 | public function is_main_network_option( $option ) { |
||
978 | // return '1' or '' |
||
979 | return (string) (bool) Jetpack::is_multi_network(); |
||
980 | } |
||
981 | |||
982 | /** |
||
983 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
984 | * |
||
985 | * @param string $option |
||
986 | * @return boolean |
||
987 | */ |
||
988 | public function is_multisite( $option ) { |
||
989 | return (string) (bool) is_multisite(); |
||
990 | } |
||
991 | |||
992 | /** |
||
993 | * Implemented since there is no core is multi network function |
||
994 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
995 | * |
||
996 | * @since 3.3 |
||
997 | * @return boolean |
||
998 | */ |
||
999 | public static function is_multi_network() { |
||
1000 | global $wpdb; |
||
1001 | |||
1002 | // if we don't have a multi site setup no need to do any more |
||
1003 | if ( ! is_multisite() ) { |
||
1004 | return false; |
||
1005 | } |
||
1006 | |||
1007 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
1008 | if ( $num_sites > 1 ) { |
||
1009 | return true; |
||
1010 | } else { |
||
1011 | return false; |
||
1012 | } |
||
1013 | } |
||
1014 | |||
1015 | /** |
||
1016 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1017 | * @return null |
||
1018 | */ |
||
1019 | function update_jetpack_main_network_site_option() { |
||
1020 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1021 | } |
||
1022 | /** |
||
1023 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1024 | * |
||
1025 | */ |
||
1026 | function update_jetpack_network_settings() { |
||
1027 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1028 | // Only sync this info for the main network site. |
||
1029 | } |
||
1030 | |||
1031 | /** |
||
1032 | * Get back if the current site is single user site. |
||
1033 | * |
||
1034 | * @return bool |
||
1035 | */ |
||
1036 | public static function is_single_user_site() { |
||
1037 | $user_query = new WP_User_Query( array( |
||
1038 | 'blog_id' => get_current_blog_id(), |
||
1039 | 'fields' => 'ID', |
||
1040 | 'number' => 2 |
||
1041 | ) ); |
||
1042 | return 1 === (int) $user_query->get_total(); |
||
1043 | } |
||
1044 | |||
1045 | /** |
||
1046 | * Returns true if the site has file write access false otherwise. |
||
1047 | * @return string ( '1' | '0' ) |
||
1048 | **/ |
||
1049 | public static function file_system_write_access() { |
||
1069 | |||
1070 | /** |
||
1071 | * Finds out if a site is using a version control system. |
||
1072 | * @return string ( '1' | '0' ) |
||
1073 | **/ |
||
1074 | public static function is_version_controlled() { |
||
1078 | |||
1079 | /** |
||
1080 | * Determines whether the current theme supports featured images or not. |
||
1081 | * @return string ( '1' | '0' ) |
||
1082 | */ |
||
1083 | public static function featured_images_enabled() { |
||
1084 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1085 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
1086 | } |
||
1087 | |||
1088 | /** |
||
1089 | * jetpack_updates is saved in the following schema: |
||
1090 | * |
||
1091 | * array ( |
||
1092 | * 'plugins' => (int) Number of plugin updates available. |
||
1093 | * 'themes' => (int) Number of theme updates available. |
||
1094 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1095 | * 'translations' => (int) Number of translation updates available. |
||
1096 | * 'total' => (int) Total of all available updates. |
||
1097 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1098 | * ) |
||
1099 | * @return array |
||
1100 | */ |
||
1101 | public static function get_updates() { |
||
1102 | $update_data = wp_get_update_data(); |
||
1103 | |||
1104 | // Stores the individual update counts as well as the total count. |
||
1105 | if ( isset( $update_data['counts'] ) ) { |
||
1106 | $updates = $update_data['counts']; |
||
1107 | } |
||
1108 | |||
1118 | |||
1119 | public static function get_update_details() { |
||
1127 | |||
1128 | public static function refresh_update_data() { |
||
1132 | |||
1133 | public static function refresh_theme_data() { |
||
1136 | |||
1137 | /** |
||
1138 | * Is Jetpack active? |
||
1139 | */ |
||
1140 | public static function is_active() { |
||
1143 | |||
1144 | /** |
||
1145 | * Is Jetpack in development (offline) mode? |
||
1146 | */ |
||
1147 | public static function is_development_mode() { |
||
1168 | |||
1169 | /** |
||
1170 | * Get Jetpack development mode notice text and notice class. |
||
1171 | * |
||
1172 | * Mirrors the checks made in Jetpack::is_development_mode |
||
1173 | * |
||
1174 | */ |
||
1175 | public static function show_development_mode_notice() { |
||
1215 | |||
1216 | /** |
||
1217 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1218 | */ |
||
1219 | public static function is_development_version() { |
||
1222 | |||
1223 | /** |
||
1224 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1225 | */ |
||
1226 | public static function is_user_connected( $user_id = false ) { |
||
1234 | |||
1235 | /** |
||
1236 | * Get the wpcom user data of the current|specified connected user. |
||
1237 | */ |
||
1238 | public static function get_connected_user_data( $user_id = null ) { |
||
1262 | |||
1263 | /** |
||
1264 | * Get the wpcom email of the current|specified connected user. |
||
1265 | */ |
||
1266 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
1280 | |||
1281 | /** |
||
1282 | * Get the wpcom email of the master user. |
||
1283 | */ |
||
1284 | public static function get_master_user_email() { |
||
1291 | |||
1292 | function current_user_is_connection_owner() { |
||
1296 | |||
1297 | /** |
||
1298 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
1299 | */ |
||
1300 | function extra_oembed_providers() { |
||
1308 | |||
1309 | /** |
||
1310 | * Synchronize connected user role changes |
||
1311 | */ |
||
1312 | function user_role_change( $user_id ) { |
||
1316 | |||
1317 | /** |
||
1318 | * Loads the currently active modules. |
||
1319 | */ |
||
1320 | public static function load_modules() { |
||
1404 | |||
1405 | /** |
||
1406 | * Check if Jetpack's REST API compat file should be included |
||
1407 | * @action plugins_loaded |
||
1408 | * @return null |
||
1409 | */ |
||
1410 | public function check_rest_api_compat() { |
||
1426 | |||
1427 | /** |
||
1428 | * Gets all plugins currently active in values, regardless of whether they're |
||
1429 | * traditionally activated or network activated. |
||
1430 | * |
||
1431 | * @todo Store the result in core's object cache maybe? |
||
1432 | */ |
||
1433 | public static function get_active_plugins() { |
||
1449 | |||
1450 | /** |
||
1451 | * Gets and parses additional plugin data to send with the heartbeat data |
||
1452 | * |
||
1453 | * @since 3.8.1 |
||
1454 | * |
||
1455 | * @return array Array of plugin data |
||
1456 | */ |
||
1457 | public static function get_parsed_plugin_data() { |
||
1478 | |||
1479 | /** |
||
1480 | * Gets and parses theme data to send with the heartbeat data |
||
1481 | * |
||
1482 | * @since 3.8.1 |
||
1483 | * |
||
1484 | * @return array Array of theme data |
||
1485 | */ |
||
1486 | public static function get_parsed_theme_data() { |
||
1508 | |||
1509 | /** |
||
1510 | * Checks whether a specific plugin is active. |
||
1511 | * |
||
1512 | * We don't want to store these in a static variable, in case |
||
1513 | * there are switch_to_blog() calls involved. |
||
1514 | */ |
||
1515 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
1518 | |||
1519 | /** |
||
1520 | * Check if Jetpack's Open Graph tags should be used. |
||
1521 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
1522 | * |
||
1523 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
1524 | * @action plugins_loaded |
||
1525 | * @return null |
||
1526 | */ |
||
1527 | public function check_open_graph() { |
||
1554 | |||
1555 | /** |
||
1556 | * Check if Jetpack's Twitter tags should be used. |
||
1557 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
1558 | * |
||
1559 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
1560 | * @action plugins_loaded |
||
1561 | * @return null |
||
1562 | */ |
||
1563 | public function check_twitter_tags() { |
||
1587 | |||
1588 | /** |
||
1589 | * Allows plugins to submit security reports. |
||
1590 | * |
||
1591 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
1592 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
1593 | * @param array $args See definitions above |
||
1594 | */ |
||
1595 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
1598 | |||
1599 | /* Jetpack Options API */ |
||
1600 | |||
1601 | public static function get_option_names( $type = 'compact' ) { |
||
1604 | |||
1605 | /** |
||
1606 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
1607 | * |
||
1608 | * @param string $name Option name |
||
1609 | * @param mixed $default (optional) |
||
1610 | */ |
||
1611 | public static function get_option( $name, $default = false ) { |
||
1614 | |||
1615 | /** |
||
1616 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
1617 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
1618 | * $name must be a registered option name. |
||
1619 | */ |
||
1620 | public static function create_nonce( $name ) { |
||
1634 | |||
1635 | /** |
||
1636 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
1637 | * |
||
1638 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
1639 | * @param string $name Option name |
||
1640 | * @param mixed $value Option value |
||
1641 | */ |
||
1642 | public static function update_option( $name, $value ) { |
||
1646 | |||
1647 | /** |
||
1648 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
1649 | * |
||
1650 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
1651 | * @param array $array array( option name => option value, ... ) |
||
1652 | */ |
||
1653 | public static function update_options( $array ) { |
||
1657 | |||
1658 | /** |
||
1659 | * Deletes the given option. May be passed multiple option names as an array. |
||
1660 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
1661 | * |
||
1662 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
1663 | * @param string|array $names |
||
1664 | */ |
||
1665 | public static function delete_option( $names ) { |
||
1669 | |||
1670 | /** |
||
1671 | * Enters a user token into the user_tokens option |
||
1672 | * |
||
1673 | * @param int $user_id |
||
1674 | * @param string $token |
||
1675 | * return bool |
||
1676 | */ |
||
1677 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
1691 | |||
1692 | /** |
||
1693 | * Returns an array of all PHP files in the specified absolute path. |
||
1694 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
1695 | * |
||
1696 | * @param string $absolute_path The absolute path of the directory to search. |
||
1697 | * @return array Array of absolute paths to the PHP files. |
||
1698 | */ |
||
1699 | public static function glob_php( $absolute_path ) { |
||
1728 | |||
1729 | public static function activate_new_modules( $redirect = false ) { |
||
1787 | |||
1788 | /** |
||
1789 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
1790 | * Make sure to tuck away module "library" files in a sub-directory. |
||
1791 | */ |
||
1792 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
1849 | |||
1850 | /** |
||
1851 | * Default modules loaded on activation. |
||
1852 | */ |
||
1853 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
1884 | |||
1885 | /** |
||
1886 | * Checks activated modules during auto-activation to determine |
||
1887 | * if any of those modules are being deprecated. If so, close |
||
1888 | * them out, and add any replacement modules. |
||
1889 | * |
||
1890 | * Runs at priority 99 by default. |
||
1891 | * |
||
1892 | * This is run late, so that it can still activate a module if |
||
1893 | * the new module is a replacement for another that the user |
||
1894 | * currently has active, even if something at the normal priority |
||
1895 | * would kibosh everything. |
||
1896 | * |
||
1897 | * @since 2.6 |
||
1898 | * @uses jetpack_get_default_modules filter |
||
1899 | * @param array $modules |
||
1900 | * @return array |
||
1901 | */ |
||
1902 | function handle_deprecated_modules( $modules ) { |
||
1928 | |||
1929 | /** |
||
1930 | * Checks activated plugins during auto-activation to determine |
||
1931 | * if any of those plugins are in the list with a corresponding module |
||
1932 | * that is not compatible with the plugin. The module will not be allowed |
||
1933 | * to auto-activate. |
||
1934 | * |
||
1935 | * @since 2.6 |
||
1936 | * @uses jetpack_get_default_modules filter |
||
1937 | * @param array $modules |
||
1938 | * @return array |
||
1939 | */ |
||
1940 | function filter_default_modules( $modules ) { |
||
1964 | |||
1965 | /** |
||
1966 | * Extract a module's slug from its full path. |
||
1967 | */ |
||
1968 | public static function get_module_slug( $file ) { |
||
1971 | |||
1972 | /** |
||
1973 | * Generate a module's path from its slug. |
||
1974 | */ |
||
1975 | public static function get_module_path( $slug ) { |
||
1978 | |||
1979 | /** |
||
1980 | * Load module data from module file. Headers differ from WordPress |
||
1981 | * plugin headers to avoid them being identified as standalone |
||
1982 | * plugins on the WordPress plugins page. |
||
1983 | */ |
||
1984 | public static function get_module( $module ) { |
||
2067 | |||
2068 | /** |
||
2069 | * Like core's get_file_data implementation, but caches the result. |
||
2070 | */ |
||
2071 | public static function get_file_data( $file, $headers ) { |
||
2092 | |||
2093 | /** |
||
2094 | * Return translated module tag. |
||
2095 | * |
||
2096 | * @param string $tag Tag as it appears in each module heading. |
||
2097 | * |
||
2098 | * @return mixed |
||
2099 | */ |
||
2100 | public static function translate_module_tag( $tag ) { |
||
2103 | |||
2104 | /** |
||
2105 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2106 | * |
||
2107 | * @since 3.9.2 |
||
2108 | * |
||
2109 | * @param array $modules |
||
2110 | * |
||
2111 | * @return string|void |
||
2112 | */ |
||
2113 | public static function get_translated_modules( $modules ) { |
||
2126 | |||
2127 | /** |
||
2128 | * Get a list of activated modules as an array of module slugs. |
||
2129 | */ |
||
2130 | public static function get_active_modules() { |
||
2147 | |||
2148 | /** |
||
2149 | * Check whether or not a Jetpack module is active. |
||
2150 | * |
||
2151 | * @param string $module The slug of a Jetpack module. |
||
2152 | * @return bool |
||
2153 | * |
||
2154 | * @static |
||
2155 | */ |
||
2156 | public static function is_module_active( $module ) { |
||
2159 | |||
2160 | public static function is_module( $module ) { |
||
2163 | |||
2164 | /** |
||
2165 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2166 | * |
||
2167 | * @param bool $catch True to start catching, False to stop. |
||
2168 | * |
||
2169 | * @static |
||
2170 | */ |
||
2171 | public static function catch_errors( $catch ) { |
||
2184 | |||
2185 | /** |
||
2186 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2187 | */ |
||
2188 | public static function catch_errors_on_shutdown() { |
||
2191 | |||
2192 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
2309 | |||
2310 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
2311 | /** |
||
2312 | * Fires before a module is activated. |
||
2313 | * |
||
2314 | * @since 2.6.0 |
||
2315 | * |
||
2316 | * @param string $module Module slug. |
||
2317 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
2318 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
2319 | */ |
||
2320 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
2321 | |||
2322 | $jetpack = Jetpack::init(); |
||
2323 | |||
2324 | if ( ! strlen( $module ) ) |
||
2325 | return false; |
||
2326 | |||
2327 | if ( ! Jetpack::is_module( $module ) ) |
||
2328 | return false; |
||
2329 | |||
2330 | // If it's already active, then don't do it again |
||
2331 | $active = Jetpack::get_active_modules(); |
||
2332 | foreach ( $active as $act ) { |
||
2333 | if ( $act == $module ) |
||
2334 | return true; |
||
2335 | } |
||
2336 | |||
2337 | $module_data = Jetpack::get_module( $module ); |
||
2338 | |||
2339 | if ( ! Jetpack::is_active() ) { |
||
2340 | if ( !Jetpack::is_development_mode() ) |
||
2341 | return false; |
||
2342 | |||
2343 | // If we're not connected but in development mode, make sure the module doesn't require a connection |
||
2344 | if ( Jetpack::is_development_mode() && $module_data['requires_connection'] ) |
||
2345 | return false; |
||
2346 | } |
||
2347 | |||
2348 | // Check and see if the old plugin is active |
||
2349 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
2350 | // Deactivate the old plugin |
||
2351 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
2352 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
2353 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
2354 | Jetpack::state( 'deactivated_plugins', $module ); |
||
2355 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
2356 | exit; |
||
2357 | } |
||
2358 | } |
||
2359 | |||
2360 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
2361 | Jetpack::state( 'module', $module ); |
||
2362 | Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
2363 | |||
2364 | Jetpack::catch_errors( true ); |
||
2365 | ob_start(); |
||
2366 | require Jetpack::get_module_path( $module ); |
||
2367 | |||
2368 | $active[] = $module; |
||
2369 | Jetpack::update_active_modules( $active ); |
||
2370 | |||
2371 | Jetpack::state( 'error', false ); // the override |
||
2372 | ob_end_clean(); |
||
2373 | Jetpack::catch_errors( false ); |
||
2374 | |||
2375 | // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. |
||
2376 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
2377 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
2378 | |||
2379 | //Jump start is being dismissed send data to MC Stats |
||
2380 | $jetpack->stat( 'jumpstart', 'manual,'.$module ); |
||
2381 | |||
2382 | $jetpack->do_stats( 'server_side' ); |
||
2383 | } |
||
2384 | |||
2385 | if ( $redirect ) { |
||
2386 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
2387 | } |
||
2388 | if ( $exit ) { |
||
2389 | exit; |
||
2390 | } |
||
2391 | return true; |
||
2392 | } |
||
2393 | |||
2394 | function activate_module_actions( $module ) { |
||
2397 | |||
2398 | public static function deactivate_module( $module ) { |
||
2399 | /** |
||
2400 | * Fires when a module is deactivated. |
||
2401 | * |
||
2402 | * @since 1.9.0 |
||
2403 | * |
||
2404 | * @param string $module Module slug. |
||
2405 | */ |
||
2406 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
2407 | |||
2408 | $jetpack = Jetpack::init(); |
||
2409 | |||
2410 | $active = Jetpack::get_active_modules(); |
||
2411 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
2412 | |||
2413 | // A flag for Jump Start so it's not shown again. |
||
2414 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
2415 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
2416 | |||
2417 | //Jump start is being dismissed send data to MC Stats |
||
2418 | $jetpack->stat( 'jumpstart', 'manual,deactivated-'.$module ); |
||
2419 | |||
2420 | $jetpack->do_stats( 'server_side' ); |
||
2421 | } |
||
2422 | |||
2423 | return self::update_active_modules( $new ); |
||
2424 | } |
||
2425 | |||
2426 | public static function enable_module_configurable( $module ) { |
||
2430 | |||
2431 | public static function module_configuration_url( $module ) { |
||
2435 | |||
2436 | public static function module_configuration_load( $module, $method ) { |
||
2440 | |||
2441 | public static function module_configuration_head( $module, $method ) { |
||
2445 | |||
2446 | public static function module_configuration_screen( $module, $method ) { |
||
2450 | |||
2451 | public static function module_configuration_activation_screen( $module, $method ) { |
||
2455 | |||
2456 | /* Installation */ |
||
2457 | |||
2458 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
2498 | |||
2499 | /** |
||
2500 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
2501 | * @static |
||
2502 | */ |
||
2503 | public static function plugin_activation( $network_wide ) { |
||
2515 | /** |
||
2516 | * Runs before bumping version numbers up to a new version |
||
2517 | * @param (string) $version Version:timestamp |
||
2518 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
2519 | * @return null [description] |
||
2520 | */ |
||
2521 | public static function do_version_bump( $version, $old_version ) { |
||
2528 | |||
2529 | /** |
||
2530 | * Sets the internal version number and activation state. |
||
2531 | * @static |
||
2532 | */ |
||
2533 | public static function plugin_initialize() { |
||
2549 | |||
2550 | /** |
||
2551 | * Removes all connection options |
||
2552 | * @static |
||
2553 | */ |
||
2554 | public static function plugin_deactivation( ) { |
||
2563 | |||
2564 | /** |
||
2565 | * Disconnects from the Jetpack servers. |
||
2566 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
2567 | * @static |
||
2568 | */ |
||
2569 | public static function disconnect( $update_activated_state = true ) { |
||
2619 | |||
2620 | /** |
||
2621 | * Unlinks the current user from the linked WordPress.com user |
||
2622 | */ |
||
2623 | public static function unlink_user( $user_id = null ) { |
||
2654 | |||
2655 | /** |
||
2656 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
2657 | */ |
||
2658 | public static function try_registration() { |
||
2683 | |||
2684 | /** |
||
2685 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
2686 | * |
||
2687 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
2688 | */ |
||
2689 | public static function log( $code, $data = null ) { |
||
2729 | |||
2730 | /** |
||
2731 | * Get the internal event log. |
||
2732 | * |
||
2733 | * @param $event (string) - only return the specific log events |
||
2734 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
2735 | * |
||
2736 | * @return array of log events || WP_Error for invalid params |
||
2737 | */ |
||
2738 | public static function get_log( $event = false, $num = false ) { |
||
2774 | |||
2775 | /** |
||
2776 | * Log modification of important settings. |
||
2777 | */ |
||
2778 | public static function log_settings_change( $option, $old_value, $value ) { |
||
2785 | |||
2786 | /** |
||
2787 | * Return stat data for WPCOM sync |
||
2788 | */ |
||
2789 | function get_stat_data() { |
||
2795 | |||
2796 | /** |
||
2797 | * Get additional stat data to sync to WPCOM |
||
2798 | */ |
||
2799 | function get_additional_stat_data( $prefix = '' ) { |
||
2809 | |||
2810 | /* Admin Pages */ |
||
2811 | |||
2812 | function admin_init() { |
||
2866 | |||
2867 | function admin_body_class( $admin_body_class = '' ) { |
||
2875 | |||
2876 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
2879 | |||
2880 | function prepare_connect_notice() { |
||
2888 | /** |
||
2889 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
2890 | * |
||
2891 | * @return null |
||
2892 | */ |
||
2893 | function prepare_manage_jetpack_notice() { |
||
2898 | |||
2899 | function manage_activate_screen() { |
||
2902 | /** |
||
2903 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
2904 | * This function artificially throws errors for such cases (whitelisted). |
||
2905 | * |
||
2906 | * @param string $plugin The activated plugin. |
||
2907 | */ |
||
2908 | function throw_error_on_activate_plugin( $plugin ) { |
||
2932 | |||
2933 | function intercept_plugin_error_scrape_init() { |
||
2936 | |||
2937 | function intercept_plugin_error_scrape( $action, $result ) { |
||
2948 | |||
2949 | function add_remote_request_handlers() { |
||
2952 | |||
2953 | function remote_request_handlers() { |
||
2987 | |||
2988 | function upload_handler() { |
||
3073 | |||
3074 | /** |
||
3075 | * Add help to the Jetpack page |
||
3076 | * |
||
3077 | * @since Jetpack (1.2.3) |
||
3078 | * @return false if not the Jetpack page |
||
3079 | */ |
||
3080 | function admin_help() { |
||
3121 | |||
3122 | function admin_menu_css() { |
||
3125 | |||
3126 | function admin_menu_order() { |
||
3129 | |||
3130 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
3145 | |||
3146 | function admin_head() { |
||
3151 | |||
3152 | View Code Duplication | function admin_banner_styles() { |
|
3159 | |||
3160 | function admin_scripts() { |
||
3173 | |||
3174 | function plugin_action_links( $actions ) { |
||
3189 | |||
3190 | function admin_connect_notice() { |
||
3225 | |||
3226 | /** |
||
3227 | * This is the first banner |
||
3228 | * It should be visible only to user that can update the option |
||
3229 | * Are not connected |
||
3230 | * |
||
3231 | * @return null |
||
3232 | */ |
||
3233 | function admin_jetpack_manage_notice() { |
||
3268 | |||
3269 | /** |
||
3270 | * Returns the url that the user clicks to remove the notice for the big banner |
||
3271 | * @return (string) |
||
3272 | */ |
||
3273 | function opt_out_jetpack_manage_url() { |
||
3277 | /** |
||
3278 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
3279 | * @return (string) |
||
3280 | */ |
||
3281 | function opt_in_jetpack_manage_url() { |
||
3284 | |||
3285 | function opt_in_jetpack_manage_notice() { |
||
3295 | /** |
||
3296 | * Determines whether to show the notice of not true = display notice |
||
3297 | * @return (bool) |
||
3298 | */ |
||
3299 | function can_display_jetpack_manage_notice() { |
||
3321 | |||
3322 | function network_connect_notice() { |
||
3331 | |||
3332 | /* |
||
3333 | * Registration flow: |
||
3334 | * 1 - ::admin_page_load() action=register |
||
3335 | * 2 - ::try_registration() |
||
3336 | * 3 - ::register() |
||
3337 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
3338 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
3339 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
3340 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
3341 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
3342 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
3343 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
3344 | * jetpack_id, jetpack_secret, jetpack_public |
||
3345 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
3346 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
3347 | * 5 - user logs in with WP.com account |
||
3348 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
3349 | * - Jetpack_Client_Server::authorize() |
||
3350 | * - Jetpack_Client_Server::get_token() |
||
3351 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
3352 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
3353 | * - which responds with access_token, token_type, scope |
||
3354 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
3355 | * - Jetpack::activate_default_modules() |
||
3356 | * - Deactivates deprecated plugins |
||
3357 | * - Activates all default modules |
||
3358 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
3359 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
3360 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
3361 | * Done! |
||
3362 | */ |
||
3363 | |||
3364 | /** |
||
3365 | * Handles the page load events for the Jetpack admin page |
||
3366 | */ |
||
3367 | function admin_page_load() { |
||
3593 | |||
3594 | function admin_notices() { |
||
3691 | |||
3692 | /** |
||
3693 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
3694 | */ |
||
3695 | function stat( $group, $detail ) { |
||
3700 | |||
3701 | /** |
||
3702 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
3703 | */ |
||
3704 | function do_stats( $method = '' ) { |
||
3719 | |||
3720 | /** |
||
3721 | * Runs stats code for a one-off, server-side. |
||
3722 | * |
||
3723 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
3724 | * |
||
3725 | * @return bool If it worked. |
||
3726 | */ |
||
3727 | static function do_server_side_stat( $args ) { |
||
3737 | |||
3738 | /** |
||
3739 | * Builds the stats url. |
||
3740 | * |
||
3741 | * @param $args array|string The arguments to append to the URL. |
||
3742 | * |
||
3743 | * @return string The URL to be pinged. |
||
3744 | */ |
||
3745 | static function build_stats_url( $args ) { |
||
3765 | |||
3766 | static function translate_current_user_to_role() { |
||
3775 | |||
3776 | static function translate_role_to_cap( $role ) { |
||
3783 | |||
3784 | static function sign_role( $role ) { |
||
3796 | |||
3797 | |||
3798 | /** |
||
3799 | * Builds a URL to the Jetpack connection auth page |
||
3800 | * |
||
3801 | * @since 3.9.5 |
||
3802 | * |
||
3803 | * @param bool $raw If true, URL will not be escaped. |
||
3804 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
3805 | * If string, will be a custom redirect. |
||
3806 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
3807 | * |
||
3808 | * @return string Connect URL |
||
3809 | */ |
||
3810 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
3884 | |||
3885 | function build_reconnect_url( $raw = false ) { |
||
3889 | |||
3890 | public static function admin_url( $args = null ) { |
||
3895 | |||
3896 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
3900 | |||
3901 | function dismiss_jetpack_notice() { |
||
3975 | |||
3976 | function debugger_page() { |
||
3984 | |||
3985 | public static function admin_screen_configure_module( $module_id ) { |
||
4037 | |||
4038 | /** |
||
4039 | * Display link to activate the module to see the settings screen. |
||
4040 | * @param string $module_id |
||
4041 | * @return null |
||
4042 | */ |
||
4043 | public static function display_activate_module_link( $module_id ) { |
||
4095 | |||
4096 | public static function sort_modules( $a, $b ) { |
||
4102 | |||
4103 | function ajax_recheck_ssl() { |
||
4111 | |||
4112 | /* Client API */ |
||
4113 | |||
4114 | /** |
||
4115 | * Returns the requested Jetpack API URL |
||
4116 | * |
||
4117 | * @return string |
||
4118 | */ |
||
4119 | public static function api_url( $relative_url ) { |
||
4122 | |||
4123 | /** |
||
4124 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
4125 | */ |
||
4126 | public static function fix_url_for_bad_hosts( $url ) { |
||
4142 | |||
4143 | /** |
||
4144 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
4145 | * |
||
4146 | * @since 2.3.3 |
||
4147 | * @return boolean |
||
4148 | */ |
||
4149 | public static function permit_ssl( $force_recheck = false ) { |
||
4191 | |||
4192 | /* |
||
4193 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
4194 | */ |
||
4195 | public function alert_auto_ssl_fail() { |
||
4244 | |||
4245 | /** |
||
4246 | * Returns the Jetpack XML-RPC API |
||
4247 | * |
||
4248 | * @return string |
||
4249 | */ |
||
4250 | public static function xmlrpc_api_url() { |
||
4254 | |||
4255 | /** |
||
4256 | * Creates two secret tokens and the end of life timestamp for them. |
||
4257 | * |
||
4258 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
4259 | * |
||
4260 | * @since 2.6 |
||
4261 | * @return array |
||
4262 | */ |
||
4263 | public function generate_secrets( $action, $exp = 600 ) { |
||
4271 | |||
4272 | /** |
||
4273 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
4274 | * |
||
4275 | * Based on local php max_execution_time in php.ini |
||
4276 | * |
||
4277 | * @since 2.6 |
||
4278 | * @return int |
||
4279 | **/ |
||
4280 | public function get_remote_query_timeout_limit() { |
||
4286 | |||
4287 | |||
4288 | /** |
||
4289 | * Takes the response from the Jetpack register new site endpoint and |
||
4290 | * verifies it worked properly. |
||
4291 | * |
||
4292 | * @since 2.6 |
||
4293 | * @return true or Jetpack_Error |
||
4294 | **/ |
||
4295 | public function validate_remote_register_response( $response ) { |
||
4330 | /** |
||
4331 | * @return bool|WP_Error |
||
4332 | */ |
||
4333 | public static function register() { |
||
4430 | |||
4431 | /** |
||
4432 | * If the db version is showing something other that what we've got now, bump it to current. |
||
4433 | * |
||
4434 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
4435 | */ |
||
4436 | public static function maybe_set_version_option() { |
||
4450 | |||
4451 | /* Client Server API */ |
||
4452 | |||
4453 | /** |
||
4454 | * Loads the Jetpack XML-RPC client |
||
4455 | */ |
||
4456 | public static function load_xml_rpc_client() { |
||
4460 | |||
4461 | function verify_xml_rpc_signature() { |
||
4559 | |||
4560 | /** |
||
4561 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
4562 | */ |
||
4563 | function authenticate_jetpack( $user, $username, $password ) { |
||
4586 | |||
4587 | function add_nonce( $timestamp, $nonce ) { |
||
4625 | |||
4626 | /** |
||
4627 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
4628 | * Capture it here so we can verify the signature later. |
||
4629 | */ |
||
4630 | function xmlrpc_methods( $methods ) { |
||
4634 | |||
4635 | function public_xmlrpc_methods( $methods ) { |
||
4641 | |||
4642 | function jetpack_getOptions( $args ) { |
||
4682 | |||
4683 | function xmlrpc_options( $options ) { |
||
4701 | |||
4702 | public static function clean_nonces( $all = false ) { |
||
4727 | |||
4728 | /** |
||
4729 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
4730 | * SET: state( $key, $value ); |
||
4731 | * GET: $value = state( $key ); |
||
4732 | * |
||
4733 | * @param string $key |
||
4734 | * @param string $value |
||
4735 | * @param bool $restate private |
||
4736 | */ |
||
4737 | public static function state( $key = null, $value = null, $restate = false ) { |
||
4787 | |||
4788 | public static function restate() { |
||
4791 | |||
4792 | public static function check_privacy( $file ) { |
||
4827 | |||
4828 | /** |
||
4829 | * Helper method for multicall XMLRPC. |
||
4830 | */ |
||
4831 | public static function xmlrpc_async_call() { |
||
4873 | |||
4874 | public static function staticize_subdomain( $url ) { |
||
4909 | |||
4910 | /* JSON API Authorization */ |
||
4911 | |||
4912 | /** |
||
4913 | * Handles the login action for Authorizing the JSON API |
||
4914 | */ |
||
4915 | function login_form_json_api_authorization() { |
||
4924 | |||
4925 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
4926 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
4939 | |||
4940 | // Make sure the POSTed request is handled by the same action |
||
4941 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
4945 | |||
4946 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
4947 | function store_json_api_authorization_token( $user_login, $user ) { |
||
4953 | |||
4954 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
4955 | function allow_wpcom_public_api_domain( $domains ) { |
||
4959 | |||
4960 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
4961 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
4973 | |||
4974 | // Verifies the request by checking the signature |
||
4975 | function verify_json_api_authorization_request() { |
||
5054 | |||
5055 | function login_message_json_api_authorization( $message ) { |
||
5061 | |||
5062 | /** |
||
5063 | * Get $content_width, but with a <s>twist</s> filter. |
||
5064 | */ |
||
5065 | public static function get_content_width() { |
||
5076 | |||
5077 | /** |
||
5078 | * Centralize the function here until it gets added to core. |
||
5079 | * |
||
5080 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
5081 | * @param int $size Size of the avatar image |
||
5082 | * @param string $default URL to a default image to use if no avatar is available |
||
5083 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
5084 | * |
||
5085 | * @return array First element is the URL, second is the class. |
||
5086 | */ |
||
5087 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
5115 | |||
5116 | /** |
||
5117 | * Pings the WordPress.com Mirror Site for the specified options. |
||
5118 | * |
||
5119 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
5120 | * |
||
5121 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
5122 | */ |
||
5123 | public function get_cloud_site_options( $option_names ) { |
||
5139 | |||
5140 | /** |
||
5141 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
5142 | * |
||
5143 | * @return array An array of options to check. |
||
5144 | */ |
||
5145 | public static function identity_crisis_options_to_check() { |
||
5151 | |||
5152 | /** |
||
5153 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
5154 | * |
||
5155 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
5156 | * |
||
5157 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
5158 | */ |
||
5159 | public static function check_identity_crisis( $force_recheck = false ) { |
||
5225 | |||
5226 | /* |
||
5227 | * Resolve ID crisis |
||
5228 | * |
||
5229 | * If the URL has changed, but the rest of the options are the same (i.e. blog/user tokens) |
||
5230 | * The user has the option to update the shadow site with the new URL before a new |
||
5231 | * token is created. |
||
5232 | * |
||
5233 | * @param $key : Which option to sync. null defautlts to home and siteurl |
||
5234 | */ |
||
5235 | public static function resolve_identity_crisis( $key = null ) { |
||
5255 | |||
5256 | /* |
||
5257 | * Whitelist URL |
||
5258 | * |
||
5259 | * Ignore the URL differences between the blog and the shadow site. |
||
5260 | */ |
||
5261 | public static function whitelist_current_url() { |
||
5269 | |||
5270 | /* |
||
5271 | * Ajax callbacks for ID crisis resolutions |
||
5272 | * |
||
5273 | * Things that could happen here: |
||
5274 | * - site_migrated : Update the URL on the shadow blog to match new domain |
||
5275 | * - whitelist : Ignore the URL difference |
||
5276 | * - default : Error message |
||
5277 | */ |
||
5278 | public static function resolve_identity_crisis_ajax_callback() { |
||
5318 | |||
5319 | /** |
||
5320 | * Adds a value to the whitelist for the specified key. |
||
5321 | * |
||
5322 | * @param string $key The option name that we're whitelisting the value for. |
||
5323 | * @param string $value The value that we're intending to add to the whitelist. |
||
5324 | * |
||
5325 | * @return bool Whether the value was added to the whitelist, or false if it was already there. |
||
5326 | */ |
||
5327 | public static function whitelist_identity_crisis_value( $key, $value ) { |
||
5341 | |||
5342 | /** |
||
5343 | * Checks whether a value is already whitelisted. |
||
5344 | * |
||
5345 | * @param string $key The option name that we're checking the value for. |
||
5346 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
5347 | * |
||
5348 | * @return bool Whether the value is whitelisted. |
||
5349 | */ |
||
5350 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
5357 | |||
5358 | /** |
||
5359 | * Checks whether the home and siteurl specifically are whitelisted |
||
5360 | * Written so that we don't have re-check $key and $value params every time |
||
5361 | * we want to check if this site is whitelisted, for example in footer.php |
||
5362 | * |
||
5363 | * @return bool True = already whitelisted False = not whitelisted |
||
5364 | */ |
||
5365 | public static function is_staging_site() { |
||
5366 | $is_staging = false; |
||
5367 | |||
5368 | $current_whitelist = Jetpack_Options::get_option( 'identity_crisis_whitelist' ); |
||
5369 | if ( $current_whitelist && ! get_transient( 'jetpack_checked_is_staging' ) ) { |
||
5370 | $options_to_check = Jetpack::identity_crisis_options_to_check(); |
||
5371 | $cloud_options = Jetpack::init()->get_cloud_site_options( $options_to_check ); |
||
5372 | |||
5373 | foreach ( $cloud_options as $cloud_key => $cloud_value ) { |
||
5374 | if ( self::is_identity_crisis_value_whitelisted( $cloud_key, $cloud_value ) ) { |
||
5375 | $is_staging = true; |
||
5376 | break; |
||
5377 | } |
||
5378 | } |
||
5379 | // set a flag so we don't check again for an hour |
||
5380 | set_transient( 'jetpack_checked_is_staging', 1, HOUR_IN_SECONDS ); |
||
5381 | } |
||
5382 | $known_staging = array( |
||
5383 | 'urls' => array( |
||
5384 | '#\.staging\.wpengine\.com$#i', // WP Engine |
||
5385 | ), |
||
5386 | 'constants' => array( |
||
5387 | 'IS_WPE_SNAPSHOT', // WP Engine |
||
5388 | 'KINSTA_DEV_ENV', // Kinsta.com |
||
5389 | 'WPSTAGECOACH_STAGING', // WP Stagecoach |
||
5390 | 'JETPACK_STAGING_MODE', // Generic |
||
5391 | ) |
||
5392 | ); |
||
5393 | /** |
||
5394 | * Filters the flags of known staging sites. |
||
5395 | * |
||
5396 | * @since 3.9.0 |
||
5397 | * |
||
5398 | * @param array $known_staging { |
||
5399 | * An array of arrays that each are used to check if the current site is staging. |
||
5400 | * @type array $urls URLs of staging sites in regex to check against site_url. |
||
5401 | * @type array $constants PHP constants of known staging/developement environments. |
||
5402 | * } |
||
5403 | */ |
||
5404 | $known_staging = apply_filters( 'jetpack_known_staging', $known_staging ); |
||
5405 | |||
5406 | if ( isset( $known_staging['urls'] ) ) { |
||
5407 | foreach ( $known_staging['urls'] as $url ){ |
||
5408 | if ( preg_match( $url, site_url() ) ) { |
||
5409 | $is_staging = true; |
||
5410 | break; |
||
5411 | } |
||
5412 | } |
||
5413 | } |
||
5414 | |||
5415 | if ( isset( $known_staging['constants'] ) ) { |
||
5416 | foreach ( $known_staging['constants'] as $constant ) { |
||
5417 | if ( defined( $constant ) && constant( $constant ) ) { |
||
5418 | $is_staging = true; |
||
5419 | } |
||
5420 | } |
||
5421 | } |
||
5422 | |||
5423 | /** |
||
5424 | * Filters is_staging_site check. |
||
5425 | * |
||
5426 | * @since 3.9.0 |
||
5427 | * |
||
5428 | * @param bool $is_staging If the current site is a staging site. |
||
5429 | */ |
||
5430 | return apply_filters( 'jetpack_is_staging_site', $is_staging ); |
||
5431 | } |
||
5432 | |||
5433 | public function identity_crisis_js( $nonce ) { |
||
5503 | |||
5504 | /** |
||
5505 | * Maybe Use a .min.css stylesheet, maybe not. |
||
5506 | * |
||
5507 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
5508 | */ |
||
5509 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
5544 | |||
5545 | /** |
||
5546 | * Maybe inlines a stylesheet. |
||
5547 | * |
||
5548 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
5549 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
5550 | * |
||
5551 | * Attached to `style_loader_tag` filter. |
||
5552 | * |
||
5553 | * @param string $tag The tag that would link to the external asset. |
||
5554 | * @param string $handle The registered handle of the script in question. |
||
5555 | * |
||
5556 | * @return string |
||
5557 | */ |
||
5558 | public static function maybe_inline_style( $tag, $handle ) { |
||
5608 | |||
5609 | /** |
||
5610 | * Loads a view file from the views |
||
5611 | * |
||
5612 | * Data passed in with the $data parameter will be available in the |
||
5613 | * template file as $data['value'] |
||
5614 | * |
||
5615 | * @param string $template - Template file to load |
||
5616 | * @param array $data - Any data to pass along to the template |
||
5617 | * @return boolean - If template file was found |
||
5618 | **/ |
||
5619 | public function load_view( $template, $data = array() ) { |
||
5630 | |||
5631 | /** |
||
5632 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
5633 | */ |
||
5634 | public function deprecated_hooks() { |
||
5676 | |||
5677 | /** |
||
5678 | * Converts any url in a stylesheet, to the correct absolute url. |
||
5679 | * |
||
5680 | * Considerations: |
||
5681 | * - Normal, relative URLs `feh.png` |
||
5682 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
5683 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
5684 | * - Absolute URLs `http://domain.com/feh.png` |
||
5685 | * - Domain root relative URLs `/feh.png` |
||
5686 | * |
||
5687 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
5688 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
5689 | * |
||
5690 | * @return mixed|string |
||
5691 | */ |
||
5692 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
5736 | |||
5737 | /** |
||
5738 | * This method checks to see if SSL is required by the site in |
||
5739 | * order to visit it in some way other than only setting the |
||
5740 | * https value in the home or siteurl values. |
||
5741 | * |
||
5742 | * @since 3.2 |
||
5743 | * @return boolean |
||
5744 | **/ |
||
5745 | private function is_ssl_required_to_visit_site() { |
||
5746 | global $wp_version; |
||
5747 | $ssl = is_ssl(); |
||
5748 | |||
5749 | if ( force_ssl_admin() ) { |
||
5750 | $ssl = true; |
||
5751 | } |
||
5752 | return $ssl; |
||
5753 | } |
||
5754 | |||
5755 | /** |
||
5756 | * This methods removes all of the registered css files on the front end |
||
5757 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
5758 | * all the files into one file. |
||
5759 | * |
||
5760 | * Pros: |
||
5761 | * - Uses only ONE css asset connection instead of 15 |
||
5762 | * - Saves a minimum of 56k |
||
5763 | * - Reduces server load |
||
5764 | * - Reduces time to first painted byte |
||
5765 | * |
||
5766 | * Cons: |
||
5767 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
5768 | * should not cause any issues with themes. |
||
5769 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
5770 | * jetpack_implode_frontend_css filter for a workaround |
||
5771 | * |
||
5772 | * For some situations developers may wish to disable css imploding and |
||
5773 | * instead operate in legacy mode where each file loads seperately and |
||
5774 | * can be edited individually or dequeued. This can be accomplished with |
||
5775 | * the following line: |
||
5776 | * |
||
5777 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
5778 | * |
||
5779 | * @since 3.2 |
||
5780 | **/ |
||
5781 | public function implode_frontend_css( $travis_test = false ) { |
||
5833 | |||
5834 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
5844 | |||
5845 | /* |
||
5846 | * Check the heartbeat data |
||
5847 | * |
||
5848 | * Organizes the heartbeat data by severity. For example, if the site |
||
5849 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
5850 | * |
||
5851 | * Data will be added to "caution" array, if it either: |
||
5852 | * - Out of date Jetpack version |
||
5853 | * - Out of date WP version |
||
5854 | * - Out of date PHP version |
||
5855 | * |
||
5856 | * $return array $filtered_data |
||
5857 | */ |
||
5858 | public static function jetpack_check_heartbeat_data() { |
||
5911 | |||
5912 | |||
5913 | /* |
||
5914 | * This method is used to organize all options that can be reset |
||
5915 | * without disconnecting Jetpack. |
||
5916 | * |
||
5917 | * It is used in class.jetpack-cli.php to reset options |
||
5918 | * |
||
5919 | * @return array of options to delete. |
||
5920 | */ |
||
5921 | public static function get_jetpack_options_for_reset() { |
||
5988 | |||
5989 | /** |
||
5990 | * Check if an option of a Jetpack module has been updated. |
||
5991 | * |
||
5992 | * If any module option has been updated before Jump Start has been dismissed, |
||
5993 | * update the 'jumpstart' option so we can hide Jump Start. |
||
5994 | * |
||
5995 | * @param string $option_name |
||
5996 | * |
||
5997 | * @return bool |
||
5998 | */ |
||
5999 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
6020 | |||
6021 | /* |
||
6022 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
6023 | * so we can bring them directly to their site in calypso. |
||
6024 | * |
||
6025 | * @param string | url |
||
6026 | * @return string | url without the guff |
||
6027 | */ |
||
6028 | public static function build_raw_urls( $url ) { |
||
6034 | |||
6035 | /** |
||
6036 | * Stores and prints out domains to prefetch for page speed optimization. |
||
6037 | * |
||
6038 | * @param mixed $new_urls |
||
6039 | */ |
||
6040 | public static function dns_prefetch( $new_urls = null ) { |
||
6057 | |||
6058 | public function wp_dashboard_setup() { |
||
6086 | |||
6087 | /** |
||
6088 | * @param mixed $result Value for the user's option |
||
6089 | * @return mixed |
||
6090 | */ |
||
6091 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
6116 | |||
6117 | public static function dashboard_widget() { |
||
6125 | |||
6126 | public static function dashboard_widget_footer() { |
||
6159 | |||
6160 | public function dashboard_widget_connect_to_wpcom() { |
||
6182 | |||
6183 | /* |
||
6184 | * A graceful transition to using Core's site icon. |
||
6185 | * |
||
6186 | * All of the hard work has already been done with the image |
||
6187 | * in all_done_page(). All that needs to be done now is update |
||
6188 | * the option and display proper messaging. |
||
6189 | * |
||
6190 | * @todo remove when WP 4.3 is minimum |
||
6191 | * |
||
6192 | * @since 3.6.1 |
||
6193 | * |
||
6194 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
6195 | */ |
||
6196 | public static function jetpack_site_icon_available_in_core() { |
||
6231 | |||
6232 | /** |
||
6233 | * Return string containing the Jetpack logo. |
||
6234 | * |
||
6235 | * @since 3.9.0 |
||
6236 | * |
||
6237 | * @return string |
||
6238 | */ |
||
6239 | public static function get_jp_emblem() { |
||
6242 | |||
6243 | /* |
||
6244 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
6245 | */ |
||
6246 | function jetpack_icon_user_connected( $columns ) { |
||
6250 | |||
6251 | /* |
||
6252 | * Show Jetpack icon if the user is linked. |
||
6253 | */ |
||
6254 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
6266 | |||
6267 | /* |
||
6268 | * Style the Jetpack user column |
||
6269 | */ |
||
6270 | function jetpack_user_col_style() { |
||
6283 | |||
6284 | } |
||
6285 |
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.