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 | public $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 | * Allows us to build a temporary security report |
||
283 | * |
||
284 | * @var array |
||
285 | */ |
||
286 | static $security_report = array(); |
||
|
|||
287 | |||
288 | /** |
||
289 | * Jetpack_Sync object |
||
290 | */ |
||
291 | public $sync; |
||
292 | |||
293 | /** |
||
294 | * Verified data for JSON authorization request |
||
295 | */ |
||
296 | public $json_api_authorization_request = array(); |
||
297 | |||
298 | /** |
||
299 | * Holds the singleton instance of this class |
||
300 | * @since 2.3.3 |
||
301 | * @var Jetpack |
||
302 | */ |
||
303 | static $instance = false; |
||
304 | |||
305 | /** |
||
306 | * Singleton |
||
307 | * @static |
||
308 | */ |
||
309 | public static function init() { |
||
310 | if ( ! self::$instance ) { |
||
311 | if ( did_action( 'plugins_loaded' ) ) |
||
312 | self::plugin_textdomain(); |
||
313 | else |
||
314 | add_action( 'plugins_loaded', array( __CLASS__, 'plugin_textdomain' ), 99 ); |
||
315 | |||
316 | self::$instance = new Jetpack; |
||
317 | |||
318 | self::$instance->plugin_upgrade(); |
||
319 | |||
320 | } |
||
321 | |||
322 | return self::$instance; |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * Must never be called statically |
||
327 | */ |
||
328 | function plugin_upgrade() { |
||
329 | if ( Jetpack::is_active() ) { |
||
330 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
331 | if ( JETPACK__VERSION != $version ) { |
||
332 | |||
333 | // Check which active modules actually exist and remove others from active_modules list |
||
334 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
335 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
336 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
337 | Jetpack_Options::update_option( 'active_modules', $modules ); |
||
338 | } |
||
339 | |||
340 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
341 | /** |
||
342 | * Fires when synchronizing all registered options and constants. |
||
343 | * |
||
344 | * @since 3.3.0 |
||
345 | */ |
||
346 | do_action( 'jetpack_sync_all_registered_options' ); |
||
347 | |||
348 | Jetpack::maybe_set_version_option(); |
||
349 | } |
||
350 | } |
||
351 | } |
||
352 | |||
353 | static function activate_manage( ) { |
||
354 | |||
355 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
356 | self::activate_module( 'manage', false, false ); |
||
357 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
358 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
359 | } |
||
360 | |||
361 | } |
||
362 | |||
363 | /** |
||
364 | * Constructor. Initializes WordPress hooks |
||
365 | */ |
||
366 | private function __construct() { |
||
367 | /* |
||
368 | * Check for and alert any deprecated hooks |
||
369 | */ |
||
370 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
371 | |||
372 | /** |
||
373 | * We need sync object even in Multisite mode |
||
374 | */ |
||
375 | $this->sync = new Jetpack_Sync; |
||
376 | |||
377 | /** |
||
378 | * Trigger a wp_version sync when updating WP versions |
||
379 | **/ |
||
380 | add_action( 'upgrader_process_complete', array( 'Jetpack', 'update_get_wp_version' ), 10, 2 ); |
||
381 | $this->sync->mock_option( 'wp_version', array( 'Jetpack', 'get_wp_version' ) ); |
||
382 | |||
383 | add_action( 'init', array( $this, 'sync_update_data') ); |
||
384 | add_action( 'init', array( $this, 'sync_theme_data' ) ); |
||
385 | |||
386 | /* |
||
387 | * Load things that should only be in Network Admin. |
||
388 | * |
||
389 | * For now blow away everything else until a more full |
||
390 | * understanding of what is needed at the network level is |
||
391 | * available |
||
392 | */ |
||
393 | if( is_multisite() ) { |
||
394 | Jetpack_Network::init(); |
||
395 | |||
396 | // Only sync this info if we are on a multi site |
||
397 | // @since 3.7 |
||
398 | $this->sync->mock_option( 'network_name', array( 'Jetpack', 'network_name' ) ); |
||
399 | $this->sync->mock_option( 'network_allow_new_registrations', array( 'Jetpack', 'network_allow_new_registrations' ) ); |
||
400 | $this->sync->mock_option( 'network_add_new_users', array( 'Jetpack', 'network_add_new_users' ) ); |
||
401 | $this->sync->mock_option( 'network_site_upload_space', array( 'Jetpack', 'network_site_upload_space' ) ); |
||
402 | $this->sync->mock_option( 'network_upload_file_types', array( 'Jetpack', 'network_upload_file_types' ) ); |
||
403 | $this->sync->mock_option( 'network_enable_administration_menus', array( 'Jetpack', 'network_enable_administration_menus' ) ); |
||
404 | |||
405 | if( is_network_admin() ) { |
||
406 | // Sync network site data if it is updated or not. |
||
407 | add_action( 'update_wpmu_options', array( $this, 'update_jetpack_network_settings' ) ); |
||
408 | return; // End here to prevent single site actions from firing |
||
409 | } |
||
410 | } |
||
411 | |||
412 | |||
413 | $theme_slug = get_option( 'stylesheet' ); |
||
414 | |||
415 | |||
416 | // Modules should do Jetpack_Sync::sync_options( __FILE__, $option, ... ); instead |
||
417 | // We access the "internal" method here only because the Jetpack object isn't instantiated yet |
||
418 | $this->sync->options( |
||
419 | JETPACK__PLUGIN_DIR . 'jetpack.php', |
||
420 | 'home', |
||
421 | 'siteurl', |
||
422 | 'blogname', |
||
423 | 'gmt_offset', |
||
424 | 'timezone_string', |
||
425 | 'security_report', |
||
426 | 'stylesheet', |
||
427 | "theme_mods_{$theme_slug}", |
||
428 | 'jetpack_sync_non_public_post_stati', |
||
429 | 'jetpack_options', |
||
430 | 'site_icon', // (int) - ID of core's Site Icon attachment ID |
||
431 | 'default_post_format', |
||
432 | 'default_category', |
||
433 | 'large_size_w', |
||
434 | 'large_size_h', |
||
435 | 'thumbnail_size_w', |
||
436 | 'thumbnail_size_h', |
||
437 | 'medium_size_w', |
||
438 | 'medium_size_h', |
||
439 | 'thumbnail_crop', |
||
440 | 'image_default_link_type' |
||
441 | ); |
||
442 | |||
443 | foreach( Jetpack_Options::get_option_names( 'non-compact' ) as $option ) { |
||
444 | $this->sync->options( __FILE__, 'jetpack_' . $option ); |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * Sometimes you want to sync data to .com without adding options to .org sites. |
||
449 | * The mock option allows you to do just that. |
||
450 | */ |
||
451 | $this->sync->mock_option( 'is_main_network', array( $this, 'is_main_network_option' ) ); |
||
452 | $this->sync->mock_option( 'is_multi_site', array( $this, 'is_multisite' ) ); |
||
453 | $this->sync->mock_option( 'main_network_site', array( $this, 'jetpack_main_network_site_option' ) ); |
||
454 | $this->sync->mock_option( 'single_user_site', array( 'Jetpack', 'is_single_user_site' ) ); |
||
455 | $this->sync->mock_option( 'stat_data', array( $this, 'get_stat_data' ) ); |
||
456 | |||
457 | $this->sync->mock_option( 'has_file_system_write_access', array( 'Jetpack', 'file_system_write_access' ) ); |
||
458 | $this->sync->mock_option( 'is_version_controlled', array( 'Jetpack', 'is_version_controlled' ) ); |
||
459 | $this->sync->mock_option( 'max_upload_size', 'wp_max_upload_size' ); |
||
460 | $this->sync->mock_option( 'content_width', array( 'Jetpack', 'get_content_width' ) ); |
||
461 | |||
462 | /** |
||
463 | * Trigger an update to the main_network_site when we update the blogname of a site. |
||
464 | * |
||
465 | */ |
||
466 | add_action( 'update_option_siteurl', array( $this, 'update_jetpack_main_network_site_option' ) ); |
||
467 | |||
468 | add_action( 'update_option', array( $this, 'log_settings_change' ), 10, 3 ); |
||
469 | |||
470 | // Update the settings everytime the we register a new user to the site or we delete a user. |
||
471 | add_action( 'user_register', array( $this, 'is_single_user_site_invalidate' ) ); |
||
472 | add_action( 'deleted_user', array( $this, 'is_single_user_site_invalidate' ) ); |
||
473 | |||
474 | // Unlink user before deleting the user from .com |
||
475 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
476 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
477 | |||
478 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
479 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
480 | |||
481 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
482 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
483 | |||
484 | $this->require_jetpack_authentication(); |
||
485 | |||
486 | if ( Jetpack::is_active() ) { |
||
487 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
488 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
489 | |||
490 | $signed = $this->verify_xml_rpc_signature(); |
||
491 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
492 | // The actual API methods. |
||
493 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
494 | } else { |
||
495 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
496 | // active Jetpack connection, so that additional users can link their account. |
||
497 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
498 | } |
||
499 | } else { |
||
500 | // The bootstrap API methods. |
||
501 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
502 | } |
||
503 | |||
504 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
505 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
506 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
507 | $this->require_jetpack_authentication(); |
||
508 | $this->add_remote_request_handlers(); |
||
509 | } else { |
||
510 | if ( Jetpack::is_active() ) { |
||
511 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
512 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
513 | } |
||
514 | } |
||
515 | |||
516 | if ( Jetpack::is_active() ) { |
||
517 | Jetpack_Heartbeat::init(); |
||
518 | } |
||
519 | |||
520 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
521 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
522 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
523 | } |
||
524 | |||
525 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
526 | |||
527 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
528 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
529 | |||
530 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
531 | |||
532 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
533 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
534 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
535 | |||
536 | add_action( 'wp_ajax_jetpack-sync-reindex-trigger', array( $this, 'sync_reindex_trigger' ) ); |
||
537 | add_action( 'wp_ajax_jetpack-sync-reindex-status', array( $this, 'sync_reindex_status' ) ); |
||
538 | |||
539 | // returns HTTPS support status |
||
540 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
541 | |||
542 | // Jump Start AJAX callback function |
||
543 | add_action( 'wp_ajax_jetpack_jumpstart_ajax', array( $this, 'jetpack_jumpstart_ajax_callback' ) ); |
||
544 | |||
545 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
546 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
547 | |||
548 | // Identity Crisis AJAX callback function |
||
549 | add_action( 'wp_ajax_jetpack_resolve_identity_crisis', array( $this, 'resolve_identity_crisis_ajax_callback' ) ); |
||
550 | |||
551 | // JITM AJAX callback function |
||
552 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
553 | |||
554 | add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) ); |
||
555 | add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) ); |
||
556 | |||
557 | // Universal ajax callback for all tracking events triggered via js |
||
558 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
559 | |||
560 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
561 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
562 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
563 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
564 | |||
565 | add_action( 'jetpack_activate_module', array( $this, 'activate_module_actions' ) ); |
||
566 | |||
567 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
568 | |||
569 | add_action( 'jetpack_notices', array( $this, 'show_development_mode_notice' ) ); |
||
570 | |||
571 | /** |
||
572 | * These actions run checks to load additional files. |
||
573 | * They check for external files or plugins, so they need to run as late as possible. |
||
574 | */ |
||
575 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
576 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
577 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
578 | |||
579 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
580 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
581 | |||
582 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
583 | |||
584 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
585 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
586 | |||
587 | // A filter to control all just in time messages |
||
588 | add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); |
||
589 | |||
590 | /** |
||
591 | * This is the hack to concatinate all css files into one. |
||
592 | * For description and reasoning see the implode_frontend_css method |
||
593 | * |
||
594 | * Super late priority so we catch all the registered styles |
||
595 | */ |
||
596 | if( !is_admin() ) { |
||
597 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
598 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
599 | } |
||
600 | |||
601 | // Sync Core Icon: Detect changes in Core's Site Icon and make it syncable. |
||
602 | add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
603 | add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
604 | add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
605 | add_action( 'jetpack_heartbeat', array( $this, 'jetpack_sync_core_icon' ) ); |
||
606 | |||
607 | } |
||
608 | |||
609 | /* |
||
610 | * Make sure any site icon added to core can get |
||
611 | * synced back to dotcom, so we can display it there. |
||
612 | */ |
||
613 | function jetpack_sync_core_icon() { |
||
629 | |||
630 | function jetpack_admin_ajax_tracks_callback() { |
||
649 | |||
650 | function jetpack_admin_ajax_callback() { |
||
677 | |||
678 | /* |
||
679 | * Sometimes we need to refresh the data, |
||
680 | * especially if the page is visited via a 'history' |
||
681 | * event like back/forward |
||
682 | */ |
||
683 | function jetpack_admin_ajax_refresh_data() { |
||
697 | |||
698 | /** |
||
699 | * The callback for the Jump Start ajax requests. |
||
700 | */ |
||
701 | function jetpack_jumpstart_ajax_callback() { |
||
791 | |||
792 | /** |
||
793 | * The callback for the JITM ajax requests. |
||
794 | */ |
||
795 | function jetpack_jitm_ajax_callback() { |
||
852 | |||
853 | /** |
||
854 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
855 | */ |
||
856 | function __destruct() { |
||
861 | |||
862 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
863 | switch( $cap ) { |
||
864 | case 'jetpack_connect' : |
||
865 | case 'jetpack_reconnect' : |
||
866 | if ( Jetpack::is_development_mode() ) { |
||
867 | $caps = array( 'do_not_allow' ); |
||
868 | break; |
||
869 | } |
||
870 | /** |
||
871 | * Pass through. If it's not development mode, these should match disconnect. |
||
872 | * Let users disconnect if it's development mode, just in case things glitch. |
||
873 | */ |
||
874 | case 'jetpack_disconnect' : |
||
875 | /** |
||
876 | * In multisite, can individual site admins manage their own connection? |
||
877 | * |
||
878 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
879 | */ |
||
880 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
881 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
882 | /** |
||
883 | * We need to update the option name -- it's terribly unclear which |
||
884 | * direction the override goes. |
||
885 | * |
||
886 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
887 | */ |
||
888 | $caps = array( 'do_not_allow' ); |
||
889 | break; |
||
890 | } |
||
891 | } |
||
892 | |||
893 | $caps = array( 'manage_options' ); |
||
894 | break; |
||
895 | case 'jetpack_manage_modules' : |
||
896 | case 'jetpack_activate_modules' : |
||
897 | case 'jetpack_deactivate_modules' : |
||
898 | $caps = array( 'manage_options' ); |
||
899 | break; |
||
900 | case 'jetpack_configure_modules' : |
||
901 | $caps = array( 'manage_options' ); |
||
902 | break; |
||
903 | case 'jetpack_network_admin_page': |
||
904 | case 'jetpack_network_settings_page': |
||
905 | $caps = array( 'manage_network_plugins' ); |
||
906 | break; |
||
907 | case 'jetpack_network_sites_page': |
||
908 | $caps = array( 'manage_sites' ); |
||
909 | break; |
||
910 | case 'jetpack_admin_page' : |
||
911 | if ( Jetpack::is_development_mode() ) { |
||
912 | $caps = array( 'manage_options' ); |
||
913 | break; |
||
914 | } else { |
||
915 | $caps = array( 'read' ); |
||
916 | } |
||
917 | break; |
||
918 | case 'jetpack_connect_user' : |
||
919 | if ( Jetpack::is_development_mode() ) { |
||
920 | $caps = array( 'do_not_allow' ); |
||
921 | break; |
||
922 | } |
||
923 | $caps = array( 'read' ); |
||
924 | break; |
||
925 | } |
||
926 | return $caps; |
||
927 | } |
||
928 | |||
929 | function require_jetpack_authentication() { |
||
930 | // Don't let anyone authenticate |
||
931 | $_COOKIE = array(); |
||
932 | remove_all_filters( 'authenticate' ); |
||
933 | |||
934 | /** |
||
935 | * For the moment, remove Limit Login Attempts if its xmlrpc for Jetpack. |
||
936 | * If Limit Login Attempts is installed as a mu-plugin, it can occasionally |
||
937 | * generate false-positives. |
||
938 | */ |
||
939 | remove_filter( 'wp_login_failed', 'limit_login_failed' ); |
||
940 | |||
941 | if ( Jetpack::is_active() ) { |
||
942 | // Allow Jetpack authentication |
||
943 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
944 | } |
||
945 | } |
||
946 | |||
947 | /** |
||
948 | * Load language files |
||
949 | */ |
||
950 | public static function plugin_textdomain() { |
||
954 | |||
955 | /** |
||
956 | * Register assets for use in various modules and the Jetpack admin page. |
||
957 | * |
||
958 | * @uses wp_script_is, wp_register_script, plugins_url |
||
959 | * @action wp_loaded |
||
960 | * @return null |
||
961 | */ |
||
962 | public function register_assets() { |
||
1014 | |||
1015 | /** |
||
1016 | * Guess locale from language code. |
||
1017 | * |
||
1018 | * @param string $lang Language code. |
||
1019 | * @return string|bool |
||
1020 | */ |
||
1021 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
1060 | |||
1061 | /** |
||
1062 | * Get the locale. |
||
1063 | * |
||
1064 | * @return string|bool |
||
1065 | */ |
||
1066 | function get_locale() { |
||
1075 | |||
1076 | /** |
||
1077 | * Device Pixels support |
||
1078 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
1079 | */ |
||
1080 | function devicepx() { |
||
1085 | |||
1086 | /** |
||
1087 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
1088 | * @param bool $option |
||
1089 | * @return string |
||
1090 | */ |
||
1091 | public function jetpack_main_network_site_option( $option ) { |
||
1094 | /** |
||
1095 | * Network Name. |
||
1096 | */ |
||
1097 | static function network_name( $option = null ) { |
||
1101 | /** |
||
1102 | * Does the network allow new user and site registrations. |
||
1103 | * @return string |
||
1104 | */ |
||
1105 | static function network_allow_new_registrations( $option = null ) { |
||
1108 | /** |
||
1109 | * Does the network allow admins to add new users. |
||
1110 | * @return boolian |
||
1111 | */ |
||
1112 | static function network_add_new_users( $option = null ) { |
||
1115 | /** |
||
1116 | * File upload psace left per site in MB. |
||
1117 | * -1 means NO LIMIT. |
||
1118 | * @return number |
||
1119 | */ |
||
1120 | static function network_site_upload_space( $option = null ) { |
||
1124 | |||
1125 | /** |
||
1126 | * Network allowed file types. |
||
1127 | * @return string |
||
1128 | */ |
||
1129 | static function network_upload_file_types( $option = null ) { |
||
1132 | |||
1133 | /** |
||
1134 | * Maximum file upload size set by the network. |
||
1135 | * @return number |
||
1136 | */ |
||
1137 | static function network_max_upload_file_size( $option = null ) { |
||
1141 | |||
1142 | /** |
||
1143 | * Lets us know if a site allows admins to manage the network. |
||
1144 | * @return array |
||
1145 | */ |
||
1146 | static function network_enable_administration_menus( $option = null ) { |
||
1149 | |||
1150 | /** |
||
1151 | * Return whether we are dealing with a multi network setup or not. |
||
1152 | * The reason we are type casting this is because we want to avoid the situation where |
||
1153 | * the result is false since when is_main_network_option return false it cases |
||
1154 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
1155 | * database which could be set to anything as opposed to what this function returns. |
||
1156 | * @param bool $option |
||
1157 | * |
||
1158 | * @return boolean |
||
1159 | */ |
||
1160 | public function is_main_network_option( $option ) { |
||
1164 | |||
1165 | /** |
||
1166 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
1167 | * |
||
1168 | * @param string $option |
||
1169 | * @return boolean |
||
1170 | */ |
||
1171 | public function is_multisite( $option ) { |
||
1174 | |||
1175 | /** |
||
1176 | * Implemented since there is no core is multi network function |
||
1177 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
1178 | * |
||
1179 | * @since 3.3 |
||
1180 | * @return boolean |
||
1181 | */ |
||
1182 | public static function is_multi_network() { |
||
1197 | |||
1198 | /** |
||
1199 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1200 | * @return null |
||
1201 | */ |
||
1202 | function update_jetpack_main_network_site_option() { |
||
1235 | /** |
||
1236 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1237 | * |
||
1238 | */ |
||
1239 | function update_jetpack_network_settings() { |
||
1249 | |||
1250 | /** |
||
1251 | * Get back if the current site is single user site. |
||
1252 | * |
||
1253 | * @return bool |
||
1254 | */ |
||
1255 | public static function is_single_user_site() { |
||
1264 | |||
1265 | /** |
||
1266 | * Returns true if the site has file write access false otherwise. |
||
1267 | * @return string ( '1' | '0' ) |
||
1268 | **/ |
||
1269 | public static function file_system_write_access() { |
||
1289 | |||
1290 | /** |
||
1291 | * Finds out if a site is using a version control system. |
||
1292 | * @return string ( '1' | '0' ) |
||
1293 | **/ |
||
1294 | public static function is_version_controlled() { |
||
1307 | |||
1308 | /** |
||
1309 | * Determines whether the current theme supports featured images or not. |
||
1310 | * @return string ( '1' | '0' ) |
||
1311 | */ |
||
1312 | public static function featured_images_enabled() { |
||
1315 | |||
1316 | /* |
||
1317 | * Sync back wp_version |
||
1318 | */ |
||
1319 | public static function get_wp_version() { |
||
1323 | |||
1324 | /** |
||
1325 | * Keeps wp_version in sync with .com when WordPress core updates |
||
1326 | **/ |
||
1327 | public static function update_get_wp_version( $update, $meta_data ) { |
||
1337 | |||
1338 | /** |
||
1339 | * Triggers a sync of update counts and update details |
||
1340 | */ |
||
1341 | function sync_update_data() { |
||
1357 | |||
1358 | /** |
||
1359 | * Triggers a sync of information specific to the current theme. |
||
1360 | */ |
||
1361 | function sync_theme_data() { |
||
1365 | |||
1366 | /** |
||
1367 | * jetpack_updates is saved in the following schema: |
||
1368 | * |
||
1369 | * array ( |
||
1370 | * 'plugins' => (int) Number of plugin updates available. |
||
1371 | * 'themes' => (int) Number of theme updates available. |
||
1372 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1373 | * 'translations' => (int) Number of translation updates available. |
||
1374 | * 'total' => (int) Total of all available updates. |
||
1375 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1376 | * ) |
||
1377 | * @return array |
||
1378 | */ |
||
1379 | public static function get_updates() { |
||
1396 | |||
1397 | public static function get_update_details() { |
||
1405 | |||
1406 | public static function refresh_update_data() { |
||
1430 | |||
1431 | public static function refresh_theme_data() { |
||
1442 | |||
1443 | /** |
||
1444 | * Invalides the transient as well as triggers the update of the mock option. |
||
1445 | * |
||
1446 | * @return null |
||
1447 | */ |
||
1448 | function is_single_user_site_invalidate() { |
||
1460 | |||
1461 | /** |
||
1462 | * Is Jetpack active? |
||
1463 | */ |
||
1464 | public static function is_active() { |
||
1467 | |||
1468 | /** |
||
1469 | * Is Jetpack in development (offline) mode? |
||
1470 | */ |
||
1471 | public static function is_development_mode() { |
||
1492 | |||
1493 | /** |
||
1494 | * Get Jetpack development mode notice text and notice class. |
||
1495 | * |
||
1496 | * Mirrors the checks made in Jetpack::is_development_mode |
||
1497 | * |
||
1498 | */ |
||
1499 | public static function show_development_mode_notice() { |
||
1500 | if ( Jetpack::is_development_mode() ) { |
||
1501 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
1502 | $notice = sprintf( |
||
1503 | /* translators: %s is a URL */ |
||
1504 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), |
||
1505 | 'https://jetpack.com/support/development-mode/' |
||
1506 | ); |
||
1507 | } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
1508 | $notice = sprintf( |
||
1509 | /* translators: %s is a URL */ |
||
1510 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), |
||
1511 | 'https://jetpack.com/support/development-mode/' |
||
1512 | ); |
||
1513 | } else { |
||
1514 | $notice = sprintf( |
||
1515 | /* translators: %s is a URL */ |
||
1516 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), |
||
1517 | 'https://jetpack.com/support/development-mode/' |
||
1518 | ); |
||
1519 | } |
||
1520 | |||
1521 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1522 | } |
||
1523 | |||
1524 | // Throw up a notice if using a development version and as for feedback. |
||
1525 | if ( Jetpack::is_development_version() ) { |
||
1526 | /* translators: %s is a URL */ |
||
1527 | $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.com/contact-support/beta-group/' ); |
||
1528 | |||
1529 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1530 | } |
||
1531 | // Throw up a notice if using staging mode |
||
1532 | if ( Jetpack::is_staging_site() ) { |
||
1533 | /* translators: %s is a URL */ |
||
1534 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); |
||
1535 | |||
1536 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1537 | } |
||
1538 | } |
||
1539 | |||
1540 | /** |
||
1541 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1542 | */ |
||
1543 | public static function is_development_version() { |
||
1546 | |||
1547 | /** |
||
1548 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1549 | */ |
||
1550 | public static function is_user_connected( $user_id = false ) { |
||
1557 | |||
1558 | /** |
||
1559 | * Get the wpcom user data of the current|specified connected user. |
||
1560 | */ |
||
1561 | View Code Duplication | public static function get_connected_user_data( $user_id = null ) { |
|
1575 | |||
1576 | /** |
||
1577 | * Get the wpcom email of the current|specified connected user. |
||
1578 | */ |
||
1579 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
1593 | |||
1594 | /** |
||
1595 | * Get the wpcom email of the master user. |
||
1596 | */ |
||
1597 | public static function get_master_user_email() { |
||
1604 | |||
1605 | function current_user_is_connection_owner() { |
||
1609 | |||
1610 | /** |
||
1611 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
1612 | */ |
||
1613 | function extra_oembed_providers() { |
||
1621 | |||
1622 | /** |
||
1623 | * Synchronize connected user role changes |
||
1624 | */ |
||
1625 | function user_role_change( $user_id ) { |
||
1668 | |||
1669 | /** |
||
1670 | * Loads the currently active modules. |
||
1671 | */ |
||
1672 | public static function load_modules() { |
||
1756 | |||
1757 | /** |
||
1758 | * Check if Jetpack's REST API compat file should be included |
||
1759 | * @action plugins_loaded |
||
1760 | * @return null |
||
1761 | */ |
||
1762 | public function check_rest_api_compat() { |
||
1778 | |||
1779 | /** |
||
1780 | * Gets all plugins currently active in values, regardless of whether they're |
||
1781 | * traditionally activated or network activated. |
||
1782 | * |
||
1783 | * @todo Store the result in core's object cache maybe? |
||
1784 | */ |
||
1785 | public static function get_active_plugins() { |
||
1801 | |||
1802 | /** |
||
1803 | * Gets and parses additional plugin data to send with the heartbeat data |
||
1804 | * |
||
1805 | * @since 3.8.1 |
||
1806 | * |
||
1807 | * @return array Array of plugin data |
||
1808 | */ |
||
1809 | public static function get_parsed_plugin_data() { |
||
1829 | |||
1830 | /** |
||
1831 | * Gets and parses theme data to send with the heartbeat data |
||
1832 | * |
||
1833 | * @since 3.8.1 |
||
1834 | * |
||
1835 | * @return array Array of theme data |
||
1836 | */ |
||
1837 | public static function get_parsed_theme_data() { |
||
1859 | |||
1860 | /** |
||
1861 | * Checks whether a specific plugin is active. |
||
1862 | * |
||
1863 | * We don't want to store these in a static variable, in case |
||
1864 | * there are switch_to_blog() calls involved. |
||
1865 | */ |
||
1866 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
1869 | |||
1870 | /** |
||
1871 | * Check if Jetpack's Open Graph tags should be used. |
||
1872 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
1873 | * |
||
1874 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
1875 | * @action plugins_loaded |
||
1876 | * @return null |
||
1877 | */ |
||
1878 | public function check_open_graph() { |
||
1905 | |||
1906 | /** |
||
1907 | * Check if Jetpack's Twitter tags should be used. |
||
1908 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
1909 | * |
||
1910 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
1911 | * @action plugins_loaded |
||
1912 | * @return null |
||
1913 | */ |
||
1914 | public function check_twitter_tags() { |
||
1938 | |||
1939 | |||
1940 | |||
1941 | |||
1942 | /* |
||
1943 | * |
||
1944 | * Jetpack Security Reports |
||
1945 | * |
||
1946 | * Allowed types: login_form, backup, file_scanning, spam |
||
1947 | * |
||
1948 | * Args for login_form and spam: 'blocked'=>(int)(optional), 'status'=>(string)(ok, warning, error), 'message'=>(optional, disregarded if status is ok, allowed tags: a, em, strong) |
||
1949 | * |
||
1950 | * Args for backup and file_scanning: 'last'=>(timestamp)(optional), 'next'=>(timestamp)(optional), 'status'=>(string)(ok, warning, error), 'message'=>(optional, disregarded if status is ok, allowed tags: a, em, strong) |
||
1951 | * |
||
1952 | * |
||
1953 | * Example code to submit a security report: |
||
1954 | * |
||
1955 | * function akismet_submit_jetpack_security_report() { |
||
1956 | * Jetpack::submit_security_report( 'spam', __FILE__, $args = array( 'blocked' => 138284, status => 'ok' ) ); |
||
1957 | * } |
||
1958 | * add_action( 'jetpack_security_report', 'akismet_submit_jetpack_security_report' ); |
||
1959 | * |
||
1960 | */ |
||
1961 | |||
1962 | |||
1963 | /** |
||
1964 | * Calls for security report submissions. |
||
1965 | * |
||
1966 | * @return null |
||
1967 | */ |
||
1968 | public static function perform_security_reporting() { |
||
1985 | |||
1986 | /** |
||
1987 | * Allows plugins to submit security reports. |
||
1988 | * |
||
1989 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
1990 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
1991 | * @param array $args See definitions above |
||
1992 | */ |
||
1993 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
2057 | |||
2058 | /** |
||
2059 | * Collects a new report if needed, then returns it. |
||
2060 | */ |
||
2061 | public function get_security_report() { |
||
2065 | |||
2066 | |||
2067 | /* Jetpack Options API */ |
||
2068 | |||
2069 | public static function get_option_names( $type = 'compact' ) { |
||
2072 | |||
2073 | /** |
||
2074 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
2075 | * |
||
2076 | * @param string $name Option name |
||
2077 | * @param mixed $default (optional) |
||
2078 | */ |
||
2079 | public static function get_option( $name, $default = false ) { |
||
2082 | |||
2083 | /** |
||
2084 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
2085 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
2086 | * $name must be a registered option name. |
||
2087 | */ |
||
2088 | public static function create_nonce( $name ) { |
||
2102 | |||
2103 | /** |
||
2104 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
2105 | * |
||
2106 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
2107 | * @param string $name Option name |
||
2108 | * @param mixed $value Option value |
||
2109 | */ |
||
2110 | public static function update_option( $name, $value ) { |
||
2114 | |||
2115 | /** |
||
2116 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
2117 | * |
||
2118 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
2119 | * @param array $array array( option name => option value, ... ) |
||
2120 | */ |
||
2121 | public static function update_options( $array ) { |
||
2125 | |||
2126 | /** |
||
2127 | * Deletes the given option. May be passed multiple option names as an array. |
||
2128 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
2129 | * |
||
2130 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
2131 | * @param string|array $names |
||
2132 | */ |
||
2133 | public static function delete_option( $names ) { |
||
2137 | |||
2138 | /** |
||
2139 | * Enters a user token into the user_tokens option |
||
2140 | * |
||
2141 | * @param int $user_id |
||
2142 | * @param string $token |
||
2143 | * return bool |
||
2144 | */ |
||
2145 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
2159 | |||
2160 | /** |
||
2161 | * Returns an array of all PHP files in the specified absolute path. |
||
2162 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
2163 | * |
||
2164 | * @param string $absolute_path The absolute path of the directory to search. |
||
2165 | * @return array Array of absolute paths to the PHP files. |
||
2166 | */ |
||
2167 | public static function glob_php( $absolute_path ) { |
||
2196 | |||
2197 | public static function activate_new_modules( $redirect = false ) { |
||
2255 | |||
2256 | /** |
||
2257 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
2258 | * Make sure to tuck away module "library" files in a sub-directory. |
||
2259 | */ |
||
2260 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
2317 | |||
2318 | /** |
||
2319 | * Default modules loaded on activation. |
||
2320 | */ |
||
2321 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
2352 | |||
2353 | /** |
||
2354 | * Checks activated modules during auto-activation to determine |
||
2355 | * if any of those modules are being deprecated. If so, close |
||
2356 | * them out, and add any replacement modules. |
||
2357 | * |
||
2358 | * Runs at priority 99 by default. |
||
2359 | * |
||
2360 | * This is run late, so that it can still activate a module if |
||
2361 | * the new module is a replacement for another that the user |
||
2362 | * currently has active, even if something at the normal priority |
||
2363 | * would kibosh everything. |
||
2364 | * |
||
2365 | * @since 2.6 |
||
2366 | * @uses jetpack_get_default_modules filter |
||
2367 | * @param array $modules |
||
2368 | * @return array |
||
2369 | */ |
||
2370 | function handle_deprecated_modules( $modules ) { |
||
2396 | |||
2397 | /** |
||
2398 | * Checks activated plugins during auto-activation to determine |
||
2399 | * if any of those plugins are in the list with a corresponding module |
||
2400 | * that is not compatible with the plugin. The module will not be allowed |
||
2401 | * to auto-activate. |
||
2402 | * |
||
2403 | * @since 2.6 |
||
2404 | * @uses jetpack_get_default_modules filter |
||
2405 | * @param array $modules |
||
2406 | * @return array |
||
2407 | */ |
||
2408 | function filter_default_modules( $modules ) { |
||
2432 | |||
2433 | /** |
||
2434 | * Extract a module's slug from its full path. |
||
2435 | */ |
||
2436 | public static function get_module_slug( $file ) { |
||
2439 | |||
2440 | /** |
||
2441 | * Generate a module's path from its slug. |
||
2442 | */ |
||
2443 | public static function get_module_path( $slug ) { |
||
2446 | |||
2447 | /** |
||
2448 | * Load module data from module file. Headers differ from WordPress |
||
2449 | * plugin headers to avoid them being identified as standalone |
||
2450 | * plugins on the WordPress plugins page. |
||
2451 | */ |
||
2452 | public static function get_module( $module ) { |
||
2535 | |||
2536 | /** |
||
2537 | * Like core's get_file_data implementation, but caches the result. |
||
2538 | */ |
||
2539 | public static function get_file_data( $file, $headers ) { |
||
2560 | |||
2561 | /** |
||
2562 | * Return translated module tag. |
||
2563 | * |
||
2564 | * @param string $tag Tag as it appears in each module heading. |
||
2565 | * |
||
2566 | * @return mixed |
||
2567 | */ |
||
2568 | public static function translate_module_tag( $tag ) { |
||
2571 | |||
2572 | /** |
||
2573 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2574 | * |
||
2575 | * @since 3.9.2 |
||
2576 | * |
||
2577 | * @param array $modules |
||
2578 | * |
||
2579 | * @return string|void |
||
2580 | */ |
||
2581 | public static function get_translated_modules( $modules ) { |
||
2582 | foreach ( $modules as $index => $module ) { |
||
2583 | $i18n_module = jetpack_get_module_i18n( $module['module'] ); |
||
2584 | if ( isset( $module['name'] ) ) { |
||
2585 | $modules[ $index ]['name'] = $i18n_module['name']; |
||
2586 | } |
||
2587 | if ( isset( $module['description'] ) ) { |
||
2588 | $modules[ $index ]['description'] = $i18n_module['description']; |
||
2589 | $modules[ $index ]['short_description'] = $i18n_module['description']; |
||
2590 | } |
||
2591 | } |
||
2592 | if ( Jetpack::is_module_active( 'manage' ) ) { |
||
2593 | unset( $modules['manage'] ); |
||
2594 | } |
||
2595 | return $modules; |
||
2596 | } |
||
2597 | |||
2598 | /** |
||
2599 | * Get a list of activated modules as an array of module slugs. |
||
2600 | */ |
||
2601 | public static function get_active_modules() { |
||
2602 | $active = Jetpack_Options::get_option( 'active_modules' ); |
||
2603 | if ( ! is_array( $active ) ) |
||
2604 | $active = array(); |
||
2605 | if ( is_admin() && ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) ) { |
||
2606 | $active[] = 'vaultpress'; |
||
2607 | } else { |
||
2608 | $active = array_diff( $active, array( 'vaultpress' ) ); |
||
2609 | } |
||
2610 | |||
2611 | //If protect is active on the main site of a multisite, it should be active on all sites. |
||
2612 | if ( ! in_array( 'protect', $active ) && is_multisite() && get_site_option( 'jetpack_protect_active' ) ) { |
||
2613 | $active[] = 'protect'; |
||
2614 | } |
||
2615 | |||
2616 | return array_unique( $active ); |
||
2617 | } |
||
2618 | |||
2619 | /** |
||
2620 | * Check whether or not a Jetpack module is active. |
||
2621 | * |
||
2622 | * @param string $module The slug of a Jetpack module. |
||
2623 | * @return bool |
||
2624 | * |
||
2625 | * @static |
||
2626 | */ |
||
2627 | public static function is_module_active( $module ) { |
||
2628 | return in_array( $module, self::get_active_modules() ); |
||
2629 | } |
||
2630 | |||
2631 | public static function is_module( $module ) { |
||
2632 | return ! empty( $module ) && ! validate_file( $module, Jetpack::get_available_modules() ); |
||
2633 | } |
||
2634 | |||
2635 | /** |
||
2636 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2637 | * |
||
2638 | * @param bool $catch True to start catching, False to stop. |
||
2639 | * |
||
2640 | * @static |
||
2641 | */ |
||
2642 | public static function catch_errors( $catch ) { |
||
2643 | static $display_errors, $error_reporting; |
||
2644 | |||
2645 | if ( $catch ) { |
||
2646 | $display_errors = @ini_set( 'display_errors', 1 ); |
||
2647 | $error_reporting = @error_reporting( E_ALL ); |
||
2648 | add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
2649 | } else { |
||
2650 | @ini_set( 'display_errors', $display_errors ); |
||
2651 | @error_reporting( $error_reporting ); |
||
2652 | remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
2653 | } |
||
2654 | } |
||
2655 | |||
2656 | /** |
||
2657 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2658 | */ |
||
2659 | public static function catch_errors_on_shutdown() { |
||
2660 | Jetpack::state( 'php_errors', ob_get_clean() ); |
||
2661 | } |
||
2662 | |||
2663 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
2664 | $jetpack = Jetpack::init(); |
||
2665 | |||
2666 | $modules = Jetpack::get_default_modules( $min_version, $max_version ); |
||
2667 | $modules = array_merge( $other_modules, $modules ); |
||
2668 | |||
2669 | // Look for standalone plugins and disable if active. |
||
2670 | |||
2671 | $to_deactivate = array(); |
||
2672 | foreach ( $modules as $module ) { |
||
2673 | if ( isset( $jetpack->plugins_to_deactivate[$module] ) ) { |
||
2674 | $to_deactivate[$module] = $jetpack->plugins_to_deactivate[$module]; |
||
2675 | } |
||
2676 | } |
||
2677 | |||
2678 | $deactivated = array(); |
||
2679 | foreach ( $to_deactivate as $module => $deactivate_me ) { |
||
2680 | list( $probable_file, $probable_title ) = $deactivate_me; |
||
2681 | if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) { |
||
2682 | $deactivated[] = $module; |
||
2683 | } |
||
2684 | } |
||
2685 | |||
2686 | if ( $deactivated && $redirect ) { |
||
2687 | Jetpack::state( 'deactivated_plugins', join( ',', $deactivated ) ); |
||
2688 | |||
2689 | $url = add_query_arg( |
||
2690 | array( |
||
2691 | 'action' => 'activate_default_modules', |
||
2692 | '_wpnonce' => wp_create_nonce( 'activate_default_modules' ), |
||
2693 | ), |
||
2694 | add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), Jetpack::admin_url( 'page=jetpack' ) ) |
||
2695 | ); |
||
2696 | wp_safe_redirect( $url ); |
||
2697 | exit; |
||
2698 | } |
||
2699 | |||
2700 | /** |
||
2701 | * Fires before default modules are activated. |
||
2702 | * |
||
2703 | * @since 1.9.0 |
||
2704 | * |
||
2705 | * @param string $min_version Minimum version number required to use modules. |
||
2706 | * @param string $max_version Maximum version number required to use modules. |
||
2707 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
2708 | */ |
||
2709 | do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
2710 | |||
2711 | // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating |
||
2712 | Jetpack::restate(); |
||
2713 | Jetpack::catch_errors( true ); |
||
2714 | |||
2715 | $active = Jetpack::get_active_modules(); |
||
2716 | |||
2717 | foreach ( $modules as $module ) { |
||
2718 | if ( did_action( "jetpack_module_loaded_$module" ) ) { |
||
2719 | $active[] = $module; |
||
2720 | Jetpack_Options::update_option( 'active_modules', array_unique( $active ) ); |
||
2721 | continue; |
||
2722 | } |
||
2723 | |||
2724 | if ( in_array( $module, $active ) ) { |
||
2725 | $module_info = Jetpack::get_module( $module ); |
||
2726 | if ( ! $module_info['deactivate'] ) { |
||
2727 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
2728 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
2729 | $active_state = explode( ',', $active_state ); |
||
2730 | } else { |
||
2731 | $active_state = array(); |
||
2732 | } |
||
2733 | $active_state[] = $module; |
||
2734 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
2735 | } |
||
2736 | continue; |
||
2737 | } |
||
2738 | |||
2739 | $file = Jetpack::get_module_path( $module ); |
||
2740 | if ( ! file_exists( $file ) ) { |
||
2741 | continue; |
||
2742 | } |
||
2743 | |||
2744 | // we'll override this later if the plugin can be included without fatal error |
||
2745 | if ( $redirect ) { |
||
2746 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
2747 | } |
||
2748 | Jetpack::state( 'error', 'module_activation_failed' ); |
||
2749 | Jetpack::state( 'module', $module ); |
||
2750 | ob_start(); |
||
2751 | require $file; |
||
2752 | /** |
||
2753 | * Fires when a specific module is activated. |
||
2754 | * |
||
2755 | * @since 1.9.0 |
||
2756 | * |
||
2757 | * @param string $module Module slug. |
||
2758 | */ |
||
2759 | do_action( 'jetpack_activate_module', $module ); |
||
2760 | $active[] = $module; |
||
2761 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
2762 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
2763 | $active_state = explode( ',', $active_state ); |
||
2764 | } else { |
||
2765 | $active_state = array(); |
||
2766 | } |
||
2767 | $active_state[] = $module; |
||
2768 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
2769 | Jetpack_Options::update_option( 'active_modules', array_unique( $active ) ); |
||
2770 | ob_end_clean(); |
||
2771 | } |
||
2772 | Jetpack::state( 'error', false ); |
||
2773 | Jetpack::state( 'module', false ); |
||
2774 | Jetpack::catch_errors( false ); |
||
2775 | /** |
||
2776 | * Fires when default modules are activated. |
||
2777 | * |
||
2778 | * @since 1.9.0 |
||
2779 | * |
||
2780 | * @param string $min_version Minimum version number required to use modules. |
||
2781 | * @param string $max_version Maximum version number required to use modules. |
||
2782 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
2783 | */ |
||
2784 | do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
2785 | } |
||
2786 | |||
2787 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
2788 | /** |
||
2789 | * Fires before a module is activated. |
||
2790 | * |
||
2791 | * @since 2.6.0 |
||
2792 | * |
||
2793 | * @param string $module Module slug. |
||
2794 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
2795 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
2796 | */ |
||
2797 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
2798 | |||
2799 | $jetpack = Jetpack::init(); |
||
2800 | |||
2801 | if ( ! strlen( $module ) ) |
||
2802 | return false; |
||
2803 | |||
2804 | if ( ! Jetpack::is_module( $module ) ) |
||
2805 | return false; |
||
2806 | |||
2807 | // If it's already active, then don't do it again |
||
2808 | $active = Jetpack::get_active_modules(); |
||
2809 | foreach ( $active as $act ) { |
||
2810 | if ( $act == $module ) |
||
2811 | return true; |
||
2812 | } |
||
2813 | |||
2814 | $module_data = Jetpack::get_module( $module ); |
||
2815 | |||
2816 | if ( ! Jetpack::is_active() ) { |
||
2817 | if ( !Jetpack::is_development_mode() ) |
||
2818 | return false; |
||
2819 | |||
2820 | // If we're not connected but in development mode, make sure the module doesn't require a connection |
||
2821 | if ( Jetpack::is_development_mode() && $module_data['requires_connection'] ) |
||
2822 | return false; |
||
2823 | } |
||
2824 | |||
2825 | // Check and see if the old plugin is active |
||
2826 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
2827 | // Deactivate the old plugin |
||
2828 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
2829 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
2830 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
2831 | Jetpack::state( 'deactivated_plugins', $module ); |
||
2832 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
2833 | exit; |
||
2834 | } |
||
2835 | } |
||
2836 | |||
2837 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
2838 | Jetpack::state( 'module', $module ); |
||
2839 | Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
2840 | |||
2841 | Jetpack::catch_errors( true ); |
||
2842 | ob_start(); |
||
2843 | require Jetpack::get_module_path( $module ); |
||
2844 | /** This action is documented in class.jetpack.php */ |
||
2845 | do_action( 'jetpack_activate_module', $module ); |
||
2846 | $active[] = $module; |
||
2847 | Jetpack_Options::update_option( 'active_modules', array_unique( $active ) ); |
||
2848 | Jetpack::state( 'error', false ); // the override |
||
2849 | Jetpack::state( 'message', 'module_activated' ); |
||
2850 | Jetpack::state( 'module', $module ); |
||
2851 | ob_end_clean(); |
||
2852 | Jetpack::catch_errors( false ); |
||
2853 | |||
2854 | // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. |
||
2855 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
2856 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
2857 | |||
2858 | //Jump start is being dismissed send data to MC Stats |
||
2859 | $jetpack->stat( 'jumpstart', 'manual,'.$module ); |
||
2860 | |||
2861 | $jetpack->do_stats( 'server_side' ); |
||
2862 | } |
||
2863 | |||
2864 | if ( $redirect ) { |
||
2865 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
2866 | } |
||
2867 | if ( $exit ) { |
||
2868 | exit; |
||
2869 | } |
||
2870 | return true; |
||
2871 | } |
||
2872 | |||
2873 | function activate_module_actions( $module ) { |
||
2874 | /** |
||
2875 | * Fires when a module is activated. |
||
2876 | * The dynamic part of the filter, $module, is the module slug. |
||
2877 | * |
||
2878 | * @since 1.9.0 |
||
2879 | * |
||
2880 | * @param string $module Module slug. |
||
2881 | */ |
||
2882 | do_action( "jetpack_activate_module_$module", $module ); |
||
2883 | |||
2884 | $this->sync->sync_all_module_options( $module ); |
||
2885 | } |
||
2886 | |||
2887 | public static function deactivate_module( $module ) { |
||
2888 | /** |
||
2889 | * Fires when a module is deactivated. |
||
2890 | * |
||
2891 | * @since 1.9.0 |
||
2892 | * |
||
2893 | * @param string $module Module slug. |
||
2894 | */ |
||
2895 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
2896 | |||
2897 | $jetpack = Jetpack::init(); |
||
2898 | |||
2899 | $active = Jetpack::get_active_modules(); |
||
2900 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
2901 | |||
2902 | /** |
||
2903 | * Fires when a module is deactivated. |
||
2904 | * The dynamic part of the filter, $module, is the module slug. |
||
2905 | * |
||
2906 | * @since 1.9.0 |
||
2907 | * |
||
2908 | * @param string $module Module slug. |
||
2909 | */ |
||
2910 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
2911 | |||
2912 | // A flag for Jump Start so it's not shown again. |
||
2913 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
2914 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
2915 | |||
2916 | //Jump start is being dismissed send data to MC Stats |
||
2917 | $jetpack->stat( 'jumpstart', 'manual,deactivated-'.$module ); |
||
2918 | |||
2919 | $jetpack->do_stats( 'server_side' ); |
||
2920 | } |
||
2921 | |||
2922 | return Jetpack_Options::update_option( 'active_modules', array_unique( $new ) ); |
||
2923 | } |
||
2924 | |||
2925 | public static function enable_module_configurable( $module ) { |
||
2926 | $module = Jetpack::get_module_slug( $module ); |
||
2927 | add_filter( 'jetpack_module_configurable_' . $module, '__return_true' ); |
||
2928 | } |
||
2929 | |||
2930 | public static function module_configuration_url( $module ) { |
||
2931 | $module = Jetpack::get_module_slug( $module ); |
||
2932 | return Jetpack::admin_url( array( 'page' => 'jetpack', 'configure' => $module ) ); |
||
2933 | } |
||
2934 | |||
2935 | public static function module_configuration_load( $module, $method ) { |
||
2936 | $module = Jetpack::get_module_slug( $module ); |
||
2937 | add_action( 'jetpack_module_configuration_load_' . $module, $method ); |
||
2938 | } |
||
2939 | |||
2940 | public static function module_configuration_head( $module, $method ) { |
||
2941 | $module = Jetpack::get_module_slug( $module ); |
||
2942 | add_action( 'jetpack_module_configuration_head_' . $module, $method ); |
||
2943 | } |
||
2944 | |||
2945 | public static function module_configuration_screen( $module, $method ) { |
||
2946 | $module = Jetpack::get_module_slug( $module ); |
||
2947 | add_action( 'jetpack_module_configuration_screen_' . $module, $method ); |
||
2948 | } |
||
2949 | |||
2950 | public static function module_configuration_activation_screen( $module, $method ) { |
||
2951 | $module = Jetpack::get_module_slug( $module ); |
||
2952 | add_action( 'display_activate_module_setting_' . $module, $method ); |
||
2953 | } |
||
2954 | |||
2955 | /* Installation */ |
||
2956 | |||
2957 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
2958 | ?> |
||
2959 | <!doctype html> |
||
2960 | <html> |
||
2961 | <head> |
||
2962 | <meta charset="<?php bloginfo( 'charset' ); ?>"> |
||
2963 | <style> |
||
2964 | * { |
||
2965 | text-align: center; |
||
2966 | margin: 0; |
||
2967 | padding: 0; |
||
2968 | font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; |
||
2969 | } |
||
2970 | p { |
||
2971 | margin-top: 1em; |
||
2972 | font-size: 18px; |
||
2973 | } |
||
2974 | </style> |
||
2975 | <body> |
||
2976 | <p><?php echo esc_html( $message ); ?></p> |
||
2977 | </body> |
||
2978 | </html> |
||
2979 | <?php |
||
2980 | if ( $deactivate ) { |
||
2981 | $plugins = get_option( 'active_plugins' ); |
||
2982 | $jetpack = plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ); |
||
2983 | $update = false; |
||
2984 | foreach ( $plugins as $i => $plugin ) { |
||
2985 | if ( $plugin === $jetpack ) { |
||
2986 | $plugins[$i] = false; |
||
2987 | $update = true; |
||
2988 | } |
||
2989 | } |
||
2990 | |||
2991 | if ( $update ) { |
||
2992 | update_option( 'active_plugins', array_filter( $plugins ) ); |
||
2993 | } |
||
2994 | } |
||
2995 | exit; |
||
2996 | } |
||
2997 | |||
2998 | /** |
||
2999 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
3000 | * @static |
||
3001 | */ |
||
3002 | public static function plugin_activation( $network_wide ) { |
||
3003 | Jetpack_Options::update_option( 'activated', 1 ); |
||
3004 | |||
3005 | if ( version_compare( $GLOBALS['wp_version'], JETPACK__MINIMUM_WP_VERSION, '<' ) ) { |
||
3006 | Jetpack::bail_on_activation( sprintf( __( 'Jetpack requires WordPress version %s or later.', 'jetpack' ), JETPACK__MINIMUM_WP_VERSION ) ); |
||
3007 | } |
||
3008 | |||
3009 | if ( $network_wide ) |
||
3010 | Jetpack::state( 'network_nag', true ); |
||
3011 | |||
3012 | Jetpack::plugin_initialize(); |
||
3013 | } |
||
3014 | /** |
||
3015 | * Runs before bumping version numbers up to a new version |
||
3016 | * @param (string) $version Version:timestamp |
||
3017 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
3018 | * @return null [description] |
||
3019 | */ |
||
3020 | public static function do_version_bump( $version, $old_version ) { |
||
3021 | |||
3022 | if ( ! $old_version ) { // For new sites |
||
3023 | // Setting up jetpack manage |
||
3024 | Jetpack::activate_manage(); |
||
3025 | } |
||
3026 | } |
||
3027 | |||
3028 | /** |
||
3029 | * Sets the internal version number and activation state. |
||
3030 | * @static |
||
3031 | */ |
||
3032 | public static function plugin_initialize() { |
||
3033 | if ( ! Jetpack_Options::get_option( 'activated' ) ) { |
||
3034 | Jetpack_Options::update_option( 'activated', 2 ); |
||
3035 | } |
||
3036 | |||
3037 | View Code Duplication | if ( ! Jetpack_Options::get_option( 'version' ) ) { |
|
3038 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
3039 | /** This action is documented in class.jetpack.php */ |
||
3040 | do_action( 'updating_jetpack_version', $version, false ); |
||
3041 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
3042 | } |
||
3043 | |||
3044 | Jetpack::load_modules(); |
||
3045 | |||
3046 | Jetpack_Options::delete_option( 'do_activate' ); |
||
3047 | } |
||
3048 | |||
3049 | /** |
||
3050 | * Removes all connection options |
||
3051 | * @static |
||
3052 | */ |
||
3053 | public static function plugin_deactivation( ) { |
||
3054 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
||
3055 | if( is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
3056 | Jetpack_Network::init()->deactivate(); |
||
3057 | } else { |
||
3058 | Jetpack::disconnect( false ); |
||
3059 | //Jetpack_Heartbeat::init()->deactivate(); |
||
3060 | } |
||
3061 | } |
||
3062 | |||
3063 | /** |
||
3064 | * Disconnects from the Jetpack servers. |
||
3065 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
3066 | * @static |
||
3067 | */ |
||
3068 | public static function disconnect( $update_activated_state = true ) { |
||
3069 | wp_clear_scheduled_hook( 'jetpack_clean_nonces' ); |
||
3070 | Jetpack::clean_nonces( true ); |
||
3071 | |||
3072 | Jetpack::load_xml_rpc_client(); |
||
3073 | $xml = new Jetpack_IXR_Client(); |
||
3074 | $xml->query( 'jetpack.deregister' ); |
||
3075 | |||
3076 | Jetpack_Options::delete_option( |
||
3077 | array( |
||
3078 | 'register', |
||
3079 | 'blog_token', |
||
3080 | 'user_token', |
||
3081 | 'user_tokens', |
||
3082 | 'master_user', |
||
3083 | 'time_diff', |
||
3084 | 'fallback_no_verify_ssl_certs', |
||
3085 | ) |
||
3086 | ); |
||
3087 | |||
3088 | if ( $update_activated_state ) { |
||
3089 | Jetpack_Options::update_option( 'activated', 4 ); |
||
3090 | } |
||
3091 | |||
3092 | $jetpack_unique_connection = Jetpack_Options::get_option( 'unique_connection' ); |
||
3093 | // Check then record unique disconnection if site has never been disconnected previously |
||
3094 | if ( -1 == $jetpack_unique_connection['disconnected'] ) { |
||
3095 | $jetpack_unique_connection['disconnected'] = 1; |
||
3096 | } |
||
3097 | else { |
||
3098 | if ( 0 == $jetpack_unique_connection['disconnected'] ) { |
||
3099 | //track unique disconnect |
||
3100 | $jetpack = Jetpack::init(); |
||
3101 | |||
3102 | $jetpack->stat( 'connections', 'unique-disconnect' ); |
||
3103 | $jetpack->do_stats( 'server_side' ); |
||
3104 | } |
||
3105 | // increment number of times disconnected |
||
3106 | $jetpack_unique_connection['disconnected'] += 1; |
||
3107 | } |
||
3108 | |||
3109 | Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection ); |
||
3110 | |||
3111 | // Disable the Heartbeat cron |
||
3112 | Jetpack_Heartbeat::init()->deactivate(); |
||
3113 | } |
||
3114 | |||
3115 | /** |
||
3116 | * Unlinks the current user from the linked WordPress.com user |
||
3117 | */ |
||
3118 | public static function unlink_user( $user_id = null ) { |
||
3119 | if ( ! $tokens = Jetpack_Options::get_option( 'user_tokens' ) ) |
||
3120 | return false; |
||
3121 | |||
3122 | $user_id = empty( $user_id ) ? get_current_user_id() : intval( $user_id ); |
||
3123 | |||
3124 | if ( Jetpack_Options::get_option( 'master_user' ) == $user_id ) |
||
3125 | return false; |
||
3126 | |||
3127 | if ( ! isset( $tokens[ $user_id ] ) ) |
||
3128 | return false; |
||
3129 | |||
3130 | Jetpack::load_xml_rpc_client(); |
||
3131 | $xml = new Jetpack_IXR_Client( compact( 'user_id' ) ); |
||
3132 | $xml->query( 'jetpack.unlink_user', $user_id ); |
||
3133 | |||
3134 | unset( $tokens[ $user_id ] ); |
||
3135 | |||
3136 | Jetpack_Options::update_option( 'user_tokens', $tokens ); |
||
3137 | |||
3138 | /** |
||
3139 | * Fires after the current user has been unlinked from WordPress.com. |
||
3140 | * |
||
3141 | * @since 4.1.0 |
||
3142 | * |
||
3143 | * @param int $user_id The current user's ID. |
||
3144 | */ |
||
3145 | do_action( 'jetpack_unlinked_user', $user_id ); |
||
3146 | |||
3147 | return true; |
||
3148 | } |
||
3149 | |||
3150 | /** |
||
3151 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
3152 | */ |
||
3153 | public static function try_registration() { |
||
3154 | // Let's get some testing in beta versions and such. |
||
3155 | if ( self::is_development_version() && defined( 'PHP_URL_HOST' ) ) { |
||
3156 | // Before attempting to connect, let's make sure that the domains are viable. |
||
3157 | $domains_to_check = array_unique( array( |
||
3158 | 'siteurl' => parse_url( get_site_url(), PHP_URL_HOST ), |
||
3159 | 'homeurl' => parse_url( get_home_url(), PHP_URL_HOST ), |
||
3160 | ) ); |
||
3161 | foreach ( $domains_to_check as $domain ) { |
||
3162 | $result = Jetpack_Data::is_usable_domain( $domain ); |
||
3163 | if ( is_wp_error( $result ) ) { |
||
3164 | return $result; |
||
3165 | } |
||
3166 | } |
||
3167 | } |
||
3168 | |||
3169 | $result = Jetpack::register(); |
||
3170 | |||
3171 | // If there was an error with registration and the site was not registered, record this so we can show a message. |
||
3172 | if ( ! $result || is_wp_error( $result ) ) { |
||
3173 | return $result; |
||
3174 | } else { |
||
3175 | return true; |
||
3176 | } |
||
3177 | } |
||
3178 | |||
3179 | /** |
||
3180 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
3181 | * |
||
3182 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
3183 | */ |
||
3184 | public static function log( $code, $data = null ) { |
||
3185 | // only grab the latest 200 entries |
||
3186 | $log = array_slice( Jetpack_Options::get_option( 'log', array() ), -199, 199 ); |
||
3187 | |||
3188 | // Append our event to the log |
||
3189 | $log_entry = array( |
||
3190 | 'time' => time(), |
||
3191 | 'user_id' => get_current_user_id(), |
||
3192 | 'blog_id' => Jetpack_Options::get_option( 'id' ), |
||
3193 | 'code' => $code, |
||
3194 | ); |
||
3195 | // Don't bother storing it unless we've got some. |
||
3196 | if ( ! is_null( $data ) ) { |
||
3197 | $log_entry['data'] = $data; |
||
3198 | } |
||
3199 | $log[] = $log_entry; |
||
3200 | |||
3201 | // Try add_option first, to make sure it's not autoloaded. |
||
3202 | // @todo: Add an add_option method to Jetpack_Options |
||
3203 | if ( ! add_option( 'jetpack_log', $log, null, 'no' ) ) { |
||
3204 | Jetpack_Options::update_option( 'log', $log ); |
||
3205 | } |
||
3206 | |||
3207 | /** |
||
3208 | * Fires when Jetpack logs an internal event. |
||
3209 | * |
||
3210 | * @since 3.0.0 |
||
3211 | * |
||
3212 | * @param array $log_entry { |
||
3213 | * Array of details about the log entry. |
||
3214 | * |
||
3215 | * @param string time Time of the event. |
||
3216 | * @param int user_id ID of the user who trigerred the event. |
||
3217 | * @param int blog_id Jetpack Blog ID. |
||
3218 | * @param string code Unique name for the event. |
||
3219 | * @param string data Data about the event. |
||
3220 | * } |
||
3221 | */ |
||
3222 | do_action( 'jetpack_log_entry', $log_entry ); |
||
3223 | } |
||
3224 | |||
3225 | /** |
||
3226 | * Get the internal event log. |
||
3227 | * |
||
3228 | * @param $event (string) - only return the specific log events |
||
3229 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
3230 | * |
||
3231 | * @return array of log events || WP_Error for invalid params |
||
3232 | */ |
||
3233 | public static function get_log( $event = false, $num = false ) { |
||
3234 | if ( $event && ! is_string( $event ) ) { |
||
3235 | return new WP_Error( __( 'First param must be string or empty', 'jetpack' ) ); |
||
3236 | } |
||
3237 | |||
3238 | if ( $num && ! is_numeric( $num ) ) { |
||
3239 | return new WP_Error( __( 'Second param must be numeric or empty', 'jetpack' ) ); |
||
3240 | } |
||
3241 | |||
3242 | $entire_log = Jetpack_Options::get_option( 'log', array() ); |
||
3243 | |||
3244 | // If nothing set - act as it did before, otherwise let's start customizing the output |
||
3245 | if ( ! $num && ! $event ) { |
||
3246 | return $entire_log; |
||
3247 | } else { |
||
3248 | $entire_log = array_reverse( $entire_log ); |
||
3249 | } |
||
3250 | |||
3251 | $custom_log_output = array(); |
||
3252 | |||
3253 | if ( $event ) { |
||
3254 | foreach ( $entire_log as $log_event ) { |
||
3255 | if ( $event == $log_event[ 'code' ] ) { |
||
3256 | $custom_log_output[] = $log_event; |
||
3257 | } |
||
3258 | } |
||
3259 | } else { |
||
3260 | $custom_log_output = $entire_log; |
||
3261 | } |
||
3262 | |||
3263 | if ( $num ) { |
||
3264 | $custom_log_output = array_slice( $custom_log_output, 0, $num ); |
||
3265 | } |
||
3266 | |||
3267 | return $custom_log_output; |
||
3268 | } |
||
3269 | |||
3270 | /** |
||
3271 | * Log modification of important settings. |
||
3272 | */ |
||
3273 | public static function log_settings_change( $option, $old_value, $value ) { |
||
3274 | switch( $option ) { |
||
3275 | case 'jetpack_sync_non_public_post_stati': |
||
3276 | self::log( $option, $value ); |
||
3277 | break; |
||
3278 | } |
||
3279 | } |
||
3280 | |||
3281 | /** |
||
3282 | * Return stat data for WPCOM sync |
||
3283 | */ |
||
3284 | function get_stat_data() { |
||
3285 | $heartbeat_data = Jetpack_Heartbeat::generate_stats_array(); |
||
3286 | $additional_data = $this->get_additional_stat_data(); |
||
3287 | |||
3288 | return json_encode( array_merge( $heartbeat_data, $additional_data ) ); |
||
3289 | } |
||
3290 | |||
3291 | /** |
||
3292 | * Get additional stat data to sync to WPCOM |
||
3293 | */ |
||
3294 | function get_additional_stat_data( $prefix = '' ) { |
||
3295 | $return["{$prefix}themes"] = Jetpack::get_parsed_theme_data(); |
||
3296 | $return["{$prefix}plugins-extra"] = Jetpack::get_parsed_plugin_data(); |
||
3297 | $return["{$prefix}users"] = count_users(); |
||
3298 | $return["{$prefix}site-count"] = 0; |
||
3299 | if ( function_exists( 'get_blog_count' ) ) { |
||
3300 | $return["{$prefix}site-count"] = get_blog_count(); |
||
3301 | } |
||
3302 | return $return; |
||
3303 | } |
||
3304 | |||
3305 | /* Admin Pages */ |
||
3306 | |||
3307 | function admin_init() { |
||
3308 | // If the plugin is not connected, display a connect message. |
||
3309 | if ( |
||
3310 | // the plugin was auto-activated and needs its candy |
||
3311 | Jetpack_Options::get_option( 'do_activate' ) |
||
3312 | || |
||
3313 | // the plugin is active, but was never activated. Probably came from a site-wide network activation |
||
3314 | ! Jetpack_Options::get_option( 'activated' ) |
||
3315 | ) { |
||
3316 | Jetpack::plugin_initialize(); |
||
3317 | } |
||
3318 | |||
3319 | if ( ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) { |
||
3320 | if ( 4 != Jetpack_Options::get_option( 'activated' ) ) { |
||
3321 | // Show connect notice on dashboard and plugins pages |
||
3322 | add_action( 'load-index.php', array( $this, 'prepare_connect_notice' ) ); |
||
3323 | add_action( 'load-plugins.php', array( $this, 'prepare_connect_notice' ) ); |
||
3324 | } |
||
3325 | } elseif ( false === Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ) ) { |
||
3326 | // Upgrade: 1.1 -> 1.1.1 |
||
3327 | // Check and see if host can verify the Jetpack servers' SSL certificate |
||
3328 | $args = array(); |
||
3329 | Jetpack_Client::_wp_remote_request( |
||
3330 | Jetpack::fix_url_for_bad_hosts( Jetpack::api_url( 'test' ) ), |
||
3331 | $args, |
||
3332 | true |
||
3333 | ); |
||
3334 | } else { |
||
3335 | // Show the notice on the Dashboard only for now |
||
3336 | |||
3337 | add_action( 'load-index.php', array( $this, 'prepare_manage_jetpack_notice' ) ); |
||
3338 | } |
||
3339 | |||
3340 | // If the plugin has just been disconnected from WP.com, show the survey notice |
||
3341 | if ( isset( $_GET['disconnected'] ) && 'true' === $_GET['disconnected'] ) { |
||
3342 | add_action( 'jetpack_notices', array( $this, 'disconnect_survey_notice' ) ); |
||
3343 | } |
||
3344 | |||
3345 | if ( current_user_can( 'manage_options' ) && 'AUTO' == JETPACK_CLIENT__HTTPS && ! self::permit_ssl() ) { |
||
3346 | add_action( 'jetpack_notices', array( $this, 'alert_auto_ssl_fail' ) ); |
||
3347 | } |
||
3348 | |||
3349 | add_action( 'load-plugins.php', array( $this, 'intercept_plugin_error_scrape_init' ) ); |
||
3350 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
||
3351 | add_filter( 'plugin_action_links_' . plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ), array( $this, 'plugin_action_links' ) ); |
||
3352 | |||
3353 | if ( Jetpack::is_active() || Jetpack::is_development_mode() ) { |
||
3354 | // Artificially throw errors in certain whitelisted cases during plugin activation |
||
3355 | add_action( 'activate_plugin', array( $this, 'throw_error_on_activate_plugin' ) ); |
||
3356 | |||
3357 | // Kick off synchronization of user role when it changes |
||
3358 | add_action( 'set_user_role', array( $this, 'user_role_change' ) ); |
||
3359 | } |
||
3360 | |||
3361 | // Jetpack Manage Activation Screen from .com |
||
3362 | Jetpack::module_configuration_activation_screen( 'manage', array( $this, 'manage_activate_screen' ) ); |
||
3363 | |||
3364 | // Add custom column in wp-admin/users.php to show whether user is linked. |
||
3365 | add_filter( 'manage_users_columns', array( $this, 'jetpack_icon_user_connected' ) ); |
||
3366 | add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_user_connected_icon' ), 10, 3 ); |
||
3367 | add_action( 'admin_print_styles', array( $this, 'jetpack_user_col_style' ) ); |
||
3368 | } |
||
3369 | |||
3370 | function admin_body_class( $admin_body_class = '' ) { |
||
3378 | |||
3379 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
3382 | |||
3383 | function prepare_connect_notice() { |
||
3391 | /** |
||
3392 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
3393 | * |
||
3394 | * @return null |
||
3395 | */ |
||
3396 | function prepare_manage_jetpack_notice() { |
||
3401 | |||
3402 | function manage_activate_screen() { |
||
3405 | /** |
||
3406 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
3407 | * This function artificially throws errors for such cases (whitelisted). |
||
3408 | * |
||
3409 | * @param string $plugin The activated plugin. |
||
3410 | */ |
||
3411 | function throw_error_on_activate_plugin( $plugin ) { |
||
3435 | |||
3436 | function intercept_plugin_error_scrape_init() { |
||
3439 | |||
3440 | function intercept_plugin_error_scrape( $action, $result ) { |
||
3451 | |||
3452 | function add_remote_request_handlers() { |
||
3455 | |||
3456 | function remote_request_handlers() { |
||
3490 | |||
3491 | function upload_handler() { |
||
3576 | |||
3577 | /** |
||
3578 | * Add help to the Jetpack page |
||
3579 | * |
||
3580 | * @since Jetpack (1.2.3) |
||
3581 | * @return false if not the Jetpack page |
||
3582 | */ |
||
3583 | function admin_help() { |
||
3584 | $current_screen = get_current_screen(); |
||
3585 | |||
3586 | // Overview |
||
3587 | $current_screen->add_help_tab( |
||
3588 | array( |
||
3589 | 'id' => 'home', |
||
3590 | 'title' => __( 'Home', 'jetpack' ), |
||
3591 | 'content' => |
||
3592 | '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' . |
||
3593 | '<p>' . __( 'Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack' ) . '</p>' . |
||
3594 | '<p>' . __( 'On this page, you are able to view the modules available within Jetpack, learn more about them, and activate or deactivate them as needed.', 'jetpack' ) . '</p>', |
||
3595 | ) |
||
3596 | ); |
||
3597 | |||
3598 | // Screen Content |
||
3599 | if ( current_user_can( 'manage_options' ) ) { |
||
3600 | $current_screen->add_help_tab( |
||
3601 | array( |
||
3602 | 'id' => 'settings', |
||
3603 | 'title' => __( 'Settings', 'jetpack' ), |
||
3604 | 'content' => |
||
3605 | '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' . |
||
3606 | '<p>' . __( 'You can activate or deactivate individual Jetpack modules to suit your needs.', 'jetpack' ) . '</p>' . |
||
3607 | '<ol>' . |
||
3608 | '<li>' . __( 'Each module has an Activate or Deactivate link so you can toggle one individually.', 'jetpack' ) . '</li>' . |
||
3609 | '<li>' . __( 'Using the checkboxes next to each module, you can select multiple modules to toggle via the Bulk Actions menu at the top of the list.', 'jetpack' ) . '</li>' . |
||
3610 | '</ol>' . |
||
3611 | '<p>' . __( 'Using the tools on the right, you can search for specific modules, filter by module categories or which are active, or change the sorting order.', 'jetpack' ) . '</p>' |
||
3612 | ) |
||
3613 | ); |
||
3614 | } |
||
3615 | |||
3616 | // Help Sidebar |
||
3617 | $current_screen->set_help_sidebar( |
||
3618 | '<p><strong>' . __( 'For more information:', 'jetpack' ) . '</strong></p>' . |
||
3619 | '<p><a href="https://jetpack.com/faq/" target="_blank">' . __( 'Jetpack FAQ', 'jetpack' ) . '</a></p>' . |
||
3620 | '<p><a href="https://jetpack.com/support/" target="_blank">' . __( 'Jetpack Support', 'jetpack' ) . '</a></p>' . |
||
3621 | '<p><a href="' . Jetpack::admin_url( array( 'page' => 'jetpack-debugger' ) ) .'">' . __( 'Jetpack Debugging Center', 'jetpack' ) . '</a></p>' |
||
3622 | ); |
||
3623 | } |
||
3624 | |||
3625 | function admin_menu_css() { |
||
3628 | |||
3629 | function admin_menu_order() { |
||
3632 | |||
3633 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
3648 | |||
3649 | function admin_head() { |
||
3654 | |||
3655 | function admin_banner_styles() { |
||
3662 | |||
3663 | function admin_scripts() { |
||
3676 | |||
3677 | function plugin_action_links( $actions ) { |
||
3692 | |||
3693 | function admin_connect_notice() { |
||
3694 | // Don't show the connect notice anywhere but the plugins.php after activating |
||
3695 | $current = get_current_screen(); |
||
3696 | if ( 'plugins' !== $current->parent_base ) |
||
3697 | return; |
||
3698 | |||
3699 | if ( ! current_user_can( 'jetpack_connect' ) ) |
||
3700 | return; |
||
3701 | |||
3702 | $dismiss_and_deactivate_url = wp_nonce_url( Jetpack::admin_url( '?page=jetpack&jetpack-notice=dismiss' ), 'jetpack-deactivate' ); |
||
3703 | ?> |
||
3704 | <div id="message" class="updated jp-banner"> |
||
3705 | <a href="<?php echo esc_url( $dismiss_and_deactivate_url ); ?>" class="notice-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>"></a> |
||
3706 | <?php if ( in_array( Jetpack_Options::get_option( 'activated' ) , array( 1, 2, 3 ) ) ) : ?> |
||
3707 | <div class="jp-banner__description-container"> |
||
3708 | <h2 class="jp-banner__header"><?php _e( 'Your Jetpack is almost ready!', 'jetpack' ); ?></h2> |
||
3709 | <p class="jp-banner__description"><?php _e( 'Please connect to or create a WordPress.com account to enable Jetpack, including powerful security, traffic, and customization services.', 'jetpack' ); ?></p> |
||
3710 | <p class="jp-banner__button-container"> |
||
3711 | <a href="<?php echo $this->build_connect_url( false, false, 'banner' ) ?>" class="button button-primary" id="wpcom-connect"><?php _e( 'Connect to WordPress.com', 'jetpack' ); ?></a> |
||
3712 | <a href="<?php echo Jetpack::admin_url( 'admin.php?page=jetpack' ) ?>" class="button" title="<?php esc_attr_e( 'Learn about the benefits you receive when you connect Jetpack to WordPress.com', 'jetpack' ); ?>"><?php _e( 'Learn more', 'jetpack' ); ?></a> |
||
3713 | </p> |
||
3714 | </div> |
||
3715 | View Code Duplication | <?php else : ?> |
|
3716 | <div class="jp-banner__content"> |
||
3717 | <h2><?php _e( 'Jetpack is installed!', 'jetpack' ) ?></h2> |
||
3718 | <p><?php _e( 'It\'s ready to bring awesome, WordPress.com cloud-powered features to your site.', 'jetpack' ) ?></p> |
||
3719 | </div> |
||
3720 | <div class="jp-banner__action-container"> |
||
3721 | <a href="<?php echo Jetpack::admin_url() ?>" class="jp-banner__button" id="wpcom-connect"><?php _e( 'Learn More', 'jetpack' ); ?></a> |
||
3722 | </div> |
||
3723 | <?php endif; ?> |
||
3724 | </div> |
||
3725 | |||
3726 | <?php |
||
3727 | } |
||
3728 | |||
3729 | /** |
||
3730 | * This is the first banner |
||
3731 | * It should be visible only to user that can update the option |
||
3732 | * Are not connected |
||
3733 | * |
||
3734 | * @return null |
||
3735 | */ |
||
3736 | function admin_jetpack_manage_notice() { |
||
3737 | $screen = get_current_screen(); |
||
3738 | |||
3739 | // Don't show the connect notice on the jetpack settings page. |
||
3740 | if ( ! in_array( $screen->base, array( 'dashboard' ) ) || $screen->is_network || $screen->action ) |
||
3741 | return; |
||
3742 | |||
3743 | // Only show it if don't have the managment option set. |
||
3744 | // And not dismissed it already. |
||
3745 | if ( ! $this->can_display_jetpack_manage_notice() || Jetpack_Options::get_option( 'dismissed_manage_banner' ) ) { |
||
3746 | return; |
||
3747 | } |
||
3748 | |||
3749 | $opt_out_url = $this->opt_out_jetpack_manage_url(); |
||
3750 | $opt_in_url = $this->opt_in_jetpack_manage_url(); |
||
3751 | /** |
||
3752 | * I think it would be great to have different wordsing depending on where you are |
||
3753 | * for example if we show the notice on dashboard and a different one if we show it on Plugins screen |
||
3754 | * etc.. |
||
3755 | */ |
||
3756 | |||
3757 | ?> |
||
3758 | <div id="message" class="updated jp-banner"> |
||
3759 | <a href="<?php echo esc_url( $opt_out_url ); ?>" class="notice-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>"></a> |
||
3760 | <div class="jp-banner__description-container"> |
||
3761 | <h2 class="jp-banner__header"><?php esc_html_e( 'Jetpack Centralized Site Management', 'jetpack' ); ?></h2> |
||
3762 | <p class="jp-banner__description"><?php printf( __( 'Manage multiple Jetpack enabled sites from one single dashboard at wordpress.com. Allows all existing, connected Administrators to modify your site.', 'jetpack' ), 'https://jetpack.com/support/site-management' ); ?></p> |
||
3763 | <p class="jp-banner__button-container"> |
||
3764 | <a href="<?php echo esc_url( $opt_in_url ); ?>" class="button button-primary" id="wpcom-connect"><?php _e( 'Activate Jetpack Manage', 'jetpack' ); ?></a> |
||
3765 | <a href="https://jetpack.com/support/site-management" class="button" target="_blank" title="<?php esc_attr_e( 'Learn more about Jetpack Manage on Jetpack.com', 'jetpack' ); ?>"><?php _e( 'Learn more', 'jetpack' ); ?></a> |
||
3766 | </p> |
||
3767 | </div> |
||
3768 | </div> |
||
3769 | <?php |
||
3770 | } |
||
3771 | |||
3772 | /** |
||
3773 | * Returns the url that the user clicks to remove the notice for the big banner |
||
3774 | * @return (string) |
||
3775 | */ |
||
3776 | function opt_out_jetpack_manage_url() { |
||
3780 | /** |
||
3781 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
3782 | * @return (string) |
||
3783 | */ |
||
3784 | function opt_in_jetpack_manage_url() { |
||
3787 | |||
3788 | function opt_in_jetpack_manage_notice() { |
||
3798 | /** |
||
3799 | * Determines whether to show the notice of not true = display notice |
||
3800 | * @return (bool) |
||
3801 | */ |
||
3802 | function can_display_jetpack_manage_notice() { |
||
3824 | |||
3825 | function network_connect_notice() { |
||
3834 | |||
3835 | public static function jetpack_comment_notice() { |
||
3870 | |||
3871 | /** |
||
3872 | * Show the survey link when the user has just disconnected Jetpack. |
||
3873 | */ |
||
3874 | function disconnect_survey_notice() { |
||
3893 | |||
3894 | /* |
||
3895 | * Registration flow: |
||
3896 | * 1 - ::admin_page_load() action=register |
||
3897 | * 2 - ::try_registration() |
||
3898 | * 3 - ::register() |
||
3899 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
3900 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
3901 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
3902 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
3903 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
3904 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
3905 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
3906 | * jetpack_id, jetpack_secret, jetpack_public |
||
3907 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
3908 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
3909 | * 5 - user logs in with WP.com account |
||
3910 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
3911 | * - Jetpack_Client_Server::authorize() |
||
3912 | * - Jetpack_Client_Server::get_token() |
||
3913 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
3914 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
3915 | * - which responds with access_token, token_type, scope |
||
3916 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
3917 | * - Jetpack::activate_default_modules() |
||
3918 | * - Deactivates deprecated plugins |
||
3919 | * - Activates all default modules |
||
3920 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
3921 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
3922 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
3923 | * Done! |
||
3924 | */ |
||
3925 | |||
3926 | /** |
||
3927 | * Handles the page load events for the Jetpack admin page |
||
3928 | */ |
||
3929 | function admin_page_load() { |
||
4387 | |||
4388 | function admin_notices() { |
||
4485 | |||
4486 | /** |
||
4487 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
4488 | */ |
||
4489 | function stat( $group, $detail ) { |
||
4494 | |||
4495 | /** |
||
4496 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
4497 | */ |
||
4498 | function do_stats( $method = '' ) { |
||
4513 | |||
4514 | /** |
||
4515 | * Runs stats code for a one-off, server-side. |
||
4516 | * |
||
4517 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
4518 | * |
||
4519 | * @return bool If it worked. |
||
4520 | */ |
||
4521 | static function do_server_side_stat( $args ) { |
||
4531 | |||
4532 | /** |
||
4533 | * Builds the stats url. |
||
4534 | * |
||
4535 | * @param $args array|string The arguments to append to the URL. |
||
4536 | * |
||
4537 | * @return string The URL to be pinged. |
||
4538 | */ |
||
4539 | static function build_stats_url( $args ) { |
||
4559 | |||
4560 | function translate_current_user_to_role() { |
||
4569 | |||
4570 | function translate_role_to_cap( $role ) { |
||
4577 | |||
4578 | function sign_role( $role ) { |
||
4590 | |||
4591 | |||
4592 | /** |
||
4593 | * Builds a URL to the Jetpack connection auth page |
||
4594 | * |
||
4595 | * @since 3.9.5 |
||
4596 | * |
||
4597 | * @param bool $raw If true, URL will not be escaped. |
||
4598 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
4599 | * If string, will be a custom redirect. |
||
4600 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
4601 | * |
||
4602 | * @return string Connect URL |
||
4603 | */ |
||
4604 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
4605 | if ( ! Jetpack_Options::get_option( 'blog_token' ) || ! Jetpack_Options::get_option( 'id' ) ) { |
||
4606 | $url = Jetpack::nonce_url_no_esc( Jetpack::admin_url( 'action=register' ), 'jetpack-register' ); |
||
4607 | if( is_network_admin() ) { |
||
4608 | $url = add_query_arg( 'is_multisite', network_admin_url( |
||
4609 | 'admin.php?page=jetpack-settings' ), $url ); |
||
4610 | } |
||
4611 | } else { |
||
4612 | if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && include_once JETPACK__GLOTPRESS_LOCALES_PATH ) { |
||
4613 | $gp_locale = GP_Locales::by_field( 'wp_locale', get_locale() ); |
||
4614 | } |
||
4615 | |||
4616 | $role = $this->translate_current_user_to_role(); |
||
4617 | $signed_role = $this->sign_role( $role ); |
||
4618 | |||
4619 | $user = wp_get_current_user(); |
||
4620 | |||
4621 | $redirect = $redirect ? esc_url_raw( $redirect ) : esc_url_raw( menu_page_url( 'jetpack', false ) ); |
||
4622 | |||
4675 | |||
4676 | function build_reconnect_url( $raw = false ) { |
||
4680 | |||
4681 | public static function admin_url( $args = null ) { |
||
4686 | |||
4687 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
4691 | |||
4692 | function dismiss_jetpack_notice() { |
||
4766 | |||
4767 | function debugger_page() { |
||
4775 | |||
4776 | public static function admin_screen_configure_module( $module_id ) { |
||
4828 | |||
4829 | /** |
||
4830 | * Display link to activate the module to see the settings screen. |
||
4831 | * @param string $module_id |
||
4832 | * @return null |
||
4833 | */ |
||
4834 | public static function display_activate_module_link( $module_id ) { |
||
4886 | |||
4887 | public static function sort_modules( $a, $b ) { |
||
4893 | |||
4894 | View Code Duplication | function sync_reindex_trigger() { |
|
4902 | |||
4903 | View Code Duplication | function sync_reindex_status(){ |
|
4911 | |||
4912 | function ajax_recheck_ssl() { |
||
4920 | |||
4921 | /* Client API */ |
||
4922 | |||
4923 | /** |
||
4924 | * Returns the requested Jetpack API URL |
||
4925 | * |
||
4926 | * @return string |
||
4927 | */ |
||
4928 | public static function api_url( $relative_url ) { |
||
4931 | |||
4932 | /** |
||
4933 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
4934 | */ |
||
4935 | public static function fix_url_for_bad_hosts( $url ) { |
||
4951 | |||
4952 | /** |
||
4953 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
4954 | * |
||
4955 | * @since 2.3.3 |
||
4956 | * @return boolean |
||
4957 | */ |
||
4958 | public static function permit_ssl( $force_recheck = false ) { |
||
5000 | |||
5001 | /* |
||
5002 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
5003 | */ |
||
5004 | public function alert_auto_ssl_fail() { |
||
5053 | |||
5054 | /** |
||
5055 | * Returns the Jetpack XML-RPC API |
||
5056 | * |
||
5057 | * @return string |
||
5058 | */ |
||
5059 | public static function xmlrpc_api_url() { |
||
5063 | |||
5064 | /** |
||
5065 | * Creates two secret tokens and the end of life timestamp for them. |
||
5066 | * |
||
5067 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
5068 | * |
||
5069 | * @since 2.6 |
||
5070 | * @return array |
||
5071 | */ |
||
5072 | public function generate_secrets( $action, $exp = 600 ) { |
||
5080 | |||
5081 | /** |
||
5082 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5083 | * |
||
5084 | * Based on local php max_execution_time in php.ini |
||
5085 | * |
||
5086 | * @since 2.6 |
||
5087 | * @return int |
||
5088 | **/ |
||
5089 | public function get_remote_query_timeout_limit() { |
||
5095 | |||
5096 | |||
5097 | /** |
||
5098 | * Takes the response from the Jetpack register new site endpoint and |
||
5099 | * verifies it worked properly. |
||
5100 | * |
||
5101 | * @since 2.6 |
||
5102 | * @return true or Jetpack_Error |
||
5103 | **/ |
||
5104 | public function validate_remote_register_response( $response ) { |
||
5139 | /** |
||
5140 | * @return bool|WP_Error |
||
5141 | */ |
||
5142 | public static function register() { |
||
5239 | |||
5240 | /** |
||
5241 | * If the db version is showing something other that what we've got now, bump it to current. |
||
5242 | * |
||
5243 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
5244 | */ |
||
5245 | public static function maybe_set_version_option() { |
||
5253 | |||
5254 | /* Client Server API */ |
||
5255 | |||
5256 | /** |
||
5257 | * Loads the Jetpack XML-RPC client |
||
5258 | */ |
||
5259 | public static function load_xml_rpc_client() { |
||
5263 | |||
5264 | function verify_xml_rpc_signature() { |
||
5362 | |||
5363 | /** |
||
5364 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
5365 | */ |
||
5366 | function authenticate_jetpack( $user, $username, $password ) { |
||
5389 | |||
5390 | function add_nonce( $timestamp, $nonce ) { |
||
5428 | |||
5429 | /** |
||
5430 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
5431 | * Capture it here so we can verify the signature later. |
||
5432 | */ |
||
5433 | function xmlrpc_methods( $methods ) { |
||
5437 | |||
5438 | function public_xmlrpc_methods( $methods ) { |
||
5444 | |||
5445 | function jetpack_getOptions( $args ) { |
||
5485 | |||
5486 | function xmlrpc_options( $options ) { |
||
5504 | |||
5505 | public static function clean_nonces( $all = false ) { |
||
5530 | |||
5531 | /** |
||
5532 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
5533 | * SET: state( $key, $value ); |
||
5534 | * GET: $value = state( $key ); |
||
5535 | * |
||
5536 | * @param string $key |
||
5537 | * @param string $value |
||
5538 | * @param bool $restate private |
||
5539 | */ |
||
5540 | public static function state( $key = null, $value = null, $restate = false ) { |
||
5590 | |||
5591 | public static function restate() { |
||
5594 | |||
5595 | public static function check_privacy( $file ) { |
||
5630 | |||
5631 | /** |
||
5632 | * Helper method for multicall XMLRPC. |
||
5633 | */ |
||
5634 | public static function xmlrpc_async_call() { |
||
5676 | |||
5677 | public static function staticize_subdomain( $url ) { |
||
5712 | |||
5713 | /* JSON API Authorization */ |
||
5714 | |||
5715 | /** |
||
5716 | * Handles the login action for Authorizing the JSON API |
||
5717 | */ |
||
5718 | function login_form_json_api_authorization() { |
||
5727 | |||
5728 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
5729 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
5742 | |||
5743 | // Make sure the POSTed request is handled by the same action |
||
5744 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
5748 | |||
5749 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
5750 | function store_json_api_authorization_token( $user_login, $user ) { |
||
5756 | |||
5757 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
5758 | function allow_wpcom_public_api_domain( $domains ) { |
||
5762 | |||
5763 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
5764 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
5776 | |||
5777 | // Verifies the request by checking the signature |
||
5778 | function verify_json_api_authorization_request() { |
||
5857 | |||
5858 | function login_message_json_api_authorization( $message ) { |
||
5864 | |||
5865 | /** |
||
5866 | * Get $content_width, but with a <s>twist</s> filter. |
||
5867 | */ |
||
5868 | public static function get_content_width() { |
||
5879 | |||
5880 | /** |
||
5881 | * Centralize the function here until it gets added to core. |
||
5882 | * |
||
5883 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
5884 | * @param int $size Size of the avatar image |
||
5885 | * @param string $default URL to a default image to use if no avatar is available |
||
5886 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
5887 | * |
||
5888 | * @return array First element is the URL, second is the class. |
||
5889 | */ |
||
5890 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
5918 | |||
5919 | /** |
||
5920 | * Pings the WordPress.com Mirror Site for the specified options. |
||
5921 | * |
||
5922 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
5923 | * |
||
5924 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
5925 | */ |
||
5926 | public function get_cloud_site_options( $option_names ) { |
||
5942 | |||
5943 | /** |
||
5944 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
5945 | * |
||
5946 | * @return array An array of options to check. |
||
5947 | */ |
||
5948 | public static function identity_crisis_options_to_check() { |
||
5954 | |||
5955 | /** |
||
5956 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
5957 | * |
||
5958 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
5959 | * |
||
5960 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
5961 | */ |
||
5962 | public static function check_identity_crisis( $force_recheck = false ) { |
||
6028 | |||
6029 | /* |
||
6030 | * Resolve ID crisis |
||
6031 | * |
||
6032 | * If the URL has changed, but the rest of the options are the same (i.e. blog/user tokens) |
||
6033 | * The user has the option to update the shadow site with the new URL before a new |
||
6034 | * token is created. |
||
6035 | * |
||
6036 | * @param $key : Which option to sync. null defautlts to home and siteurl |
||
6037 | */ |
||
6038 | public static function resolve_identity_crisis( $key = null ) { |
||
6060 | |||
6061 | /* |
||
6062 | * Whitelist URL |
||
6063 | * |
||
6064 | * Ignore the URL differences between the blog and the shadow site. |
||
6065 | */ |
||
6066 | public static function whitelist_current_url() { |
||
6074 | |||
6075 | /* |
||
6076 | * Ajax callbacks for ID crisis resolutions |
||
6077 | * |
||
6078 | * Things that could happen here: |
||
6079 | * - site_migrated : Update the URL on the shadow blog to match new domain |
||
6080 | * - whitelist : Ignore the URL difference |
||
6081 | * - default : Error message |
||
6082 | */ |
||
6083 | public static function resolve_identity_crisis_ajax_callback() { |
||
6123 | |||
6124 | /** |
||
6125 | * Adds a value to the whitelist for the specified key. |
||
6126 | * |
||
6127 | * @param string $key The option name that we're whitelisting the value for. |
||
6128 | * @param string $value The value that we're intending to add to the whitelist. |
||
6129 | * |
||
6130 | * @return bool Whether the value was added to the whitelist, or false if it was already there. |
||
6131 | */ |
||
6132 | public static function whitelist_identity_crisis_value( $key, $value ) { |
||
6146 | |||
6147 | /** |
||
6148 | * Checks whether a value is already whitelisted. |
||
6149 | * |
||
6150 | * @param string $key The option name that we're checking the value for. |
||
6151 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
6152 | * |
||
6153 | * @return bool Whether the value is whitelisted. |
||
6154 | */ |
||
6155 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
6162 | |||
6163 | /** |
||
6164 | * Checks whether the home and siteurl specifically are whitelisted |
||
6165 | * Written so that we don't have re-check $key and $value params every time |
||
6166 | * we want to check if this site is whitelisted, for example in footer.php |
||
6167 | * |
||
6168 | * @return bool True = already whitelsisted False = not whitelisted |
||
6169 | */ |
||
6170 | public static function is_staging_site() { |
||
6234 | |||
6235 | public function identity_crisis_js( $nonce ) { |
||
6305 | |||
6306 | /** |
||
6307 | * Maybe Use a .min.css stylesheet, maybe not. |
||
6308 | * |
||
6309 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
6310 | */ |
||
6311 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
6346 | |||
6347 | /** |
||
6348 | * Maybe inlines a stylesheet. |
||
6349 | * |
||
6350 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
6351 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
6352 | * |
||
6353 | * Attached to `style_loader_tag` filter. |
||
6354 | * |
||
6355 | * @param string $tag The tag that would link to the external asset. |
||
6356 | * @param string $handle The registered handle of the script in question. |
||
6357 | * |
||
6358 | * @return string |
||
6359 | */ |
||
6360 | public static function maybe_inline_style( $tag, $handle ) { |
||
6410 | |||
6411 | /** |
||
6412 | * Loads a view file from the views |
||
6413 | * |
||
6414 | * Data passed in with the $data parameter will be available in the |
||
6415 | * template file as $data['value'] |
||
6416 | * |
||
6417 | * @param string $template - Template file to load |
||
6418 | * @param array $data - Any data to pass along to the template |
||
6419 | * @return boolean - If template file was found |
||
6420 | **/ |
||
6421 | public function load_view( $template, $data = array() ) { |
||
6432 | |||
6433 | /** |
||
6434 | * Sends a ping to the Jetpack servers to toggle on/off remote portions |
||
6435 | * required by some modules. |
||
6436 | * |
||
6437 | * @param string $module_slug |
||
6438 | */ |
||
6439 | public function toggle_module_on_wpcom( $module_slug ) { |
||
6447 | |||
6448 | /** |
||
6449 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
6450 | */ |
||
6451 | public function deprecated_hooks() { |
||
6479 | |||
6480 | /** |
||
6481 | * Converts any url in a stylesheet, to the correct absolute url. |
||
6482 | * |
||
6483 | * Considerations: |
||
6484 | * - Normal, relative URLs `feh.png` |
||
6485 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
6486 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
6487 | * - Absolute URLs `http://domain.com/feh.png` |
||
6488 | * - Domain root relative URLs `/feh.png` |
||
6489 | * |
||
6490 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
6491 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
6492 | * |
||
6493 | * @return mixed|string |
||
6494 | */ |
||
6495 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
6539 | |||
6540 | /** |
||
6541 | * This method checks to see if SSL is required by the site in |
||
6542 | * order to visit it in some way other than only setting the |
||
6543 | * https value in the home or siteurl values. |
||
6544 | * |
||
6545 | * @since 3.2 |
||
6546 | * @return boolean |
||
6547 | **/ |
||
6548 | private function is_ssl_required_to_visit_site() { |
||
6557 | |||
6558 | /** |
||
6559 | * This methods removes all of the registered css files on the frontend |
||
6560 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
6561 | * all the files into one file. |
||
6562 | * |
||
6563 | * Pros: |
||
6564 | * - Uses only ONE css asset connection instead of 15 |
||
6565 | * - Saves a minimum of 56k |
||
6566 | * - Reduces server load |
||
6567 | * - Reduces time to first painted byte |
||
6568 | * |
||
6569 | * Cons: |
||
6570 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
6571 | * should not cause any issues with themes. |
||
6572 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
6573 | * jetpack_implode_frontend_css filter for a workaround |
||
6574 | * |
||
6575 | * For some situations developers may wish to disable css imploding and |
||
6576 | * instead operate in legacy mode where each file loads seperately and |
||
6577 | * can be edited individually or dequeued. This can be accomplished with |
||
6578 | * the following line: |
||
6579 | * |
||
6580 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
6581 | * |
||
6582 | * @since 3.2 |
||
6583 | **/ |
||
6584 | public function implode_frontend_css( $travis_test = false ) { |
||
6636 | |||
6637 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
6647 | |||
6648 | /* |
||
6649 | * Check the heartbeat data |
||
6650 | * |
||
6651 | * Organizes the heartbeat data by severity. For example, if the site |
||
6652 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
6653 | * |
||
6654 | * Data will be added to "caution" array, if it either: |
||
6655 | * - Out of date Jetpack version |
||
6656 | * - Out of date WP version |
||
6657 | * - Out of date PHP version |
||
6658 | * |
||
6659 | * $return array $filtered_data |
||
6660 | */ |
||
6661 | public static function jetpack_check_heartbeat_data() { |
||
6714 | |||
6715 | |||
6716 | /* |
||
6717 | * This method is used to organize all options that can be reset |
||
6718 | * without disconnecting Jetpack. |
||
6719 | * |
||
6720 | * It is used in class.jetpack-cli.php to reset options |
||
6721 | * |
||
6722 | * @return array of options to delete. |
||
6723 | */ |
||
6724 | public static function get_jetpack_options_for_reset() { |
||
6790 | |||
6791 | /* |
||
6792 | * Check if an option of a Jetpack module has been updated. |
||
6793 | * |
||
6794 | * If any module option has been updated before Jump Start has been dismissed, |
||
6795 | * update the 'jumpstart' option so we can hide Jump Start. |
||
6796 | */ |
||
6797 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
6819 | |||
6820 | /* |
||
6821 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
6822 | * so we can bring them directly to their site in calypso. |
||
6823 | * |
||
6824 | * @param string | url |
||
6825 | * @return string | url without the guff |
||
6826 | */ |
||
6827 | public static function build_raw_urls( $url ) { |
||
6833 | |||
6834 | /** |
||
6835 | * Stores and prints out domains to prefetch for page speed optimization. |
||
6836 | * |
||
6837 | * @param mixed $new_urls |
||
6838 | */ |
||
6839 | public static function dns_prefetch( $new_urls = null ) { |
||
6856 | |||
6857 | public function wp_dashboard_setup() { |
||
6885 | |||
6886 | /** |
||
6887 | * @param mixed $result Value for the user's option |
||
6888 | * @return mixed |
||
6889 | */ |
||
6890 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
6915 | |||
6916 | public static function dashboard_widget() { |
||
6924 | |||
6925 | public static function dashboard_widget_footer() { |
||
6958 | |||
6959 | public function dashboard_widget_connect_to_wpcom() { |
||
6981 | |||
6982 | /* |
||
6983 | * A graceful transition to using Core's site icon. |
||
6984 | * |
||
6985 | * All of the hard work has already been done with the image |
||
6986 | * in all_done_page(). All that needs to be done now is update |
||
6987 | * the option and display proper messaging. |
||
6988 | * |
||
6989 | * @todo remove when WP 4.3 is minimum |
||
6990 | * |
||
6991 | * @since 3.6.1 |
||
6992 | * |
||
6993 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
6994 | */ |
||
6995 | public static function jetpack_site_icon_available_in_core() { |
||
7030 | |||
7031 | /** |
||
7032 | * Return string containing the Jetpack logo. |
||
7033 | * |
||
7034 | * @since 3.9.0 |
||
7035 | * |
||
7036 | * @return string |
||
7037 | */ |
||
7038 | public static function get_jp_emblem() { |
||
7041 | |||
7042 | /* |
||
7043 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
7044 | */ |
||
7045 | function jetpack_icon_user_connected( $columns ) { |
||
7049 | |||
7050 | /* |
||
7051 | * Show Jetpack icon if the user is linked. |
||
7052 | */ |
||
7053 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
7065 | |||
7066 | /* |
||
7067 | * Style the Jetpack user column |
||
7068 | */ |
||
7069 | function jetpack_user_col_style() { |
||
7082 | |||
7083 | } |
||
7084 |
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.