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 |
||
53 | class Jetpack { |
||
54 | public $xmlrpc_server = null; |
||
55 | |||
56 | /** |
||
57 | * @var array The handles of styles that are concatenated into jetpack.css. |
||
58 | * |
||
59 | * When making changes to that list, you must also update concat_list in tools/builder/frontend-css.js. |
||
60 | */ |
||
61 | public $concatenated_style_handles = array( |
||
62 | 'jetpack-carousel', |
||
63 | 'grunion.css', |
||
64 | 'the-neverending-homepage', |
||
65 | 'jetpack_likes', |
||
66 | 'jetpack_related-posts', |
||
67 | 'sharedaddy', |
||
68 | 'jetpack-slideshow', |
||
69 | 'presentations', |
||
70 | 'quiz', |
||
71 | 'jetpack-subscriptions', |
||
72 | 'jetpack-responsive-videos-style', |
||
73 | 'jetpack-social-menu', |
||
74 | 'tiled-gallery', |
||
75 | 'jetpack_display_posts_widget', |
||
76 | 'gravatar-profile-widget', |
||
77 | 'goodreads-widget', |
||
78 | 'jetpack_social_media_icons_widget', |
||
79 | 'jetpack-top-posts-widget', |
||
80 | 'jetpack_image_widget', |
||
81 | 'jetpack-my-community-widget', |
||
82 | 'jetpack-authors-widget', |
||
83 | 'wordads', |
||
84 | 'eu-cookie-law-style', |
||
85 | 'flickr-widget-style', |
||
86 | 'jetpack-search-widget', |
||
87 | 'jetpack-simple-payments-widget-style', |
||
88 | 'jetpack-widget-social-icons-styles', |
||
89 | 'wpcom_instagram_widget', |
||
90 | ); |
||
91 | |||
92 | /** |
||
93 | * Contains all assets that have had their URL rewritten to minified versions. |
||
94 | * |
||
95 | * @var array |
||
96 | */ |
||
97 | static $min_assets = array(); |
||
98 | |||
99 | public $plugins_to_deactivate = array( |
||
100 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
101 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
102 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
103 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
104 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
105 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
106 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
107 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
108 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
109 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
110 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
111 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
112 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
113 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ), |
||
114 | ); |
||
115 | |||
116 | /** |
||
117 | * Map of roles we care about, and their corresponding minimum capabilities. |
||
118 | * |
||
119 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead. |
||
120 | * |
||
121 | * @access public |
||
122 | * @static |
||
123 | * |
||
124 | * @var array |
||
125 | */ |
||
126 | public static $capability_translations = array( |
||
127 | 'administrator' => 'manage_options', |
||
128 | 'editor' => 'edit_others_posts', |
||
129 | 'author' => 'publish_posts', |
||
130 | 'contributor' => 'edit_posts', |
||
131 | 'subscriber' => 'read', |
||
132 | ); |
||
133 | |||
134 | /** |
||
135 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
136 | * if the plugins are active. Used by filter_default_modules |
||
137 | * |
||
138 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
139 | * change `module-slug` and add this to your plugin: |
||
140 | * |
||
141 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
142 | * function my_jetpack_get_default_modules( $modules ) { |
||
143 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
144 | * } |
||
145 | * |
||
146 | * @var array |
||
147 | */ |
||
148 | private $conflicting_plugins = array( |
||
149 | 'comments' => array( |
||
150 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
151 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
152 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
153 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
154 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
155 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
156 | ), |
||
157 | 'comment-likes' => array( |
||
158 | 'Epoch' => 'epoch/plugincore.php', |
||
159 | ), |
||
160 | 'contact-form' => array( |
||
161 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
162 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
163 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
164 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
165 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
166 | 'Ninja Forms' => 'ninja-forms/ninja-forms.php', |
||
167 | ), |
||
168 | 'latex' => array( |
||
169 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
170 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
171 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
172 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
173 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
174 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
175 | ), |
||
176 | 'protect' => array( |
||
177 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
178 | 'Captcha' => 'captcha/captcha.php', |
||
179 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
180 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
181 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
182 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
183 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
184 | 'Security-protection' => 'security-protection/security-protection.php', |
||
185 | 'Login Security' => 'login-security/login-security.php', |
||
186 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
187 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
188 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
189 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
190 | ), |
||
191 | 'random-redirect' => array( |
||
192 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
193 | ), |
||
194 | 'related-posts' => array( |
||
195 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
196 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
197 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
198 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
199 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
200 | 'outbrain' => 'outbrain/outbrain.php', |
||
201 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
202 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
203 | ), |
||
204 | 'sharedaddy' => array( |
||
205 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
206 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
207 | 'ShareThis' => 'share-this/sharethis.php', |
||
208 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
209 | ), |
||
210 | 'seo-tools' => array( |
||
211 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
212 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
213 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
214 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
215 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
216 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
217 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
218 | ), |
||
219 | 'verification-tools' => array( |
||
220 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
221 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
222 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
223 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
224 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
225 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
226 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
227 | ), |
||
228 | 'widget-visibility' => array( |
||
229 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
230 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
231 | ), |
||
232 | 'sitemaps' => array( |
||
233 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
234 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
235 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
236 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
237 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
238 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
239 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
240 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
241 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
242 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
243 | 'Sitemap' => 'sitemap/sitemap.php', |
||
244 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
245 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
246 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
247 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
248 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
249 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
250 | ), |
||
251 | 'lazy-images' => array( |
||
252 | 'Lazy Load' => 'lazy-load/lazy-load.php', |
||
253 | 'BJ Lazy Load' => 'bj-lazy-load/bj-lazy-load.php', |
||
254 | 'Lazy Load by WP Rocket' => 'rocket-lazy-load/rocket-lazy-load.php', |
||
255 | ), |
||
256 | ); |
||
257 | |||
258 | /** |
||
259 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
260 | * |
||
261 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
262 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
263 | * |
||
264 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
265 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
266 | */ |
||
267 | private $open_graph_conflicting_plugins = array( |
||
268 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
269 | // 2 Click Social Media Buttons |
||
270 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
271 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
272 | 'complete-open-graph/complete-open-graph.php', // Complete Open Graph |
||
273 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
274 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
275 | // Open Graph Meta Tags by Heateor |
||
276 | 'facebook/facebook.php', // Facebook (official plugin) |
||
277 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
278 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
279 | // Facebook Featured Image & OG Meta Tags |
||
280 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
281 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
282 | // Facebook Open Graph Meta Tags for WordPress |
||
283 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
284 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
285 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
286 | // Fedmich's Facebook Open Graph Meta |
||
287 | 'network-publisher/networkpub.php', // Network Publisher |
||
288 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
289 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
290 | // NextScripts SNAP |
||
291 | 'og-tags/og-tags.php', // OG Tags |
||
292 | 'opengraph/opengraph.php', // Open Graph |
||
293 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
294 | // Open Graph Protocol Framework |
||
295 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
296 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
297 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
298 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
299 | 'sharepress/sharepress.php', // SharePress |
||
300 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
301 | 'social-discussions/social-discussions.php', // Social Discussions |
||
302 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
303 | 'socialize/socialize.php', // Socialize |
||
304 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
305 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
306 | // Tweet, Like, Google +1 and Share |
||
307 | 'wordbooker/wordbooker.php', // Wordbooker |
||
308 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
309 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
310 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
311 | // WP Facebook Like Send & Open Graph Meta |
||
312 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
313 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
314 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
315 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button |
||
316 | 'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox |
||
317 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
318 | 'slim-seo/slim-seo.php', // Slim SEO |
||
319 | ); |
||
320 | |||
321 | /** |
||
322 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
323 | */ |
||
324 | private $twitter_cards_conflicting_plugins = array( |
||
325 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
326 | // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
327 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
328 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
329 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
330 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
331 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
332 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
333 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
334 | 'wp-to-twitter/wp-to-twitter.php', // WP to Twitter |
||
335 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
336 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
337 | 'slim-seo/slim-seo.php', // Slim SEO |
||
338 | ); |
||
339 | |||
340 | /** |
||
341 | * Message to display in admin_notice |
||
342 | * |
||
343 | * @var string |
||
344 | */ |
||
345 | public $message = ''; |
||
346 | |||
347 | /** |
||
348 | * Error to display in admin_notice |
||
349 | * |
||
350 | * @var string |
||
351 | */ |
||
352 | public $error = ''; |
||
353 | |||
354 | /** |
||
355 | * Modules that need more privacy description. |
||
356 | * |
||
357 | * @var string |
||
358 | */ |
||
359 | public $privacy_checks = ''; |
||
360 | |||
361 | /** |
||
362 | * Stats to record once the page loads |
||
363 | * |
||
364 | * @var array |
||
365 | */ |
||
366 | public $stats = array(); |
||
367 | |||
368 | /** |
||
369 | * Jetpack_Sync object |
||
370 | */ |
||
371 | public $sync; |
||
372 | |||
373 | /** |
||
374 | * Verified data for JSON authorization request |
||
375 | */ |
||
376 | public $json_api_authorization_request = array(); |
||
377 | |||
378 | /** |
||
379 | * @var Automattic\Jetpack\Connection\Manager |
||
380 | */ |
||
381 | protected $connection_manager; |
||
382 | |||
383 | /** |
||
384 | * @var string Transient key used to prevent multiple simultaneous plugin upgrades |
||
385 | */ |
||
386 | public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock'; |
||
387 | |||
388 | /** |
||
389 | * Holds an instance of Automattic\Jetpack\A8c_Mc_Stats |
||
390 | * |
||
391 | * @var Automattic\Jetpack\A8c_Mc_Stats |
||
392 | */ |
||
393 | public $a8c_mc_stats_instance; |
||
394 | |||
395 | /** |
||
396 | * Constant for login redirect key. |
||
397 | * |
||
398 | * @var string |
||
399 | * @since 8.4.0 |
||
400 | */ |
||
401 | public static $jetpack_redirect_login = 'jetpack_connect_login_redirect'; |
||
402 | |||
403 | /** |
||
404 | * Holds the singleton instance of this class |
||
405 | * |
||
406 | * @since 2.3.3 |
||
407 | * @var Jetpack |
||
408 | */ |
||
409 | static $instance = false; |
||
410 | |||
411 | /** |
||
412 | * Singleton |
||
413 | * |
||
414 | * @static |
||
415 | */ |
||
416 | public static function init() { |
||
424 | |||
425 | /** |
||
426 | * Must never be called statically |
||
427 | */ |
||
428 | function plugin_upgrade() { |
||
516 | |||
517 | /** |
||
518 | * Runs upgrade routines that need to have modules loaded. |
||
519 | */ |
||
520 | static function upgrade_on_load() { |
||
550 | |||
551 | /** |
||
552 | * Saves all the currently active modules to options. |
||
553 | * Also fires Action hooks for each newly activated and deactivated module. |
||
554 | * |
||
555 | * @param $modules Array Array of active modules to be saved in options. |
||
556 | * |
||
557 | * @return $success bool true for success, false for failure. |
||
|
|||
558 | */ |
||
559 | static function update_active_modules( $modules ) { |
||
612 | |||
613 | static function delete_active_modules() { |
||
616 | |||
617 | /** |
||
618 | * Adds a hook to plugins_loaded at a priority that's currently the earliest |
||
619 | * available. |
||
620 | */ |
||
621 | public function add_configure_hook() { |
||
642 | |||
643 | /** |
||
644 | * Constructor. Initializes WordPress hooks |
||
645 | */ |
||
646 | private function __construct() { |
||
819 | |||
820 | /** |
||
821 | * Before everything else starts getting initalized, we need to initialize Jetpack using the |
||
822 | * Config object. |
||
823 | */ |
||
824 | public function configure() { |
||
905 | |||
906 | /** |
||
907 | * Runs on plugins_loaded. Use this to add code that needs to be executed later than other |
||
908 | * initialization code. |
||
909 | * |
||
910 | * @action plugins_loaded |
||
911 | */ |
||
912 | public function late_initialization() { |
||
929 | |||
930 | /** |
||
931 | * Sets up the XMLRPC request handlers. |
||
932 | * |
||
933 | * @deprecated since 7.7.0 |
||
934 | * @see Automattic\Jetpack\Connection\Manager::setup_xmlrpc_handlers() |
||
935 | * |
||
936 | * @param array $request_params Incoming request parameters. |
||
937 | * @param Boolean $is_active Whether the connection is currently active. |
||
938 | * @param Boolean $is_signed Whether the signature check has been successful. |
||
939 | * @param Jetpack_XMLRPC_Server $xmlrpc_server (optional) An instance of the server to use instead of instantiating a new one. |
||
940 | */ |
||
941 | View Code Duplication | public function setup_xmlrpc_handlers( |
|
960 | |||
961 | /** |
||
962 | * Initialize REST API registration connector. |
||
963 | * |
||
964 | * @deprecated since 7.7.0 |
||
965 | * @see Automattic\Jetpack\Connection\Manager::initialize_rest_api_registration_connector() |
||
966 | */ |
||
967 | View Code Duplication | public function initialize_rest_api_registration_connector() { |
|
976 | |||
977 | /** |
||
978 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
979 | * |
||
980 | * @param $domains |
||
981 | */ |
||
982 | function add_wpcom_to_allowed_redirect_hosts( $domains ) { |
||
985 | |||
986 | /** |
||
987 | * Return $domains, with 'wordpress.com' appended. |
||
988 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
989 | * |
||
990 | * @param $domains |
||
991 | * @return array |
||
992 | */ |
||
993 | function allow_wpcom_domain( $domains ) { |
||
1000 | |||
1001 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
1030 | |||
1031 | function point_edit_comment_links_to_calypso( $url ) { |
||
1043 | |||
1044 | /** |
||
1045 | * Extend Sync callables with Jetpack Plugin functions. |
||
1046 | * |
||
1047 | * @param array $callables list of callables. |
||
1048 | * |
||
1049 | * @return array list of callables. |
||
1050 | */ |
||
1051 | public function filter_sync_callable_whitelist( $callables ) { |
||
1076 | |||
1077 | /** |
||
1078 | * Extend Sync multisite callables with Jetpack Plugin functions. |
||
1079 | * |
||
1080 | * @param array $callables list of callables. |
||
1081 | * |
||
1082 | * @return array list of callables. |
||
1083 | */ |
||
1084 | public function filter_sync_multisite_callable_whitelist( $callables ) { |
||
1099 | |||
1100 | function jetpack_track_last_sync_callback( $params ) { |
||
1122 | |||
1123 | function jetpack_connection_banner_callback() { |
||
1137 | |||
1138 | /** |
||
1139 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
1140 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
1141 | * ensure that Core and other plugins' methods are not exposed. |
||
1142 | * |
||
1143 | * @deprecated since 7.7.0 |
||
1144 | * @see Automattic\Jetpack\Connection\Manager::remove_non_jetpack_xmlrpc_methods() |
||
1145 | * |
||
1146 | * @param array $methods A list of registered WordPress XMLRPC methods. |
||
1147 | * @return array Filtered $methods |
||
1148 | */ |
||
1149 | View Code Duplication | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
|
1158 | |||
1159 | /** |
||
1160 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
1161 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
1162 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
1163 | * which is accessible via a different URI. Most of the below is copied directly |
||
1164 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
1165 | * |
||
1166 | * @deprecated since 7.7.0 |
||
1167 | * @see Automattic\Jetpack\Connection\Manager::alternate_xmlrpc() |
||
1168 | */ |
||
1169 | View Code Duplication | public function alternate_xmlrpc() { |
|
1178 | |||
1179 | /** |
||
1180 | * The callback for the JITM ajax requests. |
||
1181 | * |
||
1182 | * @deprecated since 7.9.0 |
||
1183 | */ |
||
1184 | function jetpack_jitm_ajax_callback() { |
||
1187 | |||
1188 | /** |
||
1189 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
1190 | */ |
||
1191 | function push_stats() { |
||
1196 | |||
1197 | /** |
||
1198 | * Sets the Jetpack custom capabilities. |
||
1199 | * |
||
1200 | * @param string[] $caps Array of the user's capabilities. |
||
1201 | * @param string $cap Capability name. |
||
1202 | * @param int $user_id The user ID. |
||
1203 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1204 | */ |
||
1205 | public function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
1240 | |||
1241 | /** |
||
1242 | * Require a Jetpack authentication. |
||
1243 | * |
||
1244 | * @deprecated since 7.7.0 |
||
1245 | * @see Automattic\Jetpack\Connection\Manager::require_jetpack_authentication() |
||
1246 | */ |
||
1247 | View Code Duplication | public function require_jetpack_authentication() { |
|
1256 | |||
1257 | /** |
||
1258 | * Register assets for use in various modules and the Jetpack admin page. |
||
1259 | * |
||
1260 | * @uses wp_script_is, wp_register_script, plugins_url |
||
1261 | * @action wp_loaded |
||
1262 | * @return null |
||
1263 | */ |
||
1264 | public function register_assets() { |
||
1326 | |||
1327 | /** |
||
1328 | * Guess locale from language code. |
||
1329 | * |
||
1330 | * @param string $lang Language code. |
||
1331 | * @return string|bool |
||
1332 | */ |
||
1333 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
1372 | |||
1373 | /** |
||
1374 | * Get the locale. |
||
1375 | * |
||
1376 | * @return string|bool |
||
1377 | */ |
||
1378 | function get_locale() { |
||
1387 | |||
1388 | /** |
||
1389 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
1390 | * |
||
1391 | * @param bool $option |
||
1392 | * @return string |
||
1393 | */ |
||
1394 | public function jetpack_main_network_site_option( $option ) { |
||
1397 | /** |
||
1398 | * Network Name. |
||
1399 | */ |
||
1400 | static function network_name( $option = null ) { |
||
1404 | /** |
||
1405 | * Does the network allow new user and site registrations. |
||
1406 | * |
||
1407 | * @return string |
||
1408 | */ |
||
1409 | static function network_allow_new_registrations( $option = null ) { |
||
1412 | /** |
||
1413 | * Does the network allow admins to add new users. |
||
1414 | * |
||
1415 | * @return boolian |
||
1416 | */ |
||
1417 | static function network_add_new_users( $option = null ) { |
||
1420 | /** |
||
1421 | * File upload psace left per site in MB. |
||
1422 | * -1 means NO LIMIT. |
||
1423 | * |
||
1424 | * @return number |
||
1425 | */ |
||
1426 | static function network_site_upload_space( $option = null ) { |
||
1430 | |||
1431 | /** |
||
1432 | * Network allowed file types. |
||
1433 | * |
||
1434 | * @return string |
||
1435 | */ |
||
1436 | static function network_upload_file_types( $option = null ) { |
||
1439 | |||
1440 | /** |
||
1441 | * Maximum file upload size set by the network. |
||
1442 | * |
||
1443 | * @return number |
||
1444 | */ |
||
1445 | static function network_max_upload_file_size( $option = null ) { |
||
1449 | |||
1450 | /** |
||
1451 | * Lets us know if a site allows admins to manage the network. |
||
1452 | * |
||
1453 | * @return array |
||
1454 | */ |
||
1455 | static function network_enable_administration_menus( $option = null ) { |
||
1458 | |||
1459 | /** |
||
1460 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
1461 | * jetpack_other_linked_admins transient. |
||
1462 | * |
||
1463 | * @since 4.3.2 |
||
1464 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
1465 | * |
||
1466 | * @param int $user_id The user ID whose role changed. |
||
1467 | * @param string $role The new role. |
||
1468 | * @param array $old_roles An array of the user's previous roles. |
||
1469 | */ |
||
1470 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
1478 | |||
1479 | /** |
||
1480 | * Checks to see if there are any other users available to become primary |
||
1481 | * Users must both: |
||
1482 | * - Be linked to wpcom |
||
1483 | * - Be an admin |
||
1484 | * |
||
1485 | * @return mixed False if no other users are linked, Int if there are. |
||
1486 | */ |
||
1487 | static function get_other_linked_admins() { |
||
1515 | |||
1516 | /** |
||
1517 | * Return whether we are dealing with a multi network setup or not. |
||
1518 | * The reason we are type casting this is because we want to avoid the situation where |
||
1519 | * the result is false since when is_main_network_option return false it cases |
||
1520 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
1521 | * database which could be set to anything as opposed to what this function returns. |
||
1522 | * |
||
1523 | * @param bool $option |
||
1524 | * |
||
1525 | * @return boolean |
||
1526 | */ |
||
1527 | public function is_main_network_option( $option ) { |
||
1531 | |||
1532 | /** |
||
1533 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
1534 | * |
||
1535 | * @param string $option |
||
1536 | * @return boolean |
||
1537 | */ |
||
1538 | public function is_multisite( $option ) { |
||
1541 | |||
1542 | /** |
||
1543 | * Implemented since there is no core is multi network function |
||
1544 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
1545 | * |
||
1546 | * @since 3.3 |
||
1547 | * @return boolean |
||
1548 | */ |
||
1549 | View Code Duplication | public static function is_multi_network() { |
|
1564 | |||
1565 | /** |
||
1566 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1567 | * |
||
1568 | * @return null |
||
1569 | */ |
||
1570 | function update_jetpack_main_network_site_option() { |
||
1573 | /** |
||
1574 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1575 | */ |
||
1576 | function update_jetpack_network_settings() { |
||
1580 | |||
1581 | /** |
||
1582 | * Get back if the current site is single user site. |
||
1583 | * |
||
1584 | * @return bool |
||
1585 | */ |
||
1586 | View Code Duplication | public static function is_single_user_site() { |
|
1595 | |||
1596 | /** |
||
1597 | * Returns true if the site has file write access false otherwise. |
||
1598 | * |
||
1599 | * @return string ( '1' | '0' ) |
||
1600 | **/ |
||
1601 | public static function file_system_write_access() { |
||
1621 | |||
1622 | /** |
||
1623 | * Finds out if a site is using a version control system. |
||
1624 | * |
||
1625 | * @return string ( '1' | '0' ) |
||
1626 | **/ |
||
1627 | public static function is_version_controlled() { |
||
1631 | |||
1632 | /** |
||
1633 | * Determines whether the current theme supports featured images or not. |
||
1634 | * |
||
1635 | * @return string ( '1' | '0' ) |
||
1636 | */ |
||
1637 | public static function featured_images_enabled() { |
||
1641 | |||
1642 | /** |
||
1643 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
1644 | * |
||
1645 | * @deprecated 4.7 use get_avatar_url instead. |
||
1646 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
1647 | * @param int $size Size of the avatar image |
||
1648 | * @param string $default URL to a default image to use if no avatar is available |
||
1649 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
1650 | * |
||
1651 | * @return array |
||
1652 | */ |
||
1653 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
1664 | // phpcs:disable WordPress.WP.CapitalPDangit.Misspelled |
||
1665 | /** |
||
1666 | * jetpack_updates is saved in the following schema: |
||
1667 | * |
||
1668 | * array ( |
||
1669 | * 'plugins' => (int) Number of plugin updates available. |
||
1670 | * 'themes' => (int) Number of theme updates available. |
||
1671 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1672 | * 'translations' => (int) Number of translation updates available. |
||
1673 | * 'total' => (int) Total of all available updates. |
||
1674 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1675 | * ) |
||
1676 | * |
||
1677 | * @return array |
||
1678 | */ |
||
1679 | public static function get_updates() { |
||
1696 | // phpcs:enable |
||
1697 | |||
1698 | public static function get_update_details() { |
||
1706 | |||
1707 | public static function refresh_update_data() { |
||
1711 | |||
1712 | public static function refresh_theme_data() { |
||
1715 | |||
1716 | /** |
||
1717 | * Is Jetpack active? |
||
1718 | * The method only checks if there's an existing token for the master user. It doesn't validate the token. |
||
1719 | * |
||
1720 | * This method is deprecated since 9.6.0. Please use one of the methods provided by the Manager class in the Connection package, |
||
1721 | * or Jetpack::is_connection_ready if you want to know when the Jetpack plugin starts considering the connection ready to be used. |
||
1722 | * |
||
1723 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
1724 | * |
||
1725 | * @deprecated 9.6.0 |
||
1726 | * |
||
1727 | * @return bool |
||
1728 | */ |
||
1729 | public static function is_active() { |
||
1732 | |||
1733 | /** |
||
1734 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI |
||
1735 | * |
||
1736 | * This method was introduced just before the release of the possibility to use Jetpack without a user connection, while |
||
1737 | * it was available only when no_user_testing_mode was enabled. In the near future, this will return is_connected for all |
||
1738 | * users and this option will be available by default for everybody. |
||
1739 | * |
||
1740 | * @since 9.6.0 |
||
1741 | * @since 9.7.0 returns is_connected in all cases and adds filter to the returned value |
||
1742 | * |
||
1743 | * @return bool is the site connection ready to be used? |
||
1744 | */ |
||
1745 | public static function is_connection_ready() { |
||
1746 | /** |
||
1747 | * Allows filtering whether the connection is ready to be used. If true, this will enable the Jetpack UI and modules |
||
1748 | * |
||
1749 | * Modules will be enabled depending on the connection status and if the module requires a connection or user connection. |
||
1750 | * |
||
1751 | * @since 9.7.0 |
||
1752 | * |
||
1753 | * @param bool $is_connection_ready Is the connection ready? |
||
1754 | * @param Automattic\Jetpack\Connection\Manager $connection_manager Instance of the Manager class, can be used to check the connection status. |
||
1755 | */ |
||
1756 | return apply_filters( 'jetpack_is_connection_ready', self::connection()->is_connected(), self::connection() ); |
||
1757 | } |
||
1758 | |||
1759 | /** |
||
1760 | * Make an API call to WordPress.com for plan status |
||
1761 | * |
||
1762 | * @deprecated 7.2.0 Use Jetpack_Plan::refresh_from_wpcom. |
||
1763 | * |
||
1764 | * @return bool True if plan is updated, false if no update |
||
1765 | */ |
||
1766 | public static function refresh_active_plan_from_wpcom() { |
||
1767 | _deprecated_function( __METHOD__, 'jetpack-7.2.0', 'Jetpack_Plan::refresh_from_wpcom' ); |
||
1768 | return Jetpack_Plan::refresh_from_wpcom(); |
||
1769 | } |
||
1770 | |||
1771 | /** |
||
1772 | * Get the plan that this Jetpack site is currently using |
||
1773 | * |
||
1774 | * @deprecated 7.2.0 Use Jetpack_Plan::get. |
||
1775 | * @return array Active Jetpack plan details. |
||
1776 | */ |
||
1777 | public static function get_active_plan() { |
||
1778 | _deprecated_function( __METHOD__, 'jetpack-7.2.0', 'Jetpack_Plan::get' ); |
||
1779 | return Jetpack_Plan::get(); |
||
1780 | } |
||
1781 | |||
1782 | /** |
||
1783 | * Determine whether the active plan supports a particular feature |
||
1784 | * |
||
1785 | * @deprecated 7.2.0 Use Jetpack_Plan::supports. |
||
1786 | * @return bool True if plan supports feature, false if not. |
||
1787 | */ |
||
1788 | public static function active_plan_supports( $feature ) { |
||
1789 | _deprecated_function( __METHOD__, 'jetpack-7.2.0', 'Jetpack_Plan::supports' ); |
||
1790 | return Jetpack_Plan::supports( $feature ); |
||
1791 | } |
||
1792 | |||
1793 | /** |
||
1794 | * Deprecated: Is Jetpack in development (offline) mode? |
||
1795 | * |
||
1796 | * This static method is being left here intentionally without the use of _deprecated_function(), as other plugins |
||
1797 | * and themes still use it, and we do not want to flood them with notices. |
||
1798 | * |
||
1799 | * Please use Automattic\Jetpack\Status()->is_offline_mode() instead. |
||
1800 | * |
||
1801 | * @deprecated since 8.0. |
||
1802 | */ |
||
1803 | public static function is_development_mode() { |
||
1804 | _deprecated_function( __METHOD__, 'jetpack-8.0', '\Automattic\Jetpack\Status->is_offline_mode' ); |
||
1805 | return ( new Status() )->is_offline_mode(); |
||
1806 | } |
||
1807 | |||
1808 | /** |
||
1809 | * Whether the site is currently onboarding or not. |
||
1810 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
1811 | * |
||
1812 | * @since 5.8 |
||
1813 | * |
||
1814 | * @access public |
||
1815 | * @static |
||
1816 | * |
||
1817 | * @return bool True if the site is currently onboarding, false otherwise |
||
1818 | */ |
||
1819 | public static function is_onboarding() { |
||
1820 | return Jetpack_Options::get_option( 'onboarding' ) !== false; |
||
1821 | } |
||
1822 | |||
1823 | /** |
||
1824 | * Determines reason for Jetpack offline mode. |
||
1825 | */ |
||
1826 | public static function development_mode_trigger_text() { |
||
1827 | $status = new Status(); |
||
1828 | |||
1829 | if ( ! $status->is_offline_mode() ) { |
||
1830 | return __( 'Jetpack is not in Offline Mode.', 'jetpack' ); |
||
1831 | } |
||
1832 | |||
1833 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
1834 | $notice = __( 'The JETPACK_DEV_DEBUG constant is defined in wp-config.php or elsewhere.', 'jetpack' ); |
||
1835 | } elseif ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) { |
||
1836 | $notice = __( 'The WP_LOCAL_DEV constant is defined in wp-config.php or elsewhere.', 'jetpack' ); |
||
1837 | } elseif ( $status->is_local_site() ) { |
||
1838 | $notice = __( 'The site URL is a known local development environment URL (e.g. http://localhost).', 'jetpack' ); |
||
1839 | /** This filter is documented in packages/status/src/class-status.php */ |
||
1840 | } elseif ( has_filter( 'jetpack_development_mode' ) && apply_filters( 'jetpack_development_mode', false ) ) { // This is a deprecated filter name. |
||
1841 | $notice = __( 'The jetpack_development_mode filter is set to true.', 'jetpack' ); |
||
1842 | } else { |
||
1843 | $notice = __( 'The jetpack_offline_mode filter is set to true.', 'jetpack' ); |
||
1844 | } |
||
1845 | |||
1846 | return $notice; |
||
1847 | |||
1848 | } |
||
1849 | /** |
||
1850 | * Get Jetpack offline mode notice text and notice class. |
||
1851 | * |
||
1852 | * Mirrors the checks made in Automattic\Jetpack\Status->is_offline_mode |
||
1853 | */ |
||
1854 | public static function show_development_mode_notice() { |
||
1855 | View Code Duplication | if ( ( new Status() )->is_offline_mode() ) { |
|
1856 | $notice = sprintf( |
||
1857 | /* translators: %s is a URL */ |
||
1858 | __( 'In <a href="%s" target="_blank">Offline Mode</a>:', 'jetpack' ), |
||
1859 | Redirect::get_url( 'jetpack-support-development-mode' ) |
||
1860 | ); |
||
1861 | |||
1862 | $notice .= ' ' . self::development_mode_trigger_text(); |
||
1863 | |||
1864 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1865 | } |
||
1866 | |||
1867 | // Throw up a notice if using a development version and as for feedback. |
||
1868 | if ( self::is_development_version() ) { |
||
1869 | /* translators: %s is a URL */ |
||
1870 | $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), Redirect::get_url( 'jetpack-contact-support-beta-group' ) ); |
||
1871 | |||
1872 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1873 | } |
||
1874 | // Throw up a notice if using staging mode |
||
1875 | View Code Duplication | if ( ( new Status() )->is_staging_site() ) { |
|
1876 | /* translators: %s is a URL */ |
||
1877 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), Redirect::get_url( 'jetpack-support-staging-sites' ) ); |
||
1878 | |||
1879 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1880 | } |
||
1881 | } |
||
1882 | |||
1883 | /** |
||
1884 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1885 | */ |
||
1886 | public static function is_development_version() { |
||
1887 | /** |
||
1888 | * Allows filtering whether this is a development version of Jetpack. |
||
1889 | * |
||
1890 | * This filter is especially useful for tests. |
||
1891 | * |
||
1892 | * @since 4.3.0 |
||
1893 | * |
||
1894 | * @param bool $development_version Is this a develoment version of Jetpack? |
||
1895 | */ |
||
1896 | return (bool) apply_filters( |
||
1897 | 'jetpack_development_version', |
||
1898 | ! preg_match( '/^\d+(\.\d+)+$/', Constants::get_constant( 'JETPACK__VERSION' ) ) |
||
1899 | ); |
||
1900 | } |
||
1901 | |||
1902 | /** |
||
1903 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1904 | */ |
||
1905 | public static function is_user_connected( $user_id = false ) { |
||
1906 | _deprecated_function( __METHOD__, 'jetpack-9.5', 'Automattic\\Jetpack\\Connection\\Manager\\is_user_connected' ); |
||
1907 | return self::connection()->is_user_connected( $user_id ); |
||
1908 | } |
||
1909 | |||
1910 | /** |
||
1911 | * Get the wpcom user data of the current|specified connected user. |
||
1912 | */ |
||
1913 | public static function get_connected_user_data( $user_id = null ) { |
||
1914 | _deprecated_function( __METHOD__, 'jetpack-9.5', 'Automattic\\Jetpack\\Connection\\Manager\\get_connected_user_data' ); |
||
1915 | return self::connection()->get_connected_user_data( $user_id ); |
||
1916 | } |
||
1917 | |||
1918 | /** |
||
1919 | * Get the wpcom email of the current|specified connected user. |
||
1920 | */ |
||
1921 | public static function get_connected_user_email( $user_id = null ) { |
||
1922 | if ( ! $user_id ) { |
||
1923 | $user_id = get_current_user_id(); |
||
1924 | } |
||
1925 | |||
1926 | $xml = new Jetpack_IXR_Client( |
||
1927 | array( |
||
1928 | 'user_id' => $user_id, |
||
1929 | ) |
||
1930 | ); |
||
1931 | $xml->query( 'wpcom.getUserEmail' ); |
||
1932 | if ( ! $xml->isError() ) { |
||
1933 | return $xml->getResponse(); |
||
1934 | } |
||
1935 | return false; |
||
1936 | } |
||
1937 | |||
1938 | /** |
||
1939 | * Get the wpcom email of the master user. |
||
1940 | */ |
||
1941 | public static function get_master_user_email() { |
||
1942 | $master_user_id = Jetpack_Options::get_option( 'master_user' ); |
||
1943 | if ( $master_user_id ) { |
||
1944 | return self::get_connected_user_email( $master_user_id ); |
||
1945 | } |
||
1946 | return ''; |
||
1947 | } |
||
1948 | |||
1949 | /** |
||
1950 | * Whether the current user is the connection owner. |
||
1951 | * |
||
1952 | * @deprecated since 7.7 |
||
1953 | * |
||
1954 | * @return bool Whether the current user is the connection owner. |
||
1955 | */ |
||
1956 | public function current_user_is_connection_owner() { |
||
1957 | _deprecated_function( __METHOD__, 'jetpack-7.7', 'Automattic\\Jetpack\\Connection\\Manager::is_connection_owner' ); |
||
1958 | return self::connection()->is_connection_owner(); |
||
1959 | } |
||
1960 | |||
1961 | /** |
||
1962 | * Gets current user IP address. |
||
1963 | * |
||
1964 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
1965 | * |
||
1966 | * @return string Current user IP address. |
||
1967 | */ |
||
1968 | public static function current_user_ip( $check_all_headers = false ) { |
||
1969 | if ( $check_all_headers ) { |
||
1970 | foreach ( array( |
||
1971 | 'HTTP_CF_CONNECTING_IP', |
||
1972 | 'HTTP_CLIENT_IP', |
||
1973 | 'HTTP_X_FORWARDED_FOR', |
||
1974 | 'HTTP_X_FORWARDED', |
||
1975 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
1976 | 'HTTP_FORWARDED_FOR', |
||
1977 | 'HTTP_FORWARDED', |
||
1978 | 'HTTP_VIA', |
||
1979 | ) as $key ) { |
||
1980 | if ( ! empty( $_SERVER[ $key ] ) ) { |
||
1981 | return $_SERVER[ $key ]; |
||
1982 | } |
||
1983 | } |
||
1984 | } |
||
1985 | |||
1986 | return ! empty( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : ''; |
||
1987 | } |
||
1988 | |||
1989 | /** |
||
1990 | * Synchronize connected user role changes |
||
1991 | */ |
||
1992 | function user_role_change( $user_id ) { |
||
1993 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Users::user_role_change()' ); |
||
1994 | Users::user_role_change( $user_id ); |
||
1995 | } |
||
1996 | |||
1997 | /** |
||
1998 | * Loads the currently active modules. |
||
1999 | */ |
||
2000 | public static function load_modules() { |
||
2001 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
2002 | if ( |
||
2003 | ! self::is_connection_ready() |
||
2004 | && ! $is_offline_mode |
||
2005 | && ! self::is_onboarding() |
||
2006 | && ( |
||
2007 | ! is_multisite() |
||
2008 | || ! get_site_option( 'jetpack_protect_active' ) |
||
2009 | ) |
||
2010 | ) { |
||
2011 | return; |
||
2012 | } |
||
2013 | |||
2014 | $version = Jetpack_Options::get_option( 'version' ); |
||
2015 | View Code Duplication | if ( ! $version ) { |
|
2016 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
2017 | /** This action is documented in class.jetpack.php */ |
||
2018 | do_action( 'updating_jetpack_version', $version, false ); |
||
2019 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
2020 | } |
||
2021 | list( $version ) = explode( ':', $version ); |
||
2022 | |||
2023 | $modules = array_filter( self::get_active_modules(), array( 'Jetpack', 'is_module' ) ); |
||
2024 | |||
2025 | $modules_data = array(); |
||
2026 | |||
2027 | // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check. |
||
2028 | if ( version_compare( $version, JETPACK__VERSION, '<' ) ) { |
||
2029 | $updated_modules = array(); |
||
2030 | foreach ( $modules as $module ) { |
||
2031 | $modules_data[ $module ] = self::get_module( $module ); |
||
2032 | if ( ! isset( $modules_data[ $module ]['changed'] ) ) { |
||
2033 | continue; |
||
2034 | } |
||
2035 | |||
2036 | if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) { |
||
2037 | continue; |
||
2038 | } |
||
2039 | |||
2040 | $updated_modules[] = $module; |
||
2041 | } |
||
2042 | |||
2043 | $modules = array_diff( $modules, $updated_modules ); |
||
2044 | } |
||
2045 | |||
2046 | $is_userless = self::connection()->is_userless(); |
||
2047 | |||
2048 | foreach ( $modules as $index => $module ) { |
||
2049 | // If we're in offline/user-less mode, disable modules requiring a connection/user connection. |
||
2050 | if ( $is_offline_mode || $is_userless ) { |
||
2051 | // Prime the pump if we need to |
||
2052 | if ( empty( $modules_data[ $module ] ) ) { |
||
2053 | $modules_data[ $module ] = self::get_module( $module ); |
||
2054 | } |
||
2055 | // If the module requires a connection, but we're in local mode, don't include it. |
||
2056 | if ( $is_offline_mode && $modules_data[ $module ]['requires_connection'] ) { |
||
2057 | continue; |
||
2058 | } |
||
2059 | |||
2060 | if ( $is_userless && $modules_data[ $module ]['requires_user_connection'] ) { |
||
2061 | continue; |
||
2062 | } |
||
2063 | } |
||
2064 | |||
2065 | if ( did_action( 'jetpack_module_loaded_' . $module ) ) { |
||
2066 | continue; |
||
2067 | } |
||
2068 | |||
2069 | if ( ! include_once self::get_module_path( $module ) ) { |
||
2070 | unset( $modules[ $index ] ); |
||
2071 | self::update_active_modules( array_values( $modules ) ); |
||
2072 | continue; |
||
2073 | } |
||
2074 | |||
2075 | /** |
||
2076 | * Fires when a specific module is loaded. |
||
2077 | * The dynamic part of the hook, $module, is the module slug. |
||
2078 | * |
||
2079 | * @since 1.1.0 |
||
2080 | */ |
||
2081 | do_action( 'jetpack_module_loaded_' . $module ); |
||
2082 | } |
||
2083 | |||
2084 | /** |
||
2085 | * Fires when all the modules are loaded. |
||
2086 | * |
||
2087 | * @since 1.1.0 |
||
2088 | */ |
||
2089 | do_action( 'jetpack_modules_loaded' ); |
||
2090 | |||
2091 | // Load module-specific code that is needed even when a module isn't active. Loaded here because code contained therein may need actions such as setup_theme. |
||
2092 | require_once JETPACK__PLUGIN_DIR . 'modules/module-extras.php'; |
||
2093 | } |
||
2094 | |||
2095 | /** |
||
2096 | * Check if Jetpack's REST API compat file should be included |
||
2097 | * |
||
2098 | * @action plugins_loaded |
||
2099 | * @return null |
||
2100 | */ |
||
2101 | public function check_rest_api_compat() { |
||
2102 | /** |
||
2103 | * Filters the list of REST API compat files to be included. |
||
2104 | * |
||
2105 | * @since 2.2.5 |
||
2106 | * |
||
2107 | * @param array $args Array of REST API compat files to include. |
||
2108 | */ |
||
2109 | $_jetpack_rest_api_compat_includes = apply_filters( 'jetpack_rest_api_compat', array() ); |
||
2110 | |||
2111 | foreach ( $_jetpack_rest_api_compat_includes as $_jetpack_rest_api_compat_include ) { |
||
2112 | require_once $_jetpack_rest_api_compat_include; |
||
2113 | } |
||
2114 | } |
||
2115 | |||
2116 | /** |
||
2117 | * Gets all plugins currently active in values, regardless of whether they're |
||
2118 | * traditionally activated or network activated. |
||
2119 | * |
||
2120 | * @todo Store the result in core's object cache maybe? |
||
2121 | */ |
||
2122 | public static function get_active_plugins() { |
||
2123 | $active_plugins = (array) get_option( 'active_plugins', array() ); |
||
2124 | |||
2125 | if ( is_multisite() ) { |
||
2126 | // Due to legacy code, active_sitewide_plugins stores them in the keys, |
||
2127 | // whereas active_plugins stores them in the values. |
||
2128 | $network_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
||
2129 | if ( $network_plugins ) { |
||
2130 | $active_plugins = array_merge( $active_plugins, $network_plugins ); |
||
2131 | } |
||
2132 | } |
||
2133 | |||
2134 | sort( $active_plugins ); |
||
2135 | |||
2136 | return array_unique( $active_plugins ); |
||
2137 | } |
||
2138 | |||
2139 | /** |
||
2140 | * Gets and parses additional plugin data to send with the heartbeat data |
||
2141 | * |
||
2142 | * @since 3.8.1 |
||
2143 | * |
||
2144 | * @return array Array of plugin data |
||
2145 | */ |
||
2146 | public static function get_parsed_plugin_data() { |
||
2147 | if ( ! function_exists( 'get_plugins' ) ) { |
||
2148 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
||
2149 | } |
||
2150 | /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
||
2151 | $all_plugins = apply_filters( 'all_plugins', get_plugins() ); |
||
2152 | $active_plugins = self::get_active_plugins(); |
||
2153 | |||
2154 | $plugins = array(); |
||
2155 | foreach ( $all_plugins as $path => $plugin_data ) { |
||
2156 | $plugins[ $path ] = array( |
||
2157 | 'is_active' => in_array( $path, $active_plugins ), |
||
2158 | 'file' => $path, |
||
2159 | 'name' => $plugin_data['Name'], |
||
2160 | 'version' => $plugin_data['Version'], |
||
2161 | 'author' => $plugin_data['Author'], |
||
2162 | ); |
||
2163 | } |
||
2164 | |||
2165 | return $plugins; |
||
2166 | } |
||
2167 | |||
2168 | /** |
||
2169 | * Gets and parses theme data to send with the heartbeat data |
||
2170 | * |
||
2171 | * @since 3.8.1 |
||
2172 | * |
||
2173 | * @return array Array of theme data |
||
2174 | */ |
||
2175 | public static function get_parsed_theme_data() { |
||
2176 | $all_themes = wp_get_themes( array( 'allowed' => true ) ); |
||
2177 | $header_keys = array( 'Name', 'Author', 'Version', 'ThemeURI', 'AuthorURI', 'Status', 'Tags' ); |
||
2178 | |||
2179 | $themes = array(); |
||
2180 | foreach ( $all_themes as $slug => $theme_data ) { |
||
2181 | $theme_headers = array(); |
||
2182 | foreach ( $header_keys as $header_key ) { |
||
2183 | $theme_headers[ $header_key ] = $theme_data->get( $header_key ); |
||
2184 | } |
||
2185 | |||
2186 | $themes[ $slug ] = array( |
||
2187 | 'is_active_theme' => $slug == wp_get_theme()->get_template(), |
||
2188 | 'slug' => $slug, |
||
2189 | 'theme_root' => $theme_data->get_theme_root_uri(), |
||
2190 | 'parent' => $theme_data->parent(), |
||
2191 | 'headers' => $theme_headers, |
||
2192 | ); |
||
2193 | } |
||
2194 | |||
2195 | return $themes; |
||
2196 | } |
||
2197 | |||
2198 | /** |
||
2199 | * Checks whether a specific plugin is active. |
||
2200 | * |
||
2201 | * We don't want to store these in a static variable, in case |
||
2202 | * there are switch_to_blog() calls involved. |
||
2203 | */ |
||
2204 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
2205 | return in_array( $plugin, self::get_active_plugins() ); |
||
2206 | } |
||
2207 | |||
2208 | /** |
||
2209 | * Check if Jetpack's Open Graph tags should be used. |
||
2210 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
2211 | * |
||
2212 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2213 | * @action plugins_loaded |
||
2214 | * @return null |
||
2215 | */ |
||
2216 | public function check_open_graph() { |
||
2217 | if ( in_array( 'publicize', self::get_active_modules() ) || in_array( 'sharedaddy', self::get_active_modules() ) ) { |
||
2218 | add_filter( 'jetpack_enable_open_graph', '__return_true', 0 ); |
||
2219 | } |
||
2220 | |||
2221 | $active_plugins = self::get_active_plugins(); |
||
2222 | |||
2223 | if ( ! empty( $active_plugins ) ) { |
||
2224 | foreach ( $this->open_graph_conflicting_plugins as $plugin ) { |
||
2225 | if ( in_array( $plugin, $active_plugins ) ) { |
||
2226 | add_filter( 'jetpack_enable_open_graph', '__return_false', 99 ); |
||
2227 | break; |
||
2228 | } |
||
2229 | } |
||
2230 | } |
||
2231 | |||
2232 | /** |
||
2233 | * Allow the addition of Open Graph Meta Tags to all pages. |
||
2234 | * |
||
2235 | * @since 2.0.3 |
||
2236 | * |
||
2237 | * @param bool false Should Open Graph Meta tags be added. Default to false. |
||
2238 | */ |
||
2239 | if ( apply_filters( 'jetpack_enable_open_graph', false ) ) { |
||
2240 | require_once JETPACK__PLUGIN_DIR . 'functions.opengraph.php'; |
||
2241 | } |
||
2242 | } |
||
2243 | |||
2244 | /** |
||
2245 | * Check if Jetpack's Twitter tags should be used. |
||
2246 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
2247 | * |
||
2248 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2249 | * @action plugins_loaded |
||
2250 | * @return null |
||
2251 | */ |
||
2252 | public function check_twitter_tags() { |
||
2253 | |||
2254 | $active_plugins = self::get_active_plugins(); |
||
2255 | |||
2256 | if ( ! empty( $active_plugins ) ) { |
||
2257 | foreach ( $this->twitter_cards_conflicting_plugins as $plugin ) { |
||
2258 | if ( in_array( $plugin, $active_plugins ) ) { |
||
2259 | add_filter( 'jetpack_disable_twitter_cards', '__return_true', 99 ); |
||
2260 | break; |
||
2261 | } |
||
2262 | } |
||
2263 | } |
||
2264 | |||
2265 | /** |
||
2266 | * Allow Twitter Card Meta tags to be disabled. |
||
2267 | * |
||
2268 | * @since 2.6.0 |
||
2269 | * |
||
2270 | * @param bool true Should Twitter Card Meta tags be disabled. Default to true. |
||
2271 | */ |
||
2272 | if ( ! apply_filters( 'jetpack_disable_twitter_cards', false ) ) { |
||
2273 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-twitter-cards.php'; |
||
2274 | } |
||
2275 | } |
||
2276 | |||
2277 | /** |
||
2278 | * Allows plugins to submit security reports. |
||
2279 | * |
||
2280 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
2281 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
2282 | * @param array $args See definitions above |
||
2283 | */ |
||
2284 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
2285 | _deprecated_function( __FUNCTION__, 'jetpack-4.2', null ); |
||
2286 | } |
||
2287 | |||
2288 | /* Jetpack Options API */ |
||
2289 | |||
2290 | public static function get_option_names( $type = 'compact' ) { |
||
2291 | return Jetpack_Options::get_option_names( $type ); |
||
2292 | } |
||
2293 | |||
2294 | /** |
||
2295 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
2296 | * |
||
2297 | * @param string $name Option name |
||
2298 | * @param mixed $default (optional) |
||
2299 | */ |
||
2300 | public static function get_option( $name, $default = false ) { |
||
2301 | return Jetpack_Options::get_option( $name, $default ); |
||
2302 | } |
||
2303 | |||
2304 | /** |
||
2305 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
2306 | * |
||
2307 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
2308 | * @param string $name Option name |
||
2309 | * @param mixed $value Option value |
||
2310 | */ |
||
2311 | public static function update_option( $name, $value ) { |
||
2312 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::update_option()' ); |
||
2313 | return Jetpack_Options::update_option( $name, $value ); |
||
2314 | } |
||
2315 | |||
2316 | /** |
||
2317 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
2318 | * |
||
2319 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
2320 | * @param array $array array( option name => option value, ... ) |
||
2321 | */ |
||
2322 | public static function update_options( $array ) { |
||
2323 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::update_options()' ); |
||
2324 | return Jetpack_Options::update_options( $array ); |
||
2325 | } |
||
2326 | |||
2327 | /** |
||
2328 | * Deletes the given option. May be passed multiple option names as an array. |
||
2329 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
2330 | * |
||
2331 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
2332 | * @param string|array $names |
||
2333 | */ |
||
2334 | public static function delete_option( $names ) { |
||
2335 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::delete_option()' ); |
||
2336 | return Jetpack_Options::delete_option( $names ); |
||
2337 | } |
||
2338 | |||
2339 | /** |
||
2340 | * Enters a user token into the user_tokens option |
||
2341 | * |
||
2342 | * @deprecated 8.0 Use Automattic\Jetpack\Connection\Tokens->update_user_token() instead. |
||
2343 | * |
||
2344 | * @param int $user_id The user id. |
||
2345 | * @param string $token The user token. |
||
2346 | * @param bool $is_master_user Whether the user is the master user. |
||
2347 | * @return bool |
||
2348 | */ |
||
2349 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
2350 | _deprecated_function( __METHOD__, 'jetpack-9.5', 'Automattic\\Jetpack\\Connection\\Tokens->update_user_token' ); |
||
2351 | return ( new Tokens() )->update_user_token( $user_id, $token, $is_master_user ); |
||
2352 | } |
||
2353 | |||
2354 | /** |
||
2355 | * Returns an array of all PHP files in the specified absolute path. |
||
2356 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
2357 | * |
||
2358 | * @param string $absolute_path The absolute path of the directory to search. |
||
2359 | * @return array Array of absolute paths to the PHP files. |
||
2360 | */ |
||
2361 | public static function glob_php( $absolute_path ) { |
||
2362 | if ( function_exists( 'glob' ) ) { |
||
2363 | return glob( "$absolute_path/*.php" ); |
||
2364 | } |
||
2365 | |||
2366 | $absolute_path = untrailingslashit( $absolute_path ); |
||
2367 | $files = array(); |
||
2368 | if ( ! $dir = @opendir( $absolute_path ) ) { |
||
2369 | return $files; |
||
2370 | } |
||
2371 | |||
2372 | while ( false !== $file = readdir( $dir ) ) { |
||
2373 | if ( '.' == substr( $file, 0, 1 ) || '.php' != substr( $file, -4 ) ) { |
||
2374 | continue; |
||
2375 | } |
||
2376 | |||
2377 | $file = "$absolute_path/$file"; |
||
2378 | |||
2379 | if ( ! is_file( $file ) ) { |
||
2380 | continue; |
||
2381 | } |
||
2382 | |||
2383 | $files[] = $file; |
||
2384 | } |
||
2385 | |||
2386 | closedir( $dir ); |
||
2387 | |||
2388 | return $files; |
||
2389 | } |
||
2390 | |||
2391 | public static function activate_new_modules( $redirect = false ) { |
||
2392 | if ( ! self::is_connection_ready() && ! ( new Status() )->is_offline_mode() ) { |
||
2393 | return; |
||
2394 | } |
||
2395 | |||
2396 | $jetpack_old_version = Jetpack_Options::get_option( 'version' ); // [sic] |
||
2397 | View Code Duplication | if ( ! $jetpack_old_version ) { |
|
2398 | $jetpack_old_version = $version = $old_version = '1.1:' . time(); |
||
2399 | /** This action is documented in class.jetpack.php */ |
||
2400 | do_action( 'updating_jetpack_version', $version, false ); |
||
2401 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
2402 | } |
||
2403 | |||
2404 | list( $jetpack_version ) = explode( ':', $jetpack_old_version ); // [sic] |
||
2405 | |||
2406 | if ( version_compare( JETPACK__VERSION, $jetpack_version, '<=' ) ) { |
||
2407 | return; |
||
2408 | } |
||
2409 | |||
2410 | $active_modules = self::get_active_modules(); |
||
2411 | $reactivate_modules = array(); |
||
2412 | foreach ( $active_modules as $active_module ) { |
||
2413 | $module = self::get_module( $active_module ); |
||
2414 | if ( ! isset( $module['changed'] ) ) { |
||
2415 | continue; |
||
2416 | } |
||
2417 | |||
2418 | if ( version_compare( $module['changed'], $jetpack_version, '<=' ) ) { |
||
2419 | continue; |
||
2420 | } |
||
2421 | |||
2422 | $reactivate_modules[] = $active_module; |
||
2423 | self::deactivate_module( $active_module ); |
||
2424 | } |
||
2425 | |||
2426 | $new_version = JETPACK__VERSION . ':' . time(); |
||
2427 | /** This action is documented in class.jetpack.php */ |
||
2428 | do_action( 'updating_jetpack_version', $new_version, $jetpack_old_version ); |
||
2429 | Jetpack_Options::update_options( |
||
2430 | array( |
||
2431 | 'version' => $new_version, |
||
2432 | 'old_version' => $jetpack_old_version, |
||
2433 | ) |
||
2434 | ); |
||
2435 | |||
2436 | self::state( 'message', 'modules_activated' ); |
||
2437 | |||
2438 | self::activate_default_modules( $jetpack_version, JETPACK__VERSION, $reactivate_modules, $redirect ); |
||
2439 | |||
2440 | if ( $redirect ) { |
||
2441 | $page = 'jetpack'; // make sure we redirect to either settings or the jetpack page |
||
2442 | if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'jetpack', 'jetpack_modules' ) ) ) { |
||
2443 | $page = $_GET['page']; |
||
2444 | } |
||
2445 | |||
2446 | wp_safe_redirect( self::admin_url( 'page=' . $page ) ); |
||
2447 | exit; |
||
2448 | } |
||
2449 | } |
||
2450 | |||
2451 | /** |
||
2452 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
2453 | * Make sure to tuck away module "library" files in a sub-directory. |
||
2454 | * |
||
2455 | * @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter. |
||
2456 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
2457 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
2458 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
2459 | * |
||
2460 | * @return array $modules Array of module slugs |
||
2461 | */ |
||
2462 | public static function get_available_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
2463 | static $modules = null; |
||
2464 | |||
2465 | if ( ! isset( $modules ) ) { |
||
2466 | $available_modules_option = Jetpack_Options::get_option( 'available_modules', array() ); |
||
2467 | // Use the cache if we're on the front-end and it's available... |
||
2468 | if ( ! is_admin() && ! empty( $available_modules_option[ JETPACK__VERSION ] ) ) { |
||
2469 | $modules = $available_modules_option[ JETPACK__VERSION ]; |
||
2470 | } else { |
||
2471 | $files = self::glob_php( JETPACK__PLUGIN_DIR . 'modules' ); |
||
2472 | |||
2473 | $modules = array(); |
||
2474 | |||
2475 | foreach ( $files as $file ) { |
||
2476 | if ( ! $headers = self::get_module( $file ) ) { |
||
2477 | continue; |
||
2478 | } |
||
2479 | |||
2480 | $modules[ self::get_module_slug( $file ) ] = $headers['introduced']; |
||
2481 | } |
||
2482 | |||
2483 | Jetpack_Options::update_option( |
||
2484 | 'available_modules', |
||
2485 | array( |
||
2486 | JETPACK__VERSION => $modules, |
||
2487 | ) |
||
2488 | ); |
||
2489 | } |
||
2490 | } |
||
2491 | |||
2492 | /** |
||
2493 | * Filters the array of modules available to be activated. |
||
2494 | * |
||
2495 | * @since 2.4.0 |
||
2496 | * |
||
2497 | * @param array $modules Array of available modules. |
||
2498 | * @param string $min_version Minimum version number required to use modules. |
||
2499 | * @param string $max_version Maximum version number required to use modules. |
||
2500 | * @param bool|null $requires_connection Value of the Requires Connection filter. |
||
2501 | * @param bool|null $requires_user_connection Value of the Requires User Connection filter. |
||
2502 | */ |
||
2503 | $mods = apply_filters( 'jetpack_get_available_modules', $modules, $min_version, $max_version, $requires_connection, $requires_user_connection ); |
||
2504 | |||
2505 | if ( ! $min_version && ! $max_version && is_null( $requires_connection ) && is_null( $requires_user_connection ) ) { |
||
2506 | return array_keys( $mods ); |
||
2507 | } |
||
2508 | |||
2509 | $r = array(); |
||
2510 | foreach ( $mods as $slug => $introduced ) { |
||
2511 | if ( $min_version && version_compare( $min_version, $introduced, '>=' ) ) { |
||
2512 | continue; |
||
2513 | } |
||
2514 | |||
2515 | if ( $max_version && version_compare( $max_version, $introduced, '<' ) ) { |
||
2516 | continue; |
||
2517 | } |
||
2518 | |||
2519 | $mod_details = self::get_module( $slug ); |
||
2520 | |||
2521 | if ( null !== $requires_connection && (bool) $requires_connection !== $mod_details['requires_connection'] ) { |
||
2522 | continue; |
||
2523 | } |
||
2524 | |||
2525 | if ( null !== $requires_user_connection && (bool) $requires_user_connection !== $mod_details['requires_user_connection'] ) { |
||
2526 | continue; |
||
2527 | } |
||
2528 | |||
2529 | $r[] = $slug; |
||
2530 | } |
||
2531 | |||
2532 | return $r; |
||
2533 | } |
||
2534 | |||
2535 | /** |
||
2536 | * Get default modules loaded on activation. |
||
2537 | * |
||
2538 | * @param bool|string $min_version Onlu return modules introduced in this version or later. Default is false, do not filter. |
||
2539 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
2540 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
2541 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
2542 | * |
||
2543 | * @return array $modules Array of module slugs |
||
2544 | */ |
||
2545 | public static function get_default_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
2546 | $return = array(); |
||
2547 | |||
2548 | foreach ( self::get_available_modules( $min_version, $max_version, $requires_connection, $requires_user_connection ) as $module ) { |
||
2549 | $module_data = self::get_module( $module ); |
||
2550 | |||
2551 | switch ( strtolower( $module_data['auto_activate'] ) ) { |
||
2552 | case 'yes': |
||
2553 | $return[] = $module; |
||
2554 | break; |
||
2555 | case 'public': |
||
2556 | if ( Jetpack_Options::get_option( 'public' ) ) { |
||
2557 | $return[] = $module; |
||
2558 | } |
||
2559 | break; |
||
2560 | case 'no': |
||
2561 | default: |
||
2562 | break; |
||
2563 | } |
||
2564 | } |
||
2565 | /** |
||
2566 | * Filters the array of default modules. |
||
2567 | * |
||
2568 | * @since 2.5.0 |
||
2569 | * |
||
2570 | * @param array $return Array of default modules. |
||
2571 | * @param string $min_version Minimum version number required to use modules. |
||
2572 | * @param string $max_version Maximum version number required to use modules. |
||
2573 | * @param bool|null $requires_connection Value of the Requires Connection filter. |
||
2574 | * @param bool|null $requires_user_connection Value of the Requires User Connection filter. |
||
2575 | */ |
||
2576 | return apply_filters( 'jetpack_get_default_modules', $return, $min_version, $max_version, $requires_connection, $requires_user_connection ); |
||
2577 | } |
||
2578 | |||
2579 | /** |
||
2580 | * Checks activated modules during auto-activation to determine |
||
2581 | * if any of those modules are being deprecated. If so, close |
||
2582 | * them out, and add any replacement modules. |
||
2583 | * |
||
2584 | * Runs at priority 99 by default. |
||
2585 | * |
||
2586 | * This is run late, so that it can still activate a module if |
||
2587 | * the new module is a replacement for another that the user |
||
2588 | * currently has active, even if something at the normal priority |
||
2589 | * would kibosh everything. |
||
2590 | * |
||
2591 | * @since 2.6 |
||
2592 | * @uses jetpack_get_default_modules filter |
||
2593 | * @param array $modules |
||
2594 | * @return array |
||
2595 | */ |
||
2596 | function handle_deprecated_modules( $modules ) { |
||
2597 | $deprecated_modules = array( |
||
2598 | 'debug' => null, // Closed out and moved to the debugger library. |
||
2599 | 'wpcc' => 'sso', // Closed out in 2.6 -- SSO provides the same functionality. |
||
2600 | 'gplus-authorship' => null, // Closed out in 3.2 -- Google dropped support. |
||
2601 | 'minileven' => null, // Closed out in 8.3 -- Responsive themes are common now, and so is AMP. |
||
2602 | ); |
||
2603 | |||
2604 | // Don't activate SSO if they never completed activating WPCC. |
||
2605 | if ( self::is_module_active( 'wpcc' ) ) { |
||
2606 | $wpcc_options = Jetpack_Options::get_option( 'wpcc_options' ); |
||
2607 | if ( empty( $wpcc_options ) || empty( $wpcc_options['client_id'] ) || empty( $wpcc_options['client_id'] ) ) { |
||
2608 | $deprecated_modules['wpcc'] = null; |
||
2609 | } |
||
2610 | } |
||
2611 | |||
2612 | foreach ( $deprecated_modules as $module => $replacement ) { |
||
2613 | if ( self::is_module_active( $module ) ) { |
||
2614 | self::deactivate_module( $module ); |
||
2615 | if ( $replacement ) { |
||
2616 | $modules[] = $replacement; |
||
2617 | } |
||
2618 | } |
||
2619 | } |
||
2620 | |||
2621 | return array_unique( $modules ); |
||
2622 | } |
||
2623 | |||
2624 | /** |
||
2625 | * Checks activated plugins during auto-activation to determine |
||
2626 | * if any of those plugins are in the list with a corresponding module |
||
2627 | * that is not compatible with the plugin. The module will not be allowed |
||
2628 | * to auto-activate. |
||
2629 | * |
||
2630 | * @since 2.6 |
||
2631 | * @uses jetpack_get_default_modules filter |
||
2632 | * @param array $modules |
||
2633 | * @return array |
||
2634 | */ |
||
2635 | function filter_default_modules( $modules ) { |
||
2636 | |||
2637 | $active_plugins = self::get_active_plugins(); |
||
2638 | |||
2639 | if ( ! empty( $active_plugins ) ) { |
||
2640 | |||
2641 | // For each module we'd like to auto-activate... |
||
2642 | foreach ( $modules as $key => $module ) { |
||
2643 | // If there are potential conflicts for it... |
||
2644 | if ( ! empty( $this->conflicting_plugins[ $module ] ) ) { |
||
2645 | // For each potential conflict... |
||
2646 | foreach ( $this->conflicting_plugins[ $module ] as $title => $plugin ) { |
||
2647 | // If that conflicting plugin is active... |
||
2648 | if ( in_array( $plugin, $active_plugins ) ) { |
||
2649 | // Remove that item from being auto-activated. |
||
2650 | unset( $modules[ $key ] ); |
||
2651 | } |
||
2652 | } |
||
2653 | } |
||
2654 | } |
||
2655 | } |
||
2656 | |||
2657 | return $modules; |
||
2658 | } |
||
2659 | |||
2660 | /** |
||
2661 | * Extract a module's slug from its full path. |
||
2662 | */ |
||
2663 | public static function get_module_slug( $file ) { |
||
2664 | return str_replace( '.php', '', basename( $file ) ); |
||
2665 | } |
||
2666 | |||
2667 | /** |
||
2668 | * Generate a module's path from its slug. |
||
2669 | */ |
||
2670 | public static function get_module_path( $slug ) { |
||
2671 | /** |
||
2672 | * Filters the path of a modules. |
||
2673 | * |
||
2674 | * @since 7.4.0 |
||
2675 | * |
||
2676 | * @param array $return The absolute path to a module's root php file |
||
2677 | * @param string $slug The module slug |
||
2678 | */ |
||
2679 | return apply_filters( 'jetpack_get_module_path', JETPACK__PLUGIN_DIR . "modules/$slug.php", $slug ); |
||
2680 | } |
||
2681 | |||
2682 | /** |
||
2683 | * Load module data from module file. Headers differ from WordPress |
||
2684 | * plugin headers to avoid them being identified as standalone |
||
2685 | * plugins on the WordPress plugins page. |
||
2686 | */ |
||
2687 | public static function get_module( $module ) { |
||
2688 | $headers = array( |
||
2689 | 'name' => 'Module Name', |
||
2690 | 'description' => 'Module Description', |
||
2691 | 'sort' => 'Sort Order', |
||
2692 | 'recommendation_order' => 'Recommendation Order', |
||
2693 | 'introduced' => 'First Introduced', |
||
2694 | 'changed' => 'Major Changes In', |
||
2695 | 'deactivate' => 'Deactivate', |
||
2696 | 'free' => 'Free', |
||
2697 | 'requires_connection' => 'Requires Connection', |
||
2698 | 'requires_user_connection' => 'Requires User Connection', |
||
2699 | 'auto_activate' => 'Auto Activate', |
||
2700 | 'module_tags' => 'Module Tags', |
||
2701 | 'feature' => 'Feature', |
||
2702 | 'additional_search_queries' => 'Additional Search Queries', |
||
2703 | 'plan_classes' => 'Plans', |
||
2704 | ); |
||
2705 | |||
2706 | static $modules_details; |
||
2707 | $file = self::get_module_path( self::get_module_slug( $module ) ); |
||
2708 | |||
2709 | if ( isset( $modules_details[ $module ] ) ) { |
||
2710 | $mod = $modules_details[ $module ]; |
||
2711 | } else { |
||
2712 | |||
2713 | $mod = self::get_file_data( $file, $headers ); |
||
2714 | if ( empty( $mod['name'] ) ) { |
||
2715 | return false; |
||
2716 | } |
||
2717 | |||
2718 | $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort']; |
||
2719 | $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order']; |
||
2720 | $mod['deactivate'] = empty( $mod['deactivate'] ); |
||
2721 | $mod['free'] = empty( $mod['free'] ); |
||
2722 | $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' === $mod['requires_connection'] ) ? false : true; |
||
2723 | $mod['requires_user_connection'] = ( empty( $mod['requires_user_connection'] ) || 'No' === $mod['requires_user_connection'] ) ? false : true; |
||
2724 | |||
2725 | if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ), true ) ) { |
||
2726 | $mod['auto_activate'] = 'No'; |
||
2727 | } else { |
||
2728 | $mod['auto_activate'] = (string) $mod['auto_activate']; |
||
2729 | } |
||
2730 | |||
2731 | if ( $mod['module_tags'] ) { |
||
2732 | $mod['module_tags'] = explode( ',', $mod['module_tags'] ); |
||
2733 | $mod['module_tags'] = array_map( 'trim', $mod['module_tags'] ); |
||
2734 | $mod['module_tags'] = array_map( array( __CLASS__, 'translate_module_tag' ), $mod['module_tags'] ); |
||
2735 | } else { |
||
2736 | $mod['module_tags'] = array( self::translate_module_tag( 'Other' ) ); |
||
2737 | } |
||
2738 | |||
2739 | View Code Duplication | if ( $mod['plan_classes'] ) { |
|
2740 | $mod['plan_classes'] = explode( ',', $mod['plan_classes'] ); |
||
2741 | $mod['plan_classes'] = array_map( 'strtolower', array_map( 'trim', $mod['plan_classes'] ) ); |
||
2742 | } else { |
||
2743 | $mod['plan_classes'] = array( 'free' ); |
||
2744 | } |
||
2745 | |||
2746 | View Code Duplication | if ( $mod['feature'] ) { |
|
2747 | $mod['feature'] = explode( ',', $mod['feature'] ); |
||
2748 | $mod['feature'] = array_map( 'trim', $mod['feature'] ); |
||
2749 | } else { |
||
2750 | $mod['feature'] = array( self::translate_module_tag( 'Other' ) ); |
||
2751 | } |
||
2752 | |||
2753 | $modules_details[ $module ] = $mod; |
||
2754 | |||
2755 | } |
||
2756 | |||
2757 | /** |
||
2758 | * Filters the feature array on a module. |
||
2759 | * |
||
2760 | * This filter allows you to control where each module is filtered: Recommended, |
||
2761 | * and the default "Other" listing. |
||
2762 | * |
||
2763 | * @since 3.5.0 |
||
2764 | * |
||
2765 | * @param array $mod['feature'] The areas to feature this module: |
||
2766 | * 'Recommended' shows on the main Jetpack admin screen. |
||
2767 | * 'Other' should be the default if no other value is in the array. |
||
2768 | * @param string $module The slug of the module, e.g. sharedaddy. |
||
2769 | * @param array $mod All the currently assembled module data. |
||
2770 | */ |
||
2771 | $mod['feature'] = apply_filters( 'jetpack_module_feature', $mod['feature'], $module, $mod ); |
||
2772 | |||
2773 | /** |
||
2774 | * Filter the returned data about a module. |
||
2775 | * |
||
2776 | * This filter allows overriding any info about Jetpack modules. It is dangerous, |
||
2777 | * so please be careful. |
||
2778 | * |
||
2779 | * @since 3.6.0 |
||
2780 | * |
||
2781 | * @param array $mod The details of the requested module. |
||
2782 | * @param string $module The slug of the module, e.g. sharedaddy |
||
2783 | * @param string $file The path to the module source file. |
||
2784 | */ |
||
2785 | return apply_filters( 'jetpack_get_module', $mod, $module, $file ); |
||
2786 | } |
||
2787 | |||
2788 | /** |
||
2789 | * Like core's get_file_data implementation, but caches the result. |
||
2790 | */ |
||
2791 | public static function get_file_data( $file, $headers ) { |
||
2792 | // Get just the filename from $file (i.e. exclude full path) so that a consistent hash is generated |
||
2793 | $file_name = basename( $file ); |
||
2794 | |||
2795 | $cache_key = 'jetpack_file_data_' . JETPACK__VERSION; |
||
2796 | |||
2797 | $file_data_option = get_transient( $cache_key ); |
||
2798 | |||
2799 | if ( ! is_array( $file_data_option ) ) { |
||
2800 | delete_transient( $cache_key ); |
||
2801 | $file_data_option = false; |
||
2802 | } |
||
2803 | |||
2804 | if ( false === $file_data_option ) { |
||
2805 | $file_data_option = array(); |
||
2806 | } |
||
2807 | |||
2808 | $key = md5( $file_name . serialize( $headers ) ); |
||
2809 | $refresh_cache = is_admin() && isset( $_GET['page'] ) && 'jetpack' === substr( $_GET['page'], 0, 7 ); |
||
2810 | |||
2811 | // If we don't need to refresh the cache, and already have the value, short-circuit! |
||
2812 | if ( ! $refresh_cache && isset( $file_data_option[ $key ] ) ) { |
||
2813 | return $file_data_option[ $key ]; |
||
2814 | } |
||
2815 | |||
2816 | $data = get_file_data( $file, $headers ); |
||
2817 | |||
2818 | $file_data_option[ $key ] = $data; |
||
2819 | |||
2820 | set_transient( $cache_key, $file_data_option, 29 * DAY_IN_SECONDS ); |
||
2821 | |||
2822 | return $data; |
||
2823 | } |
||
2824 | |||
2825 | /** |
||
2826 | * Return translated module tag. |
||
2827 | * |
||
2828 | * @param string $tag Tag as it appears in each module heading. |
||
2829 | * |
||
2830 | * @return mixed |
||
2831 | */ |
||
2832 | public static function translate_module_tag( $tag ) { |
||
2833 | return jetpack_get_module_i18n_tag( $tag ); |
||
2834 | } |
||
2835 | |||
2836 | /** |
||
2837 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2838 | * |
||
2839 | * @since 3.9.2 |
||
2840 | * |
||
2841 | * @param array $modules |
||
2842 | * |
||
2843 | * @return string|void |
||
2844 | */ |
||
2845 | public static function get_translated_modules( $modules ) { |
||
2846 | foreach ( $modules as $index => $module ) { |
||
2847 | $i18n_module = jetpack_get_module_i18n( $module['module'] ); |
||
2848 | if ( isset( $module['name'] ) ) { |
||
2849 | $modules[ $index ]['name'] = $i18n_module['name']; |
||
2850 | } |
||
2851 | if ( isset( $module['description'] ) ) { |
||
2852 | $modules[ $index ]['description'] = $i18n_module['description']; |
||
2853 | $modules[ $index ]['short_description'] = $i18n_module['description']; |
||
2854 | } |
||
2855 | } |
||
2856 | return $modules; |
||
2857 | } |
||
2858 | |||
2859 | /** |
||
2860 | * Get a list of activated modules as an array of module slugs. |
||
2861 | */ |
||
2862 | public static function get_active_modules() { |
||
2863 | $active = Jetpack_Options::get_option( 'active_modules' ); |
||
2864 | |||
2865 | if ( ! is_array( $active ) ) { |
||
2866 | $active = array(); |
||
2867 | } |
||
2868 | |||
2869 | if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) { |
||
2870 | $active[] = 'vaultpress'; |
||
2871 | } else { |
||
2872 | $active = array_diff( $active, array( 'vaultpress' ) ); |
||
2873 | } |
||
2874 | |||
2875 | // If protect is active on the main site of a multisite, it should be active on all sites. |
||
2876 | if ( ! in_array( 'protect', $active ) && is_multisite() && get_site_option( 'jetpack_protect_active' ) ) { |
||
2877 | $active[] = 'protect'; |
||
2878 | } |
||
2879 | |||
2880 | /** |
||
2881 | * Allow filtering of the active modules. |
||
2882 | * |
||
2883 | * Gives theme and plugin developers the power to alter the modules that |
||
2884 | * are activated on the fly. |
||
2885 | * |
||
2886 | * @since 5.8.0 |
||
2887 | * |
||
2888 | * @param array $active Array of active module slugs. |
||
2889 | */ |
||
2890 | $active = apply_filters( 'jetpack_active_modules', $active ); |
||
2891 | |||
2892 | return array_unique( $active ); |
||
2893 | } |
||
2894 | |||
2895 | /** |
||
2896 | * Check whether or not a Jetpack module is active. |
||
2897 | * |
||
2898 | * @param string $module The slug of a Jetpack module. |
||
2899 | * @return bool |
||
2900 | * |
||
2901 | * @static |
||
2902 | */ |
||
2903 | public static function is_module_active( $module ) { |
||
2904 | return in_array( $module, self::get_active_modules() ); |
||
2905 | } |
||
2906 | |||
2907 | public static function is_module( $module ) { |
||
2908 | return ! empty( $module ) && ! validate_file( $module, self::get_available_modules() ); |
||
2909 | } |
||
2910 | |||
2911 | /** |
||
2912 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2913 | * |
||
2914 | * @param bool $catch True to start catching, False to stop. |
||
2915 | * |
||
2916 | * @static |
||
2917 | */ |
||
2918 | public static function catch_errors( $catch ) { |
||
2919 | static $display_errors, $error_reporting; |
||
2920 | |||
2921 | if ( $catch ) { |
||
2922 | $display_errors = @ini_set( 'display_errors', 1 ); |
||
2923 | $error_reporting = @error_reporting( E_ALL ); |
||
2924 | add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
2925 | } else { |
||
2926 | @ini_set( 'display_errors', $display_errors ); |
||
2927 | @error_reporting( $error_reporting ); |
||
2928 | remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
2929 | } |
||
2930 | } |
||
2931 | |||
2932 | /** |
||
2933 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2934 | */ |
||
2935 | public static function catch_errors_on_shutdown() { |
||
2936 | self::state( 'php_errors', self::alias_directories( ob_get_clean() ) ); |
||
2937 | } |
||
2938 | |||
2939 | /** |
||
2940 | * Rewrite any string to make paths easier to read. |
||
2941 | * |
||
2942 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
2943 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
2944 | * |
||
2945 | * @param $string |
||
2946 | * @return mixed |
||
2947 | */ |
||
2948 | public static function alias_directories( $string ) { |
||
2949 | // ABSPATH has a trailing slash. |
||
2950 | $string = str_replace( ABSPATH, 'ABSPATH/', $string ); |
||
2951 | // WP_CONTENT_DIR does not have a trailing slash. |
||
2952 | $string = str_replace( WP_CONTENT_DIR, 'WP_CONTENT_DIR', $string ); |
||
2953 | |||
2954 | return $string; |
||
2955 | } |
||
2956 | |||
2957 | public static function activate_default_modules( |
||
2958 | $min_version = false, |
||
2959 | $max_version = false, |
||
2960 | $other_modules = array(), |
||
2961 | $redirect = null, |
||
2962 | $send_state_messages = null, |
||
2963 | $requires_connection = null, |
||
2964 | $requires_user_connection = null |
||
2965 | ) { |
||
2966 | $jetpack = self::init(); |
||
2967 | |||
2968 | if ( is_null( $redirect ) ) { |
||
2969 | if ( |
||
2970 | ( defined( 'REST_REQUEST' ) && REST_REQUEST ) |
||
2971 | || |
||
2972 | ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
||
2973 | || |
||
2974 | ( defined( 'WP_CLI' ) && WP_CLI ) |
||
2975 | || |
||
2976 | ( defined( 'DOING_CRON' ) && DOING_CRON ) |
||
2977 | || |
||
2978 | ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
||
2979 | ) { |
||
2980 | $redirect = false; |
||
2981 | } elseif ( is_admin() ) { |
||
2982 | $redirect = true; |
||
2983 | } else { |
||
2984 | $redirect = false; |
||
2985 | } |
||
2986 | } |
||
2987 | |||
2988 | if ( is_null( $send_state_messages ) ) { |
||
2989 | $send_state_messages = current_user_can( 'jetpack_activate_modules' ); |
||
2990 | } |
||
2991 | |||
2992 | $modules = self::get_default_modules( $min_version, $max_version, $requires_connection, $requires_user_connection ); |
||
2993 | $modules = array_merge( $other_modules, $modules ); |
||
2994 | |||
2995 | // Look for standalone plugins and disable if active. |
||
2996 | |||
2997 | $to_deactivate = array(); |
||
2998 | foreach ( $modules as $module ) { |
||
2999 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
3000 | $to_deactivate[ $module ] = $jetpack->plugins_to_deactivate[ $module ]; |
||
3001 | } |
||
3002 | } |
||
3003 | |||
3004 | $deactivated = array(); |
||
3005 | foreach ( $to_deactivate as $module => $deactivate_me ) { |
||
3006 | list( $probable_file, $probable_title ) = $deactivate_me; |
||
3007 | if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) { |
||
3008 | $deactivated[] = $module; |
||
3009 | } |
||
3010 | } |
||
3011 | |||
3012 | if ( $deactivated ) { |
||
3013 | if ( $send_state_messages ) { |
||
3014 | self::state( 'deactivated_plugins', join( ',', $deactivated ) ); |
||
3015 | } |
||
3016 | |||
3017 | if ( $redirect ) { |
||
3018 | $url = add_query_arg( |
||
3019 | array( |
||
3020 | 'action' => 'activate_default_modules', |
||
3021 | '_wpnonce' => wp_create_nonce( 'activate_default_modules' ), |
||
3022 | ), |
||
3023 | add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), self::admin_url( 'page=jetpack' ) ) |
||
3024 | ); |
||
3025 | wp_safe_redirect( $url ); |
||
3026 | exit; |
||
3027 | } |
||
3028 | } |
||
3029 | |||
3030 | /** |
||
3031 | * Fires before default modules are activated. |
||
3032 | * |
||
3033 | * @since 1.9.0 |
||
3034 | * |
||
3035 | * @param string $min_version Minimum version number required to use modules. |
||
3036 | * @param string $max_version Maximum version number required to use modules. |
||
3037 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
3038 | * @param bool|null $requires_connection Value of the Requires Connection filter. |
||
3039 | * @param bool|null $requires_user_connection Value of the Requires User Connection filter. |
||
3040 | */ |
||
3041 | do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules, $requires_connection, $requires_user_connection ); |
||
3042 | |||
3043 | // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating |
||
3044 | if ( $send_state_messages ) { |
||
3045 | self::restate(); |
||
3046 | self::catch_errors( true ); |
||
3047 | } |
||
3048 | |||
3049 | $active = self::get_active_modules(); |
||
3050 | |||
3051 | foreach ( $modules as $module ) { |
||
3052 | if ( did_action( "jetpack_module_loaded_$module" ) ) { |
||
3053 | $active[] = $module; |
||
3054 | self::update_active_modules( $active ); |
||
3055 | continue; |
||
3056 | } |
||
3057 | |||
3058 | if ( $send_state_messages && in_array( $module, $active ) ) { |
||
3059 | $module_info = self::get_module( $module ); |
||
3060 | View Code Duplication | if ( ! $module_info['deactivate'] ) { |
|
3061 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
3062 | if ( $active_state = self::state( $state ) ) { |
||
3063 | $active_state = explode( ',', $active_state ); |
||
3064 | } else { |
||
3065 | $active_state = array(); |
||
3066 | } |
||
3067 | $active_state[] = $module; |
||
3068 | self::state( $state, implode( ',', $active_state ) ); |
||
3069 | } |
||
3070 | continue; |
||
3071 | } |
||
3072 | |||
3073 | $file = self::get_module_path( $module ); |
||
3074 | if ( ! file_exists( $file ) ) { |
||
3075 | continue; |
||
3076 | } |
||
3077 | |||
3078 | // we'll override this later if the plugin can be included without fatal error |
||
3079 | if ( $redirect ) { |
||
3080 | wp_safe_redirect( self::admin_url( 'page=jetpack' ) ); |
||
3081 | } |
||
3082 | |||
3083 | if ( $send_state_messages ) { |
||
3084 | self::state( 'error', 'module_activation_failed' ); |
||
3085 | self::state( 'module', $module ); |
||
3086 | } |
||
3087 | |||
3088 | ob_start(); |
||
3089 | require_once $file; |
||
3090 | |||
3091 | $active[] = $module; |
||
3092 | |||
3093 | View Code Duplication | if ( $send_state_messages ) { |
|
3094 | |||
3095 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
3096 | if ( $active_state = self::state( $state ) ) { |
||
3097 | $active_state = explode( ',', $active_state ); |
||
3098 | } else { |
||
3099 | $active_state = array(); |
||
3100 | } |
||
3101 | $active_state[] = $module; |
||
3102 | self::state( $state, implode( ',', $active_state ) ); |
||
3103 | } |
||
3104 | |||
3105 | self::update_active_modules( $active ); |
||
3106 | |||
3107 | ob_end_clean(); |
||
3108 | } |
||
3109 | |||
3110 | if ( $send_state_messages ) { |
||
3111 | self::state( 'error', false ); |
||
3112 | self::state( 'module', false ); |
||
3113 | } |
||
3114 | |||
3115 | self::catch_errors( false ); |
||
3116 | /** |
||
3117 | * Fires when default modules are activated. |
||
3118 | * |
||
3119 | * @since 1.9.0 |
||
3120 | * |
||
3121 | * @param string $min_version Minimum version number required to use modules. |
||
3122 | * @param string $max_version Maximum version number required to use modules. |
||
3123 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
3124 | * @param bool|null $requires_connection Value of the Requires Connection filter. |
||
3125 | * @param bool|null $requires_user_connection Value of the Requires User Connection filter. |
||
3126 | */ |
||
3127 | do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules, $requires_connection, $requires_user_connection ); |
||
3128 | } |
||
3129 | |||
3130 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
3131 | /** |
||
3132 | * Fires before a module is activated. |
||
3133 | * |
||
3134 | * @since 2.6.0 |
||
3135 | * |
||
3136 | * @param string $module Module slug. |
||
3137 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
3138 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
3139 | */ |
||
3140 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
3141 | |||
3142 | $jetpack = self::init(); |
||
3143 | |||
3144 | if ( ! strlen( $module ) ) { |
||
3145 | return false; |
||
3146 | } |
||
3147 | |||
3148 | if ( ! self::is_module( $module ) ) { |
||
3149 | return false; |
||
3150 | } |
||
3151 | |||
3152 | // If it's already active, then don't do it again |
||
3153 | $active = self::get_active_modules(); |
||
3154 | foreach ( $active as $act ) { |
||
3155 | if ( $act == $module ) { |
||
3156 | return true; |
||
3157 | } |
||
3158 | } |
||
3159 | |||
3160 | $module_data = self::get_module( $module ); |
||
3161 | |||
3162 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
3163 | if ( ! self::is_connection_ready() ) { |
||
3164 | if ( ! $is_offline_mode && ! self::is_onboarding() ) { |
||
3165 | return false; |
||
3166 | } |
||
3167 | |||
3168 | // If we're not connected but in offline mode, make sure the module doesn't require a connection. |
||
3169 | if ( $is_offline_mode && $module_data['requires_connection'] ) { |
||
3170 | return false; |
||
3171 | } |
||
3172 | } |
||
3173 | |||
3174 | // Check and see if the old plugin is active |
||
3175 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
3176 | // Deactivate the old plugin |
||
3177 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
3178 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
3179 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
3180 | self::state( 'deactivated_plugins', $module ); |
||
3181 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
3182 | exit; |
||
3183 | } |
||
3184 | } |
||
3185 | |||
3186 | // Protect won't work with mis-configured IPs |
||
3187 | if ( 'protect' === $module ) { |
||
3188 | include_once JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php'; |
||
3189 | if ( ! jetpack_protect_get_ip() ) { |
||
3190 | self::state( 'message', 'protect_misconfigured_ip' ); |
||
3191 | return false; |
||
3192 | } |
||
3193 | } |
||
3194 | |||
3195 | if ( ! Jetpack_Plan::supports( $module ) ) { |
||
3196 | return false; |
||
3197 | } |
||
3198 | |||
3199 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
3200 | self::state( 'module', $module ); |
||
3201 | self::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
3202 | |||
3203 | self::catch_errors( true ); |
||
3204 | ob_start(); |
||
3205 | require self::get_module_path( $module ); |
||
3206 | /** This action is documented in class.jetpack.php */ |
||
3207 | do_action( 'jetpack_activate_module', $module ); |
||
3208 | $active[] = $module; |
||
3209 | self::update_active_modules( $active ); |
||
3210 | |||
3211 | self::state( 'error', false ); // the override |
||
3212 | ob_end_clean(); |
||
3213 | self::catch_errors( false ); |
||
3214 | |||
3215 | if ( $redirect ) { |
||
3216 | wp_safe_redirect( self::admin_url( 'page=jetpack' ) ); |
||
3217 | } |
||
3218 | if ( $exit ) { |
||
3219 | exit; |
||
3220 | } |
||
3221 | return true; |
||
3222 | } |
||
3223 | |||
3224 | function activate_module_actions( $module ) { |
||
3225 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
3226 | } |
||
3227 | |||
3228 | public static function deactivate_module( $module ) { |
||
3229 | /** |
||
3230 | * Fires when a module is deactivated. |
||
3231 | * |
||
3232 | * @since 1.9.0 |
||
3233 | * |
||
3234 | * @param string $module Module slug. |
||
3235 | */ |
||
3236 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
3237 | |||
3238 | $jetpack = self::init(); |
||
3239 | |||
3240 | $active = self::get_active_modules(); |
||
3241 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
3242 | |||
3243 | return self::update_active_modules( $new ); |
||
3244 | } |
||
3245 | |||
3246 | public static function enable_module_configurable( $module ) { |
||
3247 | $module = self::get_module_slug( $module ); |
||
3248 | add_filter( 'jetpack_module_configurable_' . $module, '__return_true' ); |
||
3249 | } |
||
3250 | |||
3251 | /** |
||
3252 | * Composes a module configure URL. It uses Jetpack settings search as default value |
||
3253 | * It is possible to redefine resulting URL by using "jetpack_module_configuration_url_$module" filter |
||
3254 | * |
||
3255 | * @param string $module Module slug |
||
3256 | * @return string $url module configuration URL |
||
3257 | */ |
||
3258 | public static function module_configuration_url( $module ) { |
||
3259 | $module = self::get_module_slug( $module ); |
||
3260 | $default_url = self::admin_url() . "#/settings?term=$module"; |
||
3261 | /** |
||
3262 | * Allows to modify configure_url of specific module to be able to redirect to some custom location. |
||
3263 | * |
||
3264 | * @since 6.9.0 |
||
3265 | * |
||
3266 | * @param string $default_url Default url, which redirects to jetpack settings page. |
||
3267 | */ |
||
3268 | $url = apply_filters( 'jetpack_module_configuration_url_' . $module, $default_url ); |
||
3269 | |||
3270 | return $url; |
||
3271 | } |
||
3272 | |||
3273 | /* Installation */ |
||
3274 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
3275 | ?> |
||
3276 | <!doctype html> |
||
3277 | <html> |
||
3278 | <head> |
||
3279 | <meta charset="<?php bloginfo( 'charset' ); ?>"> |
||
3280 | <style> |
||
3281 | * { |
||
3282 | text-align: center; |
||
3283 | margin: 0; |
||
3284 | padding: 0; |
||
3285 | font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; |
||
3286 | } |
||
3287 | p { |
||
3288 | margin-top: 1em; |
||
3289 | font-size: 18px; |
||
3290 | } |
||
3291 | </style> |
||
3292 | <body> |
||
3293 | <p><?php echo esc_html( $message ); ?></p> |
||
3294 | </body> |
||
3295 | </html> |
||
3296 | <?php |
||
3297 | if ( $deactivate ) { |
||
3298 | $plugins = get_option( 'active_plugins' ); |
||
3299 | $jetpack = plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ); |
||
3300 | $update = false; |
||
3301 | foreach ( $plugins as $i => $plugin ) { |
||
3302 | if ( $plugin === $jetpack ) { |
||
3303 | $plugins[ $i ] = false; |
||
3304 | $update = true; |
||
3305 | } |
||
3306 | } |
||
3307 | |||
3308 | if ( $update ) { |
||
3309 | update_option( 'active_plugins', array_filter( $plugins ) ); |
||
3310 | } |
||
3311 | } |
||
3312 | exit; |
||
3313 | } |
||
3314 | |||
3315 | /** |
||
3316 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
3317 | * |
||
3318 | * @static |
||
3319 | */ |
||
3320 | public static function plugin_activation( $network_wide ) { |
||
3321 | Jetpack_Options::update_option( 'activated', 1 ); |
||
3322 | |||
3323 | if ( version_compare( $GLOBALS['wp_version'], JETPACK__MINIMUM_WP_VERSION, '<' ) ) { |
||
3324 | self::bail_on_activation( sprintf( __( 'Jetpack requires WordPress version %s or later.', 'jetpack' ), JETPACK__MINIMUM_WP_VERSION ) ); |
||
3325 | } |
||
3326 | |||
3327 | if ( $network_wide ) { |
||
3328 | self::state( 'network_nag', true ); |
||
3329 | } |
||
3330 | |||
3331 | // For firing one-off events (notices) immediately after activation |
||
3332 | set_transient( 'activated_jetpack', true, 0.1 * MINUTE_IN_SECONDS ); |
||
3333 | |||
3334 | update_option( 'jetpack_activation_source', self::get_activation_source( wp_get_referer() ) ); |
||
3335 | |||
3336 | Health::on_jetpack_activated(); |
||
3337 | |||
3338 | self::plugin_initialize(); |
||
3339 | } |
||
3340 | |||
3341 | public static function get_activation_source( $referer_url ) { |
||
3342 | |||
3343 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
||
3344 | return array( 'wp-cli', null ); |
||
3345 | } |
||
3346 | |||
3347 | $referer = wp_parse_url( $referer_url ); |
||
3348 | |||
3349 | $source_type = 'unknown'; |
||
3350 | $source_query = null; |
||
3351 | |||
3352 | if ( ! is_array( $referer ) ) { |
||
3353 | return array( $source_type, $source_query ); |
||
3354 | } |
||
3355 | |||
3356 | $plugins_path = wp_parse_url( admin_url( 'plugins.php' ), PHP_URL_PATH ); |
||
3357 | $plugins_install_path = wp_parse_url( admin_url( 'plugin-install.php' ), PHP_URL_PATH );// /wp-admin/plugin-install.php |
||
3358 | |||
3359 | if ( isset( $referer['query'] ) ) { |
||
3360 | parse_str( $referer['query'], $query_parts ); |
||
3361 | } else { |
||
3362 | $query_parts = array(); |
||
3363 | } |
||
3364 | |||
3365 | if ( $plugins_path === $referer['path'] ) { |
||
3366 | $source_type = 'list'; |
||
3367 | } elseif ( $plugins_install_path === $referer['path'] ) { |
||
3368 | $tab = isset( $query_parts['tab'] ) ? $query_parts['tab'] : 'featured'; |
||
3369 | switch ( $tab ) { |
||
3370 | case 'popular': |
||
3371 | $source_type = 'popular'; |
||
3372 | break; |
||
3373 | case 'recommended': |
||
3374 | $source_type = 'recommended'; |
||
3375 | break; |
||
3376 | case 'favorites': |
||
3377 | $source_type = 'favorites'; |
||
3378 | break; |
||
3379 | case 'search': |
||
3380 | $source_type = 'search-' . ( isset( $query_parts['type'] ) ? $query_parts['type'] : 'term' ); |
||
3381 | $source_query = isset( $query_parts['s'] ) ? $query_parts['s'] : null; |
||
3382 | break; |
||
3383 | default: |
||
3384 | $source_type = 'featured'; |
||
3385 | } |
||
3386 | } |
||
3387 | |||
3388 | return array( $source_type, $source_query ); |
||
3389 | } |
||
3390 | |||
3391 | /** |
||
3392 | * Runs before bumping version numbers up to a new version |
||
3393 | * |
||
3394 | * @param string $version Version:timestamp. |
||
3395 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
3396 | */ |
||
3397 | public static function do_version_bump( $version, $old_version ) { |
||
3398 | if ( $old_version ) { // For existing Jetpack installations. |
||
3399 | |||
3400 | // If a front end page is visited after the update, the 'wp' action will fire. |
||
3401 | add_action( 'wp', 'Jetpack::set_update_modal_display' ); |
||
3402 | |||
3403 | // If an admin page is visited after the update, the 'current_screen' action will fire. |
||
3404 | add_action( 'current_screen', 'Jetpack::set_update_modal_display' ); |
||
3405 | } |
||
3406 | } |
||
3407 | |||
3408 | /** |
||
3409 | * Sets the display_update_modal state. |
||
3410 | */ |
||
3411 | public static function set_update_modal_display() { |
||
3412 | self::state( 'display_update_modal', true ); |
||
3413 | } |
||
3414 | |||
3415 | /** |
||
3416 | * Sets the internal version number and activation state. |
||
3417 | * |
||
3418 | * @static |
||
3419 | */ |
||
3420 | public static function plugin_initialize() { |
||
3437 | |||
3438 | /** |
||
3439 | * Removes all connection options |
||
3440 | * |
||
3441 | * @static |
||
3442 | */ |
||
3443 | public static function plugin_deactivation() { |
||
3454 | |||
3455 | /** |
||
3456 | * Disconnects from the Jetpack servers. |
||
3457 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
3458 | * |
||
3459 | * @static |
||
3460 | */ |
||
3461 | public static function disconnect( $update_activated_state = true ) { |
||
3507 | |||
3508 | /** |
||
3509 | * Disconnects the user |
||
3510 | * |
||
3511 | * @param int $user_id The user ID to disconnect. |
||
3512 | */ |
||
3513 | public function disconnect_user( $user_id ) { |
||
3516 | |||
3517 | /** |
||
3518 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
3519 | * |
||
3520 | * @deprecated since Jetpack 9.7.0 |
||
3521 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
3522 | * |
||
3523 | * @return bool|WP_Error |
||
3524 | */ |
||
3525 | public static function try_registration() { |
||
3529 | |||
3530 | /** |
||
3531 | * Checking the domain names in beta versions. |
||
3532 | * If this is a development version, before attempting to connect, let's make sure that the domains are viable. |
||
3533 | * |
||
3534 | * @param null|\WP_Error $error The domain validation error, or `null` if everything's fine. |
||
3535 | * |
||
3536 | * @return null|\WP_Error The domain validation error, or `null` if everything's fine. |
||
3537 | */ |
||
3538 | public static function registration_check_domains( $error ) { |
||
3556 | |||
3557 | /** |
||
3558 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
3559 | * |
||
3560 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
3561 | */ |
||
3562 | public static function log( $code, $data = null ) { |
||
3602 | |||
3603 | /** |
||
3604 | * Get the internal event log. |
||
3605 | * |
||
3606 | * @param $event (string) - only return the specific log events |
||
3607 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
3608 | * |
||
3609 | * @return array of log events || WP_Error for invalid params |
||
3610 | */ |
||
3611 | public static function get_log( $event = false, $num = false ) { |
||
3647 | |||
3648 | /** |
||
3649 | * Log modification of important settings. |
||
3650 | */ |
||
3651 | public static function log_settings_change( $option, $old_value, $value ) { |
||
3658 | |||
3659 | /** |
||
3660 | * Return stat data for WPCOM sync |
||
3661 | */ |
||
3662 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
3676 | |||
3677 | /** |
||
3678 | * Get additional stat data to sync to WPCOM |
||
3679 | */ |
||
3680 | public static function get_additional_stat_data( $prefix = '' ) { |
||
3691 | |||
3692 | private static function get_site_user_count() { |
||
3707 | |||
3708 | /* Admin Pages */ |
||
3709 | |||
3710 | function admin_init() { |
||
3711 | // If the plugin is not connected, display a connect message. |
||
3712 | if ( |
||
3713 | // the plugin was auto-activated and needs its candy |
||
3714 | Jetpack_Options::get_option_and_ensure_autoload( 'do_activate', '0' ) |
||
3715 | || |
||
3716 | // the plugin is active, but was never activated. Probably came from a site-wide network activation |
||
3717 | ! Jetpack_Options::get_option( 'activated' ) |
||
3718 | ) { |
||
3719 | self::plugin_initialize(); |
||
3720 | } |
||
3721 | |||
3722 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
3723 | $fallback_no_verify_ssl_certs = Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ); |
||
3724 | /** Already documented in automattic/jetpack-connection::src/class-client.php */ |
||
3725 | $client_verify_ssl_certs = apply_filters( 'jetpack_client_verify_ssl_certs', false ); |
||
3726 | |||
3727 | if ( ! $is_offline_mode ) { |
||
3728 | Jetpack_Connection_Banner::init(); |
||
3729 | } |
||
3730 | |||
3731 | if ( ( self::is_connection_ready() || $is_offline_mode ) && false === $fallback_no_verify_ssl_certs && ! $client_verify_ssl_certs ) { |
||
3732 | // Upgrade: 1.1 -> 1.1.1 |
||
3733 | // Check and see if host can verify the Jetpack servers' SSL certificate |
||
3734 | $args = array(); |
||
3735 | Client::_wp_remote_request( self::connection()->api_url( 'test' ), $args, true ); |
||
3736 | } |
||
3737 | |||
3738 | Jetpack_Recommendations_Banner::init(); |
||
3739 | |||
3740 | if ( current_user_can( 'manage_options' ) && ! self::permit_ssl() ) { |
||
3741 | add_action( 'jetpack_notices', array( $this, 'alert_auto_ssl_fail' ) ); |
||
3742 | } |
||
3743 | |||
3744 | add_action( 'load-plugins.php', array( $this, 'intercept_plugin_error_scrape_init' ) ); |
||
3745 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
||
3746 | add_action( 'admin_enqueue_scripts', array( $this, 'deactivate_dialog' ) ); |
||
3747 | add_filter( 'plugin_action_links_' . plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ), array( $this, 'plugin_action_links' ) ); |
||
3748 | |||
3749 | if ( self::is_connection_ready() || $is_offline_mode ) { |
||
3750 | // Artificially throw errors in certain specific cases during plugin activation. |
||
3751 | add_action( 'activate_plugin', array( $this, 'throw_error_on_activate_plugin' ) ); |
||
3752 | } |
||
3753 | |||
3754 | // Add custom column in wp-admin/users.php to show whether user is linked. |
||
3755 | add_filter( 'manage_users_columns', array( $this, 'jetpack_icon_user_connected' ) ); |
||
3756 | add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_user_connected_icon' ), 10, 3 ); |
||
3757 | add_action( 'admin_print_styles', array( $this, 'jetpack_user_col_style' ) ); |
||
3758 | } |
||
3759 | |||
3760 | function admin_body_class( $admin_body_class = '' ) { |
||
3761 | $classes = explode( ' ', trim( $admin_body_class ) ); |
||
3762 | |||
3763 | $classes[] = self::is_connection_ready() ? 'jetpack-connected' : 'jetpack-disconnected'; |
||
3764 | |||
3765 | $admin_body_class = implode( ' ', array_unique( $classes ) ); |
||
3766 | return " $admin_body_class "; |
||
3767 | } |
||
3768 | |||
3769 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
3772 | |||
3773 | /** |
||
3774 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
3775 | * This function artificially throws errors for such cases (per a specific list). |
||
3776 | * |
||
3777 | * @param string $plugin The activated plugin. |
||
3778 | */ |
||
3779 | function throw_error_on_activate_plugin( $plugin ) { |
||
3803 | |||
3804 | function intercept_plugin_error_scrape_init() { |
||
3807 | |||
3808 | function intercept_plugin_error_scrape( $action, $result ) { |
||
3819 | |||
3820 | /** |
||
3821 | * Register the remote file upload request handlers, if needed. |
||
3822 | * |
||
3823 | * @access public |
||
3824 | */ |
||
3825 | public function add_remote_request_handlers() { |
||
3854 | |||
3855 | /** |
||
3856 | * Handler for Jetpack remote file uploads. |
||
3857 | * |
||
3858 | * @access public |
||
3859 | */ |
||
3860 | public function remote_request_handlers() { |
||
3900 | |||
3901 | /** |
||
3902 | * Uploads a file gotten from the global $_FILES. |
||
3903 | * If `$update_media_item` is true and `post_id` is defined |
||
3904 | * the attachment file of the media item (gotten through of the post_id) |
||
3905 | * will be updated instead of add a new one. |
||
3906 | * |
||
3907 | * @param boolean $update_media_item - update media attachment |
||
3908 | * @return array - An array describing the uploadind files process |
||
3909 | */ |
||
3910 | function upload_handler( $update_media_item = false ) { |
||
4041 | |||
4042 | /** |
||
4043 | * Add help to the Jetpack page |
||
4044 | * |
||
4045 | * @since Jetpack (1.2.3) |
||
4046 | * @return false if not the Jetpack page |
||
4047 | */ |
||
4048 | function admin_help() { |
||
4091 | |||
4092 | function admin_menu_css() { |
||
4095 | |||
4096 | function admin_menu_order() { |
||
4099 | |||
4100 | function jetpack_menu_order( $menu_order ) { |
||
4115 | |||
4116 | function admin_banner_styles() { |
||
4137 | |||
4138 | function plugin_action_links( $actions ) { |
||
4153 | |||
4154 | /** |
||
4155 | * Adds the deactivation warning modal if there are other active plugins using the connection |
||
4156 | * |
||
4157 | * @param string $hook The current admin page. |
||
4158 | * |
||
4159 | * @return void |
||
4160 | */ |
||
4161 | public function deactivate_dialog( $hook ) { |
||
4216 | |||
4217 | /** |
||
4218 | * Outputs the content of the deactivation modal |
||
4219 | * |
||
4220 | * @return void |
||
4221 | */ |
||
4222 | public function deactivate_dialog_content() { |
||
4227 | |||
4228 | /** |
||
4229 | * Filters the login URL to include the registration flow in case the user isn't logged in. |
||
4230 | * |
||
4231 | * @param string $login_url The wp-login URL. |
||
4232 | * @param string $redirect URL to redirect users after logging in. |
||
4233 | * @since Jetpack 8.4 |
||
4234 | * @return string |
||
4235 | */ |
||
4236 | public function login_url( $login_url, $redirect ) { |
||
4243 | |||
4244 | /** |
||
4245 | * Redirects non-authenticated users to authenticate with Calypso if redirect flag is set. |
||
4246 | * |
||
4247 | * @since Jetpack 8.4 |
||
4248 | */ |
||
4249 | public function login_init() { |
||
4266 | |||
4267 | /* |
||
4268 | * Registration flow: |
||
4269 | * 1 - ::admin_page_load() action=register |
||
4270 | * 2 - ::try_registration() |
||
4271 | * 3 - ::register() |
||
4272 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
4273 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
4274 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
4275 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
4276 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
4277 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
4278 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
4279 | * jetpack_id, jetpack_secret, jetpack_public |
||
4280 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
4281 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
4282 | * 5 - user logs in with WP.com account |
||
4283 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
4284 | * - Manager::authorize() |
||
4285 | * - Manager::get_token() |
||
4286 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
4287 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
4288 | * - which responds with access_token, token_type, scope |
||
4289 | * - Manager::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
4290 | * - Jetpack::activate_default_modules() |
||
4291 | * - Deactivates deprecated plugins |
||
4292 | * - Activates all default modules |
||
4293 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
4294 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
4295 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
4296 | * Done! |
||
4297 | */ |
||
4298 | |||
4299 | /** |
||
4300 | * Handles the page load events for the Jetpack admin page |
||
4301 | */ |
||
4302 | function admin_page_load() { |
||
4621 | |||
4622 | function admin_notices() { |
||
4747 | |||
4748 | /** |
||
4749 | * We can't always respond to a signed XML-RPC request with a |
||
4750 | * helpful error message. In some circumstances, doing so could |
||
4751 | * leak information. |
||
4752 | * |
||
4753 | * Instead, track that the error occurred via a Jetpack_Option, |
||
4754 | * and send that data back in the heartbeat. |
||
4755 | * All this does is increment a number, but it's enough to find |
||
4756 | * trends. |
||
4757 | * |
||
4758 | * @param WP_Error $xmlrpc_error The error produced during |
||
4759 | * signature validation. |
||
4760 | */ |
||
4761 | function track_xmlrpc_error( $xmlrpc_error ) { |
||
4776 | |||
4777 | /** |
||
4778 | * Initialize the jetpack stats instance only when needed |
||
4779 | * |
||
4780 | * @return void |
||
4781 | */ |
||
4782 | private function initialize_stats() { |
||
4787 | |||
4788 | /** |
||
4789 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
4790 | */ |
||
4791 | function stat( $group, $detail ) { |
||
4798 | |||
4799 | /** |
||
4800 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
4801 | */ |
||
4802 | function do_stats( $method = '' ) { |
||
4813 | |||
4814 | /** |
||
4815 | * Runs stats code for a one-off, server-side. |
||
4816 | * |
||
4817 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
4818 | * |
||
4819 | * @return bool If it worked. |
||
4820 | */ |
||
4821 | static function do_server_side_stat( $args ) { |
||
4826 | |||
4827 | /** |
||
4828 | * Builds the stats url. |
||
4829 | * |
||
4830 | * @param $args array|string The arguments to append to the URL. |
||
4831 | * |
||
4832 | * @return string The URL to be pinged. |
||
4833 | */ |
||
4834 | static function build_stats_url( $args ) { |
||
4840 | |||
4841 | /** |
||
4842 | * Builds a URL to the Jetpack connection auth page |
||
4843 | * |
||
4844 | * @since 3.9.5 |
||
4845 | * |
||
4846 | * @param bool $raw If true, URL will not be escaped. |
||
4847 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
4848 | * If string, will be a custom redirect. |
||
4849 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
4850 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
4851 | * |
||
4852 | * @return string Connect URL |
||
4853 | */ |
||
4854 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
4916 | |||
4917 | public static function build_authorize_url( $redirect = false, $iframe = false ) { |
||
4945 | |||
4946 | /** |
||
4947 | * Filters the connection URL parameter array. |
||
4948 | * |
||
4949 | * @param array $args default URL parameters used by the package. |
||
4950 | * @return array the modified URL arguments array. |
||
4951 | */ |
||
4952 | public static function filter_connect_request_body( $args ) { |
||
4982 | |||
4983 | /** |
||
4984 | * Filters the URL that will process the connection data. It can be different from the URL |
||
4985 | * that we send the user to after everything is done. |
||
4986 | * |
||
4987 | * @param String $processing_url the default redirect URL used by the package. |
||
4988 | * @return String the modified URL. |
||
4989 | * |
||
4990 | * @deprecated since Jetpack 9.5.0 |
||
4991 | */ |
||
4992 | public static function filter_connect_processing_url( $processing_url ) { |
||
4998 | |||
4999 | /** |
||
5000 | * Filters the redirection URL that is used for connect requests. The redirect |
||
5001 | * URL should return the user back to the Jetpack console. |
||
5002 | * |
||
5003 | * @param String $redirect the default redirect URL used by the package. |
||
5004 | * @return String the modified URL. |
||
5005 | */ |
||
5006 | public static function filter_connect_redirect_url( $redirect ) { |
||
5018 | |||
5019 | /** |
||
5020 | * This action fires at the beginning of the Manager::authorize method. |
||
5021 | */ |
||
5022 | public static function authorize_starting() { |
||
5046 | |||
5047 | /** |
||
5048 | * This action fires when the site is registered (connected at a site level). |
||
5049 | */ |
||
5050 | public function handle_unique_registrations_stats() { |
||
5065 | |||
5066 | /** |
||
5067 | * This action fires at the end of the Manager::authorize method when a secondary user is |
||
5068 | * linked. |
||
5069 | */ |
||
5070 | public static function authorize_ending_linked() { |
||
5074 | |||
5075 | /** |
||
5076 | * This action fires at the end of the Manager::authorize method when the master user is |
||
5077 | * authorized. |
||
5078 | * |
||
5079 | * @param array $data The request data. |
||
5080 | */ |
||
5081 | public static function authorize_ending_authorized( $data ) { |
||
5101 | |||
5102 | /** |
||
5103 | * Fires on the jetpack_site_registered hook and acitvates default modules |
||
5104 | */ |
||
5105 | public static function activate_default_modules_on_site_register() { |
||
5120 | |||
5121 | /** |
||
5122 | * This action fires at the end of the REST_Connector connection_reconnect method when the |
||
5123 | * reconnect process is completed. |
||
5124 | * Note that this currently only happens when we don't need the user to re-authorize |
||
5125 | * their WP.com account, eg in cases where we are restoring a connection with |
||
5126 | * unhealthy blog token. |
||
5127 | */ |
||
5128 | public static function reconnection_completed() { |
||
5131 | |||
5132 | /** |
||
5133 | * Get our assumed site creation date. |
||
5134 | * Calculated based on the earlier date of either: |
||
5135 | * - Earliest admin user registration date. |
||
5136 | * - Earliest date of post of any post type. |
||
5137 | * |
||
5138 | * @since 7.2.0 |
||
5139 | * @deprecated since 7.8.0 |
||
5140 | * |
||
5141 | * @return string Assumed site creation date and time. |
||
5142 | */ |
||
5143 | public static function get_assumed_site_creation_date() { |
||
5147 | |||
5148 | View Code Duplication | public static function apply_activation_source_to_args( &$args ) { |
|
5159 | |||
5160 | function build_reconnect_url( $raw = false ) { |
||
5164 | |||
5165 | public static function admin_url( $args = null ) { |
||
5170 | |||
5171 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
5175 | |||
5176 | function dismiss_jetpack_notice() { |
||
5193 | |||
5194 | public static function sort_modules( $a, $b ) { |
||
5201 | |||
5202 | function ajax_recheck_ssl() { |
||
5212 | |||
5213 | /* Client API */ |
||
5214 | |||
5215 | /** |
||
5216 | * Returns the requested Jetpack API URL |
||
5217 | * |
||
5218 | * @deprecated since 7.7 |
||
5219 | * @return string |
||
5220 | */ |
||
5221 | public static function api_url( $relative_url ) { |
||
5226 | |||
5227 | /** |
||
5228 | * @deprecated 8.0 |
||
5229 | * |
||
5230 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. |
||
5231 | * But we no longer fix "bad hosts" anyway, outbound HTTPS is required for Jetpack to function. |
||
5232 | */ |
||
5233 | public static function fix_url_for_bad_hosts( $url ) { |
||
5237 | |||
5238 | public static function verify_onboarding_token( $token_data, $token, $request_data ) { |
||
5283 | |||
5284 | /** |
||
5285 | * Create a random secret for validating onboarding payload |
||
5286 | * |
||
5287 | * @return string Secret token |
||
5288 | */ |
||
5289 | public static function create_onboarding_token() { |
||
5297 | |||
5298 | /** |
||
5299 | * Remove the onboarding token |
||
5300 | * |
||
5301 | * @return bool True on success, false on failure |
||
5302 | */ |
||
5303 | public static function invalidate_onboarding_token() { |
||
5306 | |||
5307 | /** |
||
5308 | * Validate an onboarding token for a specific action |
||
5309 | * |
||
5310 | * @return boolean True if token/action pair is accepted, false if not |
||
5311 | */ |
||
5312 | public static function validate_onboarding_token_action( $token, $action ) { |
||
5330 | |||
5331 | /** |
||
5332 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
5333 | * |
||
5334 | * @since 2.3.3 |
||
5335 | * @return boolean |
||
5336 | */ |
||
5337 | public static function permit_ssl( $force_recheck = false ) { |
||
5366 | |||
5367 | /* |
||
5368 | * Displays an admin_notice, alerting the user that outbound SSL isn't working. |
||
5369 | */ |
||
5370 | public function alert_auto_ssl_fail() { |
||
5424 | |||
5425 | /** |
||
5426 | * Returns the Jetpack XML-RPC API |
||
5427 | * |
||
5428 | * @deprecated 8.0 Use Connection_Manager instead. |
||
5429 | * @return string |
||
5430 | */ |
||
5431 | public static function xmlrpc_api_url() { |
||
5435 | |||
5436 | /** |
||
5437 | * Returns the connection manager object. |
||
5438 | * |
||
5439 | * @return Automattic\Jetpack\Connection\Manager |
||
5440 | */ |
||
5441 | public static function connection() { |
||
5451 | |||
5452 | /** |
||
5453 | * Creates two secret tokens and the end of life timestamp for them. |
||
5454 | * |
||
5455 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
5456 | * |
||
5457 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->generate() instead. |
||
5458 | * |
||
5459 | * @since 2.6 |
||
5460 | * @param String $action The action name. |
||
5461 | * @param Integer $user_id The user identifier. |
||
5462 | * @param Integer $exp Expiration time in seconds. |
||
5463 | * @return array |
||
5464 | */ |
||
5465 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
5469 | |||
5470 | public static function get_secrets( $action, $user_id ) { |
||
5483 | |||
5484 | /** |
||
5485 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5486 | * |
||
5487 | * Based on local php max_execution_time in php.ini |
||
5488 | * |
||
5489 | * @since 2.6 |
||
5490 | * @return int |
||
5491 | * @deprecated |
||
5492 | **/ |
||
5493 | public function get_remote_query_timeout_limit() { |
||
5497 | |||
5498 | /** |
||
5499 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5500 | * |
||
5501 | * Based on local php max_execution_time in php.ini |
||
5502 | * |
||
5503 | * @since 5.4 |
||
5504 | * @return int |
||
5505 | **/ |
||
5506 | public static function get_max_execution_time() { |
||
5515 | |||
5516 | /** |
||
5517 | * Sets a minimum request timeout, and returns the current timeout |
||
5518 | * |
||
5519 | * @since 5.4 |
||
5520 | **/ |
||
5521 | View Code Duplication | public static function set_min_time_limit( $min_timeout ) { |
|
5529 | |||
5530 | /** |
||
5531 | * Takes the response from the Jetpack register new site endpoint and |
||
5532 | * verifies it worked properly. |
||
5533 | * |
||
5534 | * @since 2.6 |
||
5535 | * @deprecated since 7.7.0 |
||
5536 | * @see Automattic\Jetpack\Connection\Manager::validate_remote_register_response() |
||
5537 | **/ |
||
5538 | public function validate_remote_register_response() { |
||
5541 | |||
5542 | /** |
||
5543 | * @deprecated since Jetpack 9.7.0 |
||
5544 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
5545 | * |
||
5546 | * @return bool|WP_Error |
||
5547 | */ |
||
5548 | public static function register() { |
||
5552 | |||
5553 | /** |
||
5554 | * Filters the registration request body to include tracking properties. |
||
5555 | * |
||
5556 | * @deprecated since Jetpack 9.7.0 |
||
5557 | * @see Automattic\Jetpack\Connection\Utils::filter_register_request_body() |
||
5558 | * |
||
5559 | * @param array $properties |
||
5560 | * @return array amended properties. |
||
5561 | */ |
||
5562 | public static function filter_register_request_body( $properties ) { |
||
5566 | |||
5567 | /** |
||
5568 | * Filters the token request body to include tracking properties. |
||
5569 | * |
||
5570 | * @param array $properties |
||
5571 | * @return array amended properties. |
||
5572 | */ |
||
5573 | View Code Duplication | public static function filter_token_request_body( $properties ) { |
|
5585 | |||
5586 | /** |
||
5587 | * If the db version is showing something other that what we've got now, bump it to current. |
||
5588 | * |
||
5589 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
5590 | */ |
||
5591 | public static function maybe_set_version_option() { |
||
5605 | |||
5606 | /* Client Server API */ |
||
5607 | |||
5608 | /** |
||
5609 | * Loads the Jetpack XML-RPC client. |
||
5610 | * No longer necessary, as the XML-RPC client will be automagically loaded. |
||
5611 | * |
||
5612 | * @deprecated since 7.7.0 |
||
5613 | */ |
||
5614 | public static function load_xml_rpc_client() { |
||
5617 | |||
5618 | /** |
||
5619 | * Resets the saved authentication state in between testing requests. |
||
5620 | * |
||
5621 | * @deprecated since 8.9.0 |
||
5622 | * @see Automattic\Jetpack\Connection\Rest_Authentication::reset_saved_auth_state() |
||
5623 | */ |
||
5624 | public function reset_saved_auth_state() { |
||
5628 | |||
5629 | /** |
||
5630 | * Verifies the signature of the current request. |
||
5631 | * |
||
5632 | * @deprecated since 7.7.0 |
||
5633 | * @see Automattic\Jetpack\Connection\Manager::verify_xml_rpc_signature() |
||
5634 | * |
||
5635 | * @return false|array |
||
5636 | */ |
||
5637 | public function verify_xml_rpc_signature() { |
||
5641 | |||
5642 | /** |
||
5643 | * Verifies the signature of the current request. |
||
5644 | * |
||
5645 | * This function has side effects and should not be used. Instead, |
||
5646 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
5647 | * |
||
5648 | * @deprecated since 7.7.0 |
||
5649 | * @see Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature() |
||
5650 | * @internal |
||
5651 | */ |
||
5652 | private function internal_verify_xml_rpc_signature() { |
||
5655 | |||
5656 | /** |
||
5657 | * Authenticates XML-RPC and other requests from the Jetpack Server. |
||
5658 | * |
||
5659 | * @deprecated since 7.7.0 |
||
5660 | * @see Automattic\Jetpack\Connection\Manager::authenticate_jetpack() |
||
5661 | * |
||
5662 | * @param \WP_User|mixed $user User object if authenticated. |
||
5663 | * @param string $username Username. |
||
5664 | * @param string $password Password string. |
||
5665 | * @return \WP_User|mixed Authenticated user or error. |
||
5666 | */ |
||
5667 | View Code Duplication | public function authenticate_jetpack( $user, $username, $password ) { |
|
5676 | |||
5677 | /** |
||
5678 | * Authenticates requests from Jetpack server to WP REST API endpoints. |
||
5679 | * Uses the existing XMLRPC request signing implementation. |
||
5680 | * |
||
5681 | * @deprecated since 8.9.0 |
||
5682 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authenticate() |
||
5683 | */ |
||
5684 | function wp_rest_authenticate( $user ) { |
||
5688 | |||
5689 | /** |
||
5690 | * Report authentication status to the WP REST API. |
||
5691 | * |
||
5692 | * @deprecated since 8.9.0 |
||
5693 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authentication_errors() |
||
5694 | * |
||
5695 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
5696 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
5697 | */ |
||
5698 | public function wp_rest_authentication_errors( $value ) { |
||
5702 | |||
5703 | /** |
||
5704 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
5705 | * Capture it here so we can verify the signature later. |
||
5706 | * |
||
5707 | * @deprecated since 7.7.0 |
||
5708 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_methods() |
||
5709 | * |
||
5710 | * @param array $methods XMLRPC methods. |
||
5711 | * @return array XMLRPC methods, with the $HTTP_RAW_POST_DATA one. |
||
5712 | */ |
||
5713 | View Code Duplication | public function xmlrpc_methods( $methods ) { |
|
5722 | |||
5723 | /** |
||
5724 | * Register additional public XMLRPC methods. |
||
5725 | * |
||
5726 | * @deprecated since 7.7.0 |
||
5727 | * @see Automattic\Jetpack\Connection\Manager::public_xmlrpc_methods() |
||
5728 | * |
||
5729 | * @param array $methods Public XMLRPC methods. |
||
5730 | * @return array Public XMLRPC methods, with the getOptions one. |
||
5731 | */ |
||
5732 | View Code Duplication | public function public_xmlrpc_methods( $methods ) { |
|
5741 | |||
5742 | /** |
||
5743 | * Handles a getOptions XMLRPC method call. |
||
5744 | * |
||
5745 | * @deprecated since 7.7.0 |
||
5746 | * @see Automattic\Jetpack\Connection\Manager::jetpack_getOptions() |
||
5747 | * |
||
5748 | * @param array $args method call arguments. |
||
5749 | * @return array an amended XMLRPC server options array. |
||
5750 | */ |
||
5751 | View Code Duplication | public function jetpack_getOptions( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
5760 | |||
5761 | /** |
||
5762 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
5763 | * |
||
5764 | * @deprecated since 7.7.0 |
||
5765 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_options() |
||
5766 | * |
||
5767 | * @param array $options Standard Core options. |
||
5768 | * @return array Amended options. |
||
5769 | */ |
||
5770 | View Code Duplication | public function xmlrpc_options( $options ) { |
|
5779 | |||
5780 | /** |
||
5781 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
5782 | * SET: state( $key, $value ); |
||
5783 | * GET: $value = state( $key ); |
||
5784 | * |
||
5785 | * @param string $key |
||
5786 | * @param string $value |
||
5787 | * @param bool $restate private |
||
5788 | */ |
||
5789 | public static function state( $key = null, $value = null, $restate = false ) { |
||
5845 | |||
5846 | public static function restate() { |
||
5849 | |||
5850 | /** |
||
5851 | * Determines whether the jetpackState[$key] value should be added to the |
||
5852 | * cookie. |
||
5853 | * |
||
5854 | * @param string $key The state key. |
||
5855 | * |
||
5856 | * @return boolean Whether the value should be added to the cookie. |
||
5857 | */ |
||
5858 | public static function should_set_cookie( $key ) { |
||
5868 | |||
5869 | public static function check_privacy( $file ) { |
||
5903 | |||
5904 | /** |
||
5905 | * Helper method for multicall XMLRPC. |
||
5906 | * |
||
5907 | * @deprecated since 8.9.0 |
||
5908 | * @see Automattic\\Jetpack\\Connection\\Xmlrpc_Async_Call::add_call() |
||
5909 | * |
||
5910 | * @param ...$args Args for the async_call. |
||
5911 | */ |
||
5912 | public static function xmlrpc_async_call( ...$args ) { |
||
5954 | |||
5955 | /** |
||
5956 | * Serve a WordPress.com static resource via a randomized wp.com subdomain. |
||
5957 | * |
||
5958 | * @deprecated 9.3.0 Use Assets::staticize_subdomain. |
||
5959 | * |
||
5960 | * @param string $url WordPress.com static resource URL. |
||
5961 | */ |
||
5962 | public static function staticize_subdomain( $url ) { |
||
5966 | |||
5967 | /* JSON API Authorization */ |
||
5968 | |||
5969 | /** |
||
5970 | * Handles the login action for Authorizing the JSON API |
||
5971 | */ |
||
5972 | function login_form_json_api_authorization() { |
||
5981 | |||
5982 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
5983 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
5997 | |||
5998 | // Make sure the POSTed request is handled by the same action |
||
5999 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
6003 | |||
6004 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
6005 | function store_json_api_authorization_token( $user_login, $user ) { |
||
6011 | |||
6012 | // Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. |
||
6013 | function allow_wpcom_public_api_domain( $domains ) { |
||
6017 | |||
6018 | static function is_redirect_encoded( $redirect_url ) { |
||
6021 | |||
6022 | // Add all wordpress.com environments to the safe redirect allowed list. |
||
6023 | function allow_wpcom_environments( $domains ) { |
||
6030 | |||
6031 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
6032 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
6044 | |||
6045 | /** |
||
6046 | * Verifies the request by checking the signature |
||
6047 | * |
||
6048 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
6049 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
6050 | * |
||
6051 | * @param null|array $environment |
||
6052 | */ |
||
6053 | function verify_json_api_authorization_request( $environment = null ) { |
||
6175 | |||
6176 | function login_message_json_api_authorization( $message ) { |
||
6182 | |||
6183 | /** |
||
6184 | * Get $content_width, but with a <s>twist</s> filter. |
||
6185 | */ |
||
6186 | public static function get_content_width() { |
||
6199 | |||
6200 | /** |
||
6201 | * Pings the WordPress.com Mirror Site for the specified options. |
||
6202 | * |
||
6203 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
6204 | * |
||
6205 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
6206 | */ |
||
6207 | public function get_cloud_site_options( $option_names ) { |
||
6222 | |||
6223 | /** |
||
6224 | * Checks if the site is currently in an identity crisis. |
||
6225 | * |
||
6226 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
6227 | */ |
||
6228 | public static function check_identity_crisis() { |
||
6235 | |||
6236 | /** |
||
6237 | * Checks whether the home and siteurl specifically are allowed. |
||
6238 | * Written so that we don't have re-check $key and $value params every time |
||
6239 | * we want to check if this site is allowed, for example in footer.php |
||
6240 | * |
||
6241 | * @since 3.8.0 |
||
6242 | * @return bool True = already allowed False = not on the allowed list. |
||
6243 | */ |
||
6244 | public static function is_staging_site() { |
||
6248 | |||
6249 | /** |
||
6250 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
6251 | * |
||
6252 | * @since 4.4.0 |
||
6253 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
6254 | * |
||
6255 | * @return bool |
||
6256 | */ |
||
6257 | public static function validate_sync_error_idc_option() { |
||
6299 | |||
6300 | /** |
||
6301 | * Normalizes a url by doing three things: |
||
6302 | * - Strips protocol |
||
6303 | * - Strips www |
||
6304 | * - Adds a trailing slash |
||
6305 | * |
||
6306 | * @since 4.4.0 |
||
6307 | * @param string $url |
||
6308 | * @return WP_Error|string |
||
6309 | */ |
||
6310 | public static function normalize_url_protocol_agnostic( $url ) { |
||
6320 | |||
6321 | /** |
||
6322 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
6323 | * |
||
6324 | * @since 4.4.0 |
||
6325 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
6326 | * |
||
6327 | * @param array $response |
||
6328 | * @return array Array of the local urls, wpcom urls, and error code |
||
6329 | */ |
||
6330 | public static function get_sync_error_idc_option( $response = array() ) { |
||
6362 | |||
6363 | /** |
||
6364 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
6365 | * If set to true, the site will be put into staging mode. |
||
6366 | * |
||
6367 | * @since 4.3.2 |
||
6368 | * @return bool |
||
6369 | */ |
||
6370 | public static function sync_idc_optin() { |
||
6388 | |||
6389 | /** |
||
6390 | * Maybe Use a .min.css stylesheet, maybe not. |
||
6391 | * |
||
6392 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
6393 | */ |
||
6394 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
6436 | |||
6437 | /** |
||
6438 | * If the asset is minified, let's flag .min as the suffix. |
||
6439 | * |
||
6440 | * Attached to `style_loader_src` filter. |
||
6441 | * |
||
6442 | * @param string $tag The tag that would link to the external asset. |
||
6443 | * @param string $handle The registered handle of the script in question. |
||
6444 | * @param string $href The url of the asset in question. |
||
6445 | */ |
||
6446 | public static function set_suffix_on_min( $src, $handle ) { |
||
6462 | |||
6463 | /** |
||
6464 | * Maybe inlines a stylesheet. |
||
6465 | * |
||
6466 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
6467 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
6468 | * |
||
6469 | * Attached to `style_loader_tag` filter. |
||
6470 | * |
||
6471 | * @param string $tag The tag that would link to the external asset. |
||
6472 | * @param string $handle The registered handle of the script in question. |
||
6473 | * |
||
6474 | * @return string |
||
6475 | */ |
||
6476 | public static function maybe_inline_style( $tag, $handle ) { |
||
6526 | |||
6527 | /** |
||
6528 | * Loads a view file from the views |
||
6529 | * |
||
6530 | * Data passed in with the $data parameter will be available in the |
||
6531 | * template file as $data['value'] |
||
6532 | * |
||
6533 | * @param string $template - Template file to load |
||
6534 | * @param array $data - Any data to pass along to the template |
||
6535 | * @return boolean - If template file was found |
||
6536 | **/ |
||
6537 | public function load_view( $template, $data = array() ) { |
||
6548 | |||
6549 | /** |
||
6550 | * Throws warnings for deprecated hooks to be removed from Jetpack that cannot remain in the original place in the code. |
||
6551 | */ |
||
6552 | public function deprecated_hooks() { |
||
6809 | |||
6810 | /** |
||
6811 | * Converts any url in a stylesheet, to the correct absolute url. |
||
6812 | * |
||
6813 | * Considerations: |
||
6814 | * - Normal, relative URLs `feh.png` |
||
6815 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
6816 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
6817 | * - Absolute URLs `http://domain.com/feh.png` |
||
6818 | * - Domain root relative URLs `/feh.png` |
||
6819 | * |
||
6820 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
6821 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
6822 | * |
||
6823 | * @return mixed|string |
||
6824 | */ |
||
6825 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
6869 | |||
6870 | /** |
||
6871 | * This methods removes all of the registered css files on the front end |
||
6872 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
6873 | * all the files into one file. |
||
6874 | * |
||
6875 | * Pros: |
||
6876 | * - Uses only ONE css asset connection instead of 15 |
||
6877 | * - Saves a minimum of 56k |
||
6878 | * - Reduces server load |
||
6879 | * - Reduces time to first painted byte |
||
6880 | * |
||
6881 | * Cons: |
||
6882 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
6883 | * should not cause any issues with themes. |
||
6884 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
6885 | * jetpack_implode_frontend_css filter for a workaround |
||
6886 | * |
||
6887 | * For some situations developers may wish to disable css imploding and |
||
6888 | * instead operate in legacy mode where each file loads seperately and |
||
6889 | * can be edited individually or dequeued. This can be accomplished with |
||
6890 | * the following line: |
||
6891 | * |
||
6892 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
6893 | * |
||
6894 | * @since 3.2 |
||
6895 | **/ |
||
6896 | public function implode_frontend_css( $travis_test = false ) { |
||
6953 | |||
6954 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
6964 | |||
6965 | /** |
||
6966 | * @deprecated |
||
6967 | * @see Automattic\Jetpack\Assets\add_aync_script |
||
6968 | */ |
||
6969 | public function script_add_async( $tag, $handle, $src ) { |
||
6972 | |||
6973 | /* |
||
6974 | * Check the heartbeat data |
||
6975 | * |
||
6976 | * Organizes the heartbeat data by severity. For example, if the site |
||
6977 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
6978 | * |
||
6979 | * Data will be added to "caution" array, if it either: |
||
6980 | * - Out of date Jetpack version |
||
6981 | * - Out of date WP version |
||
6982 | * - Out of date PHP version |
||
6983 | * |
||
6984 | * $return array $filtered_data |
||
6985 | */ |
||
6986 | public static function jetpack_check_heartbeat_data() { |
||
7039 | |||
7040 | /* |
||
7041 | * This method is used to organize all options that can be reset |
||
7042 | * without disconnecting Jetpack. |
||
7043 | * |
||
7044 | * It is used in class.jetpack-cli.php to reset options |
||
7045 | * |
||
7046 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
7047 | * |
||
7048 | * @return array of options to delete. |
||
7049 | */ |
||
7050 | public static function get_jetpack_options_for_reset() { |
||
7053 | |||
7054 | /* |
||
7055 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
7056 | * so we can bring them directly to their site in calypso. |
||
7057 | * |
||
7058 | * @deprecated 9.2.0 Use Automattic\Jetpack\Status::get_site_suffix |
||
7059 | * |
||
7060 | * @param string | url |
||
7061 | * @return string | url without the guff |
||
7062 | */ |
||
7063 | public static function build_raw_urls( $url ) { |
||
7068 | |||
7069 | /** |
||
7070 | * Stores and prints out domains to prefetch for page speed optimization. |
||
7071 | * |
||
7072 | * @deprecated 8.8.0 Use Jetpack::add_resource_hints. |
||
7073 | * |
||
7074 | * @param string|array $urls URLs to hint. |
||
7075 | */ |
||
7076 | public static function dns_prefetch( $urls = null ) { |
||
7082 | |||
7083 | public function wp_dashboard_setup() { |
||
7121 | |||
7122 | /** |
||
7123 | * @param mixed $result Value for the user's option |
||
7124 | * @return mixed |
||
7125 | */ |
||
7126 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
7151 | |||
7152 | public static function dashboard_widget() { |
||
7160 | |||
7161 | public static function dashboard_widget_footer() { |
||
7229 | |||
7230 | /* |
||
7231 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
7232 | */ |
||
7233 | function jetpack_icon_user_connected( $columns ) { |
||
7237 | |||
7238 | /* |
||
7239 | * Show Jetpack icon if the user is linked. |
||
7240 | */ |
||
7241 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
7254 | |||
7255 | /* |
||
7256 | * Style the Jetpack user column |
||
7257 | */ |
||
7258 | function jetpack_user_col_style() { |
||
7277 | |||
7278 | /** |
||
7279 | * Checks if Akismet is active and working. |
||
7280 | * |
||
7281 | * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key |
||
7282 | * that implied usage of methods present since more recent version. |
||
7283 | * See https://github.com/Automattic/jetpack/pull/9585 |
||
7284 | * |
||
7285 | * @since 5.1.0 |
||
7286 | * |
||
7287 | * @return bool True = Akismet available. False = Aksimet not available. |
||
7288 | */ |
||
7289 | public static function is_akismet_active() { |
||
7324 | |||
7325 | /** |
||
7326 | * @deprecated |
||
7327 | * |
||
7328 | * @see Automattic\Jetpack\Sync\Modules\Users::is_function_in_backtrace |
||
7329 | */ |
||
7330 | public static function is_function_in_backtrace() { |
||
7333 | |||
7334 | /** |
||
7335 | * Given a minified path, and a non-minified path, will return |
||
7336 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
7337 | * |
||
7338 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
7339 | * root Jetpack directory. |
||
7340 | * |
||
7341 | * @since 5.6.0 |
||
7342 | * |
||
7343 | * @param string $min_path |
||
7344 | * @param string $non_min_path |
||
7345 | * @return string The URL to the file |
||
7346 | */ |
||
7347 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
7350 | |||
7351 | /** |
||
7352 | * Checks for whether Jetpack Backup is enabled. |
||
7353 | * Will return true if the state of Backup is anything except "unavailable". |
||
7354 | * |
||
7355 | * @return bool|int|mixed |
||
7356 | */ |
||
7357 | public static function is_rewind_enabled() { |
||
7377 | |||
7378 | /** |
||
7379 | * Return Calypso environment value; used for developing Jetpack and pairing |
||
7380 | * it with different Calypso enrionments, such as localhost. |
||
7381 | * |
||
7382 | * @since 7.4.0 |
||
7383 | * |
||
7384 | * @return string Calypso environment |
||
7385 | */ |
||
7386 | public static function get_calypso_env() { |
||
7401 | |||
7402 | /** |
||
7403 | * Returns the hostname with protocol for Calypso. |
||
7404 | * Used for developing Jetpack with Calypso. |
||
7405 | * |
||
7406 | * @since 8.4.0 |
||
7407 | * |
||
7408 | * @return string Calypso host. |
||
7409 | */ |
||
7410 | public static function get_calypso_host() { |
||
7423 | |||
7424 | /** |
||
7425 | * Handles activating default modules as well general cleanup for the new connection. |
||
7426 | * |
||
7427 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
7428 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
7429 | * @param boolean $send_state_messages Whether to send state messages. |
||
7430 | * @return void |
||
7431 | */ |
||
7432 | public static function handle_post_authorization_actions( |
||
7460 | |||
7461 | /** |
||
7462 | * Returns a boolean for whether backups UI should be displayed or not. |
||
7463 | * |
||
7464 | * @return bool Should backups UI be displayed? |
||
7465 | */ |
||
7466 | public static function show_backups_ui() { |
||
7476 | |||
7477 | /* |
||
7478 | * Deprecated manage functions |
||
7479 | */ |
||
7480 | function prepare_manage_jetpack_notice() { |
||
7501 | |||
7502 | /** |
||
7503 | * Clean leftoveruser meta. |
||
7504 | * |
||
7505 | * Delete Jetpack-related user meta when it is no longer needed. |
||
7506 | * |
||
7507 | * @since 7.3.0 |
||
7508 | * |
||
7509 | * @param int $user_id User ID being updated. |
||
7510 | */ |
||
7511 | public static function user_meta_cleanup( $user_id ) { |
||
7526 | |||
7527 | /** |
||
7528 | * Checks if a Jetpack site is both active and not in offline mode. |
||
7529 | * |
||
7530 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
7531 | * |
||
7532 | * @deprecated 8.8.0 |
||
7533 | * |
||
7534 | * @return bool True if Jetpack is active and not in offline mode. |
||
7535 | */ |
||
7536 | public static function is_active_and_not_development_mode() { |
||
7543 | |||
7544 | /** |
||
7545 | * Checks if a Jetpack site is both active and not in offline mode. |
||
7546 | * |
||
7547 | * This is a DRY function to avoid repeating `Jetpack::is_connection_ready && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
7548 | * |
||
7549 | * @since 8.8.0 |
||
7550 | * |
||
7551 | * @return bool True if Jetpack is active and not in offline mode. |
||
7552 | */ |
||
7553 | public static function is_active_and_not_offline_mode() { |
||
7559 | |||
7560 | /** |
||
7561 | * Returns the list of products that we have available for purchase. |
||
7562 | */ |
||
7563 | public static function get_products_for_purchase() { |
||
7657 | } |
||
7658 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.