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() { |
||
647 | /* |
||
648 | * Check for and alert any deprecated hooks |
||
649 | */ |
||
650 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
651 | |||
652 | // Note how this runs at an earlier plugin_loaded hook intentionally to accomodate for other plugins. |
||
653 | add_action( 'plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
654 | add_action( 'network_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
655 | add_action( 'mu_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
656 | add_action( 'plugins_loaded', array( $this, 'late_initialization' ), 90 ); |
||
657 | |||
658 | add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) ); |
||
659 | |||
660 | add_filter( |
||
661 | 'jetpack_signature_check_token', |
||
662 | array( __CLASS__, 'verify_onboarding_token' ), |
||
663 | 10, |
||
664 | 3 |
||
665 | ); |
||
666 | |||
667 | /** |
||
668 | * Prepare Gutenberg Editor functionality |
||
669 | */ |
||
670 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; |
||
671 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'init' ) ); |
||
672 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) ); |
||
673 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_extended_blocks' ), 9 ); |
||
674 | add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); |
||
675 | |||
676 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
677 | |||
678 | // Unlink user before deleting the user from WP.com. |
||
679 | add_action( 'deleted_user', array( $this, 'disconnect_user' ), 10, 1 ); |
||
680 | add_action( 'remove_user_from_blog', array( $this, 'disconnect_user' ), 10, 1 ); |
||
681 | |||
682 | add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 ); |
||
683 | |||
684 | add_filter( 'login_url', array( $this, 'login_url' ), 10, 2 ); |
||
685 | add_action( 'login_init', array( $this, 'login_init' ) ); |
||
686 | |||
687 | // Set up the REST authentication hooks. |
||
688 | Connection_Rest_Authentication::init(); |
||
689 | |||
690 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
691 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
692 | |||
693 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 20 ); |
||
694 | |||
695 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
696 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
697 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
698 | |||
699 | // returns HTTPS support status |
||
700 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
701 | |||
702 | add_action( 'wp_ajax_jetpack_connection_banner', array( $this, 'jetpack_connection_banner_callback' ) ); |
||
703 | |||
704 | add_action( 'wp_ajax_jetpack_recommendations_banner', array( 'Jetpack_Recommendations_Banner', 'ajax_callback' ) ); |
||
705 | |||
706 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
707 | |||
708 | /** |
||
709 | * These actions run checks to load additional files. |
||
710 | * They check for external files or plugins, so they need to run as late as possible. |
||
711 | */ |
||
712 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
713 | add_action( 'web_stories_story_head', array( $this, 'check_open_graph' ), 1 ); |
||
714 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
715 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
716 | |||
717 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
718 | add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 ); |
||
719 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
720 | |||
721 | add_filter( 'profile_update', array( 'Jetpack', 'user_meta_cleanup' ) ); |
||
722 | |||
723 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
724 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
725 | |||
726 | // A filter to control all just in time messages |
||
727 | add_filter( 'jetpack_just_in_time_msgs', '__return_true', 9 ); |
||
728 | |||
729 | add_filter( 'jetpack_just_in_time_msg_cache', '__return_true', 9 ); |
||
730 | |||
731 | require_once JETPACK__PLUGIN_DIR . 'class-jetpack-pre-connection-jitms.php'; |
||
732 | $jetpack_jitm_messages = ( new Jetpack_Pre_Connection_JITMs() ); |
||
733 | add_filter( 'jetpack_pre_connection_jitms', array( $jetpack_jitm_messages, 'add_pre_connection_jitms' ) ); |
||
734 | |||
735 | /* |
||
736 | * If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin. |
||
737 | * We should make sure to only do this for front end links. |
||
738 | */ |
||
739 | if ( self::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) { |
||
740 | add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 ); |
||
741 | add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 ); |
||
742 | |||
743 | /* |
||
744 | * We'll shortcircuit wp_notify_postauthor and wp_notify_moderator pluggable functions |
||
745 | * so they point moderation links on emails to Calypso. |
||
746 | */ |
||
747 | jetpack_require_lib( 'functions.wp-notify' ); |
||
748 | add_filter( 'comment_notification_recipients', 'jetpack_notify_postauthor', 1, 2 ); |
||
749 | add_filter( 'notify_moderator', 'jetpack_notify_moderator', 1, 2 ); |
||
750 | } |
||
751 | |||
752 | add_action( |
||
753 | 'plugins_loaded', |
||
754 | function () { |
||
755 | if ( User_Agent_Info::is_mobile_app() ) { |
||
756 | add_filter( 'get_edit_post_link', '__return_empty_string' ); |
||
757 | } |
||
758 | } |
||
759 | ); |
||
760 | |||
761 | // Update the site's Jetpack plan and products from API on heartbeats. |
||
762 | add_action( 'jetpack_heartbeat', array( 'Jetpack_Plan', 'refresh_from_wpcom' ) ); |
||
763 | |||
764 | /** |
||
765 | * This is the hack to concatenate all css files into one. |
||
766 | * For description and reasoning see the implode_frontend_css method. |
||
767 | * |
||
768 | * Super late priority so we catch all the registered styles. |
||
769 | */ |
||
770 | if ( ! is_admin() ) { |
||
771 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
772 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
773 | } |
||
774 | |||
775 | /** |
||
776 | * These are sync actions that we need to keep track of for jitms |
||
777 | */ |
||
778 | add_filter( 'jetpack_sync_before_send_updated_option', array( $this, 'jetpack_track_last_sync_callback' ), 99 ); |
||
779 | |||
780 | // Actually push the stats on shutdown. |
||
781 | if ( ! has_action( 'shutdown', array( $this, 'push_stats' ) ) ) { |
||
782 | add_action( 'shutdown', array( $this, 'push_stats' ) ); |
||
783 | } |
||
784 | |||
785 | // After a successful connection. |
||
786 | add_action( 'jetpack_site_registered', array( $this, 'activate_default_modules_on_site_register' ) ); |
||
787 | |||
788 | // Actions for Manager::authorize(). |
||
789 | add_action( 'jetpack_authorize_starting', array( $this, 'authorize_starting' ) ); |
||
790 | add_action( 'jetpack_authorize_ending_linked', array( $this, 'authorize_ending_linked' ) ); |
||
791 | add_action( 'jetpack_authorize_ending_authorized', array( $this, 'authorize_ending_authorized' ) ); |
||
792 | |||
793 | add_action( 'jetpack_client_authorize_error', array( Jetpack_Client_Server::class, 'client_authorize_error' ) ); |
||
794 | add_filter( 'jetpack_client_authorize_already_authorized_url', array( Jetpack_Client_Server::class, 'client_authorize_already_authorized_url' ) ); |
||
795 | add_action( 'jetpack_client_authorize_processing', array( Jetpack_Client_Server::class, 'client_authorize_processing' ) ); |
||
796 | add_filter( 'jetpack_client_authorize_fallback_url', array( Jetpack_Client_Server::class, 'client_authorize_fallback_url' ) ); |
||
797 | |||
798 | // Filters for the Manager::get_token() urls and request body. |
||
799 | add_filter( 'jetpack_token_redirect_url', array( __CLASS__, 'filter_connect_redirect_url' ) ); |
||
800 | add_filter( 'jetpack_token_request_body', array( __CLASS__, 'filter_token_request_body' ) ); |
||
801 | |||
802 | // Actions for successful reconnect. |
||
803 | add_action( 'jetpack_reconnection_completed', array( $this, 'reconnection_completed' ) ); |
||
804 | |||
805 | // Actions for licensing. |
||
806 | Licensing::instance()->initialize(); |
||
807 | |||
808 | // Filters for Sync Callables. |
||
809 | add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ), 10, 1 ); |
||
810 | add_filter( 'jetpack_sync_multisite_callable_whitelist', array( $this, 'filter_sync_multisite_callable_whitelist' ), 10, 1 ); |
||
811 | |||
812 | // Make resources use static domain when possible. |
||
813 | add_filter( 'jetpack_static_url', array( 'Automattic\\Jetpack\\Assets', 'staticize_subdomain' ) ); |
||
814 | |||
815 | // Validate the domain names in Jetpack development versions. |
||
816 | add_action( 'jetpack_pre_register', array( get_called_class(), 'registration_check_domains' ) ); |
||
817 | } |
||
818 | |||
819 | /** |
||
820 | * Before everything else starts getting initalized, we need to initialize Jetpack using the |
||
821 | * Config object. |
||
822 | */ |
||
823 | public function configure() { |
||
824 | $config = new Config(); |
||
825 | |||
826 | foreach ( |
||
827 | array( |
||
828 | 'sync', |
||
829 | 'jitm', |
||
830 | ) |
||
831 | as $feature |
||
832 | ) { |
||
833 | $config->ensure( $feature ); |
||
834 | } |
||
835 | |||
836 | $config->ensure( |
||
837 | 'connection', |
||
838 | array( |
||
839 | 'slug' => 'jetpack', |
||
840 | 'name' => 'Jetpack', |
||
841 | ) |
||
842 | ); |
||
843 | |||
844 | if ( ! $this->connection_manager ) { |
||
845 | $this->connection_manager = new Connection_Manager( 'jetpack' ); |
||
846 | |||
847 | /** |
||
848 | * Filter to activate Jetpack Connection UI. |
||
849 | * INTERNAL USE ONLY. |
||
850 | * |
||
851 | * @since 9.5.0 |
||
852 | * |
||
853 | * @param bool false Whether to activate the Connection UI. |
||
854 | */ |
||
855 | if ( apply_filters( 'jetpack_connection_ui_active', false ) ) { |
||
856 | Automattic\Jetpack\ConnectionUI\Admin::init(); |
||
857 | } |
||
858 | } |
||
859 | |||
860 | /* |
||
861 | * Load things that should only be in Network Admin. |
||
862 | * |
||
863 | * For now blow away everything else until a more full |
||
864 | * understanding of what is needed at the network level is |
||
865 | * available |
||
866 | */ |
||
867 | if ( is_multisite() ) { |
||
868 | $network = Jetpack_Network::init(); |
||
869 | $network->set_connection( $this->connection_manager ); |
||
870 | } |
||
871 | |||
872 | if ( self::is_connection_ready() ) { |
||
873 | add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) ); |
||
874 | |||
875 | Jetpack_Heartbeat::init(); |
||
876 | if ( self::is_module_active( 'stats' ) && self::is_module_active( 'search' ) ) { |
||
877 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php'; |
||
878 | Jetpack_Search_Performance_Logger::init(); |
||
879 | } |
||
880 | } |
||
881 | |||
882 | // Initialize remote file upload request handlers. |
||
883 | $this->add_remote_request_handlers(); |
||
884 | |||
885 | /* |
||
886 | * Enable enhanced handling of previewing sites in Calypso |
||
887 | */ |
||
888 | if ( self::is_connection_ready() ) { |
||
889 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php'; |
||
890 | add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 ); |
||
891 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php'; |
||
892 | add_action( 'init', array( 'Jetpack_Keyring_Service_Helper', 'init' ), 9, 0 ); |
||
893 | } |
||
894 | |||
895 | if ( ( new Tracking( $this->connection_manager ) )->should_enable_tracking( new Terms_Of_Service(), new Status() ) ) { |
||
896 | add_action( 'init', array( new Plugin_Tracking(), 'init' ) ); |
||
897 | } else { |
||
898 | /** |
||
899 | * Initialize tracking right after the user agrees to the terms of service. |
||
900 | */ |
||
901 | add_action( 'jetpack_agreed_to_terms_of_service', array( new Plugin_Tracking(), 'init' ) ); |
||
902 | } |
||
903 | } |
||
904 | |||
905 | /** |
||
906 | * Runs on plugins_loaded. Use this to add code that needs to be executed later than other |
||
907 | * initialization code. |
||
908 | * |
||
909 | * @action plugins_loaded |
||
910 | */ |
||
911 | public function late_initialization() { |
||
928 | |||
929 | /** |
||
930 | * Sets up the XMLRPC request handlers. |
||
931 | * |
||
932 | * @deprecated since 7.7.0 |
||
933 | * @see Automattic\Jetpack\Connection\Manager::setup_xmlrpc_handlers() |
||
934 | * |
||
935 | * @param array $request_params Incoming request parameters. |
||
936 | * @param Boolean $is_active Whether the connection is currently active. |
||
937 | * @param Boolean $is_signed Whether the signature check has been successful. |
||
938 | * @param Jetpack_XMLRPC_Server $xmlrpc_server (optional) An instance of the server to use instead of instantiating a new one. |
||
939 | */ |
||
940 | View Code Duplication | public function setup_xmlrpc_handlers( |
|
959 | |||
960 | /** |
||
961 | * Initialize REST API registration connector. |
||
962 | * |
||
963 | * @deprecated since 7.7.0 |
||
964 | * @see Automattic\Jetpack\Connection\Manager::initialize_rest_api_registration_connector() |
||
965 | */ |
||
966 | View Code Duplication | public function initialize_rest_api_registration_connector() { |
|
975 | |||
976 | /** |
||
977 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
978 | * |
||
979 | * @param $domains |
||
980 | */ |
||
981 | function add_wpcom_to_allowed_redirect_hosts( $domains ) { |
||
984 | |||
985 | /** |
||
986 | * Return $domains, with 'wordpress.com' appended. |
||
987 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
988 | * |
||
989 | * @param $domains |
||
990 | * @return array |
||
991 | */ |
||
992 | function allow_wpcom_domain( $domains ) { |
||
999 | |||
1000 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
1029 | |||
1030 | function point_edit_comment_links_to_calypso( $url ) { |
||
1042 | |||
1043 | /** |
||
1044 | * Extend Sync callables with Jetpack Plugin functions. |
||
1045 | * |
||
1046 | * @param array $callables list of callables. |
||
1047 | * |
||
1048 | * @return array list of callables. |
||
1049 | */ |
||
1050 | public function filter_sync_callable_whitelist( $callables ) { |
||
1075 | |||
1076 | /** |
||
1077 | * Extend Sync multisite callables with Jetpack Plugin functions. |
||
1078 | * |
||
1079 | * @param array $callables list of callables. |
||
1080 | * |
||
1081 | * @return array list of callables. |
||
1082 | */ |
||
1083 | public function filter_sync_multisite_callable_whitelist( $callables ) { |
||
1098 | |||
1099 | function jetpack_track_last_sync_callback( $params ) { |
||
1121 | |||
1122 | function jetpack_connection_banner_callback() { |
||
1136 | |||
1137 | /** |
||
1138 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
1139 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
1140 | * ensure that Core and other plugins' methods are not exposed. |
||
1141 | * |
||
1142 | * @deprecated since 7.7.0 |
||
1143 | * @see Automattic\Jetpack\Connection\Manager::remove_non_jetpack_xmlrpc_methods() |
||
1144 | * |
||
1145 | * @param array $methods A list of registered WordPress XMLRPC methods. |
||
1146 | * @return array Filtered $methods |
||
1147 | */ |
||
1148 | View Code Duplication | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
|
1157 | |||
1158 | /** |
||
1159 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
1160 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
1161 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
1162 | * which is accessible via a different URI. Most of the below is copied directly |
||
1163 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
1164 | * |
||
1165 | * @deprecated since 7.7.0 |
||
1166 | * @see Automattic\Jetpack\Connection\Manager::alternate_xmlrpc() |
||
1167 | */ |
||
1168 | View Code Duplication | public function alternate_xmlrpc() { |
|
1177 | |||
1178 | /** |
||
1179 | * The callback for the JITM ajax requests. |
||
1180 | * |
||
1181 | * @deprecated since 7.9.0 |
||
1182 | */ |
||
1183 | function jetpack_jitm_ajax_callback() { |
||
1186 | |||
1187 | /** |
||
1188 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
1189 | */ |
||
1190 | function push_stats() { |
||
1195 | |||
1196 | /** |
||
1197 | * Sets the Jetpack custom capabilities. |
||
1198 | * |
||
1199 | * @param string[] $caps Array of the user's capabilities. |
||
1200 | * @param string $cap Capability name. |
||
1201 | * @param int $user_id The user ID. |
||
1202 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1203 | */ |
||
1204 | public function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
1239 | |||
1240 | /** |
||
1241 | * Require a Jetpack authentication. |
||
1242 | * |
||
1243 | * @deprecated since 7.7.0 |
||
1244 | * @see Automattic\Jetpack\Connection\Manager::require_jetpack_authentication() |
||
1245 | */ |
||
1246 | View Code Duplication | public function require_jetpack_authentication() { |
|
1255 | |||
1256 | /** |
||
1257 | * Register assets for use in various modules and the Jetpack admin page. |
||
1258 | * |
||
1259 | * @uses wp_script_is, wp_register_script, plugins_url |
||
1260 | * @action wp_loaded |
||
1261 | * @return null |
||
1262 | */ |
||
1263 | public function register_assets() { |
||
1264 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
1265 | wp_register_script( |
||
1266 | 'jetpack-gallery-settings', |
||
1267 | Assets::get_file_url_for_environment( '_inc/build/gallery-settings.min.js', '_inc/gallery-settings.js' ), |
||
1268 | array( 'media-views' ), |
||
1269 | '20121225' |
||
1270 | ); |
||
1271 | } |
||
1272 | |||
1273 | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
||
1274 | wp_register_script( |
||
1275 | 'jetpack-twitter-timeline', |
||
1276 | Assets::get_file_url_for_environment( '_inc/build/twitter-timeline.min.js', '_inc/twitter-timeline.js' ), |
||
1277 | array( 'jquery' ), |
||
1278 | '4.0.0', |
||
1279 | true |
||
1280 | ); |
||
1281 | } |
||
1282 | |||
1283 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
1284 | wp_register_script( |
||
1285 | 'jetpack-facebook-embed', |
||
1286 | Assets::get_file_url_for_environment( '_inc/build/facebook-embed.min.js', '_inc/facebook-embed.js' ), |
||
1287 | array(), |
||
1288 | null, |
||
1289 | true |
||
1290 | ); |
||
1291 | |||
1292 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
1293 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
1294 | if ( ! is_numeric( $fb_app_id ) ) { |
||
1295 | $fb_app_id = ''; |
||
1296 | } |
||
1297 | wp_localize_script( |
||
1298 | 'jetpack-facebook-embed', |
||
1299 | 'jpfbembed', |
||
1300 | array( |
||
1301 | 'appid' => $fb_app_id, |
||
1302 | 'locale' => $this->get_locale(), |
||
1303 | ) |
||
1304 | ); |
||
1305 | } |
||
1306 | |||
1307 | /** |
||
1308 | * As jetpack_register_genericons is by default fired off a hook, |
||
1309 | * the hook may have already fired by this point. |
||
1310 | * So, let's just trigger it manually. |
||
1311 | */ |
||
1312 | require_once JETPACK__PLUGIN_DIR . '_inc/genericons.php'; |
||
1313 | jetpack_register_genericons(); |
||
1314 | |||
1315 | /** |
||
1316 | * Register the social logos |
||
1317 | */ |
||
1318 | require_once JETPACK__PLUGIN_DIR . '_inc/social-logos.php'; |
||
1319 | jetpack_register_social_logos(); |
||
1320 | |||
1321 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) { |
|
1322 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
1323 | } |
||
1324 | } |
||
1325 | |||
1326 | /** |
||
1327 | * Guess locale from language code. |
||
1328 | * |
||
1329 | * @param string $lang Language code. |
||
1330 | * @return string|bool |
||
1331 | */ |
||
1332 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
1371 | |||
1372 | /** |
||
1373 | * Get the locale. |
||
1374 | * |
||
1375 | * @return string|bool |
||
1376 | */ |
||
1377 | function get_locale() { |
||
1386 | |||
1387 | /** |
||
1388 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
1389 | * |
||
1390 | * @param bool $option |
||
1391 | * @return string |
||
1392 | */ |
||
1393 | public function jetpack_main_network_site_option( $option ) { |
||
1396 | /** |
||
1397 | * Network Name. |
||
1398 | */ |
||
1399 | static function network_name( $option = null ) { |
||
1403 | /** |
||
1404 | * Does the network allow new user and site registrations. |
||
1405 | * |
||
1406 | * @return string |
||
1407 | */ |
||
1408 | static function network_allow_new_registrations( $option = null ) { |
||
1411 | /** |
||
1412 | * Does the network allow admins to add new users. |
||
1413 | * |
||
1414 | * @return boolian |
||
1415 | */ |
||
1416 | static function network_add_new_users( $option = null ) { |
||
1419 | /** |
||
1420 | * File upload psace left per site in MB. |
||
1421 | * -1 means NO LIMIT. |
||
1422 | * |
||
1423 | * @return number |
||
1424 | */ |
||
1425 | static function network_site_upload_space( $option = null ) { |
||
1429 | |||
1430 | /** |
||
1431 | * Network allowed file types. |
||
1432 | * |
||
1433 | * @return string |
||
1434 | */ |
||
1435 | static function network_upload_file_types( $option = null ) { |
||
1438 | |||
1439 | /** |
||
1440 | * Maximum file upload size set by the network. |
||
1441 | * |
||
1442 | * @return number |
||
1443 | */ |
||
1444 | static function network_max_upload_file_size( $option = null ) { |
||
1448 | |||
1449 | /** |
||
1450 | * Lets us know if a site allows admins to manage the network. |
||
1451 | * |
||
1452 | * @return array |
||
1453 | */ |
||
1454 | static function network_enable_administration_menus( $option = null ) { |
||
1457 | |||
1458 | /** |
||
1459 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
1460 | * jetpack_other_linked_admins transient. |
||
1461 | * |
||
1462 | * @since 4.3.2 |
||
1463 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
1464 | * |
||
1465 | * @param int $user_id The user ID whose role changed. |
||
1466 | * @param string $role The new role. |
||
1467 | * @param array $old_roles An array of the user's previous roles. |
||
1468 | */ |
||
1469 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
1477 | |||
1478 | /** |
||
1479 | * Checks to see if there are any other users available to become primary |
||
1480 | * Users must both: |
||
1481 | * - Be linked to wpcom |
||
1482 | * - Be an admin |
||
1483 | * |
||
1484 | * @return mixed False if no other users are linked, Int if there are. |
||
1485 | */ |
||
1486 | static function get_other_linked_admins() { |
||
1514 | |||
1515 | /** |
||
1516 | * Return whether we are dealing with a multi network setup or not. |
||
1517 | * The reason we are type casting this is because we want to avoid the situation where |
||
1518 | * the result is false since when is_main_network_option return false it cases |
||
1519 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
1520 | * database which could be set to anything as opposed to what this function returns. |
||
1521 | * |
||
1522 | * @param bool $option |
||
1523 | * |
||
1524 | * @return boolean |
||
1525 | */ |
||
1526 | public function is_main_network_option( $option ) { |
||
1530 | |||
1531 | /** |
||
1532 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
1533 | * |
||
1534 | * @param string $option |
||
1535 | * @return boolean |
||
1536 | */ |
||
1537 | public function is_multisite( $option ) { |
||
1540 | |||
1541 | /** |
||
1542 | * Implemented since there is no core is multi network function |
||
1543 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
1544 | * |
||
1545 | * @since 3.3 |
||
1546 | * @return boolean |
||
1547 | */ |
||
1548 | View Code Duplication | public static function is_multi_network() { |
|
1563 | |||
1564 | /** |
||
1565 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1566 | * |
||
1567 | * @return null |
||
1568 | */ |
||
1569 | function update_jetpack_main_network_site_option() { |
||
1572 | /** |
||
1573 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1574 | */ |
||
1575 | function update_jetpack_network_settings() { |
||
1579 | |||
1580 | /** |
||
1581 | * Get back if the current site is single user site. |
||
1582 | * |
||
1583 | * @return bool |
||
1584 | */ |
||
1585 | View Code Duplication | public static function is_single_user_site() { |
|
1594 | |||
1595 | /** |
||
1596 | * Returns true if the site has file write access false otherwise. |
||
1597 | * |
||
1598 | * @return string ( '1' | '0' ) |
||
1599 | **/ |
||
1600 | public static function file_system_write_access() { |
||
1620 | |||
1621 | /** |
||
1622 | * Finds out if a site is using a version control system. |
||
1623 | * |
||
1624 | * @return string ( '1' | '0' ) |
||
1625 | **/ |
||
1626 | public static function is_version_controlled() { |
||
1630 | |||
1631 | /** |
||
1632 | * Determines whether the current theme supports featured images or not. |
||
1633 | * |
||
1634 | * @return string ( '1' | '0' ) |
||
1635 | */ |
||
1636 | public static function featured_images_enabled() { |
||
1640 | |||
1641 | /** |
||
1642 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
1643 | * |
||
1644 | * @deprecated 4.7 use get_avatar_url instead. |
||
1645 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
1646 | * @param int $size Size of the avatar image |
||
1647 | * @param string $default URL to a default image to use if no avatar is available |
||
1648 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
1649 | * |
||
1650 | * @return array |
||
1651 | */ |
||
1652 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
1663 | // phpcs:disable WordPress.WP.CapitalPDangit.Misspelled |
||
1664 | /** |
||
1665 | * jetpack_updates is saved in the following schema: |
||
1666 | * |
||
1667 | * array ( |
||
1668 | * 'plugins' => (int) Number of plugin updates available. |
||
1669 | * 'themes' => (int) Number of theme updates available. |
||
1670 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1671 | * 'translations' => (int) Number of translation updates available. |
||
1672 | * 'total' => (int) Total of all available updates. |
||
1673 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1674 | * ) |
||
1675 | * |
||
1676 | * @return array |
||
1677 | */ |
||
1678 | public static function get_updates() { |
||
1695 | // phpcs:enable |
||
1696 | |||
1697 | public static function get_update_details() { |
||
1705 | |||
1706 | public static function refresh_update_data() { |
||
1710 | |||
1711 | public static function refresh_theme_data() { |
||
1714 | |||
1715 | /** |
||
1716 | * Is Jetpack active? |
||
1717 | * The method only checks if there's an existing token for the master user. It doesn't validate the token. |
||
1718 | * |
||
1719 | * This method is deprecated since 9.6.0. Please use one of the methods provided by the Manager class in the Connection package, |
||
1720 | * or Jetpack::is_connection_ready if you want to know when the Jetpack plugin starts considering the connection ready to be used. |
||
1721 | * |
||
1722 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
1723 | * |
||
1724 | * @deprecated 9.6.0 |
||
1725 | * |
||
1726 | * @return bool |
||
1727 | */ |
||
1728 | public static function is_active() { |
||
1731 | |||
1732 | /** |
||
1733 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI |
||
1734 | * |
||
1735 | * This method was introduced just before the release of the possibility to use Jetpack without a user connection, while |
||
1736 | * it was available only when no_user_testing_mode was enabled. In the near future, this will return is_connected for all |
||
1737 | * users and this option will be available by default for everybody. |
||
1738 | * |
||
1739 | * @since 9.6.0 |
||
1740 | * |
||
1741 | * @return bool is the site connection ready to be used? |
||
1742 | */ |
||
1743 | public static function is_connection_ready() { |
||
1749 | |||
1750 | /** |
||
1751 | * Make an API call to WordPress.com for plan status |
||
1752 | * |
||
1753 | * @deprecated 7.2.0 Use Jetpack_Plan::refresh_from_wpcom. |
||
1754 | * |
||
1755 | * @return bool True if plan is updated, false if no update |
||
1756 | */ |
||
1757 | public static function refresh_active_plan_from_wpcom() { |
||
1761 | |||
1762 | /** |
||
1763 | * Get the plan that this Jetpack site is currently using |
||
1764 | * |
||
1765 | * @deprecated 7.2.0 Use Jetpack_Plan::get. |
||
1766 | * @return array Active Jetpack plan details. |
||
1767 | */ |
||
1768 | public static function get_active_plan() { |
||
1772 | |||
1773 | /** |
||
1774 | * Determine whether the active plan supports a particular feature |
||
1775 | * |
||
1776 | * @deprecated 7.2.0 Use Jetpack_Plan::supports. |
||
1777 | * @return bool True if plan supports feature, false if not. |
||
1778 | */ |
||
1779 | public static function active_plan_supports( $feature ) { |
||
1783 | |||
1784 | /** |
||
1785 | * Deprecated: Is Jetpack in development (offline) mode? |
||
1786 | * |
||
1787 | * This static method is being left here intentionally without the use of _deprecated_function(), as other plugins |
||
1788 | * and themes still use it, and we do not want to flood them with notices. |
||
1789 | * |
||
1790 | * Please use Automattic\Jetpack\Status()->is_offline_mode() instead. |
||
1791 | * |
||
1792 | * @deprecated since 8.0. |
||
1793 | */ |
||
1794 | public static function is_development_mode() { |
||
1798 | |||
1799 | /** |
||
1800 | * Whether the site is currently onboarding or not. |
||
1801 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
1802 | * |
||
1803 | * @since 5.8 |
||
1804 | * |
||
1805 | * @access public |
||
1806 | * @static |
||
1807 | * |
||
1808 | * @return bool True if the site is currently onboarding, false otherwise |
||
1809 | */ |
||
1810 | public static function is_onboarding() { |
||
1813 | |||
1814 | /** |
||
1815 | * Determines reason for Jetpack offline mode. |
||
1816 | */ |
||
1817 | public static function development_mode_trigger_text() { |
||
1840 | /** |
||
1841 | * Get Jetpack offline mode notice text and notice class. |
||
1842 | * |
||
1843 | * Mirrors the checks made in Automattic\Jetpack\Status->is_offline_mode |
||
1844 | */ |
||
1845 | public static function show_development_mode_notice() { |
||
1873 | |||
1874 | /** |
||
1875 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1876 | */ |
||
1877 | public static function is_development_version() { |
||
1892 | |||
1893 | /** |
||
1894 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1895 | */ |
||
1896 | public static function is_user_connected( $user_id = false ) { |
||
1900 | |||
1901 | /** |
||
1902 | * Get the wpcom user data of the current|specified connected user. |
||
1903 | */ |
||
1904 | public static function get_connected_user_data( $user_id = null ) { |
||
1908 | |||
1909 | /** |
||
1910 | * Get the wpcom email of the current|specified connected user. |
||
1911 | */ |
||
1912 | public static function get_connected_user_email( $user_id = null ) { |
||
1928 | |||
1929 | /** |
||
1930 | * Get the wpcom email of the master user. |
||
1931 | */ |
||
1932 | public static function get_master_user_email() { |
||
1939 | |||
1940 | /** |
||
1941 | * Whether the current user is the connection owner. |
||
1942 | * |
||
1943 | * @deprecated since 7.7 |
||
1944 | * |
||
1945 | * @return bool Whether the current user is the connection owner. |
||
1946 | */ |
||
1947 | public function current_user_is_connection_owner() { |
||
1951 | |||
1952 | /** |
||
1953 | * Gets current user IP address. |
||
1954 | * |
||
1955 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
1956 | * |
||
1957 | * @return string Current user IP address. |
||
1958 | */ |
||
1959 | public static function current_user_ip( $check_all_headers = false ) { |
||
1979 | |||
1980 | /** |
||
1981 | * Synchronize connected user role changes |
||
1982 | */ |
||
1983 | function user_role_change( $user_id ) { |
||
1987 | |||
1988 | /** |
||
1989 | * Loads the currently active modules. |
||
1990 | */ |
||
1991 | public static function load_modules() { |
||
2079 | |||
2080 | /** |
||
2081 | * Check if Jetpack's REST API compat file should be included |
||
2082 | * |
||
2083 | * @action plugins_loaded |
||
2084 | * @return null |
||
2085 | */ |
||
2086 | public function check_rest_api_compat() { |
||
2100 | |||
2101 | /** |
||
2102 | * Gets all plugins currently active in values, regardless of whether they're |
||
2103 | * traditionally activated or network activated. |
||
2104 | * |
||
2105 | * @todo Store the result in core's object cache maybe? |
||
2106 | */ |
||
2107 | public static function get_active_plugins() { |
||
2123 | |||
2124 | /** |
||
2125 | * Gets and parses additional plugin data to send with the heartbeat data |
||
2126 | * |
||
2127 | * @since 3.8.1 |
||
2128 | * |
||
2129 | * @return array Array of plugin data |
||
2130 | */ |
||
2131 | public static function get_parsed_plugin_data() { |
||
2152 | |||
2153 | /** |
||
2154 | * Gets and parses theme data to send with the heartbeat data |
||
2155 | * |
||
2156 | * @since 3.8.1 |
||
2157 | * |
||
2158 | * @return array Array of theme data |
||
2159 | */ |
||
2160 | public static function get_parsed_theme_data() { |
||
2182 | |||
2183 | /** |
||
2184 | * Checks whether a specific plugin is active. |
||
2185 | * |
||
2186 | * We don't want to store these in a static variable, in case |
||
2187 | * there are switch_to_blog() calls involved. |
||
2188 | */ |
||
2189 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
2192 | |||
2193 | /** |
||
2194 | * Check if Jetpack's Open Graph tags should be used. |
||
2195 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
2196 | * |
||
2197 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2198 | * @action plugins_loaded |
||
2199 | * @return null |
||
2200 | */ |
||
2201 | public function check_open_graph() { |
||
2228 | |||
2229 | /** |
||
2230 | * Check if Jetpack's Twitter tags should be used. |
||
2231 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
2232 | * |
||
2233 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2234 | * @action plugins_loaded |
||
2235 | * @return null |
||
2236 | */ |
||
2237 | public function check_twitter_tags() { |
||
2261 | |||
2262 | /** |
||
2263 | * Allows plugins to submit security reports. |
||
2264 | * |
||
2265 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
2266 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
2267 | * @param array $args See definitions above |
||
2268 | */ |
||
2269 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
2272 | |||
2273 | /* Jetpack Options API */ |
||
2274 | |||
2275 | public static function get_option_names( $type = 'compact' ) { |
||
2278 | |||
2279 | /** |
||
2280 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
2281 | * |
||
2282 | * @param string $name Option name |
||
2283 | * @param mixed $default (optional) |
||
2284 | */ |
||
2285 | public static function get_option( $name, $default = false ) { |
||
2288 | |||
2289 | /** |
||
2290 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
2291 | * |
||
2292 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
2293 | * @param string $name Option name |
||
2294 | * @param mixed $value Option value |
||
2295 | */ |
||
2296 | public static function update_option( $name, $value ) { |
||
2300 | |||
2301 | /** |
||
2302 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
2303 | * |
||
2304 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
2305 | * @param array $array array( option name => option value, ... ) |
||
2306 | */ |
||
2307 | public static function update_options( $array ) { |
||
2311 | |||
2312 | /** |
||
2313 | * Deletes the given option. May be passed multiple option names as an array. |
||
2314 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
2315 | * |
||
2316 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
2317 | * @param string|array $names |
||
2318 | */ |
||
2319 | public static function delete_option( $names ) { |
||
2323 | |||
2324 | /** |
||
2325 | * Enters a user token into the user_tokens option |
||
2326 | * |
||
2327 | * @deprecated 8.0 Use Automattic\Jetpack\Connection\Tokens->update_user_token() instead. |
||
2328 | * |
||
2329 | * @param int $user_id The user id. |
||
2330 | * @param string $token The user token. |
||
2331 | * @param bool $is_master_user Whether the user is the master user. |
||
2332 | * @return bool |
||
2333 | */ |
||
2334 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
2338 | |||
2339 | /** |
||
2340 | * Returns an array of all PHP files in the specified absolute path. |
||
2341 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
2342 | * |
||
2343 | * @param string $absolute_path The absolute path of the directory to search. |
||
2344 | * @return array Array of absolute paths to the PHP files. |
||
2345 | */ |
||
2346 | public static function glob_php( $absolute_path ) { |
||
2375 | |||
2376 | public static function activate_new_modules( $redirect = false ) { |
||
2435 | |||
2436 | /** |
||
2437 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
2438 | * Make sure to tuck away module "library" files in a sub-directory. |
||
2439 | * |
||
2440 | * @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter. |
||
2441 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
2442 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
2443 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
2444 | * |
||
2445 | * @return array $modules Array of module slugs |
||
2446 | */ |
||
2447 | public static function get_available_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
2519 | |||
2520 | /** |
||
2521 | * Get default modules loaded on activation. |
||
2522 | * |
||
2523 | * @param bool|string $min_version Onlu return modules introduced in this version or later. Default is false, do not filter. |
||
2524 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
2525 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
2526 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
2527 | * |
||
2528 | * @return array $modules Array of module slugs |
||
2529 | */ |
||
2530 | public static function get_default_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
2563 | |||
2564 | /** |
||
2565 | * Checks activated modules during auto-activation to determine |
||
2566 | * if any of those modules are being deprecated. If so, close |
||
2567 | * them out, and add any replacement modules. |
||
2568 | * |
||
2569 | * Runs at priority 99 by default. |
||
2570 | * |
||
2571 | * This is run late, so that it can still activate a module if |
||
2572 | * the new module is a replacement for another that the user |
||
2573 | * currently has active, even if something at the normal priority |
||
2574 | * would kibosh everything. |
||
2575 | * |
||
2576 | * @since 2.6 |
||
2577 | * @uses jetpack_get_default_modules filter |
||
2578 | * @param array $modules |
||
2579 | * @return array |
||
2580 | */ |
||
2581 | function handle_deprecated_modules( $modules ) { |
||
2608 | |||
2609 | /** |
||
2610 | * Checks activated plugins during auto-activation to determine |
||
2611 | * if any of those plugins are in the list with a corresponding module |
||
2612 | * that is not compatible with the plugin. The module will not be allowed |
||
2613 | * to auto-activate. |
||
2614 | * |
||
2615 | * @since 2.6 |
||
2616 | * @uses jetpack_get_default_modules filter |
||
2617 | * @param array $modules |
||
2618 | * @return array |
||
2619 | */ |
||
2620 | function filter_default_modules( $modules ) { |
||
2644 | |||
2645 | /** |
||
2646 | * Extract a module's slug from its full path. |
||
2647 | */ |
||
2648 | public static function get_module_slug( $file ) { |
||
2651 | |||
2652 | /** |
||
2653 | * Generate a module's path from its slug. |
||
2654 | */ |
||
2655 | public static function get_module_path( $slug ) { |
||
2666 | |||
2667 | /** |
||
2668 | * Load module data from module file. Headers differ from WordPress |
||
2669 | * plugin headers to avoid them being identified as standalone |
||
2670 | * plugins on the WordPress plugins page. |
||
2671 | */ |
||
2672 | public static function get_module( $module ) { |
||
2772 | |||
2773 | /** |
||
2774 | * Like core's get_file_data implementation, but caches the result. |
||
2775 | */ |
||
2776 | public static function get_file_data( $file, $headers ) { |
||
2809 | |||
2810 | /** |
||
2811 | * Return translated module tag. |
||
2812 | * |
||
2813 | * @param string $tag Tag as it appears in each module heading. |
||
2814 | * |
||
2815 | * @return mixed |
||
2816 | */ |
||
2817 | public static function translate_module_tag( $tag ) { |
||
2820 | |||
2821 | /** |
||
2822 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2823 | * |
||
2824 | * @since 3.9.2 |
||
2825 | * |
||
2826 | * @param array $modules |
||
2827 | * |
||
2828 | * @return string|void |
||
2829 | */ |
||
2830 | public static function get_translated_modules( $modules ) { |
||
2843 | |||
2844 | /** |
||
2845 | * Get a list of activated modules as an array of module slugs. |
||
2846 | */ |
||
2847 | public static function get_active_modules() { |
||
2879 | |||
2880 | /** |
||
2881 | * Check whether or not a Jetpack module is active. |
||
2882 | * |
||
2883 | * @param string $module The slug of a Jetpack module. |
||
2884 | * @return bool |
||
2885 | * |
||
2886 | * @static |
||
2887 | */ |
||
2888 | public static function is_module_active( $module ) { |
||
2891 | |||
2892 | public static function is_module( $module ) { |
||
2895 | |||
2896 | /** |
||
2897 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2898 | * |
||
2899 | * @param bool $catch True to start catching, False to stop. |
||
2900 | * |
||
2901 | * @static |
||
2902 | */ |
||
2903 | public static function catch_errors( $catch ) { |
||
2916 | |||
2917 | /** |
||
2918 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2919 | */ |
||
2920 | public static function catch_errors_on_shutdown() { |
||
2923 | |||
2924 | /** |
||
2925 | * Rewrite any string to make paths easier to read. |
||
2926 | * |
||
2927 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
2928 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
2929 | * |
||
2930 | * @param $string |
||
2931 | * @return mixed |
||
2932 | */ |
||
2933 | public static function alias_directories( $string ) { |
||
2941 | |||
2942 | public static function activate_default_modules( |
||
3114 | |||
3115 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
3208 | |||
3209 | function activate_module_actions( $module ) { |
||
3212 | |||
3213 | public static function deactivate_module( $module ) { |
||
3230 | |||
3231 | public static function enable_module_configurable( $module ) { |
||
3235 | |||
3236 | /** |
||
3237 | * Composes a module configure URL. It uses Jetpack settings search as default value |
||
3238 | * It is possible to redefine resulting URL by using "jetpack_module_configuration_url_$module" filter |
||
3239 | * |
||
3240 | * @param string $module Module slug |
||
3241 | * @return string $url module configuration URL |
||
3242 | */ |
||
3243 | public static function module_configuration_url( $module ) { |
||
3257 | |||
3258 | /* Installation */ |
||
3259 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
3299 | |||
3300 | /** |
||
3301 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
3302 | * |
||
3303 | * @static |
||
3304 | */ |
||
3305 | public static function plugin_activation( $network_wide ) { |
||
3325 | |||
3326 | public static function get_activation_source( $referer_url ) { |
||
3375 | |||
3376 | /** |
||
3377 | * Runs before bumping version numbers up to a new version |
||
3378 | * |
||
3379 | * @param string $version Version:timestamp. |
||
3380 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
3381 | */ |
||
3382 | public static function do_version_bump( $version, $old_version ) { |
||
3392 | |||
3393 | /** |
||
3394 | * Sets the display_update_modal state. |
||
3395 | */ |
||
3396 | public static function set_update_modal_display() { |
||
3399 | |||
3400 | /** |
||
3401 | * Sets the internal version number and activation state. |
||
3402 | * |
||
3403 | * @static |
||
3404 | */ |
||
3405 | public static function plugin_initialize() { |
||
3422 | |||
3423 | /** |
||
3424 | * Removes all connection options |
||
3425 | * |
||
3426 | * @static |
||
3427 | */ |
||
3428 | public static function plugin_deactivation() { |
||
3439 | |||
3440 | /** |
||
3441 | * Disconnects from the Jetpack servers. |
||
3442 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
3443 | * |
||
3444 | * @static |
||
3445 | */ |
||
3446 | public static function disconnect( $update_activated_state = true ) { |
||
3492 | |||
3493 | /** |
||
3494 | * Disconnects the user |
||
3495 | * |
||
3496 | * @param int $user_id The user ID to disconnect. |
||
3497 | */ |
||
3498 | public function disconnect_user( $user_id ) { |
||
3501 | |||
3502 | /** |
||
3503 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
3504 | * |
||
3505 | * @deprecated since Jetpack 9.7.0 |
||
3506 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
3507 | * |
||
3508 | * @return bool|WP_Error |
||
3509 | */ |
||
3510 | public static function try_registration() { |
||
3511 | _deprecated_function( __METHOD__, 'jetpack-9.7', 'Automattic\\Jetpack\\Connection\\Manager::try_registration' ); |
||
3512 | return static::connection()->try_registration(); |
||
3513 | } |
||
3514 | |||
3515 | /** |
||
3516 | * Checking the domain names in beta versions. |
||
3517 | * If this is a development version, before attempting to connect, let's make sure that the domains are viable. |
||
3518 | * |
||
3519 | * @param null|\WP_Error $error The domain validation error, or `null` if everything's fine. |
||
3520 | * |
||
3521 | * @return null|\WP_Error The domain validation error, or `null` if everything's fine. |
||
3522 | */ |
||
3523 | public static function registration_check_domains( $error ) { |
||
3524 | if ( static::is_development_version() && defined( 'PHP_URL_HOST' ) ) { |
||
3525 | $domains_to_check = array_unique( |
||
3526 | array( |
||
3527 | 'siteurl' => wp_parse_url( get_site_url(), PHP_URL_HOST ), |
||
3528 | 'homeurl' => wp_parse_url( get_home_url(), PHP_URL_HOST ), |
||
3529 | ) |
||
3530 | ); |
||
3531 | foreach ( $domains_to_check as $domain ) { |
||
3532 | $result = static::connection()->is_usable_domain( $domain ); |
||
3533 | if ( is_wp_error( $result ) ) { |
||
3534 | return $result; |
||
3535 | } |
||
3536 | } |
||
3537 | } |
||
3538 | |||
3539 | return $error; |
||
3540 | } |
||
3541 | |||
3542 | /** |
||
3543 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
3544 | * |
||
3545 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
3546 | */ |
||
3547 | public static function log( $code, $data = null ) { |
||
3587 | |||
3588 | /** |
||
3589 | * Get the internal event log. |
||
3590 | * |
||
3591 | * @param $event (string) - only return the specific log events |
||
3592 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
3593 | * |
||
3594 | * @return array of log events || WP_Error for invalid params |
||
3595 | */ |
||
3596 | public static function get_log( $event = false, $num = false ) { |
||
3632 | |||
3633 | /** |
||
3634 | * Log modification of important settings. |
||
3635 | */ |
||
3636 | public static function log_settings_change( $option, $old_value, $value ) { |
||
3643 | |||
3644 | /** |
||
3645 | * Return stat data for WPCOM sync |
||
3646 | */ |
||
3647 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
3661 | |||
3662 | /** |
||
3663 | * Get additional stat data to sync to WPCOM |
||
3664 | */ |
||
3665 | public static function get_additional_stat_data( $prefix = '' ) { |
||
3676 | |||
3677 | private static function get_site_user_count() { |
||
3692 | |||
3693 | /* Admin Pages */ |
||
3694 | |||
3695 | function admin_init() { |
||
3739 | |||
3740 | function admin_body_class( $admin_body_class = '' ) { |
||
3748 | |||
3749 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
3752 | |||
3753 | /** |
||
3754 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
3755 | * This function artificially throws errors for such cases (per a specific list). |
||
3756 | * |
||
3757 | * @param string $plugin The activated plugin. |
||
3758 | */ |
||
3759 | function throw_error_on_activate_plugin( $plugin ) { |
||
3783 | |||
3784 | function intercept_plugin_error_scrape_init() { |
||
3787 | |||
3788 | function intercept_plugin_error_scrape( $action, $result ) { |
||
3799 | |||
3800 | /** |
||
3801 | * Register the remote file upload request handlers, if needed. |
||
3802 | * |
||
3803 | * @access public |
||
3804 | */ |
||
3805 | public function add_remote_request_handlers() { |
||
3834 | |||
3835 | /** |
||
3836 | * Handler for Jetpack remote file uploads. |
||
3837 | * |
||
3838 | * @access public |
||
3839 | */ |
||
3840 | public function remote_request_handlers() { |
||
3880 | |||
3881 | /** |
||
3882 | * Uploads a file gotten from the global $_FILES. |
||
3883 | * If `$update_media_item` is true and `post_id` is defined |
||
3884 | * the attachment file of the media item (gotten through of the post_id) |
||
3885 | * will be updated instead of add a new one. |
||
3886 | * |
||
3887 | * @param boolean $update_media_item - update media attachment |
||
3888 | * @return array - An array describing the uploadind files process |
||
3889 | */ |
||
3890 | function upload_handler( $update_media_item = false ) { |
||
4021 | |||
4022 | /** |
||
4023 | * Add help to the Jetpack page |
||
4024 | * |
||
4025 | * @since Jetpack (1.2.3) |
||
4026 | * @return false if not the Jetpack page |
||
4027 | */ |
||
4028 | function admin_help() { |
||
4071 | |||
4072 | function admin_menu_css() { |
||
4075 | |||
4076 | function admin_menu_order() { |
||
4079 | |||
4080 | function jetpack_menu_order( $menu_order ) { |
||
4095 | |||
4096 | function admin_banner_styles() { |
||
4117 | |||
4118 | function plugin_action_links( $actions ) { |
||
4133 | |||
4134 | /** |
||
4135 | * Adds the deactivation warning modal if there are other active plugins using the connection |
||
4136 | * |
||
4137 | * @param string $hook The current admin page. |
||
4138 | * |
||
4139 | * @return void |
||
4140 | */ |
||
4141 | public function deactivate_dialog( $hook ) { |
||
4196 | |||
4197 | /** |
||
4198 | * Outputs the content of the deactivation modal |
||
4199 | * |
||
4200 | * @return void |
||
4201 | */ |
||
4202 | public function deactivate_dialog_content() { |
||
4207 | |||
4208 | /** |
||
4209 | * Filters the login URL to include the registration flow in case the user isn't logged in. |
||
4210 | * |
||
4211 | * @param string $login_url The wp-login URL. |
||
4212 | * @param string $redirect URL to redirect users after logging in. |
||
4213 | * @since Jetpack 8.4 |
||
4214 | * @return string |
||
4215 | */ |
||
4216 | public function login_url( $login_url, $redirect ) { |
||
4223 | |||
4224 | /** |
||
4225 | * Redirects non-authenticated users to authenticate with Calypso if redirect flag is set. |
||
4226 | * |
||
4227 | * @since Jetpack 8.4 |
||
4228 | */ |
||
4229 | public function login_init() { |
||
4246 | |||
4247 | /* |
||
4248 | * Registration flow: |
||
4249 | * 1 - ::admin_page_load() action=register |
||
4250 | * 2 - ::try_registration() |
||
4251 | * 3 - ::register() |
||
4252 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
4253 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
4254 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
4255 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
4256 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
4257 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
4258 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
4259 | * jetpack_id, jetpack_secret, jetpack_public |
||
4260 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
4261 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
4262 | * 5 - user logs in with WP.com account |
||
4263 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
4264 | * - Manager::authorize() |
||
4265 | * - Manager::get_token() |
||
4266 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
4267 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
4268 | * - which responds with access_token, token_type, scope |
||
4269 | * - Manager::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
4270 | * - Jetpack::activate_default_modules() |
||
4271 | * - Deactivates deprecated plugins |
||
4272 | * - Activates all default modules |
||
4273 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
4274 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
4275 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
4276 | * Done! |
||
4277 | */ |
||
4278 | |||
4279 | /** |
||
4280 | * Handles the page load events for the Jetpack admin page |
||
4281 | */ |
||
4282 | function admin_page_load() { |
||
4598 | |||
4599 | function admin_notices() { |
||
4724 | |||
4725 | /** |
||
4726 | * We can't always respond to a signed XML-RPC request with a |
||
4727 | * helpful error message. In some circumstances, doing so could |
||
4728 | * leak information. |
||
4729 | * |
||
4730 | * Instead, track that the error occurred via a Jetpack_Option, |
||
4731 | * and send that data back in the heartbeat. |
||
4732 | * All this does is increment a number, but it's enough to find |
||
4733 | * trends. |
||
4734 | * |
||
4735 | * @param WP_Error $xmlrpc_error The error produced during |
||
4736 | * signature validation. |
||
4737 | */ |
||
4738 | function track_xmlrpc_error( $xmlrpc_error ) { |
||
4753 | |||
4754 | /** |
||
4755 | * Initialize the jetpack stats instance only when needed |
||
4756 | * |
||
4757 | * @return void |
||
4758 | */ |
||
4759 | private function initialize_stats() { |
||
4764 | |||
4765 | /** |
||
4766 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
4767 | */ |
||
4768 | function stat( $group, $detail ) { |
||
4775 | |||
4776 | /** |
||
4777 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
4778 | */ |
||
4779 | function do_stats( $method = '' ) { |
||
4790 | |||
4791 | /** |
||
4792 | * Runs stats code for a one-off, server-side. |
||
4793 | * |
||
4794 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
4795 | * |
||
4796 | * @return bool If it worked. |
||
4797 | */ |
||
4798 | static function do_server_side_stat( $args ) { |
||
4803 | |||
4804 | /** |
||
4805 | * Builds the stats url. |
||
4806 | * |
||
4807 | * @param $args array|string The arguments to append to the URL. |
||
4808 | * |
||
4809 | * @return string The URL to be pinged. |
||
4810 | */ |
||
4811 | static function build_stats_url( $args ) { |
||
4817 | |||
4818 | /** |
||
4819 | * Builds a URL to the Jetpack connection auth page |
||
4820 | * |
||
4821 | * @since 3.9.5 |
||
4822 | * |
||
4823 | * @param bool $raw If true, URL will not be escaped. |
||
4824 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
4825 | * If string, will be a custom redirect. |
||
4826 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
4827 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
4828 | * |
||
4829 | * @return string Connect URL |
||
4830 | */ |
||
4831 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
4893 | |||
4894 | public static function build_authorize_url( $redirect = false, $iframe = false ) { |
||
4922 | |||
4923 | /** |
||
4924 | * Filters the connection URL parameter array. |
||
4925 | * |
||
4926 | * @param array $args default URL parameters used by the package. |
||
4927 | * @return array the modified URL arguments array. |
||
4928 | */ |
||
4929 | public static function filter_connect_request_body( $args ) { |
||
4959 | |||
4960 | /** |
||
4961 | * Filters the URL that will process the connection data. It can be different from the URL |
||
4962 | * that we send the user to after everything is done. |
||
4963 | * |
||
4964 | * @param String $processing_url the default redirect URL used by the package. |
||
4965 | * @return String the modified URL. |
||
4966 | * |
||
4967 | * @deprecated since Jetpack 9.5.0 |
||
4968 | */ |
||
4969 | public static function filter_connect_processing_url( $processing_url ) { |
||
4975 | |||
4976 | /** |
||
4977 | * Filters the redirection URL that is used for connect requests. The redirect |
||
4978 | * URL should return the user back to the Jetpack console. |
||
4979 | * |
||
4980 | * @param String $redirect the default redirect URL used by the package. |
||
4981 | * @return String the modified URL. |
||
4982 | */ |
||
4983 | public static function filter_connect_redirect_url( $redirect ) { |
||
4995 | |||
4996 | /** |
||
4997 | * This action fires at the beginning of the Manager::authorize method. |
||
4998 | */ |
||
4999 | public static function authorize_starting() { |
||
5023 | |||
5024 | /** |
||
5025 | * This action fires at the end of the Manager::authorize method when a secondary user is |
||
5026 | * linked. |
||
5027 | */ |
||
5028 | public static function authorize_ending_linked() { |
||
5032 | |||
5033 | /** |
||
5034 | * This action fires at the end of the Manager::authorize method when the master user is |
||
5035 | * authorized. |
||
5036 | * |
||
5037 | * @param array $data The request data. |
||
5038 | */ |
||
5039 | public static function authorize_ending_authorized( $data ) { |
||
5059 | |||
5060 | /** |
||
5061 | * Fires on the jetpack_site_registered hook and acitvates default modules |
||
5062 | */ |
||
5063 | public static function activate_default_modules_on_site_register() { |
||
5078 | |||
5079 | /** |
||
5080 | * This action fires at the end of the REST_Connector connection_reconnect method when the |
||
5081 | * reconnect process is completed. |
||
5082 | * Note that this currently only happens when we don't need the user to re-authorize |
||
5083 | * their WP.com account, eg in cases where we are restoring a connection with |
||
5084 | * unhealthy blog token. |
||
5085 | */ |
||
5086 | public static function reconnection_completed() { |
||
5089 | |||
5090 | /** |
||
5091 | * Get our assumed site creation date. |
||
5092 | * Calculated based on the earlier date of either: |
||
5093 | * - Earliest admin user registration date. |
||
5094 | * - Earliest date of post of any post type. |
||
5095 | * |
||
5096 | * @since 7.2.0 |
||
5097 | * @deprecated since 7.8.0 |
||
5098 | * |
||
5099 | * @return string Assumed site creation date and time. |
||
5100 | */ |
||
5101 | public static function get_assumed_site_creation_date() { |
||
5105 | |||
5106 | View Code Duplication | public static function apply_activation_source_to_args( &$args ) { |
|
5117 | |||
5118 | function build_reconnect_url( $raw = false ) { |
||
5122 | |||
5123 | public static function admin_url( $args = null ) { |
||
5128 | |||
5129 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
5133 | |||
5134 | function dismiss_jetpack_notice() { |
||
5151 | |||
5152 | public static function sort_modules( $a, $b ) { |
||
5159 | |||
5160 | function ajax_recheck_ssl() { |
||
5170 | |||
5171 | /* Client API */ |
||
5172 | |||
5173 | /** |
||
5174 | * Returns the requested Jetpack API URL |
||
5175 | * |
||
5176 | * @deprecated since 7.7 |
||
5177 | * @return string |
||
5178 | */ |
||
5179 | public static function api_url( $relative_url ) { |
||
5184 | |||
5185 | /** |
||
5186 | * @deprecated 8.0 |
||
5187 | * |
||
5188 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. |
||
5189 | * But we no longer fix "bad hosts" anyway, outbound HTTPS is required for Jetpack to function. |
||
5190 | */ |
||
5191 | public static function fix_url_for_bad_hosts( $url ) { |
||
5195 | |||
5196 | public static function verify_onboarding_token( $token_data, $token, $request_data ) { |
||
5241 | |||
5242 | /** |
||
5243 | * Create a random secret for validating onboarding payload |
||
5244 | * |
||
5245 | * @return string Secret token |
||
5246 | */ |
||
5247 | public static function create_onboarding_token() { |
||
5255 | |||
5256 | /** |
||
5257 | * Remove the onboarding token |
||
5258 | * |
||
5259 | * @return bool True on success, false on failure |
||
5260 | */ |
||
5261 | public static function invalidate_onboarding_token() { |
||
5264 | |||
5265 | /** |
||
5266 | * Validate an onboarding token for a specific action |
||
5267 | * |
||
5268 | * @return boolean True if token/action pair is accepted, false if not |
||
5269 | */ |
||
5270 | public static function validate_onboarding_token_action( $token, $action ) { |
||
5288 | |||
5289 | /** |
||
5290 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
5291 | * |
||
5292 | * @since 2.3.3 |
||
5293 | * @return boolean |
||
5294 | */ |
||
5295 | public static function permit_ssl( $force_recheck = false ) { |
||
5324 | |||
5325 | /* |
||
5326 | * Displays an admin_notice, alerting the user that outbound SSL isn't working. |
||
5327 | */ |
||
5328 | public function alert_auto_ssl_fail() { |
||
5382 | |||
5383 | /** |
||
5384 | * Returns the Jetpack XML-RPC API |
||
5385 | * |
||
5386 | * @deprecated 8.0 Use Connection_Manager instead. |
||
5387 | * @return string |
||
5388 | */ |
||
5389 | public static function xmlrpc_api_url() { |
||
5393 | |||
5394 | /** |
||
5395 | * Returns the connection manager object. |
||
5396 | * |
||
5397 | * @return Automattic\Jetpack\Connection\Manager |
||
5398 | */ |
||
5399 | public static function connection() { |
||
5409 | |||
5410 | /** |
||
5411 | * Creates two secret tokens and the end of life timestamp for them. |
||
5412 | * |
||
5413 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
5414 | * |
||
5415 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->generate() instead. |
||
5416 | * |
||
5417 | * @since 2.6 |
||
5418 | * @param String $action The action name. |
||
5419 | * @param Integer $user_id The user identifier. |
||
5420 | * @param Integer $exp Expiration time in seconds. |
||
5421 | * @return array |
||
5422 | */ |
||
5423 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
5427 | |||
5428 | public static function get_secrets( $action, $user_id ) { |
||
5441 | |||
5442 | /** |
||
5443 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5444 | * |
||
5445 | * Based on local php max_execution_time in php.ini |
||
5446 | * |
||
5447 | * @since 2.6 |
||
5448 | * @return int |
||
5449 | * @deprecated |
||
5450 | **/ |
||
5451 | public function get_remote_query_timeout_limit() { |
||
5455 | |||
5456 | /** |
||
5457 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5458 | * |
||
5459 | * Based on local php max_execution_time in php.ini |
||
5460 | * |
||
5461 | * @since 5.4 |
||
5462 | * @return int |
||
5463 | **/ |
||
5464 | public static function get_max_execution_time() { |
||
5473 | |||
5474 | /** |
||
5475 | * Sets a minimum request timeout, and returns the current timeout |
||
5476 | * |
||
5477 | * @since 5.4 |
||
5478 | **/ |
||
5479 | View Code Duplication | public static function set_min_time_limit( $min_timeout ) { |
|
5487 | |||
5488 | /** |
||
5489 | * Takes the response from the Jetpack register new site endpoint and |
||
5490 | * verifies it worked properly. |
||
5491 | * |
||
5492 | * @since 2.6 |
||
5493 | * @deprecated since 7.7.0 |
||
5494 | * @see Automattic\Jetpack\Connection\Manager::validate_remote_register_response() |
||
5495 | **/ |
||
5496 | public function validate_remote_register_response() { |
||
5499 | |||
5500 | /** |
||
5501 | * @deprecated since Jetpack 9.7.0 |
||
5502 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
5503 | * |
||
5504 | * @return bool|WP_Error |
||
5505 | */ |
||
5506 | public static function register() { |
||
5510 | |||
5511 | /** |
||
5512 | * Filters the registration request body to include tracking properties. |
||
5513 | * |
||
5514 | * @deprecated since Jetpack 9.7.0 |
||
5515 | * @see Automattic\Jetpack\Connection\Utils::filter_register_request_body() |
||
5516 | * |
||
5517 | * @param array $properties |
||
5518 | * @return array amended properties. |
||
5519 | */ |
||
5520 | public static function filter_register_request_body( $properties ) { |
||
5524 | |||
5525 | /** |
||
5526 | * Filters the token request body to include tracking properties. |
||
5527 | * |
||
5528 | * @param array $properties |
||
5529 | * @return array amended properties. |
||
5530 | */ |
||
5531 | View Code Duplication | public static function filter_token_request_body( $properties ) { |
|
5543 | |||
5544 | /** |
||
5545 | * If the db version is showing something other that what we've got now, bump it to current. |
||
5546 | * |
||
5547 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
5548 | */ |
||
5549 | public static function maybe_set_version_option() { |
||
5563 | |||
5564 | /* Client Server API */ |
||
5565 | |||
5566 | /** |
||
5567 | * Loads the Jetpack XML-RPC client. |
||
5568 | * No longer necessary, as the XML-RPC client will be automagically loaded. |
||
5569 | * |
||
5570 | * @deprecated since 7.7.0 |
||
5571 | */ |
||
5572 | public static function load_xml_rpc_client() { |
||
5575 | |||
5576 | /** |
||
5577 | * Resets the saved authentication state in between testing requests. |
||
5578 | * |
||
5579 | * @deprecated since 8.9.0 |
||
5580 | * @see Automattic\Jetpack\Connection\Rest_Authentication::reset_saved_auth_state() |
||
5581 | */ |
||
5582 | public function reset_saved_auth_state() { |
||
5586 | |||
5587 | /** |
||
5588 | * Verifies the signature of the current request. |
||
5589 | * |
||
5590 | * @deprecated since 7.7.0 |
||
5591 | * @see Automattic\Jetpack\Connection\Manager::verify_xml_rpc_signature() |
||
5592 | * |
||
5593 | * @return false|array |
||
5594 | */ |
||
5595 | public function verify_xml_rpc_signature() { |
||
5599 | |||
5600 | /** |
||
5601 | * Verifies the signature of the current request. |
||
5602 | * |
||
5603 | * This function has side effects and should not be used. Instead, |
||
5604 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
5605 | * |
||
5606 | * @deprecated since 7.7.0 |
||
5607 | * @see Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature() |
||
5608 | * @internal |
||
5609 | */ |
||
5610 | private function internal_verify_xml_rpc_signature() { |
||
5613 | |||
5614 | /** |
||
5615 | * Authenticates XML-RPC and other requests from the Jetpack Server. |
||
5616 | * |
||
5617 | * @deprecated since 7.7.0 |
||
5618 | * @see Automattic\Jetpack\Connection\Manager::authenticate_jetpack() |
||
5619 | * |
||
5620 | * @param \WP_User|mixed $user User object if authenticated. |
||
5621 | * @param string $username Username. |
||
5622 | * @param string $password Password string. |
||
5623 | * @return \WP_User|mixed Authenticated user or error. |
||
5624 | */ |
||
5625 | View Code Duplication | public function authenticate_jetpack( $user, $username, $password ) { |
|
5634 | |||
5635 | /** |
||
5636 | * Authenticates requests from Jetpack server to WP REST API endpoints. |
||
5637 | * Uses the existing XMLRPC request signing implementation. |
||
5638 | * |
||
5639 | * @deprecated since 8.9.0 |
||
5640 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authenticate() |
||
5641 | */ |
||
5642 | function wp_rest_authenticate( $user ) { |
||
5646 | |||
5647 | /** |
||
5648 | * Report authentication status to the WP REST API. |
||
5649 | * |
||
5650 | * @deprecated since 8.9.0 |
||
5651 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authentication_errors() |
||
5652 | * |
||
5653 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
5654 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
5655 | */ |
||
5656 | public function wp_rest_authentication_errors( $value ) { |
||
5660 | |||
5661 | /** |
||
5662 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
5663 | * Capture it here so we can verify the signature later. |
||
5664 | * |
||
5665 | * @deprecated since 7.7.0 |
||
5666 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_methods() |
||
5667 | * |
||
5668 | * @param array $methods XMLRPC methods. |
||
5669 | * @return array XMLRPC methods, with the $HTTP_RAW_POST_DATA one. |
||
5670 | */ |
||
5671 | View Code Duplication | public function xmlrpc_methods( $methods ) { |
|
5680 | |||
5681 | /** |
||
5682 | * Register additional public XMLRPC methods. |
||
5683 | * |
||
5684 | * @deprecated since 7.7.0 |
||
5685 | * @see Automattic\Jetpack\Connection\Manager::public_xmlrpc_methods() |
||
5686 | * |
||
5687 | * @param array $methods Public XMLRPC methods. |
||
5688 | * @return array Public XMLRPC methods, with the getOptions one. |
||
5689 | */ |
||
5690 | View Code Duplication | public function public_xmlrpc_methods( $methods ) { |
|
5699 | |||
5700 | /** |
||
5701 | * Handles a getOptions XMLRPC method call. |
||
5702 | * |
||
5703 | * @deprecated since 7.7.0 |
||
5704 | * @see Automattic\Jetpack\Connection\Manager::jetpack_getOptions() |
||
5705 | * |
||
5706 | * @param array $args method call arguments. |
||
5707 | * @return array an amended XMLRPC server options array. |
||
5708 | */ |
||
5709 | View Code Duplication | public function jetpack_getOptions( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
5718 | |||
5719 | /** |
||
5720 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
5721 | * |
||
5722 | * @deprecated since 7.7.0 |
||
5723 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_options() |
||
5724 | * |
||
5725 | * @param array $options Standard Core options. |
||
5726 | * @return array Amended options. |
||
5727 | */ |
||
5728 | View Code Duplication | public function xmlrpc_options( $options ) { |
|
5737 | |||
5738 | /** |
||
5739 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
5740 | * SET: state( $key, $value ); |
||
5741 | * GET: $value = state( $key ); |
||
5742 | * |
||
5743 | * @param string $key |
||
5744 | * @param string $value |
||
5745 | * @param bool $restate private |
||
5746 | */ |
||
5747 | public static function state( $key = null, $value = null, $restate = false ) { |
||
5803 | |||
5804 | public static function restate() { |
||
5807 | |||
5808 | /** |
||
5809 | * Determines whether the jetpackState[$key] value should be added to the |
||
5810 | * cookie. |
||
5811 | * |
||
5812 | * @param string $key The state key. |
||
5813 | * |
||
5814 | * @return boolean Whether the value should be added to the cookie. |
||
5815 | */ |
||
5816 | public static function should_set_cookie( $key ) { |
||
5826 | |||
5827 | public static function check_privacy( $file ) { |
||
5861 | |||
5862 | /** |
||
5863 | * Helper method for multicall XMLRPC. |
||
5864 | * |
||
5865 | * @deprecated since 8.9.0 |
||
5866 | * @see Automattic\\Jetpack\\Connection\\Xmlrpc_Async_Call::add_call() |
||
5867 | * |
||
5868 | * @param ...$args Args for the async_call. |
||
5869 | */ |
||
5870 | public static function xmlrpc_async_call( ...$args ) { |
||
5912 | |||
5913 | /** |
||
5914 | * Serve a WordPress.com static resource via a randomized wp.com subdomain. |
||
5915 | * |
||
5916 | * @deprecated 9.3.0 Use Assets::staticize_subdomain. |
||
5917 | * |
||
5918 | * @param string $url WordPress.com static resource URL. |
||
5919 | */ |
||
5920 | public static function staticize_subdomain( $url ) { |
||
5924 | |||
5925 | /* JSON API Authorization */ |
||
5926 | |||
5927 | /** |
||
5928 | * Handles the login action for Authorizing the JSON API |
||
5929 | */ |
||
5930 | function login_form_json_api_authorization() { |
||
5939 | |||
5940 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
5941 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
5955 | |||
5956 | // Make sure the POSTed request is handled by the same action |
||
5957 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
5961 | |||
5962 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
5963 | function store_json_api_authorization_token( $user_login, $user ) { |
||
5969 | |||
5970 | // Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. |
||
5971 | function allow_wpcom_public_api_domain( $domains ) { |
||
5975 | |||
5976 | static function is_redirect_encoded( $redirect_url ) { |
||
5979 | |||
5980 | // Add all wordpress.com environments to the safe redirect allowed list. |
||
5981 | function allow_wpcom_environments( $domains ) { |
||
5988 | |||
5989 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
5990 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
6002 | |||
6003 | /** |
||
6004 | * Verifies the request by checking the signature |
||
6005 | * |
||
6006 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
6007 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
6008 | * |
||
6009 | * @param null|array $environment |
||
6010 | */ |
||
6011 | function verify_json_api_authorization_request( $environment = null ) { |
||
6133 | |||
6134 | function login_message_json_api_authorization( $message ) { |
||
6140 | |||
6141 | /** |
||
6142 | * Get $content_width, but with a <s>twist</s> filter. |
||
6143 | */ |
||
6144 | public static function get_content_width() { |
||
6157 | |||
6158 | /** |
||
6159 | * Pings the WordPress.com Mirror Site for the specified options. |
||
6160 | * |
||
6161 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
6162 | * |
||
6163 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
6164 | */ |
||
6165 | public function get_cloud_site_options( $option_names ) { |
||
6180 | |||
6181 | /** |
||
6182 | * Checks if the site is currently in an identity crisis. |
||
6183 | * |
||
6184 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
6185 | */ |
||
6186 | public static function check_identity_crisis() { |
||
6193 | |||
6194 | /** |
||
6195 | * Checks whether the home and siteurl specifically are allowed. |
||
6196 | * Written so that we don't have re-check $key and $value params every time |
||
6197 | * we want to check if this site is allowed, for example in footer.php |
||
6198 | * |
||
6199 | * @since 3.8.0 |
||
6200 | * @return bool True = already allowed False = not on the allowed list. |
||
6201 | */ |
||
6202 | public static function is_staging_site() { |
||
6206 | |||
6207 | /** |
||
6208 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
6209 | * |
||
6210 | * @since 4.4.0 |
||
6211 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
6212 | * |
||
6213 | * @return bool |
||
6214 | */ |
||
6215 | View Code Duplication | public static function validate_sync_error_idc_option() { |
|
6216 | $is_valid = false; |
||
6217 | |||
6218 | // Is the site opted in and does the stored sync_error_idc option match what we now generate? |
||
6219 | $sync_error = Jetpack_Options::get_option( 'sync_error_idc' ); |
||
6220 | if ( $sync_error && self::sync_idc_optin() ) { |
||
6221 | $local_options = self::get_sync_error_idc_option(); |
||
6222 | // Ensure all values are set. |
||
6223 | if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) { |
||
6224 | |||
6225 | // If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC. |
||
6226 | if ( |
||
6227 | isset( $sync_error['wpcom_home'] ) && |
||
6228 | isset( $sync_error['wpcom_siteurl'] ) && |
||
6229 | $sync_error['wpcom_home'] === $local_options['home'] && |
||
6230 | $sync_error['wpcom_siteurl'] === $local_options['siteurl'] |
||
6231 | ) { |
||
6232 | $is_valid = false; |
||
6233 | // Enable migrate_for_idc so that sync actions are accepted. |
||
6234 | Jetpack_Options::update_option( 'migrate_for_idc', true ); |
||
6235 | } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { |
||
6236 | $is_valid = true; |
||
6237 | } |
||
6238 | } |
||
6239 | } |
||
6240 | |||
6241 | /** |
||
6242 | * Filters whether the sync_error_idc option is valid. |
||
6243 | * |
||
6244 | * @since 4.4.0 |
||
6245 | * |
||
6246 | * @param bool $is_valid If the sync_error_idc is valid or not. |
||
6247 | */ |
||
6248 | $is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid ); |
||
6249 | |||
6250 | if ( ! $is_valid && $sync_error ) { |
||
6251 | // Since the option exists, and did not validate, delete it |
||
6252 | Jetpack_Options::delete_option( 'sync_error_idc' ); |
||
6253 | } |
||
6254 | |||
6255 | return $is_valid; |
||
6256 | } |
||
6257 | |||
6258 | /** |
||
6259 | * Normalizes a url by doing three things: |
||
6260 | * - Strips protocol |
||
6261 | * - Strips www |
||
6262 | * - Adds a trailing slash |
||
6263 | * |
||
6264 | * @since 4.4.0 |
||
6265 | * @param string $url |
||
6266 | * @return WP_Error|string |
||
6267 | */ |
||
6268 | View Code Duplication | public static function normalize_url_protocol_agnostic( $url ) { |
|
6269 | $parsed_url = wp_parse_url( trailingslashit( esc_url_raw( $url ) ) ); |
||
6270 | if ( ! $parsed_url || empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) ) { |
||
6271 | return new WP_Error( 'cannot_parse_url', sprintf( esc_html__( 'Cannot parse URL %s', 'jetpack' ), $url ) ); |
||
6272 | } |
||
6273 | |||
6274 | // Strip www and protocols |
||
6275 | $url = preg_replace( '/^www\./i', '', $parsed_url['host'] . $parsed_url['path'] ); |
||
6276 | return $url; |
||
6277 | } |
||
6278 | |||
6279 | /** |
||
6280 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
6281 | * |
||
6282 | * @since 4.4.0 |
||
6283 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
6284 | * |
||
6285 | * @param array $response |
||
6286 | * @return array Array of the local urls, wpcom urls, and error code |
||
6287 | */ |
||
6288 | View Code Duplication | public static function get_sync_error_idc_option( $response = array() ) { |
|
6289 | // Since the local options will hit the database directly, store the values |
||
6290 | // in a transient to allow for autoloading and caching on subsequent views. |
||
6291 | $local_options = get_transient( 'jetpack_idc_local' ); |
||
6292 | if ( false === $local_options ) { |
||
6293 | $local_options = array( |
||
6294 | 'home' => Functions::home_url(), |
||
6295 | 'siteurl' => Functions::site_url(), |
||
6296 | ); |
||
6297 | set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS ); |
||
6298 | } |
||
6299 | |||
6300 | $options = array_merge( $local_options, $response ); |
||
6301 | |||
6302 | $returned_values = array(); |
||
6303 | foreach ( $options as $key => $option ) { |
||
6304 | if ( 'error_code' === $key ) { |
||
6305 | $returned_values[ $key ] = $option; |
||
6306 | continue; |
||
6307 | } |
||
6308 | |||
6309 | if ( is_wp_error( $normalized_url = self::normalize_url_protocol_agnostic( $option ) ) ) { |
||
6310 | continue; |
||
6311 | } |
||
6312 | |||
6313 | $returned_values[ $key ] = $normalized_url; |
||
6314 | } |
||
6315 | |||
6316 | set_transient( 'jetpack_idc_option', $returned_values, MINUTE_IN_SECONDS ); |
||
6317 | |||
6318 | return $returned_values; |
||
6319 | } |
||
6320 | |||
6321 | /** |
||
6322 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
6323 | * If set to true, the site will be put into staging mode. |
||
6324 | * |
||
6325 | * @since 4.3.2 |
||
6326 | * @return bool |
||
6327 | */ |
||
6328 | View Code Duplication | public static function sync_idc_optin() { |
|
6329 | if ( Constants::is_defined( 'JETPACK_SYNC_IDC_OPTIN' ) ) { |
||
6330 | $default = Constants::get_constant( 'JETPACK_SYNC_IDC_OPTIN' ); |
||
6331 | } else { |
||
6332 | $default = ! Constants::is_defined( 'SUNRISE' ) && ! is_multisite(); |
||
6333 | } |
||
6334 | |||
6335 | /** |
||
6336 | * Allows sites to opt in for IDC mitigation which blocks the site from syncing to WordPress.com when the home |
||
6337 | * URL or site URL do not match what WordPress.com expects. The default value is either true, or the value of |
||
6338 | * JETPACK_SYNC_IDC_OPTIN constant if set. |
||
6339 | * |
||
6340 | * @since 4.3.2 |
||
6341 | * |
||
6342 | * @param bool $default Whether the site is opted in to IDC mitigation. |
||
6343 | */ |
||
6344 | return (bool) apply_filters( 'jetpack_sync_idc_optin', $default ); |
||
6345 | } |
||
6346 | |||
6347 | /** |
||
6348 | * Maybe Use a .min.css stylesheet, maybe not. |
||
6349 | * |
||
6350 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
6351 | */ |
||
6352 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
6394 | |||
6395 | /** |
||
6396 | * If the asset is minified, let's flag .min as the suffix. |
||
6397 | * |
||
6398 | * Attached to `style_loader_src` filter. |
||
6399 | * |
||
6400 | * @param string $tag The tag that would link to the external asset. |
||
6401 | * @param string $handle The registered handle of the script in question. |
||
6402 | * @param string $href The url of the asset in question. |
||
6403 | */ |
||
6404 | public static function set_suffix_on_min( $src, $handle ) { |
||
6420 | |||
6421 | /** |
||
6422 | * Maybe inlines a stylesheet. |
||
6423 | * |
||
6424 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
6425 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
6426 | * |
||
6427 | * Attached to `style_loader_tag` filter. |
||
6428 | * |
||
6429 | * @param string $tag The tag that would link to the external asset. |
||
6430 | * @param string $handle The registered handle of the script in question. |
||
6431 | * |
||
6432 | * @return string |
||
6433 | */ |
||
6434 | public static function maybe_inline_style( $tag, $handle ) { |
||
6484 | |||
6485 | /** |
||
6486 | * Loads a view file from the views |
||
6487 | * |
||
6488 | * Data passed in with the $data parameter will be available in the |
||
6489 | * template file as $data['value'] |
||
6490 | * |
||
6491 | * @param string $template - Template file to load |
||
6492 | * @param array $data - Any data to pass along to the template |
||
6493 | * @return boolean - If template file was found |
||
6494 | **/ |
||
6495 | public function load_view( $template, $data = array() ) { |
||
6506 | |||
6507 | /** |
||
6508 | * Throws warnings for deprecated hooks to be removed from Jetpack that cannot remain in the original place in the code. |
||
6509 | */ |
||
6510 | public function deprecated_hooks() { |
||
6767 | |||
6768 | /** |
||
6769 | * Converts any url in a stylesheet, to the correct absolute url. |
||
6770 | * |
||
6771 | * Considerations: |
||
6772 | * - Normal, relative URLs `feh.png` |
||
6773 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
6774 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
6775 | * - Absolute URLs `http://domain.com/feh.png` |
||
6776 | * - Domain root relative URLs `/feh.png` |
||
6777 | * |
||
6778 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
6779 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
6780 | * |
||
6781 | * @return mixed|string |
||
6782 | */ |
||
6783 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
6827 | |||
6828 | /** |
||
6829 | * This methods removes all of the registered css files on the front end |
||
6830 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
6831 | * all the files into one file. |
||
6832 | * |
||
6833 | * Pros: |
||
6834 | * - Uses only ONE css asset connection instead of 15 |
||
6835 | * - Saves a minimum of 56k |
||
6836 | * - Reduces server load |
||
6837 | * - Reduces time to first painted byte |
||
6838 | * |
||
6839 | * Cons: |
||
6840 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
6841 | * should not cause any issues with themes. |
||
6842 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
6843 | * jetpack_implode_frontend_css filter for a workaround |
||
6844 | * |
||
6845 | * For some situations developers may wish to disable css imploding and |
||
6846 | * instead operate in legacy mode where each file loads seperately and |
||
6847 | * can be edited individually or dequeued. This can be accomplished with |
||
6848 | * the following line: |
||
6849 | * |
||
6850 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
6851 | * |
||
6852 | * @since 3.2 |
||
6853 | **/ |
||
6854 | public function implode_frontend_css( $travis_test = false ) { |
||
6911 | |||
6912 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
6922 | |||
6923 | /** |
||
6924 | * @deprecated |
||
6925 | * @see Automattic\Jetpack\Assets\add_aync_script |
||
6926 | */ |
||
6927 | public function script_add_async( $tag, $handle, $src ) { |
||
6930 | |||
6931 | /* |
||
6932 | * Check the heartbeat data |
||
6933 | * |
||
6934 | * Organizes the heartbeat data by severity. For example, if the site |
||
6935 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
6936 | * |
||
6937 | * Data will be added to "caution" array, if it either: |
||
6938 | * - Out of date Jetpack version |
||
6939 | * - Out of date WP version |
||
6940 | * - Out of date PHP version |
||
6941 | * |
||
6942 | * $return array $filtered_data |
||
6943 | */ |
||
6944 | public static function jetpack_check_heartbeat_data() { |
||
6997 | |||
6998 | /* |
||
6999 | * This method is used to organize all options that can be reset |
||
7000 | * without disconnecting Jetpack. |
||
7001 | * |
||
7002 | * It is used in class.jetpack-cli.php to reset options |
||
7003 | * |
||
7004 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
7005 | * |
||
7006 | * @return array of options to delete. |
||
7007 | */ |
||
7008 | public static function get_jetpack_options_for_reset() { |
||
7011 | |||
7012 | /* |
||
7013 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
7014 | * so we can bring them directly to their site in calypso. |
||
7015 | * |
||
7016 | * @deprecated 9.2.0 Use Automattic\Jetpack\Status::get_site_suffix |
||
7017 | * |
||
7018 | * @param string | url |
||
7019 | * @return string | url without the guff |
||
7020 | */ |
||
7021 | public static function build_raw_urls( $url ) { |
||
7026 | |||
7027 | /** |
||
7028 | * Stores and prints out domains to prefetch for page speed optimization. |
||
7029 | * |
||
7030 | * @deprecated 8.8.0 Use Jetpack::add_resource_hints. |
||
7031 | * |
||
7032 | * @param string|array $urls URLs to hint. |
||
7033 | */ |
||
7034 | public static function dns_prefetch( $urls = null ) { |
||
7040 | |||
7041 | public function wp_dashboard_setup() { |
||
7079 | |||
7080 | /** |
||
7081 | * @param mixed $result Value for the user's option |
||
7082 | * @return mixed |
||
7083 | */ |
||
7084 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
7109 | |||
7110 | public static function dashboard_widget() { |
||
7118 | |||
7119 | public static function dashboard_widget_footer() { |
||
7187 | |||
7188 | /* |
||
7189 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
7190 | */ |
||
7191 | function jetpack_icon_user_connected( $columns ) { |
||
7195 | |||
7196 | /* |
||
7197 | * Show Jetpack icon if the user is linked. |
||
7198 | */ |
||
7199 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
7212 | |||
7213 | /* |
||
7214 | * Style the Jetpack user column |
||
7215 | */ |
||
7216 | function jetpack_user_col_style() { |
||
7235 | |||
7236 | /** |
||
7237 | * Checks if Akismet is active and working. |
||
7238 | * |
||
7239 | * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key |
||
7240 | * that implied usage of methods present since more recent version. |
||
7241 | * See https://github.com/Automattic/jetpack/pull/9585 |
||
7242 | * |
||
7243 | * @since 5.1.0 |
||
7244 | * |
||
7245 | * @return bool True = Akismet available. False = Aksimet not available. |
||
7246 | */ |
||
7247 | public static function is_akismet_active() { |
||
7282 | |||
7283 | /** |
||
7284 | * @deprecated |
||
7285 | * |
||
7286 | * @see Automattic\Jetpack\Sync\Modules\Users::is_function_in_backtrace |
||
7287 | */ |
||
7288 | public static function is_function_in_backtrace() { |
||
7291 | |||
7292 | /** |
||
7293 | * Given a minified path, and a non-minified path, will return |
||
7294 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
7295 | * |
||
7296 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
7297 | * root Jetpack directory. |
||
7298 | * |
||
7299 | * @since 5.6.0 |
||
7300 | * |
||
7301 | * @param string $min_path |
||
7302 | * @param string $non_min_path |
||
7303 | * @return string The URL to the file |
||
7304 | */ |
||
7305 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
7308 | |||
7309 | /** |
||
7310 | * Checks for whether Jetpack Backup is enabled. |
||
7311 | * Will return true if the state of Backup is anything except "unavailable". |
||
7312 | * |
||
7313 | * @return bool|int|mixed |
||
7314 | */ |
||
7315 | public static function is_rewind_enabled() { |
||
7335 | |||
7336 | /** |
||
7337 | * Return Calypso environment value; used for developing Jetpack and pairing |
||
7338 | * it with different Calypso enrionments, such as localhost. |
||
7339 | * |
||
7340 | * @since 7.4.0 |
||
7341 | * |
||
7342 | * @return string Calypso environment |
||
7343 | */ |
||
7344 | public static function get_calypso_env() { |
||
7359 | |||
7360 | /** |
||
7361 | * Returns the hostname with protocol for Calypso. |
||
7362 | * Used for developing Jetpack with Calypso. |
||
7363 | * |
||
7364 | * @since 8.4.0 |
||
7365 | * |
||
7366 | * @return string Calypso host. |
||
7367 | */ |
||
7368 | public static function get_calypso_host() { |
||
7381 | |||
7382 | /** |
||
7383 | * Handles activating default modules as well general cleanup for the new connection. |
||
7384 | * |
||
7385 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
7386 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
7387 | * @param boolean $send_state_messages Whether to send state messages. |
||
7388 | * @return void |
||
7389 | */ |
||
7390 | public static function handle_post_authorization_actions( |
||
7418 | |||
7419 | /** |
||
7420 | * Returns a boolean for whether backups UI should be displayed or not. |
||
7421 | * |
||
7422 | * @return bool Should backups UI be displayed? |
||
7423 | */ |
||
7424 | public static function show_backups_ui() { |
||
7434 | |||
7435 | /* |
||
7436 | * Deprecated manage functions |
||
7437 | */ |
||
7438 | function prepare_manage_jetpack_notice() { |
||
7459 | |||
7460 | /** |
||
7461 | * Clean leftoveruser meta. |
||
7462 | * |
||
7463 | * Delete Jetpack-related user meta when it is no longer needed. |
||
7464 | * |
||
7465 | * @since 7.3.0 |
||
7466 | * |
||
7467 | * @param int $user_id User ID being updated. |
||
7468 | */ |
||
7469 | public static function user_meta_cleanup( $user_id ) { |
||
7484 | |||
7485 | /** |
||
7486 | * Checks if a Jetpack site is both active and not in offline mode. |
||
7487 | * |
||
7488 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
7489 | * |
||
7490 | * @deprecated 8.8.0 |
||
7491 | * |
||
7492 | * @return bool True if Jetpack is active and not in offline mode. |
||
7493 | */ |
||
7494 | public static function is_active_and_not_development_mode() { |
||
7501 | |||
7502 | /** |
||
7503 | * Checks if a Jetpack site is both active and not in offline mode. |
||
7504 | * |
||
7505 | * This is a DRY function to avoid repeating `Jetpack::is_connection_ready && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
7506 | * |
||
7507 | * @since 8.8.0 |
||
7508 | * |
||
7509 | * @return bool True if Jetpack is active and not in offline mode. |
||
7510 | */ |
||
7511 | public static function is_active_and_not_offline_mode() { |
||
7517 | |||
7518 | /** |
||
7519 | * Returns the list of products that we have available for purchase. |
||
7520 | */ |
||
7521 | public static function get_products_for_purchase() { |
||
7615 | } |
||
7616 |
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.