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 |
||
52 | class Jetpack { |
||
53 | public $xmlrpc_server = null; |
||
54 | |||
55 | /** |
||
56 | * @var array The handles of styles that are concatenated into jetpack.css. |
||
57 | * |
||
58 | * When making changes to that list, you must also update concat_list in tools/builder/frontend-css.js. |
||
59 | */ |
||
60 | public $concatenated_style_handles = array( |
||
61 | 'jetpack-carousel', |
||
62 | 'grunion.css', |
||
63 | 'the-neverending-homepage', |
||
64 | 'jetpack_likes', |
||
65 | 'jetpack_related-posts', |
||
66 | 'sharedaddy', |
||
67 | 'jetpack-slideshow', |
||
68 | 'presentations', |
||
69 | 'quiz', |
||
70 | 'jetpack-subscriptions', |
||
71 | 'jetpack-responsive-videos-style', |
||
72 | 'jetpack-social-menu', |
||
73 | 'tiled-gallery', |
||
74 | 'jetpack_display_posts_widget', |
||
75 | 'gravatar-profile-widget', |
||
76 | 'goodreads-widget', |
||
77 | 'jetpack_social_media_icons_widget', |
||
78 | 'jetpack-top-posts-widget', |
||
79 | 'jetpack_image_widget', |
||
80 | 'jetpack-my-community-widget', |
||
81 | 'jetpack-authors-widget', |
||
82 | 'wordads', |
||
83 | 'eu-cookie-law-style', |
||
84 | 'flickr-widget-style', |
||
85 | 'jetpack-search-widget', |
||
86 | 'jetpack-simple-payments-widget-style', |
||
87 | 'jetpack-widget-social-icons-styles', |
||
88 | 'wpcom_instagram_widget', |
||
89 | ); |
||
90 | |||
91 | /** |
||
92 | * Contains all assets that have had their URL rewritten to minified versions. |
||
93 | * |
||
94 | * @var array |
||
95 | */ |
||
96 | static $min_assets = array(); |
||
97 | |||
98 | public $plugins_to_deactivate = array( |
||
99 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
100 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
101 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
102 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
103 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
104 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
105 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
106 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
107 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
108 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
109 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
110 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
111 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
112 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ), |
||
113 | ); |
||
114 | |||
115 | /** |
||
116 | * Map of roles we care about, and their corresponding minimum capabilities. |
||
117 | * |
||
118 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead. |
||
119 | * |
||
120 | * @access public |
||
121 | * @static |
||
122 | * |
||
123 | * @var array |
||
124 | */ |
||
125 | public static $capability_translations = array( |
||
126 | 'administrator' => 'manage_options', |
||
127 | 'editor' => 'edit_others_posts', |
||
128 | 'author' => 'publish_posts', |
||
129 | 'contributor' => 'edit_posts', |
||
130 | 'subscriber' => 'read', |
||
131 | ); |
||
132 | |||
133 | /** |
||
134 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
135 | * if the plugins are active. Used by filter_default_modules |
||
136 | * |
||
137 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
138 | * change `module-slug` and add this to your plugin: |
||
139 | * |
||
140 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
141 | * function my_jetpack_get_default_modules( $modules ) { |
||
142 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
143 | * } |
||
144 | * |
||
145 | * @var array |
||
146 | */ |
||
147 | private $conflicting_plugins = array( |
||
148 | 'comments' => array( |
||
149 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
150 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
151 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
152 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
153 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
154 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
155 | ), |
||
156 | 'comment-likes' => array( |
||
157 | 'Epoch' => 'epoch/plugincore.php', |
||
158 | ), |
||
159 | 'contact-form' => array( |
||
160 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
161 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
162 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
163 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
164 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
165 | 'Ninja Forms' => 'ninja-forms/ninja-forms.php', |
||
166 | ), |
||
167 | 'latex' => array( |
||
168 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
169 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
170 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
171 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
172 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
173 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
174 | ), |
||
175 | 'protect' => array( |
||
176 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
177 | 'Captcha' => 'captcha/captcha.php', |
||
178 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
179 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
180 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
181 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
182 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
183 | 'Security-protection' => 'security-protection/security-protection.php', |
||
184 | 'Login Security' => 'login-security/login-security.php', |
||
185 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
186 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
187 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
188 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
189 | ), |
||
190 | 'random-redirect' => array( |
||
191 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
192 | ), |
||
193 | 'related-posts' => array( |
||
194 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
195 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
196 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
197 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
198 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
199 | 'outbrain' => 'outbrain/outbrain.php', |
||
200 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
201 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
202 | ), |
||
203 | 'sharedaddy' => array( |
||
204 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
205 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
206 | 'ShareThis' => 'share-this/sharethis.php', |
||
207 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
208 | ), |
||
209 | 'seo-tools' => array( |
||
210 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
211 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
212 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
213 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
214 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
215 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
216 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
217 | ), |
||
218 | 'verification-tools' => array( |
||
219 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
220 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
221 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
222 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
223 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
224 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
225 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
226 | ), |
||
227 | 'widget-visibility' => array( |
||
228 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
229 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
230 | ), |
||
231 | 'sitemaps' => array( |
||
232 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
233 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
234 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
235 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
236 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
237 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
238 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
239 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
240 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
241 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
242 | 'Sitemap' => 'sitemap/sitemap.php', |
||
243 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
244 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
245 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
246 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
247 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
248 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
249 | ), |
||
250 | 'lazy-images' => array( |
||
251 | 'Lazy Load' => 'lazy-load/lazy-load.php', |
||
252 | 'BJ Lazy Load' => 'bj-lazy-load/bj-lazy-load.php', |
||
253 | 'Lazy Load by WP Rocket' => 'rocket-lazy-load/rocket-lazy-load.php', |
||
254 | ), |
||
255 | ); |
||
256 | |||
257 | /** |
||
258 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
259 | * |
||
260 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
261 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
262 | * |
||
263 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
264 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
265 | */ |
||
266 | private $open_graph_conflicting_plugins = array( |
||
267 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
268 | // 2 Click Social Media Buttons |
||
269 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
270 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
271 | 'complete-open-graph/complete-open-graph.php', // Complete Open Graph |
||
272 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
273 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
274 | // Open Graph Meta Tags by Heateor |
||
275 | 'facebook/facebook.php', // Facebook (official plugin) |
||
276 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
277 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
278 | // Facebook Featured Image & OG Meta Tags |
||
279 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
280 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
281 | // Facebook Open Graph Meta Tags for WordPress |
||
282 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
283 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
284 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
285 | // Fedmich's Facebook Open Graph Meta |
||
286 | 'network-publisher/networkpub.php', // Network Publisher |
||
287 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
288 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
289 | // NextScripts SNAP |
||
290 | 'og-tags/og-tags.php', // OG Tags |
||
291 | 'opengraph/opengraph.php', // Open Graph |
||
292 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
293 | // Open Graph Protocol Framework |
||
294 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
295 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
296 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
297 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
298 | 'sharepress/sharepress.php', // SharePress |
||
299 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
300 | 'social-discussions/social-discussions.php', // Social Discussions |
||
301 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
302 | 'socialize/socialize.php', // Socialize |
||
303 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
304 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
305 | // Tweet, Like, Google +1 and Share |
||
306 | 'wordbooker/wordbooker.php', // Wordbooker |
||
307 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
308 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
309 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
310 | // WP Facebook Like Send & Open Graph Meta |
||
311 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
312 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
313 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
314 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button |
||
315 | 'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox |
||
316 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
317 | 'slim-seo/slim-seo.php', // Slim SEO |
||
318 | ); |
||
319 | |||
320 | /** |
||
321 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
322 | */ |
||
323 | private $twitter_cards_conflicting_plugins = array( |
||
324 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
325 | // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
326 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
327 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
328 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
329 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
330 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
331 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
332 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
333 | 'wp-to-twitter/wp-to-twitter.php', // WP to Twitter |
||
334 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
335 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
336 | 'slim-seo/slim-seo.php', // Slim SEO |
||
337 | ); |
||
338 | |||
339 | /** |
||
340 | * Message to display in admin_notice |
||
341 | * |
||
342 | * @var string |
||
343 | */ |
||
344 | public $message = ''; |
||
345 | |||
346 | /** |
||
347 | * Error to display in admin_notice |
||
348 | * |
||
349 | * @var string |
||
350 | */ |
||
351 | public $error = ''; |
||
352 | |||
353 | /** |
||
354 | * Modules that need more privacy description. |
||
355 | * |
||
356 | * @var string |
||
357 | */ |
||
358 | public $privacy_checks = ''; |
||
359 | |||
360 | /** |
||
361 | * Stats to record once the page loads |
||
362 | * |
||
363 | * @var array |
||
364 | */ |
||
365 | public $stats = array(); |
||
366 | |||
367 | /** |
||
368 | * Jetpack_Sync object |
||
369 | */ |
||
370 | public $sync; |
||
371 | |||
372 | /** |
||
373 | * Verified data for JSON authorization request |
||
374 | */ |
||
375 | public $json_api_authorization_request = array(); |
||
376 | |||
377 | /** |
||
378 | * @var Automattic\Jetpack\Connection\Manager |
||
379 | */ |
||
380 | protected $connection_manager; |
||
381 | |||
382 | /** |
||
383 | * @var string Transient key used to prevent multiple simultaneous plugin upgrades |
||
384 | */ |
||
385 | public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock'; |
||
386 | |||
387 | /** |
||
388 | * Holds an instance of Automattic\Jetpack\A8c_Mc_Stats |
||
389 | * |
||
390 | * @var Automattic\Jetpack\A8c_Mc_Stats |
||
391 | */ |
||
392 | public $a8c_mc_stats_instance; |
||
393 | |||
394 | /** |
||
395 | * Constant for login redirect key. |
||
396 | * |
||
397 | * @var string |
||
398 | * @since 8.4.0 |
||
399 | */ |
||
400 | public static $jetpack_redirect_login = 'jetpack_connect_login_redirect'; |
||
401 | |||
402 | /** |
||
403 | * Holds the singleton instance of this class |
||
404 | * |
||
405 | * @since 2.3.3 |
||
406 | * @var Jetpack |
||
407 | */ |
||
408 | static $instance = false; |
||
409 | |||
410 | /** |
||
411 | * Singleton |
||
412 | * |
||
413 | * @static |
||
414 | */ |
||
415 | public static function init() { |
||
423 | |||
424 | /** |
||
425 | * Must never be called statically |
||
426 | */ |
||
427 | function plugin_upgrade() { |
||
515 | |||
516 | /** |
||
517 | * Runs upgrade routines that need to have modules loaded. |
||
518 | */ |
||
519 | static function upgrade_on_load() { |
||
549 | |||
550 | /** |
||
551 | * Saves all the currently active modules to options. |
||
552 | * Also fires Action hooks for each newly activated and deactivated module. |
||
553 | * |
||
554 | * @param $modules Array Array of active modules to be saved in options. |
||
555 | * |
||
556 | * @return $success bool true for success, false for failure. |
||
|
|||
557 | */ |
||
558 | static function update_active_modules( $modules ) { |
||
611 | |||
612 | static function delete_active_modules() { |
||
615 | |||
616 | /** |
||
617 | * Adds a hook to plugins_loaded at a priority that's currently the earliest |
||
618 | * available. |
||
619 | */ |
||
620 | public function add_configure_hook() { |
||
641 | |||
642 | /** |
||
643 | * Constructor. Initializes WordPress hooks |
||
644 | */ |
||
645 | private function __construct() { |
||
646 | /* |
||
647 | * Check for and alert any deprecated hooks |
||
648 | */ |
||
649 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
650 | |||
651 | // Note how this runs at an earlier plugin_loaded hook intentionally to accomodate for other plugins. |
||
652 | add_action( 'plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
653 | add_action( 'network_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
654 | add_action( 'mu_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
655 | add_action( 'plugins_loaded', array( $this, 'late_initialization' ), 90 ); |
||
656 | |||
657 | add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) ); |
||
658 | |||
659 | add_filter( |
||
660 | 'jetpack_signature_check_token', |
||
661 | array( __CLASS__, 'verify_onboarding_token' ), |
||
662 | 10, |
||
663 | 3 |
||
664 | ); |
||
665 | |||
666 | /** |
||
667 | * Prepare Gutenberg Editor functionality |
||
668 | */ |
||
669 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; |
||
670 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'init' ) ); |
||
671 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) ); |
||
672 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_extended_blocks' ), 9 ); |
||
673 | add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); |
||
674 | |||
675 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
676 | |||
677 | // Unlink user before deleting the user from WP.com. |
||
678 | add_action( 'deleted_user', array( $this, 'disconnect_user' ), 10, 1 ); |
||
679 | add_action( 'remove_user_from_blog', array( $this, 'disconnect_user' ), 10, 1 ); |
||
680 | |||
681 | add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 ); |
||
682 | |||
683 | add_filter( 'login_url', array( $this, 'login_url' ), 10, 2 ); |
||
684 | add_action( 'login_init', array( $this, 'login_init' ) ); |
||
685 | |||
686 | // Set up the REST authentication hooks. |
||
687 | Connection_Rest_Authentication::init(); |
||
688 | |||
689 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
690 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
691 | |||
692 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 20 ); |
||
693 | |||
694 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
695 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
696 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
697 | |||
698 | // returns HTTPS support status |
||
699 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
700 | |||
701 | add_action( 'wp_ajax_jetpack_connection_banner', array( $this, 'jetpack_connection_banner_callback' ) ); |
||
702 | |||
703 | add_action( 'wp_ajax_jetpack_recommendations_banner', array( 'Jetpack_Recommendations_Banner', 'ajax_callback' ) ); |
||
704 | |||
705 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
706 | |||
707 | /** |
||
708 | * These actions run checks to load additional files. |
||
709 | * They check for external files or plugins, so they need to run as late as possible. |
||
710 | */ |
||
711 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
712 | add_action( 'web_stories_story_head', array( $this, 'check_open_graph' ), 1 ); |
||
713 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
714 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
715 | |||
716 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
717 | add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 ); |
||
718 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
719 | |||
720 | add_filter( 'profile_update', array( 'Jetpack', 'user_meta_cleanup' ) ); |
||
721 | |||
722 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
723 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
724 | |||
725 | // A filter to control all just in time messages |
||
726 | add_filter( 'jetpack_just_in_time_msgs', '__return_true', 9 ); |
||
727 | |||
728 | add_filter( 'jetpack_just_in_time_msg_cache', '__return_true', 9 ); |
||
729 | |||
730 | require_once JETPACK__PLUGIN_DIR . 'class-jetpack-pre-connection-jitms.php'; |
||
731 | $jetpack_jitm_messages = ( new Jetpack_Pre_Connection_JITMs() ); |
||
732 | add_filter( 'jetpack_pre_connection_jitms', array( $jetpack_jitm_messages, 'add_pre_connection_jitms' ) ); |
||
733 | |||
734 | /* |
||
735 | * If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin. |
||
736 | * We should make sure to only do this for front end links. |
||
737 | */ |
||
738 | if ( self::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) { |
||
739 | add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 ); |
||
740 | add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 ); |
||
741 | |||
742 | /* |
||
743 | * We'll shortcircuit wp_notify_postauthor and wp_notify_moderator pluggable functions |
||
744 | * so they point moderation links on emails to Calypso. |
||
745 | */ |
||
746 | jetpack_require_lib( 'functions.wp-notify' ); |
||
747 | add_filter( 'comment_notification_recipients', 'jetpack_notify_postauthor', 1, 2 ); |
||
748 | add_filter( 'notify_moderator', 'jetpack_notify_moderator', 1, 2 ); |
||
749 | } |
||
750 | |||
751 | add_action( |
||
752 | 'plugins_loaded', |
||
753 | function () { |
||
754 | if ( User_Agent_Info::is_mobile_app() ) { |
||
755 | add_filter( 'get_edit_post_link', '__return_empty_string' ); |
||
756 | } |
||
757 | } |
||
758 | ); |
||
759 | |||
760 | // Update the site's Jetpack plan and products from API on heartbeats. |
||
761 | add_action( 'jetpack_heartbeat', array( 'Jetpack_Plan', 'refresh_from_wpcom' ) ); |
||
762 | |||
763 | /** |
||
764 | * This is the hack to concatenate all css files into one. |
||
765 | * For description and reasoning see the implode_frontend_css method. |
||
766 | * |
||
767 | * Super late priority so we catch all the registered styles. |
||
768 | */ |
||
769 | if ( ! is_admin() ) { |
||
770 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
771 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
772 | } |
||
773 | |||
774 | /** |
||
775 | * These are sync actions that we need to keep track of for jitms |
||
776 | */ |
||
777 | add_filter( 'jetpack_sync_before_send_updated_option', array( $this, 'jetpack_track_last_sync_callback' ), 99 ); |
||
778 | |||
779 | // Actually push the stats on shutdown. |
||
780 | if ( ! has_action( 'shutdown', array( $this, 'push_stats' ) ) ) { |
||
781 | add_action( 'shutdown', array( $this, 'push_stats' ) ); |
||
782 | } |
||
783 | |||
784 | // After a successful connection. |
||
785 | add_action( 'jetpack_site_registered', array( $this, 'activate_default_modules_on_site_register' ) ); |
||
786 | |||
787 | // Actions for Manager::authorize(). |
||
788 | add_action( 'jetpack_authorize_starting', array( $this, 'authorize_starting' ) ); |
||
789 | add_action( 'jetpack_authorize_ending_linked', array( $this, 'authorize_ending_linked' ) ); |
||
790 | add_action( 'jetpack_authorize_ending_authorized', array( $this, 'authorize_ending_authorized' ) ); |
||
791 | |||
792 | add_action( 'jetpack_client_authorize_error', array( Jetpack_Client_Server::class, 'client_authorize_error' ) ); |
||
793 | add_filter( 'jetpack_client_authorize_already_authorized_url', array( Jetpack_Client_Server::class, 'client_authorize_already_authorized_url' ) ); |
||
794 | add_action( 'jetpack_client_authorize_processing', array( Jetpack_Client_Server::class, 'client_authorize_processing' ) ); |
||
795 | add_filter( 'jetpack_client_authorize_fallback_url', array( Jetpack_Client_Server::class, 'client_authorize_fallback_url' ) ); |
||
796 | |||
797 | // Filters for the Manager::get_token() urls and request body. |
||
798 | add_filter( 'jetpack_token_redirect_url', array( __CLASS__, 'filter_connect_redirect_url' ) ); |
||
799 | add_filter( 'jetpack_token_request_body', array( __CLASS__, 'filter_token_request_body' ) ); |
||
800 | |||
801 | // Actions for successful reconnect. |
||
802 | add_action( 'jetpack_reconnection_completed', array( $this, 'reconnection_completed' ) ); |
||
803 | |||
804 | // Actions for licensing. |
||
805 | Licensing::instance()->initialize(); |
||
806 | |||
807 | // Filters for Sync Callables. |
||
808 | add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ), 10, 1 ); |
||
809 | add_filter( 'jetpack_sync_multisite_callable_whitelist', array( $this, 'filter_sync_multisite_callable_whitelist' ), 10, 1 ); |
||
810 | |||
811 | // Make resources use static domain when possible. |
||
812 | add_filter( 'jetpack_static_url', array( 'Automattic\\Jetpack\\Assets', 'staticize_subdomain' ) ); |
||
813 | } |
||
814 | |||
815 | /** |
||
816 | * Before everything else starts getting initalized, we need to initialize Jetpack using the |
||
817 | * Config object. |
||
818 | */ |
||
819 | public function configure() { |
||
820 | $config = new Config(); |
||
821 | |||
822 | foreach ( |
||
823 | array( |
||
824 | 'sync', |
||
825 | 'jitm', |
||
826 | ) |
||
827 | as $feature |
||
828 | ) { |
||
829 | $config->ensure( $feature ); |
||
830 | } |
||
831 | |||
832 | $config->ensure( |
||
833 | 'connection', |
||
834 | array( |
||
835 | 'slug' => 'jetpack', |
||
836 | 'name' => 'Jetpack', |
||
837 | ) |
||
838 | ); |
||
839 | |||
840 | if ( ! $this->connection_manager ) { |
||
841 | $this->connection_manager = new Connection_Manager( 'jetpack' ); |
||
842 | |||
843 | /** |
||
844 | * Filter to activate Jetpack Connection UI. |
||
845 | * INTERNAL USE ONLY. |
||
846 | * |
||
847 | * @since 9.5.0 |
||
848 | * |
||
849 | * @param bool false Whether to activate the Connection UI. |
||
850 | */ |
||
851 | if ( apply_filters( 'jetpack_connection_ui_active', false ) ) { |
||
852 | Automattic\Jetpack\ConnectionUI\Admin::init(); |
||
853 | } |
||
854 | } |
||
855 | |||
856 | /* |
||
857 | * Load things that should only be in Network Admin. |
||
858 | * |
||
859 | * For now blow away everything else until a more full |
||
860 | * understanding of what is needed at the network level is |
||
861 | * available |
||
862 | */ |
||
863 | if ( is_multisite() ) { |
||
864 | $network = Jetpack_Network::init(); |
||
865 | $network->set_connection( $this->connection_manager ); |
||
866 | } |
||
867 | |||
868 | if ( self::is_connection_ready() ) { |
||
869 | add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) ); |
||
870 | |||
871 | Jetpack_Heartbeat::init(); |
||
872 | if ( self::is_module_active( 'stats' ) && self::is_module_active( 'search' ) ) { |
||
873 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php'; |
||
874 | Jetpack_Search_Performance_Logger::init(); |
||
875 | } |
||
876 | } |
||
877 | |||
878 | // Initialize remote file upload request handlers. |
||
879 | $this->add_remote_request_handlers(); |
||
880 | |||
881 | /* |
||
882 | * Enable enhanced handling of previewing sites in Calypso |
||
883 | */ |
||
884 | if ( self::is_connection_ready() ) { |
||
885 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php'; |
||
886 | add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 ); |
||
887 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php'; |
||
888 | add_action( 'init', array( 'Jetpack_Keyring_Service_Helper', 'init' ), 9, 0 ); |
||
889 | } |
||
890 | |||
891 | if ( ( new Tracking( $this->connection_manager ) )->should_enable_tracking( new Terms_Of_Service(), new Status() ) ) { |
||
892 | add_action( 'init', array( new Plugin_Tracking(), 'init' ) ); |
||
893 | } else { |
||
894 | /** |
||
895 | * Initialize tracking right after the user agrees to the terms of service. |
||
896 | */ |
||
897 | add_action( 'jetpack_agreed_to_terms_of_service', array( new Plugin_Tracking(), 'init' ) ); |
||
898 | } |
||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Runs on plugins_loaded. Use this to add code that needs to be executed later than other |
||
903 | * initialization code. |
||
904 | * |
||
905 | * @action plugins_loaded |
||
906 | */ |
||
907 | public function late_initialization() { |
||
924 | |||
925 | /** |
||
926 | * Sets up the XMLRPC request handlers. |
||
927 | * |
||
928 | * @deprecated since 7.7.0 |
||
929 | * @see Automattic\Jetpack\Connection\Manager::setup_xmlrpc_handlers() |
||
930 | * |
||
931 | * @param array $request_params Incoming request parameters. |
||
932 | * @param Boolean $is_active Whether the connection is currently active. |
||
933 | * @param Boolean $is_signed Whether the signature check has been successful. |
||
934 | * @param Jetpack_XMLRPC_Server $xmlrpc_server (optional) An instance of the server to use instead of instantiating a new one. |
||
935 | */ |
||
936 | View Code Duplication | public function setup_xmlrpc_handlers( |
|
955 | |||
956 | /** |
||
957 | * Initialize REST API registration connector. |
||
958 | * |
||
959 | * @deprecated since 7.7.0 |
||
960 | * @see Automattic\Jetpack\Connection\Manager::initialize_rest_api_registration_connector() |
||
961 | */ |
||
962 | View Code Duplication | public function initialize_rest_api_registration_connector() { |
|
971 | |||
972 | /** |
||
973 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
974 | * |
||
975 | * @param $domains |
||
976 | */ |
||
977 | function add_wpcom_to_allowed_redirect_hosts( $domains ) { |
||
980 | |||
981 | /** |
||
982 | * Return $domains, with 'wordpress.com' appended. |
||
983 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
984 | * |
||
985 | * @param $domains |
||
986 | * @return array |
||
987 | */ |
||
988 | function allow_wpcom_domain( $domains ) { |
||
995 | |||
996 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
1025 | |||
1026 | function point_edit_comment_links_to_calypso( $url ) { |
||
1038 | |||
1039 | /** |
||
1040 | * Extend Sync callables with Jetpack Plugin functions. |
||
1041 | * |
||
1042 | * @param array $callables list of callables. |
||
1043 | * |
||
1044 | * @return array list of callables. |
||
1045 | */ |
||
1046 | public function filter_sync_callable_whitelist( $callables ) { |
||
1071 | |||
1072 | /** |
||
1073 | * Extend Sync multisite callables with Jetpack Plugin functions. |
||
1074 | * |
||
1075 | * @param array $callables list of callables. |
||
1076 | * |
||
1077 | * @return array list of callables. |
||
1078 | */ |
||
1079 | public function filter_sync_multisite_callable_whitelist( $callables ) { |
||
1094 | |||
1095 | function jetpack_track_last_sync_callback( $params ) { |
||
1117 | |||
1118 | function jetpack_connection_banner_callback() { |
||
1132 | |||
1133 | /** |
||
1134 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
1135 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
1136 | * ensure that Core and other plugins' methods are not exposed. |
||
1137 | * |
||
1138 | * @deprecated since 7.7.0 |
||
1139 | * @see Automattic\Jetpack\Connection\Manager::remove_non_jetpack_xmlrpc_methods() |
||
1140 | * |
||
1141 | * @param array $methods A list of registered WordPress XMLRPC methods. |
||
1142 | * @return array Filtered $methods |
||
1143 | */ |
||
1144 | View Code Duplication | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
|
1153 | |||
1154 | /** |
||
1155 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
1156 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
1157 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
1158 | * which is accessible via a different URI. Most of the below is copied directly |
||
1159 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
1160 | * |
||
1161 | * @deprecated since 7.7.0 |
||
1162 | * @see Automattic\Jetpack\Connection\Manager::alternate_xmlrpc() |
||
1163 | */ |
||
1164 | View Code Duplication | public function alternate_xmlrpc() { |
|
1173 | |||
1174 | /** |
||
1175 | * The callback for the JITM ajax requests. |
||
1176 | * |
||
1177 | * @deprecated since 7.9.0 |
||
1178 | */ |
||
1179 | function jetpack_jitm_ajax_callback() { |
||
1182 | |||
1183 | /** |
||
1184 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
1185 | */ |
||
1186 | function push_stats() { |
||
1191 | |||
1192 | /** |
||
1193 | * Sets the Jetpack custom capabilities. |
||
1194 | * |
||
1195 | * @param string[] $caps Array of the user's capabilities. |
||
1196 | * @param string $cap Capability name. |
||
1197 | * @param int $user_id The user ID. |
||
1198 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
1199 | */ |
||
1200 | public function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
1235 | |||
1236 | /** |
||
1237 | * Require a Jetpack authentication. |
||
1238 | * |
||
1239 | * @deprecated since 7.7.0 |
||
1240 | * @see Automattic\Jetpack\Connection\Manager::require_jetpack_authentication() |
||
1241 | */ |
||
1242 | View Code Duplication | public function require_jetpack_authentication() { |
|
1251 | |||
1252 | /** |
||
1253 | * Register assets for use in various modules and the Jetpack admin page. |
||
1254 | * |
||
1255 | * @uses wp_script_is, wp_register_script, plugins_url |
||
1256 | * @action wp_loaded |
||
1257 | * @return null |
||
1258 | */ |
||
1259 | public function register_assets() { |
||
1260 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
1261 | wp_register_script( |
||
1262 | 'jetpack-gallery-settings', |
||
1263 | Assets::get_file_url_for_environment( '_inc/build/gallery-settings.min.js', '_inc/gallery-settings.js' ), |
||
1264 | array( 'media-views' ), |
||
1265 | '20121225' |
||
1266 | ); |
||
1267 | } |
||
1268 | |||
1269 | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
||
1270 | wp_register_script( |
||
1271 | 'jetpack-twitter-timeline', |
||
1272 | Assets::get_file_url_for_environment( '_inc/build/twitter-timeline.min.js', '_inc/twitter-timeline.js' ), |
||
1273 | array( 'jquery' ), |
||
1274 | '4.0.0', |
||
1275 | true |
||
1276 | ); |
||
1277 | } |
||
1278 | |||
1279 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
1280 | wp_register_script( |
||
1281 | 'jetpack-facebook-embed', |
||
1282 | Assets::get_file_url_for_environment( '_inc/build/facebook-embed.min.js', '_inc/facebook-embed.js' ), |
||
1283 | array(), |
||
1284 | null, |
||
1285 | true |
||
1286 | ); |
||
1287 | |||
1288 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
1289 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
1290 | if ( ! is_numeric( $fb_app_id ) ) { |
||
1291 | $fb_app_id = ''; |
||
1292 | } |
||
1293 | wp_localize_script( |
||
1294 | 'jetpack-facebook-embed', |
||
1295 | 'jpfbembed', |
||
1296 | array( |
||
1297 | 'appid' => $fb_app_id, |
||
1298 | 'locale' => $this->get_locale(), |
||
1299 | ) |
||
1300 | ); |
||
1301 | } |
||
1302 | |||
1303 | /** |
||
1304 | * As jetpack_register_genericons is by default fired off a hook, |
||
1305 | * the hook may have already fired by this point. |
||
1306 | * So, let's just trigger it manually. |
||
1307 | */ |
||
1308 | require_once JETPACK__PLUGIN_DIR . '_inc/genericons.php'; |
||
1309 | jetpack_register_genericons(); |
||
1310 | |||
1311 | /** |
||
1312 | * Register the social logos |
||
1313 | */ |
||
1314 | require_once JETPACK__PLUGIN_DIR . '_inc/social-logos.php'; |
||
1315 | jetpack_register_social_logos(); |
||
1316 | |||
1317 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) { |
|
1318 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
1319 | } |
||
1320 | } |
||
1321 | |||
1322 | /** |
||
1323 | * Guess locale from language code. |
||
1324 | * |
||
1325 | * @param string $lang Language code. |
||
1326 | * @return string|bool |
||
1327 | */ |
||
1328 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
1367 | |||
1368 | /** |
||
1369 | * Get the locale. |
||
1370 | * |
||
1371 | * @return string|bool |
||
1372 | */ |
||
1373 | function get_locale() { |
||
1382 | |||
1383 | /** |
||
1384 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
1385 | * |
||
1386 | * @param bool $option |
||
1387 | * @return string |
||
1388 | */ |
||
1389 | public function jetpack_main_network_site_option( $option ) { |
||
1392 | /** |
||
1393 | * Network Name. |
||
1394 | */ |
||
1395 | static function network_name( $option = null ) { |
||
1399 | /** |
||
1400 | * Does the network allow new user and site registrations. |
||
1401 | * |
||
1402 | * @return string |
||
1403 | */ |
||
1404 | static function network_allow_new_registrations( $option = null ) { |
||
1407 | /** |
||
1408 | * Does the network allow admins to add new users. |
||
1409 | * |
||
1410 | * @return boolian |
||
1411 | */ |
||
1412 | static function network_add_new_users( $option = null ) { |
||
1415 | /** |
||
1416 | * File upload psace left per site in MB. |
||
1417 | * -1 means NO LIMIT. |
||
1418 | * |
||
1419 | * @return number |
||
1420 | */ |
||
1421 | static function network_site_upload_space( $option = null ) { |
||
1425 | |||
1426 | /** |
||
1427 | * Network allowed file types. |
||
1428 | * |
||
1429 | * @return string |
||
1430 | */ |
||
1431 | static function network_upload_file_types( $option = null ) { |
||
1434 | |||
1435 | /** |
||
1436 | * Maximum file upload size set by the network. |
||
1437 | * |
||
1438 | * @return number |
||
1439 | */ |
||
1440 | static function network_max_upload_file_size( $option = null ) { |
||
1444 | |||
1445 | /** |
||
1446 | * Lets us know if a site allows admins to manage the network. |
||
1447 | * |
||
1448 | * @return array |
||
1449 | */ |
||
1450 | static function network_enable_administration_menus( $option = null ) { |
||
1453 | |||
1454 | /** |
||
1455 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
1456 | * jetpack_other_linked_admins transient. |
||
1457 | * |
||
1458 | * @since 4.3.2 |
||
1459 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
1460 | * |
||
1461 | * @param int $user_id The user ID whose role changed. |
||
1462 | * @param string $role The new role. |
||
1463 | * @param array $old_roles An array of the user's previous roles. |
||
1464 | */ |
||
1465 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
1473 | |||
1474 | /** |
||
1475 | * Checks to see if there are any other users available to become primary |
||
1476 | * Users must both: |
||
1477 | * - Be linked to wpcom |
||
1478 | * - Be an admin |
||
1479 | * |
||
1480 | * @return mixed False if no other users are linked, Int if there are. |
||
1481 | */ |
||
1482 | static function get_other_linked_admins() { |
||
1510 | |||
1511 | /** |
||
1512 | * Return whether we are dealing with a multi network setup or not. |
||
1513 | * The reason we are type casting this is because we want to avoid the situation where |
||
1514 | * the result is false since when is_main_network_option return false it cases |
||
1515 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
1516 | * database which could be set to anything as opposed to what this function returns. |
||
1517 | * |
||
1518 | * @param bool $option |
||
1519 | * |
||
1520 | * @return boolean |
||
1521 | */ |
||
1522 | public function is_main_network_option( $option ) { |
||
1526 | |||
1527 | /** |
||
1528 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
1529 | * |
||
1530 | * @param string $option |
||
1531 | * @return boolean |
||
1532 | */ |
||
1533 | public function is_multisite( $option ) { |
||
1536 | |||
1537 | /** |
||
1538 | * Implemented since there is no core is multi network function |
||
1539 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
1540 | * |
||
1541 | * @since 3.3 |
||
1542 | * @return boolean |
||
1543 | */ |
||
1544 | View Code Duplication | public static function is_multi_network() { |
|
1559 | |||
1560 | /** |
||
1561 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1562 | * |
||
1563 | * @return null |
||
1564 | */ |
||
1565 | function update_jetpack_main_network_site_option() { |
||
1568 | /** |
||
1569 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1570 | */ |
||
1571 | function update_jetpack_network_settings() { |
||
1575 | |||
1576 | /** |
||
1577 | * Get back if the current site is single user site. |
||
1578 | * |
||
1579 | * @return bool |
||
1580 | */ |
||
1581 | View Code Duplication | public static function is_single_user_site() { |
|
1590 | |||
1591 | /** |
||
1592 | * Returns true if the site has file write access false otherwise. |
||
1593 | * |
||
1594 | * @return string ( '1' | '0' ) |
||
1595 | **/ |
||
1596 | public static function file_system_write_access() { |
||
1616 | |||
1617 | /** |
||
1618 | * Finds out if a site is using a version control system. |
||
1619 | * |
||
1620 | * @return string ( '1' | '0' ) |
||
1621 | **/ |
||
1622 | public static function is_version_controlled() { |
||
1626 | |||
1627 | /** |
||
1628 | * Determines whether the current theme supports featured images or not. |
||
1629 | * |
||
1630 | * @return string ( '1' | '0' ) |
||
1631 | */ |
||
1632 | public static function featured_images_enabled() { |
||
1636 | |||
1637 | /** |
||
1638 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
1639 | * |
||
1640 | * @deprecated 4.7 use get_avatar_url instead. |
||
1641 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
1642 | * @param int $size Size of the avatar image |
||
1643 | * @param string $default URL to a default image to use if no avatar is available |
||
1644 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
1645 | * |
||
1646 | * @return array |
||
1647 | */ |
||
1648 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
1659 | // phpcs:disable WordPress.WP.CapitalPDangit.Misspelled |
||
1660 | /** |
||
1661 | * jetpack_updates is saved in the following schema: |
||
1662 | * |
||
1663 | * array ( |
||
1664 | * 'plugins' => (int) Number of plugin updates available. |
||
1665 | * 'themes' => (int) Number of theme updates available. |
||
1666 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1667 | * 'translations' => (int) Number of translation updates available. |
||
1668 | * 'total' => (int) Total of all available updates. |
||
1669 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1670 | * ) |
||
1671 | * |
||
1672 | * @return array |
||
1673 | */ |
||
1674 | public static function get_updates() { |
||
1691 | // phpcs:enable |
||
1692 | |||
1693 | public static function get_update_details() { |
||
1701 | |||
1702 | public static function refresh_update_data() { |
||
1706 | |||
1707 | public static function refresh_theme_data() { |
||
1710 | |||
1711 | /** |
||
1712 | * Is Jetpack active? |
||
1713 | * The method only checks if there's an existing token for the master user. It doesn't validate the token. |
||
1714 | * |
||
1715 | * This method is deprecated since 9.6.0. Please use one of the methods provided by the Manager class in the Connection package, |
||
1716 | * or Jetpack::is_connection_ready if you want to know when the Jetpack plugin starts considering the connection ready to be used. |
||
1717 | * |
||
1718 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
1719 | * |
||
1720 | * @deprecated 9.6.0 |
||
1721 | * |
||
1722 | * @return bool |
||
1723 | */ |
||
1724 | public static function is_active() { |
||
1727 | |||
1728 | /** |
||
1729 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI |
||
1730 | * |
||
1731 | * This method was introduced just before the release of the possibility to use Jetpack without a user connection, while |
||
1732 | * it was available only when no_user_testing_mode was enabled. In the near future, this will return is_connected for all |
||
1733 | * users and this option will be available by default for everybody. |
||
1734 | * |
||
1735 | * @since 9.6.0 |
||
1736 | * |
||
1737 | * @return bool is the site connection ready to be used? |
||
1738 | */ |
||
1739 | public static function is_connection_ready() { |
||
1745 | |||
1746 | /** |
||
1747 | * Make an API call to WordPress.com for plan status |
||
1748 | * |
||
1749 | * @deprecated 7.2.0 Use Jetpack_Plan::refresh_from_wpcom. |
||
1750 | * |
||
1751 | * @return bool True if plan is updated, false if no update |
||
1752 | */ |
||
1753 | public static function refresh_active_plan_from_wpcom() { |
||
1757 | |||
1758 | /** |
||
1759 | * Get the plan that this Jetpack site is currently using |
||
1760 | * |
||
1761 | * @deprecated 7.2.0 Use Jetpack_Plan::get. |
||
1762 | * @return array Active Jetpack plan details. |
||
1763 | */ |
||
1764 | public static function get_active_plan() { |
||
1768 | |||
1769 | /** |
||
1770 | * Determine whether the active plan supports a particular feature |
||
1771 | * |
||
1772 | * @deprecated 7.2.0 Use Jetpack_Plan::supports. |
||
1773 | * @return bool True if plan supports feature, false if not. |
||
1774 | */ |
||
1775 | public static function active_plan_supports( $feature ) { |
||
1779 | |||
1780 | /** |
||
1781 | * Deprecated: Is Jetpack in development (offline) mode? |
||
1782 | * |
||
1783 | * This static method is being left here intentionally without the use of _deprecated_function(), as other plugins |
||
1784 | * and themes still use it, and we do not want to flood them with notices. |
||
1785 | * |
||
1786 | * Please use Automattic\Jetpack\Status()->is_offline_mode() instead. |
||
1787 | * |
||
1788 | * @deprecated since 8.0. |
||
1789 | */ |
||
1790 | public static function is_development_mode() { |
||
1794 | |||
1795 | /** |
||
1796 | * Whether the site is currently onboarding or not. |
||
1797 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
1798 | * |
||
1799 | * @since 5.8 |
||
1800 | * |
||
1801 | * @access public |
||
1802 | * @static |
||
1803 | * |
||
1804 | * @return bool True if the site is currently onboarding, false otherwise |
||
1805 | */ |
||
1806 | public static function is_onboarding() { |
||
1809 | |||
1810 | /** |
||
1811 | * Determines reason for Jetpack offline mode. |
||
1812 | */ |
||
1813 | public static function development_mode_trigger_text() { |
||
1836 | /** |
||
1837 | * Get Jetpack offline mode notice text and notice class. |
||
1838 | * |
||
1839 | * Mirrors the checks made in Automattic\Jetpack\Status->is_offline_mode |
||
1840 | */ |
||
1841 | public static function show_development_mode_notice() { |
||
1869 | |||
1870 | /** |
||
1871 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1872 | */ |
||
1873 | public static function is_development_version() { |
||
1888 | |||
1889 | /** |
||
1890 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1891 | */ |
||
1892 | public static function is_user_connected( $user_id = false ) { |
||
1896 | |||
1897 | /** |
||
1898 | * Get the wpcom user data of the current|specified connected user. |
||
1899 | */ |
||
1900 | public static function get_connected_user_data( $user_id = null ) { |
||
1904 | |||
1905 | /** |
||
1906 | * Get the wpcom email of the current|specified connected user. |
||
1907 | */ |
||
1908 | public static function get_connected_user_email( $user_id = null ) { |
||
1924 | |||
1925 | /** |
||
1926 | * Get the wpcom email of the master user. |
||
1927 | */ |
||
1928 | public static function get_master_user_email() { |
||
1935 | |||
1936 | /** |
||
1937 | * Whether the current user is the connection owner. |
||
1938 | * |
||
1939 | * @deprecated since 7.7 |
||
1940 | * |
||
1941 | * @return bool Whether the current user is the connection owner. |
||
1942 | */ |
||
1943 | public function current_user_is_connection_owner() { |
||
1947 | |||
1948 | /** |
||
1949 | * Gets current user IP address. |
||
1950 | * |
||
1951 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
1952 | * |
||
1953 | * @return string Current user IP address. |
||
1954 | */ |
||
1955 | public static function current_user_ip( $check_all_headers = false ) { |
||
1975 | |||
1976 | /** |
||
1977 | * Synchronize connected user role changes |
||
1978 | */ |
||
1979 | function user_role_change( $user_id ) { |
||
1983 | |||
1984 | /** |
||
1985 | * Loads the currently active modules. |
||
1986 | */ |
||
1987 | public static function load_modules() { |
||
2075 | |||
2076 | /** |
||
2077 | * Check if Jetpack's REST API compat file should be included |
||
2078 | * |
||
2079 | * @action plugins_loaded |
||
2080 | * @return null |
||
2081 | */ |
||
2082 | public function check_rest_api_compat() { |
||
2096 | |||
2097 | /** |
||
2098 | * Gets all plugins currently active in values, regardless of whether they're |
||
2099 | * traditionally activated or network activated. |
||
2100 | * |
||
2101 | * @todo Store the result in core's object cache maybe? |
||
2102 | */ |
||
2103 | public static function get_active_plugins() { |
||
2119 | |||
2120 | /** |
||
2121 | * Gets and parses additional plugin data to send with the heartbeat data |
||
2122 | * |
||
2123 | * @since 3.8.1 |
||
2124 | * |
||
2125 | * @return array Array of plugin data |
||
2126 | */ |
||
2127 | public static function get_parsed_plugin_data() { |
||
2148 | |||
2149 | /** |
||
2150 | * Gets and parses theme data to send with the heartbeat data |
||
2151 | * |
||
2152 | * @since 3.8.1 |
||
2153 | * |
||
2154 | * @return array Array of theme data |
||
2155 | */ |
||
2156 | public static function get_parsed_theme_data() { |
||
2178 | |||
2179 | /** |
||
2180 | * Checks whether a specific plugin is active. |
||
2181 | * |
||
2182 | * We don't want to store these in a static variable, in case |
||
2183 | * there are switch_to_blog() calls involved. |
||
2184 | */ |
||
2185 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
2188 | |||
2189 | /** |
||
2190 | * Check if Jetpack's Open Graph tags should be used. |
||
2191 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
2192 | * |
||
2193 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2194 | * @action plugins_loaded |
||
2195 | * @return null |
||
2196 | */ |
||
2197 | public function check_open_graph() { |
||
2224 | |||
2225 | /** |
||
2226 | * Check if Jetpack's Twitter tags should be used. |
||
2227 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
2228 | * |
||
2229 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2230 | * @action plugins_loaded |
||
2231 | * @return null |
||
2232 | */ |
||
2233 | public function check_twitter_tags() { |
||
2257 | |||
2258 | /** |
||
2259 | * Allows plugins to submit security reports. |
||
2260 | * |
||
2261 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
2262 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
2263 | * @param array $args See definitions above |
||
2264 | */ |
||
2265 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
2268 | |||
2269 | /* Jetpack Options API */ |
||
2270 | |||
2271 | public static function get_option_names( $type = 'compact' ) { |
||
2274 | |||
2275 | /** |
||
2276 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
2277 | * |
||
2278 | * @param string $name Option name |
||
2279 | * @param mixed $default (optional) |
||
2280 | */ |
||
2281 | public static function get_option( $name, $default = false ) { |
||
2284 | |||
2285 | /** |
||
2286 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
2287 | * |
||
2288 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
2289 | * @param string $name Option name |
||
2290 | * @param mixed $value Option value |
||
2291 | */ |
||
2292 | public static function update_option( $name, $value ) { |
||
2296 | |||
2297 | /** |
||
2298 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
2299 | * |
||
2300 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
2301 | * @param array $array array( option name => option value, ... ) |
||
2302 | */ |
||
2303 | public static function update_options( $array ) { |
||
2307 | |||
2308 | /** |
||
2309 | * Deletes the given option. May be passed multiple option names as an array. |
||
2310 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
2311 | * |
||
2312 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
2313 | * @param string|array $names |
||
2314 | */ |
||
2315 | public static function delete_option( $names ) { |
||
2319 | |||
2320 | /** |
||
2321 | * Enters a user token into the user_tokens option |
||
2322 | * |
||
2323 | * @deprecated 8.0 Use Automattic\Jetpack\Connection\Tokens->update_user_token() instead. |
||
2324 | * |
||
2325 | * @param int $user_id The user id. |
||
2326 | * @param string $token The user token. |
||
2327 | * @param bool $is_master_user Whether the user is the master user. |
||
2328 | * @return bool |
||
2329 | */ |
||
2330 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
2334 | |||
2335 | /** |
||
2336 | * Returns an array of all PHP files in the specified absolute path. |
||
2337 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
2338 | * |
||
2339 | * @param string $absolute_path The absolute path of the directory to search. |
||
2340 | * @return array Array of absolute paths to the PHP files. |
||
2341 | */ |
||
2342 | public static function glob_php( $absolute_path ) { |
||
2371 | |||
2372 | public static function activate_new_modules( $redirect = false ) { |
||
2431 | |||
2432 | /** |
||
2433 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
2434 | * Make sure to tuck away module "library" files in a sub-directory. |
||
2435 | * |
||
2436 | * @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter. |
||
2437 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
2438 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
2439 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
2440 | * |
||
2441 | * @return array $modules Array of module slugs |
||
2442 | */ |
||
2443 | public static function get_available_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
2515 | |||
2516 | /** |
||
2517 | * Get default modules loaded on activation. |
||
2518 | * |
||
2519 | * @param bool|string $min_version Onlu return modules introduced in this version or later. Default is false, do not filter. |
||
2520 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
2521 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
2522 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
2523 | * |
||
2524 | * @return array $modules Array of module slugs |
||
2525 | */ |
||
2526 | public static function get_default_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
2559 | |||
2560 | /** |
||
2561 | * Checks activated modules during auto-activation to determine |
||
2562 | * if any of those modules are being deprecated. If so, close |
||
2563 | * them out, and add any replacement modules. |
||
2564 | * |
||
2565 | * Runs at priority 99 by default. |
||
2566 | * |
||
2567 | * This is run late, so that it can still activate a module if |
||
2568 | * the new module is a replacement for another that the user |
||
2569 | * currently has active, even if something at the normal priority |
||
2570 | * would kibosh everything. |
||
2571 | * |
||
2572 | * @since 2.6 |
||
2573 | * @uses jetpack_get_default_modules filter |
||
2574 | * @param array $modules |
||
2575 | * @return array |
||
2576 | */ |
||
2577 | function handle_deprecated_modules( $modules ) { |
||
2604 | |||
2605 | /** |
||
2606 | * Checks activated plugins during auto-activation to determine |
||
2607 | * if any of those plugins are in the list with a corresponding module |
||
2608 | * that is not compatible with the plugin. The module will not be allowed |
||
2609 | * to auto-activate. |
||
2610 | * |
||
2611 | * @since 2.6 |
||
2612 | * @uses jetpack_get_default_modules filter |
||
2613 | * @param array $modules |
||
2614 | * @return array |
||
2615 | */ |
||
2616 | function filter_default_modules( $modules ) { |
||
2640 | |||
2641 | /** |
||
2642 | * Extract a module's slug from its full path. |
||
2643 | */ |
||
2644 | public static function get_module_slug( $file ) { |
||
2647 | |||
2648 | /** |
||
2649 | * Generate a module's path from its slug. |
||
2650 | */ |
||
2651 | public static function get_module_path( $slug ) { |
||
2662 | |||
2663 | /** |
||
2664 | * Load module data from module file. Headers differ from WordPress |
||
2665 | * plugin headers to avoid them being identified as standalone |
||
2666 | * plugins on the WordPress plugins page. |
||
2667 | */ |
||
2668 | public static function get_module( $module ) { |
||
2768 | |||
2769 | /** |
||
2770 | * Like core's get_file_data implementation, but caches the result. |
||
2771 | */ |
||
2772 | public static function get_file_data( $file, $headers ) { |
||
2805 | |||
2806 | /** |
||
2807 | * Return translated module tag. |
||
2808 | * |
||
2809 | * @param string $tag Tag as it appears in each module heading. |
||
2810 | * |
||
2811 | * @return mixed |
||
2812 | */ |
||
2813 | public static function translate_module_tag( $tag ) { |
||
2816 | |||
2817 | /** |
||
2818 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2819 | * |
||
2820 | * @since 3.9.2 |
||
2821 | * |
||
2822 | * @param array $modules |
||
2823 | * |
||
2824 | * @return string|void |
||
2825 | */ |
||
2826 | public static function get_translated_modules( $modules ) { |
||
2839 | |||
2840 | /** |
||
2841 | * Get a list of activated modules as an array of module slugs. |
||
2842 | */ |
||
2843 | public static function get_active_modules() { |
||
2875 | |||
2876 | /** |
||
2877 | * Check whether or not a Jetpack module is active. |
||
2878 | * |
||
2879 | * @param string $module The slug of a Jetpack module. |
||
2880 | * @return bool |
||
2881 | * |
||
2882 | * @static |
||
2883 | */ |
||
2884 | public static function is_module_active( $module ) { |
||
2887 | |||
2888 | public static function is_module( $module ) { |
||
2891 | |||
2892 | /** |
||
2893 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2894 | * |
||
2895 | * @param bool $catch True to start catching, False to stop. |
||
2896 | * |
||
2897 | * @static |
||
2898 | */ |
||
2899 | public static function catch_errors( $catch ) { |
||
2912 | |||
2913 | /** |
||
2914 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2915 | */ |
||
2916 | public static function catch_errors_on_shutdown() { |
||
2919 | |||
2920 | /** |
||
2921 | * Rewrite any string to make paths easier to read. |
||
2922 | * |
||
2923 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
2924 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
2925 | * |
||
2926 | * @param $string |
||
2927 | * @return mixed |
||
2928 | */ |
||
2929 | public static function alias_directories( $string ) { |
||
2937 | |||
2938 | public static function activate_default_modules( |
||
3110 | |||
3111 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
3204 | |||
3205 | function activate_module_actions( $module ) { |
||
3208 | |||
3209 | public static function deactivate_module( $module ) { |
||
3226 | |||
3227 | public static function enable_module_configurable( $module ) { |
||
3231 | |||
3232 | /** |
||
3233 | * Composes a module configure URL. It uses Jetpack settings search as default value |
||
3234 | * It is possible to redefine resulting URL by using "jetpack_module_configuration_url_$module" filter |
||
3235 | * |
||
3236 | * @param string $module Module slug |
||
3237 | * @return string $url module configuration URL |
||
3238 | */ |
||
3239 | public static function module_configuration_url( $module ) { |
||
3253 | |||
3254 | /* Installation */ |
||
3255 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
3295 | |||
3296 | /** |
||
3297 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
3298 | * |
||
3299 | * @static |
||
3300 | */ |
||
3301 | public static function plugin_activation( $network_wide ) { |
||
3321 | |||
3322 | public static function get_activation_source( $referer_url ) { |
||
3371 | |||
3372 | /** |
||
3373 | * Runs before bumping version numbers up to a new version |
||
3374 | * |
||
3375 | * @param string $version Version:timestamp. |
||
3376 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
3377 | */ |
||
3378 | public static function do_version_bump( $version, $old_version ) { |
||
3388 | |||
3389 | /** |
||
3390 | * Sets the display_update_modal state. |
||
3391 | */ |
||
3392 | public static function set_update_modal_display() { |
||
3395 | |||
3396 | /** |
||
3397 | * Sets the internal version number and activation state. |
||
3398 | * |
||
3399 | * @static |
||
3400 | */ |
||
3401 | public static function plugin_initialize() { |
||
3418 | |||
3419 | /** |
||
3420 | * Removes all connection options |
||
3421 | * |
||
3422 | * @static |
||
3423 | */ |
||
3424 | public static function plugin_deactivation() { |
||
3435 | |||
3436 | /** |
||
3437 | * Disconnects from the Jetpack servers. |
||
3438 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
3439 | * |
||
3440 | * @static |
||
3441 | */ |
||
3442 | public static function disconnect( $update_activated_state = true ) { |
||
3488 | |||
3489 | /** |
||
3490 | * Disconnects the user |
||
3491 | * |
||
3492 | * @param int $user_id The user ID to disconnect. |
||
3493 | */ |
||
3494 | public function disconnect_user( $user_id ) { |
||
3497 | |||
3498 | /** |
||
3499 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
3500 | */ |
||
3501 | public static function try_registration() { |
||
3532 | |||
3533 | /** |
||
3534 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
3535 | * |
||
3536 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
3537 | */ |
||
3538 | public static function log( $code, $data = null ) { |
||
3578 | |||
3579 | /** |
||
3580 | * Get the internal event log. |
||
3581 | * |
||
3582 | * @param $event (string) - only return the specific log events |
||
3583 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
3584 | * |
||
3585 | * @return array of log events || WP_Error for invalid params |
||
3586 | */ |
||
3587 | public static function get_log( $event = false, $num = false ) { |
||
3623 | |||
3624 | /** |
||
3625 | * Log modification of important settings. |
||
3626 | */ |
||
3627 | public static function log_settings_change( $option, $old_value, $value ) { |
||
3634 | |||
3635 | /** |
||
3636 | * Return stat data for WPCOM sync |
||
3637 | */ |
||
3638 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
3652 | |||
3653 | /** |
||
3654 | * Get additional stat data to sync to WPCOM |
||
3655 | */ |
||
3656 | public static function get_additional_stat_data( $prefix = '' ) { |
||
3667 | |||
3668 | private static function get_site_user_count() { |
||
3683 | |||
3684 | /* Admin Pages */ |
||
3685 | |||
3686 | function admin_init() { |
||
3730 | |||
3731 | function admin_body_class( $admin_body_class = '' ) { |
||
3739 | |||
3740 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
3743 | |||
3744 | /** |
||
3745 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
3746 | * This function artificially throws errors for such cases (per a specific list). |
||
3747 | * |
||
3748 | * @param string $plugin The activated plugin. |
||
3749 | */ |
||
3750 | function throw_error_on_activate_plugin( $plugin ) { |
||
3774 | |||
3775 | function intercept_plugin_error_scrape_init() { |
||
3778 | |||
3779 | function intercept_plugin_error_scrape( $action, $result ) { |
||
3790 | |||
3791 | /** |
||
3792 | * Register the remote file upload request handlers, if needed. |
||
3793 | * |
||
3794 | * @access public |
||
3795 | */ |
||
3796 | public function add_remote_request_handlers() { |
||
3825 | |||
3826 | /** |
||
3827 | * Handler for Jetpack remote file uploads. |
||
3828 | * |
||
3829 | * @access public |
||
3830 | */ |
||
3831 | public function remote_request_handlers() { |
||
3871 | |||
3872 | /** |
||
3873 | * Uploads a file gotten from the global $_FILES. |
||
3874 | * If `$update_media_item` is true and `post_id` is defined |
||
3875 | * the attachment file of the media item (gotten through of the post_id) |
||
3876 | * will be updated instead of add a new one. |
||
3877 | * |
||
3878 | * @param boolean $update_media_item - update media attachment |
||
3879 | * @return array - An array describing the uploadind files process |
||
3880 | */ |
||
3881 | function upload_handler( $update_media_item = false ) { |
||
4012 | |||
4013 | /** |
||
4014 | * Add help to the Jetpack page |
||
4015 | * |
||
4016 | * @since Jetpack (1.2.3) |
||
4017 | * @return false if not the Jetpack page |
||
4018 | */ |
||
4019 | function admin_help() { |
||
4062 | |||
4063 | function admin_menu_css() { |
||
4066 | |||
4067 | function admin_menu_order() { |
||
4070 | |||
4071 | function jetpack_menu_order( $menu_order ) { |
||
4086 | |||
4087 | function admin_banner_styles() { |
||
4108 | |||
4109 | function plugin_action_links( $actions ) { |
||
4124 | |||
4125 | /** |
||
4126 | * Adds the deactivation warning modal if there are other active plugins using the connection |
||
4127 | * |
||
4128 | * @param string $hook The current admin page. |
||
4129 | * |
||
4130 | * @return void |
||
4131 | */ |
||
4132 | public function deactivate_dialog( $hook ) { |
||
4187 | |||
4188 | /** |
||
4189 | * Outputs the content of the deactivation modal |
||
4190 | * |
||
4191 | * @return void |
||
4192 | */ |
||
4193 | public function deactivate_dialog_content() { |
||
4198 | |||
4199 | /** |
||
4200 | * Filters the login URL to include the registration flow in case the user isn't logged in. |
||
4201 | * |
||
4202 | * @param string $login_url The wp-login URL. |
||
4203 | * @param string $redirect URL to redirect users after logging in. |
||
4204 | * @since Jetpack 8.4 |
||
4205 | * @return string |
||
4206 | */ |
||
4207 | public function login_url( $login_url, $redirect ) { |
||
4214 | |||
4215 | /** |
||
4216 | * Redirects non-authenticated users to authenticate with Calypso if redirect flag is set. |
||
4217 | * |
||
4218 | * @since Jetpack 8.4 |
||
4219 | */ |
||
4220 | public function login_init() { |
||
4237 | |||
4238 | /* |
||
4239 | * Registration flow: |
||
4240 | * 1 - ::admin_page_load() action=register |
||
4241 | * 2 - ::try_registration() |
||
4242 | * 3 - ::register() |
||
4243 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
4244 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
4245 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
4246 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
4247 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
4248 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
4249 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
4250 | * jetpack_id, jetpack_secret, jetpack_public |
||
4251 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
4252 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
4253 | * 5 - user logs in with WP.com account |
||
4254 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
4255 | * - Manager::authorize() |
||
4256 | * - Manager::get_token() |
||
4257 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
4258 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
4259 | * - which responds with access_token, token_type, scope |
||
4260 | * - Manager::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
4261 | * - Jetpack::activate_default_modules() |
||
4262 | * - Deactivates deprecated plugins |
||
4263 | * - Activates all default modules |
||
4264 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
4265 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
4266 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
4267 | * Done! |
||
4268 | */ |
||
4269 | |||
4270 | /** |
||
4271 | * Handles the page load events for the Jetpack admin page |
||
4272 | */ |
||
4273 | function admin_page_load() { |
||
4589 | |||
4590 | function admin_notices() { |
||
4715 | |||
4716 | /** |
||
4717 | * We can't always respond to a signed XML-RPC request with a |
||
4718 | * helpful error message. In some circumstances, doing so could |
||
4719 | * leak information. |
||
4720 | * |
||
4721 | * Instead, track that the error occurred via a Jetpack_Option, |
||
4722 | * and send that data back in the heartbeat. |
||
4723 | * All this does is increment a number, but it's enough to find |
||
4724 | * trends. |
||
4725 | * |
||
4726 | * @param WP_Error $xmlrpc_error The error produced during |
||
4727 | * signature validation. |
||
4728 | */ |
||
4729 | function track_xmlrpc_error( $xmlrpc_error ) { |
||
4744 | |||
4745 | /** |
||
4746 | * Initialize the jetpack stats instance only when needed |
||
4747 | * |
||
4748 | * @return void |
||
4749 | */ |
||
4750 | private function initialize_stats() { |
||
4755 | |||
4756 | /** |
||
4757 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
4758 | */ |
||
4759 | function stat( $group, $detail ) { |
||
4766 | |||
4767 | /** |
||
4768 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
4769 | */ |
||
4770 | function do_stats( $method = '' ) { |
||
4781 | |||
4782 | /** |
||
4783 | * Runs stats code for a one-off, server-side. |
||
4784 | * |
||
4785 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
4786 | * |
||
4787 | * @return bool If it worked. |
||
4788 | */ |
||
4789 | static function do_server_side_stat( $args ) { |
||
4794 | |||
4795 | /** |
||
4796 | * Builds the stats url. |
||
4797 | * |
||
4798 | * @param $args array|string The arguments to append to the URL. |
||
4799 | * |
||
4800 | * @return string The URL to be pinged. |
||
4801 | */ |
||
4802 | static function build_stats_url( $args ) { |
||
4808 | |||
4809 | /** |
||
4810 | * Builds a URL to the Jetpack connection auth page |
||
4811 | * |
||
4812 | * @since 3.9.5 |
||
4813 | * |
||
4814 | * @param bool $raw If true, URL will not be escaped. |
||
4815 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
4816 | * If string, will be a custom redirect. |
||
4817 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
4818 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
4819 | * |
||
4820 | * @return string Connect URL |
||
4821 | */ |
||
4822 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
4884 | |||
4885 | public static function build_authorize_url( $redirect = false, $iframe = false ) { |
||
4913 | |||
4914 | /** |
||
4915 | * Filters the connection URL parameter array. |
||
4916 | * |
||
4917 | * @param array $args default URL parameters used by the package. |
||
4918 | * @return array the modified URL arguments array. |
||
4919 | */ |
||
4920 | public static function filter_connect_request_body( $args ) { |
||
4950 | |||
4951 | /** |
||
4952 | * Filters the URL that will process the connection data. It can be different from the URL |
||
4953 | * that we send the user to after everything is done. |
||
4954 | * |
||
4955 | * @param String $processing_url the default redirect URL used by the package. |
||
4956 | * @return String the modified URL. |
||
4957 | * |
||
4958 | * @deprecated since Jetpack 9.5.0 |
||
4959 | */ |
||
4960 | public static function filter_connect_processing_url( $processing_url ) { |
||
4966 | |||
4967 | /** |
||
4968 | * Filters the redirection URL that is used for connect requests. The redirect |
||
4969 | * URL should return the user back to the Jetpack console. |
||
4970 | * |
||
4971 | * @param String $redirect the default redirect URL used by the package. |
||
4972 | * @return String the modified URL. |
||
4973 | */ |
||
4974 | public static function filter_connect_redirect_url( $redirect ) { |
||
4986 | |||
4987 | /** |
||
4988 | * This action fires at the beginning of the Manager::authorize method. |
||
4989 | */ |
||
4990 | public static function authorize_starting() { |
||
5014 | |||
5015 | /** |
||
5016 | * This action fires at the end of the Manager::authorize method when a secondary user is |
||
5017 | * linked. |
||
5018 | */ |
||
5019 | public static function authorize_ending_linked() { |
||
5023 | |||
5024 | /** |
||
5025 | * This action fires at the end of the Manager::authorize method when the master user is |
||
5026 | * authorized. |
||
5027 | * |
||
5028 | * @param array $data The request data. |
||
5029 | */ |
||
5030 | public static function authorize_ending_authorized( $data ) { |
||
5050 | |||
5051 | /** |
||
5052 | * Fires on the jetpack_site_registered hook and acitvates default modules |
||
5053 | */ |
||
5054 | public static function activate_default_modules_on_site_register() { |
||
5069 | |||
5070 | /** |
||
5071 | * This action fires at the end of the REST_Connector connection_reconnect method when the |
||
5072 | * reconnect process is completed. |
||
5073 | * Note that this currently only happens when we don't need the user to re-authorize |
||
5074 | * their WP.com account, eg in cases where we are restoring a connection with |
||
5075 | * unhealthy blog token. |
||
5076 | */ |
||
5077 | public static function reconnection_completed() { |
||
5080 | |||
5081 | /** |
||
5082 | * Get our assumed site creation date. |
||
5083 | * Calculated based on the earlier date of either: |
||
5084 | * - Earliest admin user registration date. |
||
5085 | * - Earliest date of post of any post type. |
||
5086 | * |
||
5087 | * @since 7.2.0 |
||
5088 | * @deprecated since 7.8.0 |
||
5089 | * |
||
5090 | * @return string Assumed site creation date and time. |
||
5091 | */ |
||
5092 | public static function get_assumed_site_creation_date() { |
||
5096 | |||
5097 | View Code Duplication | public static function apply_activation_source_to_args( &$args ) { |
|
5108 | |||
5109 | function build_reconnect_url( $raw = false ) { |
||
5113 | |||
5114 | public static function admin_url( $args = null ) { |
||
5119 | |||
5120 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
5124 | |||
5125 | function dismiss_jetpack_notice() { |
||
5142 | |||
5143 | public static function sort_modules( $a, $b ) { |
||
5150 | |||
5151 | function ajax_recheck_ssl() { |
||
5161 | |||
5162 | /* Client API */ |
||
5163 | |||
5164 | /** |
||
5165 | * Returns the requested Jetpack API URL |
||
5166 | * |
||
5167 | * @deprecated since 7.7 |
||
5168 | * @return string |
||
5169 | */ |
||
5170 | public static function api_url( $relative_url ) { |
||
5175 | |||
5176 | /** |
||
5177 | * @deprecated 8.0 |
||
5178 | * |
||
5179 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. |
||
5180 | * But we no longer fix "bad hosts" anyway, outbound HTTPS is required for Jetpack to function. |
||
5181 | */ |
||
5182 | public static function fix_url_for_bad_hosts( $url ) { |
||
5186 | |||
5187 | public static function verify_onboarding_token( $token_data, $token, $request_data ) { |
||
5232 | |||
5233 | /** |
||
5234 | * Create a random secret for validating onboarding payload |
||
5235 | * |
||
5236 | * @return string Secret token |
||
5237 | */ |
||
5238 | public static function create_onboarding_token() { |
||
5246 | |||
5247 | /** |
||
5248 | * Remove the onboarding token |
||
5249 | * |
||
5250 | * @return bool True on success, false on failure |
||
5251 | */ |
||
5252 | public static function invalidate_onboarding_token() { |
||
5255 | |||
5256 | /** |
||
5257 | * Validate an onboarding token for a specific action |
||
5258 | * |
||
5259 | * @return boolean True if token/action pair is accepted, false if not |
||
5260 | */ |
||
5261 | public static function validate_onboarding_token_action( $token, $action ) { |
||
5279 | |||
5280 | /** |
||
5281 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
5282 | * |
||
5283 | * @since 2.3.3 |
||
5284 | * @return boolean |
||
5285 | */ |
||
5286 | public static function permit_ssl( $force_recheck = false ) { |
||
5315 | |||
5316 | /* |
||
5317 | * Displays an admin_notice, alerting the user that outbound SSL isn't working. |
||
5318 | */ |
||
5319 | public function alert_auto_ssl_fail() { |
||
5373 | |||
5374 | /** |
||
5375 | * Returns the Jetpack XML-RPC API |
||
5376 | * |
||
5377 | * @deprecated 8.0 Use Connection_Manager instead. |
||
5378 | * @return string |
||
5379 | */ |
||
5380 | public static function xmlrpc_api_url() { |
||
5384 | |||
5385 | /** |
||
5386 | * Returns the connection manager object. |
||
5387 | * |
||
5388 | * @return Automattic\Jetpack\Connection\Manager |
||
5389 | */ |
||
5390 | public static function connection() { |
||
5400 | |||
5401 | /** |
||
5402 | * Creates two secret tokens and the end of life timestamp for them. |
||
5403 | * |
||
5404 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
5405 | * |
||
5406 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->generate() instead. |
||
5407 | * |
||
5408 | * @since 2.6 |
||
5409 | * @param String $action The action name. |
||
5410 | * @param Integer $user_id The user identifier. |
||
5411 | * @param Integer $exp Expiration time in seconds. |
||
5412 | * @return array |
||
5413 | */ |
||
5414 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
5418 | |||
5419 | public static function get_secrets( $action, $user_id ) { |
||
5432 | |||
5433 | /** |
||
5434 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5435 | * |
||
5436 | * Based on local php max_execution_time in php.ini |
||
5437 | * |
||
5438 | * @since 2.6 |
||
5439 | * @return int |
||
5440 | * @deprecated |
||
5441 | **/ |
||
5442 | public function get_remote_query_timeout_limit() { |
||
5446 | |||
5447 | /** |
||
5448 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5449 | * |
||
5450 | * Based on local php max_execution_time in php.ini |
||
5451 | * |
||
5452 | * @since 5.4 |
||
5453 | * @return int |
||
5454 | **/ |
||
5455 | public static function get_max_execution_time() { |
||
5464 | |||
5465 | /** |
||
5466 | * Sets a minimum request timeout, and returns the current timeout |
||
5467 | * |
||
5468 | * @since 5.4 |
||
5469 | **/ |
||
5470 | View Code Duplication | public static function set_min_time_limit( $min_timeout ) { |
|
5478 | |||
5479 | /** |
||
5480 | * Takes the response from the Jetpack register new site endpoint and |
||
5481 | * verifies it worked properly. |
||
5482 | * |
||
5483 | * @since 2.6 |
||
5484 | * @deprecated since 7.7.0 |
||
5485 | * @see Automattic\Jetpack\Connection\Manager::validate_remote_register_response() |
||
5486 | **/ |
||
5487 | public function validate_remote_register_response() { |
||
5490 | |||
5491 | /** |
||
5492 | * @return bool|WP_Error |
||
5493 | */ |
||
5494 | public static function register() { |
||
5511 | |||
5512 | /** |
||
5513 | * Filters the registration request body to include tracking properties. |
||
5514 | * |
||
5515 | * @param array $properties |
||
5516 | * @return array amended properties. |
||
5517 | */ |
||
5518 | View Code Duplication | public static function filter_register_request_body( $properties ) { |
|
5530 | |||
5531 | /** |
||
5532 | * Filters the token request body to include tracking properties. |
||
5533 | * |
||
5534 | * @param array $properties |
||
5535 | * @return array amended properties. |
||
5536 | */ |
||
5537 | View Code Duplication | public static function filter_token_request_body( $properties ) { |
|
5549 | |||
5550 | /** |
||
5551 | * If the db version is showing something other that what we've got now, bump it to current. |
||
5552 | * |
||
5553 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
5554 | */ |
||
5555 | public static function maybe_set_version_option() { |
||
5569 | |||
5570 | /* Client Server API */ |
||
5571 | |||
5572 | /** |
||
5573 | * Loads the Jetpack XML-RPC client. |
||
5574 | * No longer necessary, as the XML-RPC client will be automagically loaded. |
||
5575 | * |
||
5576 | * @deprecated since 7.7.0 |
||
5577 | */ |
||
5578 | public static function load_xml_rpc_client() { |
||
5581 | |||
5582 | /** |
||
5583 | * Resets the saved authentication state in between testing requests. |
||
5584 | * |
||
5585 | * @deprecated since 8.9.0 |
||
5586 | * @see Automattic\Jetpack\Connection\Rest_Authentication::reset_saved_auth_state() |
||
5587 | */ |
||
5588 | public function reset_saved_auth_state() { |
||
5592 | |||
5593 | /** |
||
5594 | * Verifies the signature of the current request. |
||
5595 | * |
||
5596 | * @deprecated since 7.7.0 |
||
5597 | * @see Automattic\Jetpack\Connection\Manager::verify_xml_rpc_signature() |
||
5598 | * |
||
5599 | * @return false|array |
||
5600 | */ |
||
5601 | public function verify_xml_rpc_signature() { |
||
5605 | |||
5606 | /** |
||
5607 | * Verifies the signature of the current request. |
||
5608 | * |
||
5609 | * This function has side effects and should not be used. Instead, |
||
5610 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
5611 | * |
||
5612 | * @deprecated since 7.7.0 |
||
5613 | * @see Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature() |
||
5614 | * @internal |
||
5615 | */ |
||
5616 | private function internal_verify_xml_rpc_signature() { |
||
5619 | |||
5620 | /** |
||
5621 | * Authenticates XML-RPC and other requests from the Jetpack Server. |
||
5622 | * |
||
5623 | * @deprecated since 7.7.0 |
||
5624 | * @see Automattic\Jetpack\Connection\Manager::authenticate_jetpack() |
||
5625 | * |
||
5626 | * @param \WP_User|mixed $user User object if authenticated. |
||
5627 | * @param string $username Username. |
||
5628 | * @param string $password Password string. |
||
5629 | * @return \WP_User|mixed Authenticated user or error. |
||
5630 | */ |
||
5631 | View Code Duplication | public function authenticate_jetpack( $user, $username, $password ) { |
|
5640 | |||
5641 | /** |
||
5642 | * Authenticates requests from Jetpack server to WP REST API endpoints. |
||
5643 | * Uses the existing XMLRPC request signing implementation. |
||
5644 | * |
||
5645 | * @deprecated since 8.9.0 |
||
5646 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authenticate() |
||
5647 | */ |
||
5648 | function wp_rest_authenticate( $user ) { |
||
5652 | |||
5653 | /** |
||
5654 | * Report authentication status to the WP REST API. |
||
5655 | * |
||
5656 | * @deprecated since 8.9.0 |
||
5657 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authentication_errors() |
||
5658 | * |
||
5659 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
5660 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
5661 | */ |
||
5662 | public function wp_rest_authentication_errors( $value ) { |
||
5666 | |||
5667 | /** |
||
5668 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
5669 | * Capture it here so we can verify the signature later. |
||
5670 | * |
||
5671 | * @deprecated since 7.7.0 |
||
5672 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_methods() |
||
5673 | * |
||
5674 | * @param array $methods XMLRPC methods. |
||
5675 | * @return array XMLRPC methods, with the $HTTP_RAW_POST_DATA one. |
||
5676 | */ |
||
5677 | View Code Duplication | public function xmlrpc_methods( $methods ) { |
|
5686 | |||
5687 | /** |
||
5688 | * Register additional public XMLRPC methods. |
||
5689 | * |
||
5690 | * @deprecated since 7.7.0 |
||
5691 | * @see Automattic\Jetpack\Connection\Manager::public_xmlrpc_methods() |
||
5692 | * |
||
5693 | * @param array $methods Public XMLRPC methods. |
||
5694 | * @return array Public XMLRPC methods, with the getOptions one. |
||
5695 | */ |
||
5696 | View Code Duplication | public function public_xmlrpc_methods( $methods ) { |
|
5705 | |||
5706 | /** |
||
5707 | * Handles a getOptions XMLRPC method call. |
||
5708 | * |
||
5709 | * @deprecated since 7.7.0 |
||
5710 | * @see Automattic\Jetpack\Connection\Manager::jetpack_getOptions() |
||
5711 | * |
||
5712 | * @param array $args method call arguments. |
||
5713 | * @return array an amended XMLRPC server options array. |
||
5714 | */ |
||
5715 | View Code Duplication | public function jetpack_getOptions( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
5724 | |||
5725 | /** |
||
5726 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
5727 | * |
||
5728 | * @deprecated since 7.7.0 |
||
5729 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_options() |
||
5730 | * |
||
5731 | * @param array $options Standard Core options. |
||
5732 | * @return array Amended options. |
||
5733 | */ |
||
5734 | View Code Duplication | public function xmlrpc_options( $options ) { |
|
5743 | |||
5744 | /** |
||
5745 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
5746 | * SET: state( $key, $value ); |
||
5747 | * GET: $value = state( $key ); |
||
5748 | * |
||
5749 | * @param string $key |
||
5750 | * @param string $value |
||
5751 | * @param bool $restate private |
||
5752 | */ |
||
5753 | public static function state( $key = null, $value = null, $restate = false ) { |
||
5809 | |||
5810 | public static function restate() { |
||
5813 | |||
5814 | /** |
||
5815 | * Determines whether the jetpackState[$key] value should be added to the |
||
5816 | * cookie. |
||
5817 | * |
||
5818 | * @param string $key The state key. |
||
5819 | * |
||
5820 | * @return boolean Whether the value should be added to the cookie. |
||
5821 | */ |
||
5822 | public static function should_set_cookie( $key ) { |
||
5832 | |||
5833 | public static function check_privacy( $file ) { |
||
5867 | |||
5868 | /** |
||
5869 | * Helper method for multicall XMLRPC. |
||
5870 | * |
||
5871 | * @deprecated since 8.9.0 |
||
5872 | * @see Automattic\\Jetpack\\Connection\\Xmlrpc_Async_Call::add_call() |
||
5873 | * |
||
5874 | * @param ...$args Args for the async_call. |
||
5875 | */ |
||
5876 | public static function xmlrpc_async_call( ...$args ) { |
||
5918 | |||
5919 | /** |
||
5920 | * Serve a WordPress.com static resource via a randomized wp.com subdomain. |
||
5921 | * |
||
5922 | * @deprecated 9.3.0 Use Assets::staticize_subdomain. |
||
5923 | * |
||
5924 | * @param string $url WordPress.com static resource URL. |
||
5925 | */ |
||
5926 | public static function staticize_subdomain( $url ) { |
||
5930 | |||
5931 | /* JSON API Authorization */ |
||
5932 | |||
5933 | /** |
||
5934 | * Handles the login action for Authorizing the JSON API |
||
5935 | */ |
||
5936 | function login_form_json_api_authorization() { |
||
5945 | |||
5946 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
5947 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
5961 | |||
5962 | // Make sure the POSTed request is handled by the same action |
||
5963 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
5967 | |||
5968 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
5969 | function store_json_api_authorization_token( $user_login, $user ) { |
||
5975 | |||
5976 | // Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. |
||
5977 | function allow_wpcom_public_api_domain( $domains ) { |
||
5981 | |||
5982 | static function is_redirect_encoded( $redirect_url ) { |
||
5985 | |||
5986 | // Add all wordpress.com environments to the safe redirect allowed list. |
||
5987 | function allow_wpcom_environments( $domains ) { |
||
5994 | |||
5995 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
5996 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
6008 | |||
6009 | /** |
||
6010 | * Verifies the request by checking the signature |
||
6011 | * |
||
6012 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
6013 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
6014 | * |
||
6015 | * @param null|array $environment |
||
6016 | */ |
||
6017 | function verify_json_api_authorization_request( $environment = null ) { |
||
6139 | |||
6140 | function login_message_json_api_authorization( $message ) { |
||
6146 | |||
6147 | /** |
||
6148 | * Get $content_width, but with a <s>twist</s> filter. |
||
6149 | */ |
||
6150 | public static function get_content_width() { |
||
6163 | |||
6164 | /** |
||
6165 | * Pings the WordPress.com Mirror Site for the specified options. |
||
6166 | * |
||
6167 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
6168 | * |
||
6169 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
6170 | */ |
||
6171 | public function get_cloud_site_options( $option_names ) { |
||
6186 | |||
6187 | /** |
||
6188 | * Checks if the site is currently in an identity crisis. |
||
6189 | * |
||
6190 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
6191 | */ |
||
6192 | public static function check_identity_crisis() { |
||
6199 | |||
6200 | /** |
||
6201 | * Checks whether the home and siteurl specifically are allowed. |
||
6202 | * Written so that we don't have re-check $key and $value params every time |
||
6203 | * we want to check if this site is allowed, for example in footer.php |
||
6204 | * |
||
6205 | * @since 3.8.0 |
||
6206 | * @return bool True = already allowed False = not on the allowed list. |
||
6207 | */ |
||
6208 | public static function is_staging_site() { |
||
6212 | |||
6213 | /** |
||
6214 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
6215 | * |
||
6216 | * @since 4.4.0 |
||
6217 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
6218 | * |
||
6219 | * @return bool |
||
6220 | */ |
||
6221 | View Code Duplication | public static function validate_sync_error_idc_option() { |
|
6222 | $is_valid = false; |
||
6223 | |||
6224 | // Is the site opted in and does the stored sync_error_idc option match what we now generate? |
||
6225 | $sync_error = Jetpack_Options::get_option( 'sync_error_idc' ); |
||
6226 | if ( $sync_error && self::sync_idc_optin() ) { |
||
6227 | $local_options = self::get_sync_error_idc_option(); |
||
6228 | // Ensure all values are set. |
||
6229 | if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) { |
||
6230 | |||
6231 | // If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC. |
||
6232 | if ( |
||
6233 | isset( $sync_error['wpcom_home'] ) && |
||
6234 | isset( $sync_error['wpcom_siteurl'] ) && |
||
6235 | $sync_error['wpcom_home'] === $local_options['home'] && |
||
6236 | $sync_error['wpcom_siteurl'] === $local_options['siteurl'] |
||
6237 | ) { |
||
6238 | $is_valid = false; |
||
6239 | // Enable migrate_for_idc so that sync actions are accepted. |
||
6240 | Jetpack_Options::update_option( 'migrate_for_idc', true ); |
||
6241 | } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { |
||
6242 | $is_valid = true; |
||
6243 | } |
||
6244 | } |
||
6245 | } |
||
6246 | |||
6247 | /** |
||
6248 | * Filters whether the sync_error_idc option is valid. |
||
6249 | * |
||
6250 | * @since 4.4.0 |
||
6251 | * |
||
6252 | * @param bool $is_valid If the sync_error_idc is valid or not. |
||
6253 | */ |
||
6254 | $is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid ); |
||
6255 | |||
6256 | if ( ! $is_valid && $sync_error ) { |
||
6257 | // Since the option exists, and did not validate, delete it |
||
6258 | Jetpack_Options::delete_option( 'sync_error_idc' ); |
||
6259 | } |
||
6260 | |||
6261 | return $is_valid; |
||
6262 | } |
||
6263 | |||
6264 | /** |
||
6265 | * Normalizes a url by doing three things: |
||
6266 | * - Strips protocol |
||
6267 | * - Strips www |
||
6268 | * - Adds a trailing slash |
||
6269 | * |
||
6270 | * @since 4.4.0 |
||
6271 | * @param string $url |
||
6272 | * @return WP_Error|string |
||
6273 | */ |
||
6274 | View Code Duplication | public static function normalize_url_protocol_agnostic( $url ) { |
|
6275 | $parsed_url = wp_parse_url( trailingslashit( esc_url_raw( $url ) ) ); |
||
6276 | if ( ! $parsed_url || empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) ) { |
||
6277 | return new WP_Error( 'cannot_parse_url', sprintf( esc_html__( 'Cannot parse URL %s', 'jetpack' ), $url ) ); |
||
6278 | } |
||
6279 | |||
6280 | // Strip www and protocols |
||
6281 | $url = preg_replace( '/^www\./i', '', $parsed_url['host'] . $parsed_url['path'] ); |
||
6282 | return $url; |
||
6283 | } |
||
6284 | |||
6285 | /** |
||
6286 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
6287 | * |
||
6288 | * @since 4.4.0 |
||
6289 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
6290 | * |
||
6291 | * @param array $response |
||
6292 | * @return array Array of the local urls, wpcom urls, and error code |
||
6293 | */ |
||
6294 | View Code Duplication | public static function get_sync_error_idc_option( $response = array() ) { |
|
6295 | // Since the local options will hit the database directly, store the values |
||
6296 | // in a transient to allow for autoloading and caching on subsequent views. |
||
6297 | $local_options = get_transient( 'jetpack_idc_local' ); |
||
6298 | if ( false === $local_options ) { |
||
6299 | $local_options = array( |
||
6300 | 'home' => Functions::home_url(), |
||
6301 | 'siteurl' => Functions::site_url(), |
||
6302 | ); |
||
6303 | set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS ); |
||
6304 | } |
||
6305 | |||
6306 | $options = array_merge( $local_options, $response ); |
||
6307 | |||
6308 | $returned_values = array(); |
||
6309 | foreach ( $options as $key => $option ) { |
||
6310 | if ( 'error_code' === $key ) { |
||
6311 | $returned_values[ $key ] = $option; |
||
6312 | continue; |
||
6313 | } |
||
6314 | |||
6315 | if ( is_wp_error( $normalized_url = self::normalize_url_protocol_agnostic( $option ) ) ) { |
||
6316 | continue; |
||
6317 | } |
||
6318 | |||
6319 | $returned_values[ $key ] = $normalized_url; |
||
6320 | } |
||
6321 | |||
6322 | set_transient( 'jetpack_idc_option', $returned_values, MINUTE_IN_SECONDS ); |
||
6323 | |||
6324 | return $returned_values; |
||
6325 | } |
||
6326 | |||
6327 | /** |
||
6328 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
6329 | * If set to true, the site will be put into staging mode. |
||
6330 | * |
||
6331 | * @since 4.3.2 |
||
6332 | * @return bool |
||
6333 | */ |
||
6334 | View Code Duplication | public static function sync_idc_optin() { |
|
6335 | if ( Constants::is_defined( 'JETPACK_SYNC_IDC_OPTIN' ) ) { |
||
6336 | $default = Constants::get_constant( 'JETPACK_SYNC_IDC_OPTIN' ); |
||
6337 | } else { |
||
6338 | $default = ! Constants::is_defined( 'SUNRISE' ) && ! is_multisite(); |
||
6339 | } |
||
6340 | |||
6341 | /** |
||
6342 | * Allows sites to opt in for IDC mitigation which blocks the site from syncing to WordPress.com when the home |
||
6343 | * URL or site URL do not match what WordPress.com expects. The default value is either true, or the value of |
||
6344 | * JETPACK_SYNC_IDC_OPTIN constant if set. |
||
6345 | * |
||
6346 | * @since 4.3.2 |
||
6347 | * |
||
6348 | * @param bool $default Whether the site is opted in to IDC mitigation. |
||
6349 | */ |
||
6350 | return (bool) apply_filters( 'jetpack_sync_idc_optin', $default ); |
||
6351 | } |
||
6352 | |||
6353 | /** |
||
6354 | * Maybe Use a .min.css stylesheet, maybe not. |
||
6355 | * |
||
6356 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
6357 | */ |
||
6358 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
6400 | |||
6401 | /** |
||
6402 | * If the asset is minified, let's flag .min as the suffix. |
||
6403 | * |
||
6404 | * Attached to `style_loader_src` filter. |
||
6405 | * |
||
6406 | * @param string $tag The tag that would link to the external asset. |
||
6407 | * @param string $handle The registered handle of the script in question. |
||
6408 | * @param string $href The url of the asset in question. |
||
6409 | */ |
||
6410 | public static function set_suffix_on_min( $src, $handle ) { |
||
6426 | |||
6427 | /** |
||
6428 | * Maybe inlines a stylesheet. |
||
6429 | * |
||
6430 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
6431 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
6432 | * |
||
6433 | * Attached to `style_loader_tag` filter. |
||
6434 | * |
||
6435 | * @param string $tag The tag that would link to the external asset. |
||
6436 | * @param string $handle The registered handle of the script in question. |
||
6437 | * |
||
6438 | * @return string |
||
6439 | */ |
||
6440 | public static function maybe_inline_style( $tag, $handle ) { |
||
6490 | |||
6491 | /** |
||
6492 | * Loads a view file from the views |
||
6493 | * |
||
6494 | * Data passed in with the $data parameter will be available in the |
||
6495 | * template file as $data['value'] |
||
6496 | * |
||
6497 | * @param string $template - Template file to load |
||
6498 | * @param array $data - Any data to pass along to the template |
||
6499 | * @return boolean - If template file was found |
||
6500 | **/ |
||
6501 | public function load_view( $template, $data = array() ) { |
||
6512 | |||
6513 | /** |
||
6514 | * Throws warnings for deprecated hooks to be removed from Jetpack that cannot remain in the original place in the code. |
||
6515 | */ |
||
6516 | public function deprecated_hooks() { |
||
6773 | |||
6774 | /** |
||
6775 | * Converts any url in a stylesheet, to the correct absolute url. |
||
6776 | * |
||
6777 | * Considerations: |
||
6778 | * - Normal, relative URLs `feh.png` |
||
6779 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
6780 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
6781 | * - Absolute URLs `http://domain.com/feh.png` |
||
6782 | * - Domain root relative URLs `/feh.png` |
||
6783 | * |
||
6784 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
6785 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
6786 | * |
||
6787 | * @return mixed|string |
||
6788 | */ |
||
6789 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
6833 | |||
6834 | /** |
||
6835 | * This methods removes all of the registered css files on the front end |
||
6836 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
6837 | * all the files into one file. |
||
6838 | * |
||
6839 | * Pros: |
||
6840 | * - Uses only ONE css asset connection instead of 15 |
||
6841 | * - Saves a minimum of 56k |
||
6842 | * - Reduces server load |
||
6843 | * - Reduces time to first painted byte |
||
6844 | * |
||
6845 | * Cons: |
||
6846 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
6847 | * should not cause any issues with themes. |
||
6848 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
6849 | * jetpack_implode_frontend_css filter for a workaround |
||
6850 | * |
||
6851 | * For some situations developers may wish to disable css imploding and |
||
6852 | * instead operate in legacy mode where each file loads seperately and |
||
6853 | * can be edited individually or dequeued. This can be accomplished with |
||
6854 | * the following line: |
||
6855 | * |
||
6856 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
6857 | * |
||
6858 | * @since 3.2 |
||
6859 | **/ |
||
6860 | public function implode_frontend_css( $travis_test = false ) { |
||
6917 | |||
6918 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
6928 | |||
6929 | /** |
||
6930 | * @deprecated |
||
6931 | * @see Automattic\Jetpack\Assets\add_aync_script |
||
6932 | */ |
||
6933 | public function script_add_async( $tag, $handle, $src ) { |
||
6936 | |||
6937 | /* |
||
6938 | * Check the heartbeat data |
||
6939 | * |
||
6940 | * Organizes the heartbeat data by severity. For example, if the site |
||
6941 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
6942 | * |
||
6943 | * Data will be added to "caution" array, if it either: |
||
6944 | * - Out of date Jetpack version |
||
6945 | * - Out of date WP version |
||
6946 | * - Out of date PHP version |
||
6947 | * |
||
6948 | * $return array $filtered_data |
||
6949 | */ |
||
6950 | public static function jetpack_check_heartbeat_data() { |
||
7003 | |||
7004 | /* |
||
7005 | * This method is used to organize all options that can be reset |
||
7006 | * without disconnecting Jetpack. |
||
7007 | * |
||
7008 | * It is used in class.jetpack-cli.php to reset options |
||
7009 | * |
||
7010 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
7011 | * |
||
7012 | * @return array of options to delete. |
||
7013 | */ |
||
7014 | public static function get_jetpack_options_for_reset() { |
||
7017 | |||
7018 | /* |
||
7019 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
7020 | * so we can bring them directly to their site in calypso. |
||
7021 | * |
||
7022 | * @deprecated 9.2.0 Use Automattic\Jetpack\Status::get_site_suffix |
||
7023 | * |
||
7024 | * @param string | url |
||
7025 | * @return string | url without the guff |
||
7026 | */ |
||
7027 | public static function build_raw_urls( $url ) { |
||
7032 | |||
7033 | /** |
||
7034 | * Stores and prints out domains to prefetch for page speed optimization. |
||
7035 | * |
||
7036 | * @deprecated 8.8.0 Use Jetpack::add_resource_hints. |
||
7037 | * |
||
7038 | * @param string|array $urls URLs to hint. |
||
7039 | */ |
||
7040 | public static function dns_prefetch( $urls = null ) { |
||
7046 | |||
7047 | public function wp_dashboard_setup() { |
||
7085 | |||
7086 | /** |
||
7087 | * @param mixed $result Value for the user's option |
||
7088 | * @return mixed |
||
7089 | */ |
||
7090 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
7115 | |||
7116 | public static function dashboard_widget() { |
||
7124 | |||
7125 | public static function dashboard_widget_footer() { |
||
7193 | |||
7194 | /* |
||
7195 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
7196 | */ |
||
7197 | function jetpack_icon_user_connected( $columns ) { |
||
7201 | |||
7202 | /* |
||
7203 | * Show Jetpack icon if the user is linked. |
||
7204 | */ |
||
7205 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
7218 | |||
7219 | /* |
||
7220 | * Style the Jetpack user column |
||
7221 | */ |
||
7222 | function jetpack_user_col_style() { |
||
7241 | |||
7242 | /** |
||
7243 | * Checks if Akismet is active and working. |
||
7244 | * |
||
7245 | * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key |
||
7246 | * that implied usage of methods present since more recent version. |
||
7247 | * See https://github.com/Automattic/jetpack/pull/9585 |
||
7248 | * |
||
7249 | * @since 5.1.0 |
||
7250 | * |
||
7251 | * @return bool True = Akismet available. False = Aksimet not available. |
||
7252 | */ |
||
7253 | public static function is_akismet_active() { |
||
7288 | |||
7289 | /** |
||
7290 | * @deprecated |
||
7291 | * |
||
7292 | * @see Automattic\Jetpack\Sync\Modules\Users::is_function_in_backtrace |
||
7293 | */ |
||
7294 | public static function is_function_in_backtrace() { |
||
7297 | |||
7298 | /** |
||
7299 | * Given a minified path, and a non-minified path, will return |
||
7300 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
7301 | * |
||
7302 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
7303 | * root Jetpack directory. |
||
7304 | * |
||
7305 | * @since 5.6.0 |
||
7306 | * |
||
7307 | * @param string $min_path |
||
7308 | * @param string $non_min_path |
||
7309 | * @return string The URL to the file |
||
7310 | */ |
||
7311 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
7314 | |||
7315 | /** |
||
7316 | * Checks for whether Jetpack Backup is enabled. |
||
7317 | * Will return true if the state of Backup is anything except "unavailable". |
||
7318 | * |
||
7319 | * @return bool|int|mixed |
||
7320 | */ |
||
7321 | public static function is_rewind_enabled() { |
||
7341 | |||
7342 | /** |
||
7343 | * Return Calypso environment value; used for developing Jetpack and pairing |
||
7344 | * it with different Calypso enrionments, such as localhost. |
||
7345 | * |
||
7346 | * @since 7.4.0 |
||
7347 | * |
||
7348 | * @return string Calypso environment |
||
7349 | */ |
||
7350 | public static function get_calypso_env() { |
||
7365 | |||
7366 | /** |
||
7367 | * Returns the hostname with protocol for Calypso. |
||
7368 | * Used for developing Jetpack with Calypso. |
||
7369 | * |
||
7370 | * @since 8.4.0 |
||
7371 | * |
||
7372 | * @return string Calypso host. |
||
7373 | */ |
||
7374 | public static function get_calypso_host() { |
||
7387 | |||
7388 | /** |
||
7389 | * Handles activating default modules as well general cleanup for the new connection. |
||
7390 | * |
||
7391 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
7392 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
7393 | * @param boolean $send_state_messages Whether to send state messages. |
||
7394 | * @return void |
||
7395 | */ |
||
7396 | public static function handle_post_authorization_actions( |
||
7424 | |||
7425 | /** |
||
7426 | * Returns a boolean for whether backups UI should be displayed or not. |
||
7427 | * |
||
7428 | * @return bool Should backups UI be displayed? |
||
7429 | */ |
||
7430 | public static function show_backups_ui() { |
||
7440 | |||
7441 | /* |
||
7442 | * Deprecated manage functions |
||
7443 | */ |
||
7444 | function prepare_manage_jetpack_notice() { |
||
7465 | |||
7466 | /** |
||
7467 | * Clean leftoveruser meta. |
||
7468 | * |
||
7469 | * Delete Jetpack-related user meta when it is no longer needed. |
||
7470 | * |
||
7471 | * @since 7.3.0 |
||
7472 | * |
||
7473 | * @param int $user_id User ID being updated. |
||
7474 | */ |
||
7475 | public static function user_meta_cleanup( $user_id ) { |
||
7490 | |||
7491 | /** |
||
7492 | * Checks if a Jetpack site is both active and not in offline mode. |
||
7493 | * |
||
7494 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
7495 | * |
||
7496 | * @deprecated 8.8.0 |
||
7497 | * |
||
7498 | * @return bool True if Jetpack is active and not in offline mode. |
||
7499 | */ |
||
7500 | public static function is_active_and_not_development_mode() { |
||
7507 | |||
7508 | /** |
||
7509 | * Checks if a Jetpack site is both active and not in offline mode. |
||
7510 | * |
||
7511 | * This is a DRY function to avoid repeating `Jetpack::is_connection_ready && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
7512 | * |
||
7513 | * @since 8.8.0 |
||
7514 | * |
||
7515 | * @return bool True if Jetpack is active and not in offline mode. |
||
7516 | */ |
||
7517 | public static function is_active_and_not_offline_mode() { |
||
7523 | |||
7524 | /** |
||
7525 | * Returns the list of products that we have available for purchase. |
||
7526 | */ |
||
7527 | public static function get_products_for_purchase() { |
||
7621 | } |
||
7622 |
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.