Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 53 | class Jetpack { |
||
| 54 | public $xmlrpc_server = null; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var array The handles of styles that are concatenated into jetpack.css. |
||
| 58 | * |
||
| 59 | * When making changes to that list, you must also update concat_list in tools/builder/frontend-css.js. |
||
| 60 | */ |
||
| 61 | public $concatenated_style_handles = array( |
||
| 62 | 'jetpack-carousel', |
||
| 63 | 'grunion.css', |
||
| 64 | 'the-neverending-homepage', |
||
| 65 | 'jetpack_likes', |
||
| 66 | 'jetpack_related-posts', |
||
| 67 | 'sharedaddy', |
||
| 68 | 'jetpack-slideshow', |
||
| 69 | 'presentations', |
||
| 70 | 'quiz', |
||
| 71 | 'jetpack-subscriptions', |
||
| 72 | 'jetpack-responsive-videos-style', |
||
| 73 | 'jetpack-social-menu', |
||
| 74 | 'tiled-gallery', |
||
| 75 | 'jetpack_display_posts_widget', |
||
| 76 | 'gravatar-profile-widget', |
||
| 77 | 'goodreads-widget', |
||
| 78 | 'jetpack_social_media_icons_widget', |
||
| 79 | 'jetpack-top-posts-widget', |
||
| 80 | 'jetpack_image_widget', |
||
| 81 | 'jetpack-my-community-widget', |
||
| 82 | 'jetpack-authors-widget', |
||
| 83 | 'wordads', |
||
| 84 | 'eu-cookie-law-style', |
||
| 85 | 'flickr-widget-style', |
||
| 86 | 'jetpack-search-widget', |
||
| 87 | 'jetpack-simple-payments-widget-style', |
||
| 88 | 'jetpack-widget-social-icons-styles', |
||
| 89 | 'wpcom_instagram_widget', |
||
| 90 | ); |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Contains all assets that have had their URL rewritten to minified versions. |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | static $min_assets = array(); |
||
| 98 | |||
| 99 | public $plugins_to_deactivate = array( |
||
| 100 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 101 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 102 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 103 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 104 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 105 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 106 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 107 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 108 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 109 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 110 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 111 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 112 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 113 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ), |
||
| 114 | ); |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Map of roles we care about, and their corresponding minimum capabilities. |
||
| 118 | * |
||
| 119 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead. |
||
| 120 | * |
||
| 121 | * @access public |
||
| 122 | * @static |
||
| 123 | * |
||
| 124 | * @var array |
||
| 125 | */ |
||
| 126 | public static $capability_translations = array( |
||
| 127 | 'administrator' => 'manage_options', |
||
| 128 | 'editor' => 'edit_others_posts', |
||
| 129 | 'author' => 'publish_posts', |
||
| 130 | 'contributor' => 'edit_posts', |
||
| 131 | 'subscriber' => 'read', |
||
| 132 | ); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 136 | * if the plugins are active. Used by filter_default_modules |
||
| 137 | * |
||
| 138 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 139 | * change `module-slug` and add this to your plugin: |
||
| 140 | * |
||
| 141 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 142 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 143 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 144 | * } |
||
| 145 | * |
||
| 146 | * @var array |
||
| 147 | */ |
||
| 148 | private $conflicting_plugins = array( |
||
| 149 | 'comments' => array( |
||
| 150 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 151 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 152 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 153 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 154 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 155 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 156 | ), |
||
| 157 | 'comment-likes' => array( |
||
| 158 | 'Epoch' => 'epoch/plugincore.php', |
||
| 159 | ), |
||
| 160 | 'contact-form' => array( |
||
| 161 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 162 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 163 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 164 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 165 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 166 | 'Ninja Forms' => 'ninja-forms/ninja-forms.php', |
||
| 167 | ), |
||
| 168 | 'latex' => array( |
||
| 169 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 170 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 171 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 172 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 173 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 174 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 175 | ), |
||
| 176 | 'protect' => array( |
||
| 177 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 178 | 'Captcha' => 'captcha/captcha.php', |
||
| 179 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 180 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 181 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 182 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 183 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 184 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 185 | 'Login Security' => 'login-security/login-security.php', |
||
| 186 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 187 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 188 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 189 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 190 | ), |
||
| 191 | 'random-redirect' => array( |
||
| 192 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 193 | ), |
||
| 194 | 'related-posts' => array( |
||
| 195 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 196 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 197 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 198 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 199 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 200 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 201 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 202 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 203 | ), |
||
| 204 | 'sharedaddy' => array( |
||
| 205 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 206 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 207 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 208 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 209 | ), |
||
| 210 | 'seo-tools' => array( |
||
| 211 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 212 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 213 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 214 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 215 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 216 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 217 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 218 | ), |
||
| 219 | 'verification-tools' => array( |
||
| 220 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 221 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 222 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 223 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 224 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 225 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 226 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 227 | ), |
||
| 228 | 'widget-visibility' => array( |
||
| 229 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 230 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 231 | ), |
||
| 232 | 'sitemaps' => array( |
||
| 233 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 234 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 235 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 236 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 237 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 238 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 239 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 240 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 241 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 242 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 243 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 244 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 245 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 246 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 247 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 248 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 249 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 250 | ), |
||
| 251 | 'lazy-images' => array( |
||
| 252 | 'Lazy Load' => 'lazy-load/lazy-load.php', |
||
| 253 | 'BJ Lazy Load' => 'bj-lazy-load/bj-lazy-load.php', |
||
| 254 | 'Lazy Load by WP Rocket' => 'rocket-lazy-load/rocket-lazy-load.php', |
||
| 255 | ), |
||
| 256 | ); |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 260 | * |
||
| 261 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
| 262 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 263 | * |
||
| 264 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 265 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 266 | */ |
||
| 267 | private $open_graph_conflicting_plugins = array( |
||
| 268 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 269 | // 2 Click Social Media Buttons |
||
| 270 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 271 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 272 | 'complete-open-graph/complete-open-graph.php', // Complete Open Graph |
||
| 273 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 274 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
| 275 | // Open Graph Meta Tags by Heateor |
||
| 276 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 277 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 278 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 279 | // Facebook Featured Image & OG Meta Tags |
||
| 280 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 281 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 282 | // Facebook Open Graph Meta Tags for WordPress |
||
| 283 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 284 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 285 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 286 | // Fedmich's Facebook Open Graph Meta |
||
| 287 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 288 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 289 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 290 | // NextScripts SNAP |
||
| 291 | 'og-tags/og-tags.php', // OG Tags |
||
| 292 | 'opengraph/opengraph.php', // Open Graph |
||
| 293 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 294 | // Open Graph Protocol Framework |
||
| 295 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 296 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 297 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 298 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 299 | 'sharepress/sharepress.php', // SharePress |
||
| 300 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 301 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 302 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 303 | 'socialize/socialize.php', // Socialize |
||
| 304 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
| 305 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 306 | // Tweet, Like, Google +1 and Share |
||
| 307 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 308 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 309 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 310 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 311 | // WP Facebook Like Send & Open Graph Meta |
||
| 312 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 313 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 314 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 315 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button |
||
| 316 | 'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox |
||
| 317 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
| 318 | 'slim-seo/slim-seo.php', // Slim SEO |
||
| 319 | ); |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 323 | */ |
||
| 324 | private $twitter_cards_conflicting_plugins = array( |
||
| 325 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 326 | // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 327 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 328 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 329 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 330 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 331 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 332 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 333 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 334 | 'wp-to-twitter/wp-to-twitter.php', // WP to Twitter |
||
| 335 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 336 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
| 337 | 'slim-seo/slim-seo.php', // Slim SEO |
||
| 338 | ); |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Message to display in admin_notice |
||
| 342 | * |
||
| 343 | * @var string |
||
| 344 | */ |
||
| 345 | public $message = ''; |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Error to display in admin_notice |
||
| 349 | * |
||
| 350 | * @var string |
||
| 351 | */ |
||
| 352 | public $error = ''; |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Modules that need more privacy description. |
||
| 356 | * |
||
| 357 | * @var string |
||
| 358 | */ |
||
| 359 | public $privacy_checks = ''; |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Stats to record once the page loads |
||
| 363 | * |
||
| 364 | * @var array |
||
| 365 | */ |
||
| 366 | public $stats = array(); |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Jetpack_Sync object |
||
| 370 | */ |
||
| 371 | public $sync; |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Verified data for JSON authorization request |
||
| 375 | */ |
||
| 376 | public $json_api_authorization_request = array(); |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @var Automattic\Jetpack\Connection\Manager |
||
| 380 | */ |
||
| 381 | protected $connection_manager; |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @var string Transient key used to prevent multiple simultaneous plugin upgrades |
||
| 385 | */ |
||
| 386 | public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock'; |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Holds an instance of Automattic\Jetpack\A8c_Mc_Stats |
||
| 390 | * |
||
| 391 | * @var Automattic\Jetpack\A8c_Mc_Stats |
||
| 392 | */ |
||
| 393 | public $a8c_mc_stats_instance; |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Constant for login redirect key. |
||
| 397 | * |
||
| 398 | * @var string |
||
| 399 | * @since 8.4.0 |
||
| 400 | */ |
||
| 401 | public static $jetpack_redirect_login = 'jetpack_connect_login_redirect'; |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Holds the singleton instance of this class |
||
| 405 | * |
||
| 406 | * @since 2.3.3 |
||
| 407 | * @var Jetpack |
||
| 408 | */ |
||
| 409 | static $instance = false; |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Singleton |
||
| 413 | * |
||
| 414 | * @static |
||
| 415 | */ |
||
| 416 | public static function init() { |
||
| 417 | if ( ! self::$instance ) { |
||
| 418 | self::$instance = new Jetpack(); |
||
| 419 | add_action( 'plugins_loaded', array( self::$instance, 'plugin_upgrade' ) ); |
||
| 420 | } |
||
| 421 | |||
| 422 | return self::$instance; |
||
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Must never be called statically |
||
| 427 | */ |
||
| 428 | function plugin_upgrade() { |
||
| 429 | if ( self::is_connection_ready() ) { |
||
| 430 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 431 | if ( JETPACK__VERSION != $version ) { |
||
| 432 | // Prevent multiple upgrades at once - only a single process should trigger |
||
| 433 | // an upgrade to avoid stampedes |
||
| 434 | if ( false !== get_transient( self::$plugin_upgrade_lock_key ) ) { |
||
| 435 | return; |
||
| 436 | } |
||
| 437 | |||
| 438 | // Set a short lock to prevent multiple instances of the upgrade |
||
| 439 | set_transient( self::$plugin_upgrade_lock_key, 1, 10 ); |
||
| 440 | |||
| 441 | // check which active modules actually exist and remove others from active_modules list |
||
| 442 | $unfiltered_modules = self::get_active_modules(); |
||
| 443 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
| 444 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
| 445 | self::update_active_modules( $modules ); |
||
| 446 | } |
||
| 447 | |||
| 448 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
| 449 | |||
| 450 | // Upgrade to 4.3.0 |
||
| 451 | if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) { |
||
| 452 | Jetpack_Options::delete_option( 'identity_crisis_whitelist' ); |
||
| 453 | } |
||
| 454 | |||
| 455 | // Make sure Markdown for posts gets turned back on |
||
| 456 | if ( ! get_option( 'wpcom_publish_posts_with_markdown' ) ) { |
||
| 457 | update_option( 'wpcom_publish_posts_with_markdown', true ); |
||
| 458 | } |
||
| 459 | |||
| 460 | /* |
||
| 461 | * Minileven deprecation. 8.3.0. |
||
| 462 | * Only delete options if not using |
||
| 463 | * the replacement standalone Minileven plugin. |
||
| 464 | */ |
||
| 465 | if ( |
||
| 466 | ! self::is_plugin_active( 'minileven-master/minileven.php' ) |
||
| 467 | && ! self::is_plugin_active( 'minileven/minileven.php' ) |
||
| 468 | ) { |
||
| 469 | if ( get_option( 'wp_mobile_custom_css' ) ) { |
||
| 470 | delete_option( 'wp_mobile_custom_css' ); |
||
| 471 | } |
||
| 472 | if ( get_option( 'wp_mobile_excerpt' ) ) { |
||
| 473 | delete_option( 'wp_mobile_excerpt' ); |
||
| 474 | } |
||
| 475 | if ( get_option( 'wp_mobile_featured_images' ) ) { |
||
| 476 | delete_option( 'wp_mobile_featured_images' ); |
||
| 477 | } |
||
| 478 | if ( get_option( 'wp_mobile_app_promos' ) ) { |
||
| 479 | delete_option( 'wp_mobile_app_promos' ); |
||
| 480 | } |
||
| 481 | } |
||
| 482 | |||
| 483 | // Upgrade to 8.4.0. |
||
| 484 | if ( Jetpack_Options::get_option( 'ab_connect_banner_green_bar' ) ) { |
||
| 485 | Jetpack_Options::delete_option( 'ab_connect_banner_green_bar' ); |
||
| 486 | } |
||
| 487 | |||
| 488 | // Update to 8.8.x (WordPress 5.5 Compatibility). |
||
| 489 | if ( Jetpack_Options::get_option( 'autoupdate_plugins' ) ) { |
||
| 490 | $updated = update_site_option( |
||
| 491 | 'auto_update_plugins', |
||
| 492 | array_unique( |
||
| 493 | array_merge( |
||
| 494 | (array) Jetpack_Options::get_option( 'autoupdate_plugins', array() ), |
||
| 495 | (array) get_site_option( 'auto_update_plugins', array() ) |
||
| 496 | ) |
||
| 497 | ) |
||
| 498 | ); |
||
| 499 | |||
| 500 | if ( $updated ) { |
||
| 501 | Jetpack_Options::delete_option( 'autoupdate_plugins' ); |
||
| 502 | } // Should we have some type of fallback if something fails here? |
||
| 503 | } |
||
| 504 | |||
| 505 | if ( did_action( 'wp_loaded' ) ) { |
||
| 506 | self::upgrade_on_load(); |
||
| 507 | } else { |
||
| 508 | add_action( |
||
| 509 | 'wp_loaded', |
||
| 510 | array( __CLASS__, 'upgrade_on_load' ) |
||
| 511 | ); |
||
| 512 | } |
||
| 513 | } |
||
| 514 | } |
||
| 515 | } |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Runs upgrade routines that need to have modules loaded. |
||
| 519 | */ |
||
| 520 | static function upgrade_on_load() { |
||
| 521 | |||
| 522 | // Not attempting any upgrades if jetpack_modules_loaded did not fire. |
||
| 523 | // This can happen in case Jetpack has been just upgraded and is |
||
| 524 | // being initialized late during the page load. In this case we wait |
||
| 525 | // until the next proper admin page load with Jetpack active. |
||
| 526 | if ( ! did_action( 'jetpack_modules_loaded' ) ) { |
||
| 527 | delete_transient( self::$plugin_upgrade_lock_key ); |
||
| 528 | |||
| 529 | return; |
||
| 530 | } |
||
| 531 | |||
| 532 | self::maybe_set_version_option(); |
||
| 533 | |||
| 534 | if ( method_exists( 'Jetpack_Widget_Conditions', 'migrate_post_type_rules' ) ) { |
||
| 535 | Jetpack_Widget_Conditions::migrate_post_type_rules(); |
||
| 536 | } |
||
| 537 | |||
| 538 | if ( |
||
| 539 | class_exists( 'Jetpack_Sitemap_Manager' ) |
||
| 540 | && version_compare( JETPACK__VERSION, '5.3', '>=' ) |
||
| 541 | ) { |
||
| 542 | do_action( 'jetpack_sitemaps_purge_data' ); |
||
| 543 | } |
||
| 544 | |||
| 545 | // Delete old stats cache |
||
| 546 | delete_option( 'jetpack_restapi_stats_cache' ); |
||
| 547 | |||
| 548 | delete_transient( self::$plugin_upgrade_lock_key ); |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Saves all the currently active modules to options. |
||
| 553 | * Also fires Action hooks for each newly activated and deactivated module. |
||
| 554 | * |
||
| 555 | * @param $modules Array Array of active modules to be saved in options. |
||
| 556 | * |
||
| 557 | * @return $success bool true for success, false for failure. |
||
|
|
|||
| 558 | */ |
||
| 559 | static function update_active_modules( $modules ) { |
||
| 560 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
| 561 | $active_modules = self::get_active_modules(); |
||
| 562 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
| 563 | $new_inactive_modules = array_diff( $active_modules, $modules ); |
||
| 564 | $new_current_modules = array_diff( array_merge( $current_modules, $new_active_modules ), $new_inactive_modules ); |
||
| 565 | $reindexed_modules = array_values( $new_current_modules ); |
||
| 566 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $reindexed_modules ) ); |
||
| 567 | |||
| 568 | foreach ( $new_active_modules as $module ) { |
||
| 569 | /** |
||
| 570 | * Fires when a specific module is activated. |
||
| 571 | * |
||
| 572 | * @since 1.9.0 |
||
| 573 | * |
||
| 574 | * @param string $module Module slug. |
||
| 575 | * @param boolean $success whether the module was activated. @since 4.2 |
||
| 576 | */ |
||
| 577 | do_action( 'jetpack_activate_module', $module, $success ); |
||
| 578 | /** |
||
| 579 | * Fires when a module is activated. |
||
| 580 | * The dynamic part of the filter, $module, is the module slug. |
||
| 581 | * |
||
| 582 | * @since 1.9.0 |
||
| 583 | * |
||
| 584 | * @param string $module Module slug. |
||
| 585 | */ |
||
| 586 | do_action( "jetpack_activate_module_$module", $module ); |
||
| 587 | } |
||
| 588 | |||
| 589 | foreach ( $new_inactive_modules as $module ) { |
||
| 590 | /** |
||
| 591 | * Fired after a module has been deactivated. |
||
| 592 | * |
||
| 593 | * @since 4.2.0 |
||
| 594 | * |
||
| 595 | * @param string $module Module slug. |
||
| 596 | * @param boolean $success whether the module was deactivated. |
||
| 597 | */ |
||
| 598 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
| 599 | /** |
||
| 600 | * Fires when a module is deactivated. |
||
| 601 | * The dynamic part of the filter, $module, is the module slug. |
||
| 602 | * |
||
| 603 | * @since 1.9.0 |
||
| 604 | * |
||
| 605 | * @param string $module Module slug. |
||
| 606 | */ |
||
| 607 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
| 608 | } |
||
| 609 | |||
| 610 | return $success; |
||
| 611 | } |
||
| 612 | |||
| 613 | static function delete_active_modules() { |
||
| 614 | self::update_active_modules( array() ); |
||
| 615 | } |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Adds a hook to plugins_loaded at a priority that's currently the earliest |
||
| 619 | * available. |
||
| 620 | */ |
||
| 621 | public function add_configure_hook() { |
||
| 622 | global $wp_filter; |
||
| 623 | |||
| 624 | $current_priority = has_filter( 'plugins_loaded', array( $this, 'configure' ) ); |
||
| 625 | if ( false !== $current_priority ) { |
||
| 626 | remove_action( 'plugins_loaded', array( $this, 'configure' ), $current_priority ); |
||
| 627 | } |
||
| 628 | |||
| 629 | $taken_priorities = array_map( 'intval', array_keys( $wp_filter['plugins_loaded']->callbacks ) ); |
||
| 630 | sort( $taken_priorities ); |
||
| 631 | |||
| 632 | $first_priority = array_shift( $taken_priorities ); |
||
| 633 | |||
| 634 | if ( defined( 'PHP_INT_MAX' ) && $first_priority <= - PHP_INT_MAX ) { |
||
| 635 | $new_priority = - PHP_INT_MAX; |
||
| 636 | } else { |
||
| 637 | $new_priority = $first_priority - 1; |
||
| 638 | } |
||
| 639 | |||
| 640 | add_action( 'plugins_loaded', array( $this, 'configure' ), $new_priority ); |
||
| 641 | } |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Constructor. Initializes WordPress hooks |
||
| 645 | */ |
||
| 646 | private function __construct() { |
||
| 647 | /* |
||
| 648 | * Check for and alert any deprecated hooks |
||
| 649 | */ |
||
| 650 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 651 | |||
| 652 | // Note how this runs at an earlier plugin_loaded hook intentionally to accomodate for other plugins. |
||
| 653 | add_action( 'plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
| 654 | add_action( 'network_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
| 655 | add_action( 'mu_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
| 656 | add_action( 'plugins_loaded', array( $this, 'late_initialization' ), 90 ); |
||
| 657 | |||
| 658 | add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) ); |
||
| 659 | |||
| 660 | add_filter( |
||
| 661 | 'jetpack_signature_check_token', |
||
| 662 | array( __CLASS__, 'verify_onboarding_token' ), |
||
| 663 | 10, |
||
| 664 | 3 |
||
| 665 | ); |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Prepare Gutenberg Editor functionality |
||
| 669 | */ |
||
| 670 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; |
||
| 671 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'init' ) ); |
||
| 672 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) ); |
||
| 673 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_extended_blocks' ), 9 ); |
||
| 674 | add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); |
||
| 675 | |||
| 676 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
| 677 | |||
| 678 | // Unlink user before deleting the user from WP.com. |
||
| 679 | add_action( 'deleted_user', array( $this, 'disconnect_user' ), 10, 1 ); |
||
| 680 | add_action( 'remove_user_from_blog', array( $this, 'disconnect_user' ), 10, 1 ); |
||
| 681 | |||
| 682 | add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 ); |
||
| 683 | |||
| 684 | add_filter( 'login_url', array( $this, 'login_url' ), 10, 2 ); |
||
| 685 | add_action( 'login_init', array( $this, 'login_init' ) ); |
||
| 686 | |||
| 687 | // Set up the REST authentication hooks. |
||
| 688 | Connection_Rest_Authentication::init(); |
||
| 689 | |||
| 690 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 691 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 692 | |||
| 693 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 20 ); |
||
| 694 | |||
| 695 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 696 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 697 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 698 | |||
| 699 | // returns HTTPS support status |
||
| 700 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
| 701 | |||
| 702 | add_action( 'wp_ajax_jetpack_connection_banner', array( $this, 'jetpack_connection_banner_callback' ) ); |
||
| 703 | |||
| 704 | add_action( 'wp_ajax_jetpack_recommendations_banner', array( 'Jetpack_Recommendations_Banner', 'ajax_callback' ) ); |
||
| 705 | |||
| 706 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 707 | |||
| 708 | /** |
||
| 709 | * These actions run checks to load additional files. |
||
| 710 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 711 | */ |
||
| 712 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 713 | add_action( 'web_stories_story_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 714 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 715 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 716 | |||
| 717 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 718 | add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 ); |
||
| 719 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 720 | |||
| 721 | add_filter( 'profile_update', array( 'Jetpack', 'user_meta_cleanup' ) ); |
||
| 722 | |||
| 723 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 724 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 725 | |||
| 726 | require_once JETPACK__PLUGIN_DIR . 'class-jetpack-pre-connection-jitms.php'; |
||
| 727 | $jetpack_jitm_messages = ( new Jetpack_Pre_Connection_JITMs() ); |
||
| 728 | add_filter( 'jetpack_pre_connection_jitms', array( $jetpack_jitm_messages, 'add_pre_connection_jitms' ) ); |
||
| 729 | |||
| 730 | /* |
||
| 731 | * If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin. |
||
| 732 | * We should make sure to only do this for front end links. |
||
| 733 | */ |
||
| 734 | if ( self::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) { |
||
| 735 | add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 ); |
||
| 736 | add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 ); |
||
| 737 | |||
| 738 | /* |
||
| 739 | * We'll shortcircuit wp_notify_postauthor and wp_notify_moderator pluggable functions |
||
| 740 | * so they point moderation links on emails to Calypso. |
||
| 741 | */ |
||
| 742 | jetpack_require_lib( 'functions.wp-notify' ); |
||
| 743 | add_filter( 'comment_notification_recipients', 'jetpack_notify_postauthor', 1, 2 ); |
||
| 744 | add_filter( 'notify_moderator', 'jetpack_notify_moderator', 1, 2 ); |
||
| 745 | } |
||
| 746 | |||
| 747 | add_action( |
||
| 748 | 'plugins_loaded', |
||
| 749 | function () { |
||
| 750 | if ( User_Agent_Info::is_mobile_app() ) { |
||
| 751 | add_filter( 'get_edit_post_link', '__return_empty_string' ); |
||
| 752 | } |
||
| 753 | } |
||
| 754 | ); |
||
| 755 | |||
| 756 | // Update the site's Jetpack plan and products from API on heartbeats. |
||
| 757 | add_action( 'jetpack_heartbeat', array( 'Jetpack_Plan', 'refresh_from_wpcom' ) ); |
||
| 758 | |||
| 759 | /** |
||
| 760 | * This is the hack to concatenate all css files into one. |
||
| 761 | * For description and reasoning see the implode_frontend_css method. |
||
| 762 | * |
||
| 763 | * Super late priority so we catch all the registered styles. |
||
| 764 | */ |
||
| 765 | if ( ! is_admin() ) { |
||
| 766 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 767 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 768 | } |
||
| 769 | |||
| 770 | /** |
||
| 771 | * These are sync actions that we need to keep track of for jitms |
||
| 772 | */ |
||
| 773 | add_filter( 'jetpack_sync_before_send_updated_option', array( $this, 'jetpack_track_last_sync_callback' ), 99 ); |
||
| 774 | |||
| 775 | // Actually push the stats on shutdown. |
||
| 776 | if ( ! has_action( 'shutdown', array( $this, 'push_stats' ) ) ) { |
||
| 777 | add_action( 'shutdown', array( $this, 'push_stats' ) ); |
||
| 778 | } |
||
| 779 | |||
| 780 | // After a successful connection. |
||
| 781 | add_action( 'jetpack_site_registered', array( $this, 'activate_default_modules_on_site_register' ) ); |
||
| 782 | add_action( 'jetpack_site_registered', array( $this, 'handle_unique_registrations_stats' ) ); |
||
| 783 | |||
| 784 | // Actions for Manager::authorize(). |
||
| 785 | add_action( 'jetpack_authorize_starting', array( $this, 'authorize_starting' ) ); |
||
| 786 | add_action( 'jetpack_authorize_ending_linked', array( $this, 'authorize_ending_linked' ) ); |
||
| 787 | add_action( 'jetpack_authorize_ending_authorized', array( $this, 'authorize_ending_authorized' ) ); |
||
| 788 | |||
| 789 | add_action( 'jetpack_client_authorize_error', array( Jetpack_Client_Server::class, 'client_authorize_error' ) ); |
||
| 790 | add_filter( 'jetpack_client_authorize_already_authorized_url', array( Jetpack_Client_Server::class, 'client_authorize_already_authorized_url' ) ); |
||
| 791 | add_action( 'jetpack_client_authorize_processing', array( Jetpack_Client_Server::class, 'client_authorize_processing' ) ); |
||
| 792 | add_filter( 'jetpack_client_authorize_fallback_url', array( Jetpack_Client_Server::class, 'client_authorize_fallback_url' ) ); |
||
| 793 | |||
| 794 | // Filters for the Manager::get_token() urls and request body. |
||
| 795 | add_filter( 'jetpack_token_redirect_url', array( __CLASS__, 'filter_connect_redirect_url' ) ); |
||
| 796 | add_filter( 'jetpack_token_request_body', array( __CLASS__, 'filter_token_request_body' ) ); |
||
| 797 | |||
| 798 | // Actions for successful reconnect. |
||
| 799 | add_action( 'jetpack_reconnection_completed', array( $this, 'reconnection_completed' ) ); |
||
| 800 | |||
| 801 | // Actions for licensing. |
||
| 802 | Licensing::instance()->initialize(); |
||
| 803 | |||
| 804 | // Filters for Sync Callables. |
||
| 805 | add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ), 10, 1 ); |
||
| 806 | add_filter( 'jetpack_sync_multisite_callable_whitelist', array( $this, 'filter_sync_multisite_callable_whitelist' ), 10, 1 ); |
||
| 807 | |||
| 808 | // Make resources use static domain when possible. |
||
| 809 | add_filter( 'jetpack_static_url', array( 'Automattic\\Jetpack\\Assets', 'staticize_subdomain' ) ); |
||
| 810 | |||
| 811 | // Validate the domain names in Jetpack development versions. |
||
| 812 | add_action( 'jetpack_pre_register', array( get_called_class(), 'registration_check_domains' ) ); |
||
| 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() { |
||
| 908 | add_action( 'plugins_loaded', array( 'Jetpack', 'load_modules' ), 100 ); |
||
| 909 | |||
| 910 | Partner::init(); |
||
| 911 | |||
| 912 | /** |
||
| 913 | * Fires when Jetpack is fully loaded and ready. This is the point where it's safe |
||
| 914 | * to instantiate classes from packages and namespaces that are managed by the Jetpack Autoloader. |
||
| 915 | * |
||
| 916 | * @since 8.1.0 |
||
| 917 | * |
||
| 918 | * @param Jetpack $jetpack the main plugin class object. |
||
| 919 | */ |
||
| 920 | do_action( 'jetpack_loaded', $this ); |
||
| 921 | |||
| 922 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
| 923 | } |
||
| 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( |
|
| 937 | $request_params, |
||
| 938 | $is_active, |
||
| 939 | $is_signed, |
||
| 940 | Jetpack_XMLRPC_Server $xmlrpc_server = null |
||
| 941 | ) { |
||
| 942 | _deprecated_function( __METHOD__, 'jetpack-7.7', 'Automattic\\Jetpack\\Connection\\Manager::setup_xmlrpc_handlers' ); |
||
| 943 | |||
| 944 | if ( ! $this->connection_manager ) { |
||
| 945 | $this->connection_manager = new Connection_Manager(); |
||
| 946 | } |
||
| 947 | |||
| 948 | return $this->connection_manager->setup_xmlrpc_handlers( |
||
| 949 | $request_params, |
||
| 950 | $is_active, |
||
| 951 | $is_signed, |
||
| 952 | $xmlrpc_server |
||
| 953 | ); |
||
| 954 | } |
||
| 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() { |
|
| 963 | _deprecated_function( __METHOD__, 'jetpack-7.7', 'Automattic\\Jetpack\\Connection\\Manager::initialize_rest_api_registration_connector' ); |
||
| 964 | |||
| 965 | if ( ! $this->connection_manager ) { |
||
| 966 | $this->connection_manager = new Connection_Manager(); |
||
| 967 | } |
||
| 968 | |||
| 969 | $this->connection_manager->initialize_rest_api_registration_connector(); |
||
| 970 | } |
||
| 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 ) { |
||
| 978 | add_filter( 'allowed_redirect_hosts', array( $this, 'allow_wpcom_domain' ) ); |
||
| 979 | } |
||
| 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 ) { |
||
| 989 | if ( empty( $domains ) ) { |
||
| 990 | $domains = array(); |
||
| 991 | } |
||
| 992 | $domains[] = 'wordpress.com'; |
||
| 993 | return array_unique( $domains ); |
||
| 994 | } |
||
| 995 | |||
| 996 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
| 997 | $post = get_post( $post_id ); |
||
| 998 | |||
| 999 | if ( empty( $post ) ) { |
||
| 1000 | return $default_url; |
||
| 1001 | } |
||
| 1002 | |||
| 1003 | $post_type = $post->post_type; |
||
| 1004 | |||
| 1005 | // Mapping the allowed CPTs on WordPress.com to corresponding paths in Calypso. |
||
| 1006 | // https://en.support.wordpress.com/custom-post-types/ |
||
| 1007 | $allowed_post_types = array( |
||
| 1008 | 'post', |
||
| 1009 | 'page', |
||
| 1010 | 'jetpack-portfolio', |
||
| 1011 | 'jetpack-testimonial', |
||
| 1012 | ); |
||
| 1013 | |||
| 1014 | if ( ! in_array( $post_type, $allowed_post_types, true ) ) { |
||
| 1015 | return $default_url; |
||
| 1016 | } |
||
| 1017 | |||
| 1018 | return Redirect::get_url( |
||
| 1019 | 'calypso-edit-' . $post_type, |
||
| 1020 | array( |
||
| 1021 | 'path' => $post_id, |
||
| 1022 | ) |
||
| 1023 | ); |
||
| 1024 | } |
||
| 1025 | |||
| 1026 | function point_edit_comment_links_to_calypso( $url ) { |
||
| 1027 | // Take the `query` key value from the URL, and parse its parts to the $query_args. `amp;c` matches the comment ID. |
||
| 1028 | wp_parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $query_args ); |
||
| 1029 | |||
| 1030 | return Redirect::get_url( |
||
| 1031 | 'calypso-edit-comment', |
||
| 1032 | array( |
||
| 1033 | 'path' => $query_args['amp;c'], |
||
| 1034 | ) |
||
| 1035 | ); |
||
| 1036 | |||
| 1037 | } |
||
| 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 ) { |
||
| 1047 | |||
| 1048 | // Jetpack Functions. |
||
| 1049 | $jetpack_callables = array( |
||
| 1050 | 'single_user_site' => array( 'Jetpack', 'is_single_user_site' ), |
||
| 1051 | 'updates' => array( 'Jetpack', 'get_updates' ), |
||
| 1052 | 'active_modules' => array( 'Jetpack', 'get_active_modules' ), |
||
| 1053 | 'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins. |
||
| 1054 | ); |
||
| 1055 | $callables = array_merge( $callables, $jetpack_callables ); |
||
| 1056 | |||
| 1057 | // Jetpack_SSO_Helpers. |
||
| 1058 | if ( include_once JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php' ) { |
||
| 1059 | $sso_helpers = array( |
||
| 1060 | 'sso_is_two_step_required' => array( 'Jetpack_SSO_Helpers', 'is_two_step_required' ), |
||
| 1061 | 'sso_should_hide_login_form' => array( 'Jetpack_SSO_Helpers', 'should_hide_login_form' ), |
||
| 1062 | 'sso_match_by_email' => array( 'Jetpack_SSO_Helpers', 'match_by_email' ), |
||
| 1063 | 'sso_new_user_override' => array( 'Jetpack_SSO_Helpers', 'new_user_override' ), |
||
| 1064 | 'sso_bypass_default_login_form' => array( 'Jetpack_SSO_Helpers', 'bypass_login_forward_wpcom' ), |
||
| 1065 | ); |
||
| 1066 | $callables = array_merge( $callables, $sso_helpers ); |
||
| 1067 | } |
||
| 1068 | |||
| 1069 | return $callables; |
||
| 1070 | } |
||
| 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 ) { |
||
| 1080 | |||
| 1081 | // Jetpack Funtions. |
||
| 1082 | $jetpack_multisite_callables = array( |
||
| 1083 | 'network_name' => array( 'Jetpack', 'network_name' ), |
||
| 1084 | 'network_allow_new_registrations' => array( 'Jetpack', 'network_allow_new_registrations' ), |
||
| 1085 | 'network_add_new_users' => array( 'Jetpack', 'network_add_new_users' ), |
||
| 1086 | 'network_site_upload_space' => array( 'Jetpack', 'network_site_upload_space' ), |
||
| 1087 | 'network_upload_file_types' => array( 'Jetpack', 'network_upload_file_types' ), |
||
| 1088 | 'network_enable_administration_menus' => array( 'Jetpack', 'network_enable_administration_menus' ), |
||
| 1089 | ); |
||
| 1090 | $callables = array_merge( $callables, $jetpack_multisite_callables ); |
||
| 1091 | |||
| 1092 | return $callables; |
||
| 1093 | } |
||
| 1094 | |||
| 1095 | function jetpack_track_last_sync_callback( $params ) { |
||
| 1096 | /** |
||
| 1097 | * This filter is documented in the Automattic\Jetpack\JITMS\Post_Connection_JITM class. |
||
| 1098 | */ |
||
| 1099 | if ( ! apply_filters( 'jetpack_just_in_time_msg_cache', true ) ) { |
||
| 1100 | return $params; |
||
| 1101 | } |
||
| 1102 | |||
| 1103 | if ( is_array( $params ) && isset( $params[0] ) ) { |
||
| 1104 | $option = $params[0]; |
||
| 1105 | if ( 'active_plugins' === $option ) { |
||
| 1106 | // use the cache if we can, but not terribly important if it gets evicted |
||
| 1107 | set_transient( 'jetpack_last_plugin_sync', time(), HOUR_IN_SECONDS ); |
||
| 1108 | } |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | return $params; |
||
| 1112 | } |
||
| 1113 | |||
| 1114 | function jetpack_connection_banner_callback() { |
||
| 1128 | |||
| 1129 | /** |
||
| 1130 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
| 1131 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
| 1132 | * ensure that Core and other plugins' methods are not exposed. |
||
| 1133 | * |
||
| 1134 | * @deprecated since 7.7.0 |
||
| 1135 | * @see Automattic\Jetpack\Connection\Manager::remove_non_jetpack_xmlrpc_methods() |
||
| 1136 | * |
||
| 1137 | * @param array $methods A list of registered WordPress XMLRPC methods. |
||
| 1138 | * @return array Filtered $methods |
||
| 1139 | */ |
||
| 1140 | View Code Duplication | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
|
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
| 1152 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
| 1153 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
| 1154 | * which is accessible via a different URI. Most of the below is copied directly |
||
| 1155 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
| 1156 | * |
||
| 1157 | * @deprecated since 7.7.0 |
||
| 1158 | * @see Automattic\Jetpack\Connection\Manager::alternate_xmlrpc() |
||
| 1159 | */ |
||
| 1160 | View Code Duplication | public function alternate_xmlrpc() { |
|
| 1169 | |||
| 1170 | /** |
||
| 1171 | * The callback for the JITM ajax requests. |
||
| 1172 | * |
||
| 1173 | * @deprecated since 7.9.0 |
||
| 1174 | */ |
||
| 1175 | function jetpack_jitm_ajax_callback() { |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 1181 | */ |
||
| 1182 | function push_stats() { |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Sets the Jetpack custom capabilities. |
||
| 1190 | * |
||
| 1191 | * @param string[] $caps Array of the user's capabilities. |
||
| 1192 | * @param string $cap Capability name. |
||
| 1193 | * @param int $user_id The user ID. |
||
| 1194 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
| 1195 | */ |
||
| 1196 | public function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 1197 | switch ( $cap ) { |
||
| 1198 | case 'jetpack_manage_modules': |
||
| 1199 | case 'jetpack_activate_modules': |
||
| 1200 | case 'jetpack_deactivate_modules': |
||
| 1201 | $caps = array( 'manage_options' ); |
||
| 1202 | break; |
||
| 1203 | case 'jetpack_configure_modules': |
||
| 1204 | $caps = array( 'manage_options' ); |
||
| 1205 | break; |
||
| 1206 | case 'jetpack_manage_autoupdates': |
||
| 1207 | $caps = array( |
||
| 1208 | 'manage_options', |
||
| 1209 | 'update_plugins', |
||
| 1210 | ); |
||
| 1211 | break; |
||
| 1212 | case 'jetpack_network_admin_page': |
||
| 1213 | case 'jetpack_network_settings_page': |
||
| 1214 | $caps = array( 'manage_network_plugins' ); |
||
| 1215 | break; |
||
| 1216 | case 'jetpack_network_sites_page': |
||
| 1217 | $caps = array( 'manage_sites' ); |
||
| 1218 | break; |
||
| 1219 | View Code Duplication | case 'jetpack_admin_page': |
|
| 1220 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
| 1221 | if ( $is_offline_mode ) { |
||
| 1222 | $caps = array( 'manage_options' ); |
||
| 1223 | break; |
||
| 1224 | } else { |
||
| 1225 | $caps = array( 'read' ); |
||
| 1226 | } |
||
| 1227 | break; |
||
| 1228 | } |
||
| 1229 | return $caps; |
||
| 1230 | } |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Require a Jetpack authentication. |
||
| 1234 | * |
||
| 1235 | * @deprecated since 7.7.0 |
||
| 1236 | * @see Automattic\Jetpack\Connection\Manager::require_jetpack_authentication() |
||
| 1237 | */ |
||
| 1238 | View Code Duplication | public function require_jetpack_authentication() { |
|
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 1250 | * |
||
| 1251 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 1252 | * @action wp_loaded |
||
| 1253 | * @return null |
||
| 1254 | */ |
||
| 1255 | public function register_assets() { |
||
| 1256 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 1257 | wp_register_script( |
||
| 1258 | 'jetpack-gallery-settings', |
||
| 1259 | Assets::get_file_url_for_environment( '_inc/build/gallery-settings.min.js', '_inc/gallery-settings.js' ), |
||
| 1260 | array( 'media-views' ), |
||
| 1261 | '20121225' |
||
| 1262 | ); |
||
| 1263 | } |
||
| 1264 | |||
| 1265 | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
||
| 1266 | wp_register_script( |
||
| 1267 | 'jetpack-twitter-timeline', |
||
| 1268 | Assets::get_file_url_for_environment( '_inc/build/twitter-timeline.min.js', '_inc/twitter-timeline.js' ), |
||
| 1269 | array( 'jquery' ), |
||
| 1270 | '4.0.0', |
||
| 1271 | true |
||
| 1272 | ); |
||
| 1273 | } |
||
| 1274 | |||
| 1275 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 1276 | wp_register_script( |
||
| 1277 | 'jetpack-facebook-embed', |
||
| 1278 | Assets::get_file_url_for_environment( '_inc/build/facebook-embed.min.js', '_inc/facebook-embed.js' ), |
||
| 1279 | array(), |
||
| 1280 | null, |
||
| 1281 | true |
||
| 1282 | ); |
||
| 1283 | |||
| 1284 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 1285 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 1286 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 1287 | $fb_app_id = ''; |
||
| 1288 | } |
||
| 1289 | wp_localize_script( |
||
| 1290 | 'jetpack-facebook-embed', |
||
| 1291 | 'jpfbembed', |
||
| 1292 | array( |
||
| 1293 | 'appid' => $fb_app_id, |
||
| 1294 | 'locale' => $this->get_locale(), |
||
| 1295 | ) |
||
| 1296 | ); |
||
| 1297 | } |
||
| 1298 | |||
| 1299 | /** |
||
| 1300 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 1301 | * the hook may have already fired by this point. |
||
| 1302 | * So, let's just trigger it manually. |
||
| 1303 | */ |
||
| 1304 | require_once JETPACK__PLUGIN_DIR . '_inc/genericons.php'; |
||
| 1305 | jetpack_register_genericons(); |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * Register the social logos |
||
| 1309 | */ |
||
| 1310 | require_once JETPACK__PLUGIN_DIR . '_inc/social-logos.php'; |
||
| 1311 | jetpack_register_social_logos(); |
||
| 1312 | |||
| 1313 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) { |
|
| 1314 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 1315 | } |
||
| 1316 | } |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Guess locale from language code. |
||
| 1320 | * |
||
| 1321 | * @param string $lang Language code. |
||
| 1322 | * @return string|bool |
||
| 1323 | */ |
||
| 1324 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Get the locale. |
||
| 1366 | * |
||
| 1367 | * @return string|bool |
||
| 1368 | */ |
||
| 1369 | function get_locale() { |
||
| 1378 | |||
| 1379 | /** |
||
| 1380 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 1381 | * |
||
| 1382 | * @param bool $option |
||
| 1383 | * @return string |
||
| 1384 | */ |
||
| 1385 | public function jetpack_main_network_site_option( $option ) { |
||
| 1388 | /** |
||
| 1389 | * Network Name. |
||
| 1390 | */ |
||
| 1391 | static function network_name( $option = null ) { |
||
| 1395 | /** |
||
| 1396 | * Does the network allow new user and site registrations. |
||
| 1397 | * |
||
| 1398 | * @return string |
||
| 1399 | */ |
||
| 1400 | static function network_allow_new_registrations( $option = null ) { |
||
| 1403 | /** |
||
| 1404 | * Does the network allow admins to add new users. |
||
| 1405 | * |
||
| 1406 | * @return boolian |
||
| 1407 | */ |
||
| 1408 | static function network_add_new_users( $option = null ) { |
||
| 1411 | /** |
||
| 1412 | * File upload psace left per site in MB. |
||
| 1413 | * -1 means NO LIMIT. |
||
| 1414 | * |
||
| 1415 | * @return number |
||
| 1416 | */ |
||
| 1417 | static function network_site_upload_space( $option = null ) { |
||
| 1421 | |||
| 1422 | /** |
||
| 1423 | * Network allowed file types. |
||
| 1424 | * |
||
| 1425 | * @return string |
||
| 1426 | */ |
||
| 1427 | static function network_upload_file_types( $option = null ) { |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Maximum file upload size set by the network. |
||
| 1433 | * |
||
| 1434 | * @return number |
||
| 1435 | */ |
||
| 1436 | static function network_max_upload_file_size( $option = null ) { |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Lets us know if a site allows admins to manage the network. |
||
| 1443 | * |
||
| 1444 | * @return array |
||
| 1445 | */ |
||
| 1446 | static function network_enable_administration_menus( $option = null ) { |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
| 1452 | * jetpack_other_linked_admins transient. |
||
| 1453 | * |
||
| 1454 | * @since 4.3.2 |
||
| 1455 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
| 1456 | * |
||
| 1457 | * @param int $user_id The user ID whose role changed. |
||
| 1458 | * @param string $role The new role. |
||
| 1459 | * @param array $old_roles An array of the user's previous roles. |
||
| 1460 | */ |
||
| 1461 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Checks to see if there are any other users available to become primary |
||
| 1472 | * Users must both: |
||
| 1473 | * - Be linked to wpcom |
||
| 1474 | * - Be an admin |
||
| 1475 | * |
||
| 1476 | * @return mixed False if no other users are linked, Int if there are. |
||
| 1477 | */ |
||
| 1478 | static function get_other_linked_admins() { |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Return whether we are dealing with a multi network setup or not. |
||
| 1509 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 1510 | * the result is false since when is_main_network_option return false it cases |
||
| 1511 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 1512 | * database which could be set to anything as opposed to what this function returns. |
||
| 1513 | * |
||
| 1514 | * @param bool $option |
||
| 1515 | * |
||
| 1516 | * @return boolean |
||
| 1517 | */ |
||
| 1518 | public function is_main_network_option( $option ) { |
||
| 1522 | |||
| 1523 | /** |
||
| 1524 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 1525 | * |
||
| 1526 | * @param string $option |
||
| 1527 | * @return boolean |
||
| 1528 | */ |
||
| 1529 | public function is_multisite( $option ) { |
||
| 1532 | |||
| 1533 | /** |
||
| 1534 | * Implemented since there is no core is multi network function |
||
| 1535 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 1536 | * |
||
| 1537 | * @since 3.3 |
||
| 1538 | * @return boolean |
||
| 1539 | */ |
||
| 1540 | View Code Duplication | public static function is_multi_network() { |
|
| 1555 | |||
| 1556 | /** |
||
| 1557 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1558 | * |
||
| 1559 | * @return null |
||
| 1560 | */ |
||
| 1561 | function update_jetpack_main_network_site_option() { |
||
| 1564 | /** |
||
| 1565 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1566 | */ |
||
| 1567 | function update_jetpack_network_settings() { |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Get back if the current site is single user site. |
||
| 1574 | * |
||
| 1575 | * @return bool |
||
| 1576 | */ |
||
| 1577 | View Code Duplication | public static function is_single_user_site() { |
|
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Returns true if the site has file write access false otherwise. |
||
| 1589 | * |
||
| 1590 | * @return string ( '1' | '0' ) |
||
| 1591 | **/ |
||
| 1592 | public static function file_system_write_access() { |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * Finds out if a site is using a version control system. |
||
| 1615 | * |
||
| 1616 | * @return string ( '1' | '0' ) |
||
| 1617 | **/ |
||
| 1618 | public static function is_version_controlled() { |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * Determines whether the current theme supports featured images or not. |
||
| 1625 | * |
||
| 1626 | * @return string ( '1' | '0' ) |
||
| 1627 | */ |
||
| 1628 | public static function featured_images_enabled() { |
||
| 1632 | |||
| 1633 | /** |
||
| 1634 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
| 1635 | * |
||
| 1636 | * @deprecated 4.7 use get_avatar_url instead. |
||
| 1637 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 1638 | * @param int $size Size of the avatar image |
||
| 1639 | * @param string $default URL to a default image to use if no avatar is available |
||
| 1640 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 1641 | * |
||
| 1642 | * @return array |
||
| 1643 | */ |
||
| 1644 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 1655 | // phpcs:disable WordPress.WP.CapitalPDangit.Misspelled |
||
| 1656 | /** |
||
| 1657 | * jetpack_updates is saved in the following schema: |
||
| 1658 | * |
||
| 1659 | * array ( |
||
| 1660 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1661 | * 'themes' => (int) Number of theme updates available. |
||
| 1662 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1663 | * 'translations' => (int) Number of translation updates available. |
||
| 1664 | * 'total' => (int) Total of all available updates. |
||
| 1665 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1666 | * ) |
||
| 1667 | * |
||
| 1668 | * @return array |
||
| 1669 | */ |
||
| 1670 | public static function get_updates() { |
||
| 1687 | // phpcs:enable |
||
| 1688 | |||
| 1689 | public static function get_update_details() { |
||
| 1697 | |||
| 1698 | public static function refresh_update_data() { |
||
| 1702 | |||
| 1703 | public static function refresh_theme_data() { |
||
| 1706 | |||
| 1707 | /** |
||
| 1708 | * Is Jetpack active? |
||
| 1709 | * The method only checks if there's an existing token for the master user. It doesn't validate the token. |
||
| 1710 | * |
||
| 1711 | * This method is deprecated since 9.6.0. Please use one of the methods provided by the Manager class in the Connection package, |
||
| 1712 | * or Jetpack::is_connection_ready if you want to know when the Jetpack plugin starts considering the connection ready to be used. |
||
| 1713 | * |
||
| 1714 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
| 1715 | * |
||
| 1716 | * @deprecated 9.6.0 |
||
| 1717 | * |
||
| 1718 | * @return bool |
||
| 1719 | */ |
||
| 1720 | public static function is_active() { |
||
| 1721 | return self::connection()->is_active(); |
||
| 1722 | } |
||
| 1723 | |||
| 1724 | /** |
||
| 1725 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI |
||
| 1726 | * |
||
| 1727 | * This method was introduced just before the release of the possibility to use Jetpack without a user connection, while |
||
| 1728 | * it was available only when no_user_testing_mode was enabled. In the near future, this will return is_connected for all |
||
| 1729 | * users and this option will be available by default for everybody. |
||
| 1730 | * |
||
| 1731 | * @since 9.6.0 |
||
| 1732 | * @since 9.7.0 returns is_connected in all cases and adds filter to the returned value |
||
| 1733 | * |
||
| 1734 | * @return bool is the site connection ready to be used? |
||
| 1735 | */ |
||
| 1736 | public static function is_connection_ready() { |
||
| 1737 | /** |
||
| 1738 | * Allows filtering whether the connection is ready to be used. If true, this will enable the Jetpack UI and modules |
||
| 1739 | * |
||
| 1740 | * Modules will be enabled depending on the connection status and if the module requires a connection or user connection. |
||
| 1741 | * |
||
| 1742 | * @since 9.7.0 |
||
| 1743 | * |
||
| 1744 | * @param bool $is_connection_ready Is the connection ready? |
||
| 1745 | * @param Automattic\Jetpack\Connection\Manager $connection_manager Instance of the Manager class, can be used to check the connection status. |
||
| 1746 | */ |
||
| 1747 | return apply_filters( 'jetpack_is_connection_ready', self::connection()->is_connected(), self::connection() ); |
||
| 1748 | } |
||
| 1749 | |||
| 1750 | /** |
||
| 1751 | * Make an API call to WordPress.com for plan status |
||
| 1752 | * |
||
| 1753 | * @deprecated 7.2.0 Use Jetpack_Plan::refresh_from_wpcom. |
||
| 1754 | * |
||
| 1755 | * @return bool True if plan is updated, false if no update |
||
| 1756 | */ |
||
| 1757 | public static function refresh_active_plan_from_wpcom() { |
||
| 1761 | |||
| 1762 | /** |
||
| 1763 | * Get the plan that this Jetpack site is currently using |
||
| 1764 | * |
||
| 1765 | * @deprecated 7.2.0 Use Jetpack_Plan::get. |
||
| 1766 | * @return array Active Jetpack plan details. |
||
| 1767 | */ |
||
| 1768 | public static function get_active_plan() { |
||
| 1772 | |||
| 1773 | /** |
||
| 1774 | * Determine whether the active plan supports a particular feature |
||
| 1775 | * |
||
| 1776 | * @deprecated 7.2.0 Use Jetpack_Plan::supports. |
||
| 1777 | * @return bool True if plan supports feature, false if not. |
||
| 1778 | */ |
||
| 1779 | public static function active_plan_supports( $feature ) { |
||
| 1783 | |||
| 1784 | /** |
||
| 1785 | * Deprecated: Is Jetpack in development (offline) mode? |
||
| 1786 | * |
||
| 1787 | * This static method is being left here intentionally without the use of _deprecated_function(), as other plugins |
||
| 1788 | * and themes still use it, and we do not want to flood them with notices. |
||
| 1789 | * |
||
| 1790 | * Please use Automattic\Jetpack\Status()->is_offline_mode() instead. |
||
| 1791 | * |
||
| 1792 | * @deprecated since 8.0. |
||
| 1793 | */ |
||
| 1794 | public static function is_development_mode() { |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * Whether the site is currently onboarding or not. |
||
| 1801 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
| 1802 | * |
||
| 1803 | * @since 5.8 |
||
| 1804 | * |
||
| 1805 | * @access public |
||
| 1806 | * @static |
||
| 1807 | * |
||
| 1808 | * @return bool True if the site is currently onboarding, false otherwise |
||
| 1809 | */ |
||
| 1810 | public static function is_onboarding() { |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Determines reason for Jetpack offline mode. |
||
| 1816 | */ |
||
| 1817 | public static function development_mode_trigger_text() { |
||
| 1840 | /** |
||
| 1841 | * Get Jetpack offline mode notice text and notice class. |
||
| 1842 | * |
||
| 1843 | * Mirrors the checks made in Automattic\Jetpack\Status->is_offline_mode |
||
| 1844 | */ |
||
| 1845 | public static function show_development_mode_notice() { |
||
| 1873 | |||
| 1874 | /** |
||
| 1875 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1876 | */ |
||
| 1877 | public static function is_development_version() { |
||
| 1892 | |||
| 1893 | /** |
||
| 1894 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1895 | */ |
||
| 1896 | public static function is_user_connected( $user_id = false ) { |
||
| 1900 | |||
| 1901 | /** |
||
| 1902 | * Get the wpcom user data of the current|specified connected user. |
||
| 1903 | */ |
||
| 1904 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * Get the wpcom email of the current|specified connected user. |
||
| 1911 | */ |
||
| 1912 | public static function get_connected_user_email( $user_id = null ) { |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Get the wpcom email of the master user. |
||
| 1931 | */ |
||
| 1932 | public static function get_master_user_email() { |
||
| 1939 | |||
| 1940 | /** |
||
| 1941 | * Whether the current user is the connection owner. |
||
| 1942 | * |
||
| 1943 | * @deprecated since 7.7 |
||
| 1944 | * |
||
| 1945 | * @return bool Whether the current user is the connection owner. |
||
| 1946 | */ |
||
| 1947 | public function current_user_is_connection_owner() { |
||
| 1951 | |||
| 1952 | /** |
||
| 1953 | * Gets current user IP address. |
||
| 1954 | * |
||
| 1955 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
| 1956 | * |
||
| 1957 | * @return string Current user IP address. |
||
| 1958 | */ |
||
| 1959 | public static function current_user_ip( $check_all_headers = false ) { |
||
| 1979 | |||
| 1980 | /** |
||
| 1981 | * Synchronize connected user role changes |
||
| 1982 | */ |
||
| 1983 | function user_role_change( $user_id ) { |
||
| 1987 | |||
| 1988 | /** |
||
| 1989 | * Loads the currently active modules. |
||
| 1990 | */ |
||
| 1991 | public static function load_modules() { |
||
| 1992 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
| 1993 | if ( |
||
| 1994 | ! self::is_connection_ready() |
||
| 1995 | && ! $is_offline_mode |
||
| 1996 | && ! self::is_onboarding() |
||
| 1997 | && ( |
||
| 1998 | ! is_multisite() |
||
| 1999 | || ! get_site_option( 'jetpack_protect_active' ) |
||
| 2000 | ) |
||
| 2001 | ) { |
||
| 2002 | return; |
||
| 2003 | } |
||
| 2004 | |||
| 2005 | $version = Jetpack_Options::get_option( 'version' ); |
||
| 2006 | View Code Duplication | if ( ! $version ) { |
|
| 2007 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
| 2008 | /** This action is documented in class.jetpack.php */ |
||
| 2009 | do_action( 'updating_jetpack_version', $version, false ); |
||
| 2010 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
| 2011 | } |
||
| 2012 | list( $version ) = explode( ':', $version ); |
||
| 2013 | |||
| 2014 | $modules = array_filter( self::get_active_modules(), array( 'Jetpack', 'is_module' ) ); |
||
| 2015 | |||
| 2016 | $modules_data = array(); |
||
| 2017 | |||
| 2018 | // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check. |
||
| 2019 | if ( version_compare( $version, JETPACK__VERSION, '<' ) ) { |
||
| 2020 | $updated_modules = array(); |
||
| 2021 | foreach ( $modules as $module ) { |
||
| 2022 | $modules_data[ $module ] = self::get_module( $module ); |
||
| 2023 | if ( ! isset( $modules_data[ $module ]['changed'] ) ) { |
||
| 2024 | continue; |
||
| 2025 | } |
||
| 2026 | |||
| 2027 | if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) { |
||
| 2028 | continue; |
||
| 2029 | } |
||
| 2030 | |||
| 2031 | $updated_modules[] = $module; |
||
| 2032 | } |
||
| 2033 | |||
| 2034 | $modules = array_diff( $modules, $updated_modules ); |
||
| 2035 | } |
||
| 2036 | |||
| 2037 | $is_userless = self::connection()->is_userless(); |
||
| 2038 | |||
| 2039 | foreach ( $modules as $index => $module ) { |
||
| 2040 | // If we're in offline/user-less mode, disable modules requiring a connection/user connection. |
||
| 2041 | if ( $is_offline_mode || $is_userless ) { |
||
| 2042 | // Prime the pump if we need to |
||
| 2043 | if ( empty( $modules_data[ $module ] ) ) { |
||
| 2044 | $modules_data[ $module ] = self::get_module( $module ); |
||
| 2045 | } |
||
| 2046 | // If the module requires a connection, but we're in local mode, don't include it. |
||
| 2047 | if ( $is_offline_mode && $modules_data[ $module ]['requires_connection'] ) { |
||
| 2048 | continue; |
||
| 2049 | } |
||
| 2050 | |||
| 2051 | if ( $is_userless && $modules_data[ $module ]['requires_user_connection'] ) { |
||
| 2052 | continue; |
||
| 2053 | } |
||
| 2054 | } |
||
| 2055 | |||
| 2056 | if ( did_action( 'jetpack_module_loaded_' . $module ) ) { |
||
| 2057 | continue; |
||
| 2058 | } |
||
| 2059 | |||
| 2060 | if ( ! include_once self::get_module_path( $module ) ) { |
||
| 2061 | unset( $modules[ $index ] ); |
||
| 2062 | self::update_active_modules( array_values( $modules ) ); |
||
| 2063 | continue; |
||
| 2064 | } |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Fires when a specific module is loaded. |
||
| 2068 | * The dynamic part of the hook, $module, is the module slug. |
||
| 2069 | * |
||
| 2070 | * @since 1.1.0 |
||
| 2071 | */ |
||
| 2072 | do_action( 'jetpack_module_loaded_' . $module ); |
||
| 2073 | } |
||
| 2074 | |||
| 2075 | /** |
||
| 2076 | * Fires when all the modules are loaded. |
||
| 2077 | * |
||
| 2078 | * @since 1.1.0 |
||
| 2079 | */ |
||
| 2080 | do_action( 'jetpack_modules_loaded' ); |
||
| 2081 | |||
| 2082 | // Load module-specific code that is needed even when a module isn't active. Loaded here because code contained therein may need actions such as setup_theme. |
||
| 2083 | require_once JETPACK__PLUGIN_DIR . 'modules/module-extras.php'; |
||
| 2084 | } |
||
| 2085 | |||
| 2086 | /** |
||
| 2087 | * Check if Jetpack's REST API compat file should be included |
||
| 2088 | * |
||
| 2089 | * @action plugins_loaded |
||
| 2090 | * @return null |
||
| 2091 | */ |
||
| 2092 | public function check_rest_api_compat() { |
||
| 2106 | |||
| 2107 | /** |
||
| 2108 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 2109 | * traditionally activated or network activated. |
||
| 2110 | * |
||
| 2111 | * @todo Store the result in core's object cache maybe? |
||
| 2112 | */ |
||
| 2113 | public static function get_active_plugins() { |
||
| 2129 | |||
| 2130 | /** |
||
| 2131 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 2132 | * |
||
| 2133 | * @since 3.8.1 |
||
| 2134 | * |
||
| 2135 | * @return array Array of plugin data |
||
| 2136 | */ |
||
| 2137 | public static function get_parsed_plugin_data() { |
||
| 2158 | |||
| 2159 | /** |
||
| 2160 | * Gets and parses theme data to send with the heartbeat data |
||
| 2161 | * |
||
| 2162 | * @since 3.8.1 |
||
| 2163 | * |
||
| 2164 | * @return array Array of theme data |
||
| 2165 | */ |
||
| 2166 | public static function get_parsed_theme_data() { |
||
| 2188 | |||
| 2189 | /** |
||
| 2190 | * Checks whether a specific plugin is active. |
||
| 2191 | * |
||
| 2192 | * We don't want to store these in a static variable, in case |
||
| 2193 | * there are switch_to_blog() calls involved. |
||
| 2194 | */ |
||
| 2195 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 2198 | |||
| 2199 | /** |
||
| 2200 | * Check if Jetpack's Open Graph tags should be used. |
||
| 2201 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 2202 | * |
||
| 2203 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 2204 | * @action plugins_loaded |
||
| 2205 | * @return null |
||
| 2206 | */ |
||
| 2207 | public function check_open_graph() { |
||
| 2234 | |||
| 2235 | /** |
||
| 2236 | * Check if Jetpack's Twitter tags should be used. |
||
| 2237 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 2238 | * |
||
| 2239 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 2240 | * @action plugins_loaded |
||
| 2241 | * @return null |
||
| 2242 | */ |
||
| 2243 | public function check_twitter_tags() { |
||
| 2267 | |||
| 2268 | /** |
||
| 2269 | * Allows plugins to submit security reports. |
||
| 2270 | * |
||
| 2271 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 2272 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 2273 | * @param array $args See definitions above |
||
| 2274 | */ |
||
| 2275 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 2278 | |||
| 2279 | /* Jetpack Options API */ |
||
| 2280 | |||
| 2281 | public static function get_option_names( $type = 'compact' ) { |
||
| 2284 | |||
| 2285 | /** |
||
| 2286 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 2287 | * |
||
| 2288 | * @param string $name Option name |
||
| 2289 | * @param mixed $default (optional) |
||
| 2290 | */ |
||
| 2291 | public static function get_option( $name, $default = false ) { |
||
| 2294 | |||
| 2295 | /** |
||
| 2296 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 2297 | * |
||
| 2298 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 2299 | * @param string $name Option name |
||
| 2300 | * @param mixed $value Option value |
||
| 2301 | */ |
||
| 2302 | public static function update_option( $name, $value ) { |
||
| 2306 | |||
| 2307 | /** |
||
| 2308 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 2309 | * |
||
| 2310 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 2311 | * @param array $array array( option name => option value, ... ) |
||
| 2312 | */ |
||
| 2313 | public static function update_options( $array ) { |
||
| 2317 | |||
| 2318 | /** |
||
| 2319 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 2320 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 2321 | * |
||
| 2322 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 2323 | * @param string|array $names |
||
| 2324 | */ |
||
| 2325 | public static function delete_option( $names ) { |
||
| 2329 | |||
| 2330 | /** |
||
| 2331 | * Enters a user token into the user_tokens option |
||
| 2332 | * |
||
| 2333 | * @deprecated 8.0 Use Automattic\Jetpack\Connection\Tokens->update_user_token() instead. |
||
| 2334 | * |
||
| 2335 | * @param int $user_id The user id. |
||
| 2336 | * @param string $token The user token. |
||
| 2337 | * @param bool $is_master_user Whether the user is the master user. |
||
| 2338 | * @return bool |
||
| 2339 | */ |
||
| 2340 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 2344 | |||
| 2345 | /** |
||
| 2346 | * Returns an array of all PHP files in the specified absolute path. |
||
| 2347 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 2348 | * |
||
| 2349 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 2350 | * @return array Array of absolute paths to the PHP files. |
||
| 2351 | */ |
||
| 2352 | public static function glob_php( $absolute_path ) { |
||
| 2381 | |||
| 2382 | public static function activate_new_modules( $redirect = false ) { |
||
| 2441 | |||
| 2442 | /** |
||
| 2443 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 2444 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 2445 | * |
||
| 2446 | * @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter. |
||
| 2447 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
| 2448 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
| 2449 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
| 2450 | * |
||
| 2451 | * @return array $modules Array of module slugs |
||
| 2452 | */ |
||
| 2453 | public static function get_available_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
| 2525 | |||
| 2526 | /** |
||
| 2527 | * Get default modules loaded on activation. |
||
| 2528 | * |
||
| 2529 | * @param bool|string $min_version Onlu return modules introduced in this version or later. Default is false, do not filter. |
||
| 2530 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
| 2531 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
| 2532 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
| 2533 | * |
||
| 2534 | * @return array $modules Array of module slugs |
||
| 2535 | */ |
||
| 2536 | public static function get_default_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
| 2569 | |||
| 2570 | /** |
||
| 2571 | * Checks activated modules during auto-activation to determine |
||
| 2572 | * if any of those modules are being deprecated. If so, close |
||
| 2573 | * them out, and add any replacement modules. |
||
| 2574 | * |
||
| 2575 | * Runs at priority 99 by default. |
||
| 2576 | * |
||
| 2577 | * This is run late, so that it can still activate a module if |
||
| 2578 | * the new module is a replacement for another that the user |
||
| 2579 | * currently has active, even if something at the normal priority |
||
| 2580 | * would kibosh everything. |
||
| 2581 | * |
||
| 2582 | * @since 2.6 |
||
| 2583 | * @uses jetpack_get_default_modules filter |
||
| 2584 | * @param array $modules |
||
| 2585 | * @return array |
||
| 2586 | */ |
||
| 2587 | function handle_deprecated_modules( $modules ) { |
||
| 2614 | |||
| 2615 | /** |
||
| 2616 | * Checks activated plugins during auto-activation to determine |
||
| 2617 | * if any of those plugins are in the list with a corresponding module |
||
| 2618 | * that is not compatible with the plugin. The module will not be allowed |
||
| 2619 | * to auto-activate. |
||
| 2620 | * |
||
| 2621 | * @since 2.6 |
||
| 2622 | * @uses jetpack_get_default_modules filter |
||
| 2623 | * @param array $modules |
||
| 2624 | * @return array |
||
| 2625 | */ |
||
| 2626 | function filter_default_modules( $modules ) { |
||
| 2650 | |||
| 2651 | /** |
||
| 2652 | * Extract a module's slug from its full path. |
||
| 2653 | */ |
||
| 2654 | public static function get_module_slug( $file ) { |
||
| 2657 | |||
| 2658 | /** |
||
| 2659 | * Generate a module's path from its slug. |
||
| 2660 | */ |
||
| 2661 | public static function get_module_path( $slug ) { |
||
| 2672 | |||
| 2673 | /** |
||
| 2674 | * Load module data from module file. Headers differ from WordPress |
||
| 2675 | * plugin headers to avoid them being identified as standalone |
||
| 2676 | * plugins on the WordPress plugins page. |
||
| 2677 | */ |
||
| 2678 | public static function get_module( $module ) { |
||
| 2778 | |||
| 2779 | /** |
||
| 2780 | * Like core's get_file_data implementation, but caches the result. |
||
| 2781 | */ |
||
| 2782 | public static function get_file_data( $file, $headers ) { |
||
| 2815 | |||
| 2816 | /** |
||
| 2817 | * Return translated module tag. |
||
| 2818 | * |
||
| 2819 | * @param string $tag Tag as it appears in each module heading. |
||
| 2820 | * |
||
| 2821 | * @return mixed |
||
| 2822 | */ |
||
| 2823 | public static function translate_module_tag( $tag ) { |
||
| 2826 | |||
| 2827 | /** |
||
| 2828 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2829 | * |
||
| 2830 | * @since 3.9.2 |
||
| 2831 | * |
||
| 2832 | * @param array $modules |
||
| 2833 | * |
||
| 2834 | * @return string|void |
||
| 2835 | */ |
||
| 2836 | public static function get_translated_modules( $modules ) { |
||
| 2849 | |||
| 2850 | /** |
||
| 2851 | * Get a list of activated modules as an array of module slugs. |
||
| 2852 | */ |
||
| 2853 | public static function get_active_modules() { |
||
| 2885 | |||
| 2886 | /** |
||
| 2887 | * Check whether or not a Jetpack module is active. |
||
| 2888 | * |
||
| 2889 | * @param string $module The slug of a Jetpack module. |
||
| 2890 | * @return bool |
||
| 2891 | * |
||
| 2892 | * @static |
||
| 2893 | */ |
||
| 2894 | public static function is_module_active( $module ) { |
||
| 2897 | |||
| 2898 | public static function is_module( $module ) { |
||
| 2901 | |||
| 2902 | /** |
||
| 2903 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2904 | * |
||
| 2905 | * @param bool $catch True to start catching, False to stop. |
||
| 2906 | * |
||
| 2907 | * @static |
||
| 2908 | */ |
||
| 2909 | public static function catch_errors( $catch ) { |
||
| 2922 | |||
| 2923 | /** |
||
| 2924 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2925 | */ |
||
| 2926 | public static function catch_errors_on_shutdown() { |
||
| 2929 | |||
| 2930 | /** |
||
| 2931 | * Rewrite any string to make paths easier to read. |
||
| 2932 | * |
||
| 2933 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
| 2934 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
| 2935 | * |
||
| 2936 | * @param $string |
||
| 2937 | * @return mixed |
||
| 2938 | */ |
||
| 2939 | public static function alias_directories( $string ) { |
||
| 2947 | |||
| 2948 | public static function activate_default_modules( |
||
| 3120 | |||
| 3121 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 3214 | |||
| 3215 | function activate_module_actions( $module ) { |
||
| 3218 | |||
| 3219 | public static function deactivate_module( $module ) { |
||
| 3236 | |||
| 3237 | public static function enable_module_configurable( $module ) { |
||
| 3241 | |||
| 3242 | /** |
||
| 3243 | * Composes a module configure URL. It uses Jetpack settings search as default value |
||
| 3244 | * It is possible to redefine resulting URL by using "jetpack_module_configuration_url_$module" filter |
||
| 3245 | * |
||
| 3246 | * @param string $module Module slug |
||
| 3247 | * @return string $url module configuration URL |
||
| 3248 | */ |
||
| 3249 | public static function module_configuration_url( $module ) { |
||
| 3263 | |||
| 3264 | /* Installation */ |
||
| 3265 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 3305 | |||
| 3306 | /** |
||
| 3307 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 3308 | * |
||
| 3309 | * @static |
||
| 3310 | */ |
||
| 3311 | public static function plugin_activation( $network_wide ) { |
||
| 3331 | |||
| 3332 | public static function get_activation_source( $referer_url ) { |
||
| 3381 | |||
| 3382 | /** |
||
| 3383 | * Runs before bumping version numbers up to a new version |
||
| 3384 | * |
||
| 3385 | * @param string $version Version:timestamp. |
||
| 3386 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
| 3387 | */ |
||
| 3388 | public static function do_version_bump( $version, $old_version ) { |
||
| 3399 | |||
| 3400 | /** |
||
| 3401 | * Sets the display_update_modal state. |
||
| 3402 | */ |
||
| 3403 | public static function set_update_modal_display() { |
||
| 3407 | |||
| 3408 | /** |
||
| 3409 | * Enqueues the block library styles. |
||
| 3410 | * |
||
| 3411 | * @param string $hook The current admin page. |
||
| 3412 | */ |
||
| 3413 | public static function enqueue_block_style( $hook ) { |
||
| 3418 | |||
| 3419 | /** |
||
| 3420 | * Sets the internal version number and activation state. |
||
| 3421 | * |
||
| 3422 | * @static |
||
| 3423 | */ |
||
| 3424 | public static function plugin_initialize() { |
||
| 3441 | |||
| 3442 | /** |
||
| 3443 | * Removes all connection options |
||
| 3444 | * |
||
| 3445 | * @static |
||
| 3446 | */ |
||
| 3447 | public static function plugin_deactivation() { |
||
| 3458 | |||
| 3459 | /** |
||
| 3460 | * Disconnects from the Jetpack servers. |
||
| 3461 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 3462 | * |
||
| 3463 | * @static |
||
| 3464 | */ |
||
| 3465 | public static function disconnect( $update_activated_state = true ) { |
||
| 3511 | |||
| 3512 | /** |
||
| 3513 | * Disconnects the user |
||
| 3514 | * |
||
| 3515 | * @param int $user_id The user ID to disconnect. |
||
| 3516 | */ |
||
| 3517 | public function disconnect_user( $user_id ) { |
||
| 3520 | |||
| 3521 | /** |
||
| 3522 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 3523 | * |
||
| 3524 | * @deprecated since Jetpack 9.7.0 |
||
| 3525 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
| 3526 | * |
||
| 3527 | * @return bool|WP_Error |
||
| 3528 | */ |
||
| 3529 | public static function try_registration() { |
||
| 3533 | |||
| 3534 | /** |
||
| 3535 | * Checking the domain names in beta versions. |
||
| 3536 | * If this is a development version, before attempting to connect, let's make sure that the domains are viable. |
||
| 3537 | * |
||
| 3538 | * @param null|\WP_Error $error The domain validation error, or `null` if everything's fine. |
||
| 3539 | * |
||
| 3540 | * @return null|\WP_Error The domain validation error, or `null` if everything's fine. |
||
| 3541 | */ |
||
| 3542 | public static function registration_check_domains( $error ) { |
||
| 3560 | |||
| 3561 | /** |
||
| 3562 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 3563 | * |
||
| 3564 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 3565 | */ |
||
| 3566 | public static function log( $code, $data = null ) { |
||
| 3606 | |||
| 3607 | /** |
||
| 3608 | * Get the internal event log. |
||
| 3609 | * |
||
| 3610 | * @param $event (string) - only return the specific log events |
||
| 3611 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 3612 | * |
||
| 3613 | * @return array of log events || WP_Error for invalid params |
||
| 3614 | */ |
||
| 3615 | public static function get_log( $event = false, $num = false ) { |
||
| 3651 | |||
| 3652 | /** |
||
| 3653 | * Log modification of important settings. |
||
| 3654 | */ |
||
| 3655 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 3662 | |||
| 3663 | /** |
||
| 3664 | * Return stat data for WPCOM sync |
||
| 3665 | */ |
||
| 3666 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
| 3680 | |||
| 3681 | /** |
||
| 3682 | * Get additional stat data to sync to WPCOM |
||
| 3683 | */ |
||
| 3684 | public static function get_additional_stat_data( $prefix = '' ) { |
||
| 3695 | |||
| 3696 | private static function get_site_user_count() { |
||
| 3711 | |||
| 3712 | /* Admin Pages */ |
||
| 3713 | |||
| 3714 | function admin_init() { |
||
| 3768 | |||
| 3769 | function admin_body_class( $admin_body_class = '' ) { |
||
| 3777 | |||
| 3778 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 3781 | |||
| 3782 | /** |
||
| 3783 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 3784 | * This function artificially throws errors for such cases (per a specific list). |
||
| 3785 | * |
||
| 3786 | * @param string $plugin The activated plugin. |
||
| 3787 | */ |
||
| 3788 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 3812 | |||
| 3813 | function intercept_plugin_error_scrape_init() { |
||
| 3816 | |||
| 3817 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 3828 | |||
| 3829 | /** |
||
| 3830 | * Register the remote file upload request handlers, if needed. |
||
| 3831 | * |
||
| 3832 | * @access public |
||
| 3833 | */ |
||
| 3834 | public function add_remote_request_handlers() { |
||
| 3863 | |||
| 3864 | /** |
||
| 3865 | * Handler for Jetpack remote file uploads. |
||
| 3866 | * |
||
| 3867 | * @access public |
||
| 3868 | */ |
||
| 3869 | public function remote_request_handlers() { |
||
| 3909 | |||
| 3910 | /** |
||
| 3911 | * Uploads a file gotten from the global $_FILES. |
||
| 3912 | * If `$update_media_item` is true and `post_id` is defined |
||
| 3913 | * the attachment file of the media item (gotten through of the post_id) |
||
| 3914 | * will be updated instead of add a new one. |
||
| 3915 | * |
||
| 3916 | * @param boolean $update_media_item - update media attachment |
||
| 3917 | * @return array - An array describing the uploadind files process |
||
| 3918 | */ |
||
| 3919 | function upload_handler( $update_media_item = false ) { |
||
| 4050 | |||
| 4051 | /** |
||
| 4052 | * Add help to the Jetpack page |
||
| 4053 | * |
||
| 4054 | * @since Jetpack (1.2.3) |
||
| 4055 | * @return false if not the Jetpack page |
||
| 4056 | */ |
||
| 4057 | function admin_help() { |
||
| 4100 | |||
| 4101 | function admin_menu_css() { |
||
| 4104 | |||
| 4105 | function admin_menu_order() { |
||
| 4108 | |||
| 4109 | function jetpack_menu_order( $menu_order ) { |
||
| 4124 | |||
| 4125 | function admin_banner_styles() { |
||
| 4146 | |||
| 4147 | function plugin_action_links( $actions ) { |
||
| 4162 | |||
| 4163 | /** |
||
| 4164 | * Adds the deactivation warning modal if there are other active plugins using the connection |
||
| 4165 | * |
||
| 4166 | * @param string $hook The current admin page. |
||
| 4167 | * |
||
| 4168 | * @return void |
||
| 4169 | */ |
||
| 4170 | public function deactivate_dialog( $hook ) { |
||
| 4225 | |||
| 4226 | /** |
||
| 4227 | * Outputs the content of the deactivation modal |
||
| 4228 | * |
||
| 4229 | * @return void |
||
| 4230 | */ |
||
| 4231 | public function deactivate_dialog_content() { |
||
| 4236 | |||
| 4237 | /** |
||
| 4238 | * Filters the login URL to include the registration flow in case the user isn't logged in. |
||
| 4239 | * |
||
| 4240 | * @param string $login_url The wp-login URL. |
||
| 4241 | * @param string $redirect URL to redirect users after logging in. |
||
| 4242 | * @since Jetpack 8.4 |
||
| 4243 | * @return string |
||
| 4244 | */ |
||
| 4245 | public function login_url( $login_url, $redirect ) { |
||
| 4252 | |||
| 4253 | /** |
||
| 4254 | * Redirects non-authenticated users to authenticate with Calypso if redirect flag is set. |
||
| 4255 | * |
||
| 4256 | * @since Jetpack 8.4 |
||
| 4257 | */ |
||
| 4258 | public function login_init() { |
||
| 4275 | |||
| 4276 | /* |
||
| 4277 | * Registration flow: |
||
| 4278 | * 1 - ::admin_page_load() action=register |
||
| 4279 | * 2 - ::try_registration() |
||
| 4280 | * 3 - ::register() |
||
| 4281 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 4282 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 4283 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 4284 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 4285 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 4286 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 4287 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 4288 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 4289 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 4290 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 4291 | * 5 - user logs in with WP.com account |
||
| 4292 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 4293 | * - Manager::authorize() |
||
| 4294 | * - Manager::get_token() |
||
| 4295 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 4296 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 4297 | * - which responds with access_token, token_type, scope |
||
| 4298 | * - Manager::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 4299 | * - Jetpack::activate_default_modules() |
||
| 4300 | * - Deactivates deprecated plugins |
||
| 4301 | * - Activates all default modules |
||
| 4302 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 4303 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 4304 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 4305 | * Done! |
||
| 4306 | */ |
||
| 4307 | |||
| 4308 | /** |
||
| 4309 | * Handles the page load events for the Jetpack admin page |
||
| 4310 | */ |
||
| 4311 | function admin_page_load() { |
||
| 4630 | |||
| 4631 | function admin_notices() { |
||
| 4756 | |||
| 4757 | /** |
||
| 4758 | * We can't always respond to a signed XML-RPC request with a |
||
| 4759 | * helpful error message. In some circumstances, doing so could |
||
| 4760 | * leak information. |
||
| 4761 | * |
||
| 4762 | * Instead, track that the error occurred via a Jetpack_Option, |
||
| 4763 | * and send that data back in the heartbeat. |
||
| 4764 | * All this does is increment a number, but it's enough to find |
||
| 4765 | * trends. |
||
| 4766 | * |
||
| 4767 | * @param WP_Error $xmlrpc_error The error produced during |
||
| 4768 | * signature validation. |
||
| 4769 | */ |
||
| 4770 | function track_xmlrpc_error( $xmlrpc_error ) { |
||
| 4785 | |||
| 4786 | /** |
||
| 4787 | * Initialize the jetpack stats instance only when needed |
||
| 4788 | * |
||
| 4789 | * @return void |
||
| 4790 | */ |
||
| 4791 | private function initialize_stats() { |
||
| 4796 | |||
| 4797 | /** |
||
| 4798 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 4799 | */ |
||
| 4800 | function stat( $group, $detail ) { |
||
| 4807 | |||
| 4808 | /** |
||
| 4809 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 4810 | */ |
||
| 4811 | function do_stats( $method = '' ) { |
||
| 4822 | |||
| 4823 | /** |
||
| 4824 | * Runs stats code for a one-off, server-side. |
||
| 4825 | * |
||
| 4826 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 4827 | * |
||
| 4828 | * @return bool If it worked. |
||
| 4829 | */ |
||
| 4830 | static function do_server_side_stat( $args ) { |
||
| 4835 | |||
| 4836 | /** |
||
| 4837 | * Builds the stats url. |
||
| 4838 | * |
||
| 4839 | * @param $args array|string The arguments to append to the URL. |
||
| 4840 | * |
||
| 4841 | * @return string The URL to be pinged. |
||
| 4842 | */ |
||
| 4843 | static function build_stats_url( $args ) { |
||
| 4849 | |||
| 4850 | /** |
||
| 4851 | * Builds a URL to the Jetpack connection auth page |
||
| 4852 | * |
||
| 4853 | * @since 3.9.5 |
||
| 4854 | * |
||
| 4855 | * @param bool $raw If true, URL will not be escaped. |
||
| 4856 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 4857 | * If string, will be a custom redirect. |
||
| 4858 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 4859 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
| 4860 | * |
||
| 4861 | * @return string Connect URL |
||
| 4862 | */ |
||
| 4863 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
| 4925 | |||
| 4926 | public static function build_authorize_url( $redirect = false, $iframe = false ) { |
||
| 4954 | |||
| 4955 | /** |
||
| 4956 | * Filters the connection URL parameter array. |
||
| 4957 | * |
||
| 4958 | * @param array $args default URL parameters used by the package. |
||
| 4959 | * @return array the modified URL arguments array. |
||
| 4960 | */ |
||
| 4961 | public static function filter_connect_request_body( $args ) { |
||
| 4991 | |||
| 4992 | /** |
||
| 4993 | * Filters the URL that will process the connection data. It can be different from the URL |
||
| 4994 | * that we send the user to after everything is done. |
||
| 4995 | * |
||
| 4996 | * @param String $processing_url the default redirect URL used by the package. |
||
| 4997 | * @return String the modified URL. |
||
| 4998 | * |
||
| 4999 | * @deprecated since Jetpack 9.5.0 |
||
| 5000 | */ |
||
| 5001 | public static function filter_connect_processing_url( $processing_url ) { |
||
| 5007 | |||
| 5008 | /** |
||
| 5009 | * Filters the redirection URL that is used for connect requests. The redirect |
||
| 5010 | * URL should return the user back to the Jetpack console. |
||
| 5011 | * |
||
| 5012 | * @param String $redirect the default redirect URL used by the package. |
||
| 5013 | * @return String the modified URL. |
||
| 5014 | */ |
||
| 5015 | public static function filter_connect_redirect_url( $redirect ) { |
||
| 5027 | |||
| 5028 | /** |
||
| 5029 | * This action fires at the beginning of the Manager::authorize method. |
||
| 5030 | */ |
||
| 5031 | public static function authorize_starting() { |
||
| 5055 | |||
| 5056 | /** |
||
| 5057 | * This action fires when the site is registered (connected at a site level). |
||
| 5058 | */ |
||
| 5059 | public function handle_unique_registrations_stats() { |
||
| 5074 | |||
| 5075 | /** |
||
| 5076 | * This action fires at the end of the Manager::authorize method when a secondary user is |
||
| 5077 | * linked. |
||
| 5078 | */ |
||
| 5079 | public static function authorize_ending_linked() { |
||
| 5083 | |||
| 5084 | /** |
||
| 5085 | * This action fires at the end of the Manager::authorize method when the master user is |
||
| 5086 | * authorized. |
||
| 5087 | * |
||
| 5088 | * @param array $data The request data. |
||
| 5089 | */ |
||
| 5090 | public static function authorize_ending_authorized( $data ) { |
||
| 5110 | |||
| 5111 | /** |
||
| 5112 | * Fires on the jetpack_site_registered hook and acitvates default modules |
||
| 5113 | */ |
||
| 5114 | public static function activate_default_modules_on_site_register() { |
||
| 5129 | |||
| 5130 | /** |
||
| 5131 | * This action fires at the end of the REST_Connector connection_reconnect method when the |
||
| 5132 | * reconnect process is completed. |
||
| 5133 | * Note that this currently only happens when we don't need the user to re-authorize |
||
| 5134 | * their WP.com account, eg in cases where we are restoring a connection with |
||
| 5135 | * unhealthy blog token. |
||
| 5136 | */ |
||
| 5137 | public static function reconnection_completed() { |
||
| 5140 | |||
| 5141 | /** |
||
| 5142 | * Get our assumed site creation date. |
||
| 5143 | * Calculated based on the earlier date of either: |
||
| 5144 | * - Earliest admin user registration date. |
||
| 5145 | * - Earliest date of post of any post type. |
||
| 5146 | * |
||
| 5147 | * @since 7.2.0 |
||
| 5148 | * @deprecated since 7.8.0 |
||
| 5149 | * |
||
| 5150 | * @return string Assumed site creation date and time. |
||
| 5151 | */ |
||
| 5152 | public static function get_assumed_site_creation_date() { |
||
| 5156 | |||
| 5157 | View Code Duplication | public static function apply_activation_source_to_args( &$args ) { |
|
| 5168 | |||
| 5169 | function build_reconnect_url( $raw = false ) { |
||
| 5173 | |||
| 5174 | public static function admin_url( $args = null ) { |
||
| 5179 | |||
| 5180 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 5184 | |||
| 5185 | function dismiss_jetpack_notice() { |
||
| 5202 | |||
| 5203 | public static function sort_modules( $a, $b ) { |
||
| 5210 | |||
| 5211 | function ajax_recheck_ssl() { |
||
| 5221 | |||
| 5222 | /* Client API */ |
||
| 5223 | |||
| 5224 | /** |
||
| 5225 | * Returns the requested Jetpack API URL |
||
| 5226 | * |
||
| 5227 | * @deprecated since 7.7 |
||
| 5228 | * @return string |
||
| 5229 | */ |
||
| 5230 | public static function api_url( $relative_url ) { |
||
| 5235 | |||
| 5236 | /** |
||
| 5237 | * @deprecated 8.0 |
||
| 5238 | * |
||
| 5239 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. |
||
| 5240 | * But we no longer fix "bad hosts" anyway, outbound HTTPS is required for Jetpack to function. |
||
| 5241 | */ |
||
| 5242 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 5246 | |||
| 5247 | public static function verify_onboarding_token( $token_data, $token, $request_data ) { |
||
| 5292 | |||
| 5293 | /** |
||
| 5294 | * Create a random secret for validating onboarding payload |
||
| 5295 | * |
||
| 5296 | * @return string Secret token |
||
| 5297 | */ |
||
| 5298 | public static function create_onboarding_token() { |
||
| 5306 | |||
| 5307 | /** |
||
| 5308 | * Remove the onboarding token |
||
| 5309 | * |
||
| 5310 | * @return bool True on success, false on failure |
||
| 5311 | */ |
||
| 5312 | public static function invalidate_onboarding_token() { |
||
| 5315 | |||
| 5316 | /** |
||
| 5317 | * Validate an onboarding token for a specific action |
||
| 5318 | * |
||
| 5319 | * @return boolean True if token/action pair is accepted, false if not |
||
| 5320 | */ |
||
| 5321 | public static function validate_onboarding_token_action( $token, $action ) { |
||
| 5339 | |||
| 5340 | /** |
||
| 5341 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 5342 | * |
||
| 5343 | * @since 2.3.3 |
||
| 5344 | * @return boolean |
||
| 5345 | */ |
||
| 5346 | public static function permit_ssl( $force_recheck = false ) { |
||
| 5375 | |||
| 5376 | /* |
||
| 5377 | * Displays an admin_notice, alerting the user that outbound SSL isn't working. |
||
| 5378 | */ |
||
| 5379 | public function alert_auto_ssl_fail() { |
||
| 5433 | |||
| 5434 | /** |
||
| 5435 | * Returns the Jetpack XML-RPC API |
||
| 5436 | * |
||
| 5437 | * @deprecated 8.0 Use Connection_Manager instead. |
||
| 5438 | * @return string |
||
| 5439 | */ |
||
| 5440 | public static function xmlrpc_api_url() { |
||
| 5444 | |||
| 5445 | /** |
||
| 5446 | * Returns the connection manager object. |
||
| 5447 | * |
||
| 5448 | * @return Automattic\Jetpack\Connection\Manager |
||
| 5449 | */ |
||
| 5450 | public static function connection() { |
||
| 5460 | |||
| 5461 | /** |
||
| 5462 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 5463 | * |
||
| 5464 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 5465 | * |
||
| 5466 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->generate() instead. |
||
| 5467 | * |
||
| 5468 | * @since 2.6 |
||
| 5469 | * @param String $action The action name. |
||
| 5470 | * @param Integer $user_id The user identifier. |
||
| 5471 | * @param Integer $exp Expiration time in seconds. |
||
| 5472 | * @return array |
||
| 5473 | */ |
||
| 5474 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
| 5478 | |||
| 5479 | public static function get_secrets( $action, $user_id ) { |
||
| 5492 | |||
| 5493 | /** |
||
| 5494 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5495 | * |
||
| 5496 | * Based on local php max_execution_time in php.ini |
||
| 5497 | * |
||
| 5498 | * @since 2.6 |
||
| 5499 | * @return int |
||
| 5500 | * @deprecated |
||
| 5501 | **/ |
||
| 5502 | public function get_remote_query_timeout_limit() { |
||
| 5506 | |||
| 5507 | /** |
||
| 5508 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5509 | * |
||
| 5510 | * Based on local php max_execution_time in php.ini |
||
| 5511 | * |
||
| 5512 | * @since 5.4 |
||
| 5513 | * @return int |
||
| 5514 | **/ |
||
| 5515 | public static function get_max_execution_time() { |
||
| 5524 | |||
| 5525 | /** |
||
| 5526 | * Sets a minimum request timeout, and returns the current timeout |
||
| 5527 | * |
||
| 5528 | * @since 5.4 |
||
| 5529 | **/ |
||
| 5530 | View Code Duplication | public static function set_min_time_limit( $min_timeout ) { |
|
| 5538 | |||
| 5539 | /** |
||
| 5540 | * Takes the response from the Jetpack register new site endpoint and |
||
| 5541 | * verifies it worked properly. |
||
| 5542 | * |
||
| 5543 | * @since 2.6 |
||
| 5544 | * @deprecated since 7.7.0 |
||
| 5545 | * @see Automattic\Jetpack\Connection\Manager::validate_remote_register_response() |
||
| 5546 | **/ |
||
| 5547 | public function validate_remote_register_response() { |
||
| 5550 | |||
| 5551 | /** |
||
| 5552 | * @deprecated since Jetpack 9.7.0 |
||
| 5553 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
| 5554 | * |
||
| 5555 | * @return bool|WP_Error |
||
| 5556 | */ |
||
| 5557 | public static function register() { |
||
| 5561 | |||
| 5562 | /** |
||
| 5563 | * Filters the registration request body to include tracking properties. |
||
| 5564 | * |
||
| 5565 | * @deprecated since Jetpack 9.7.0 |
||
| 5566 | * @see Automattic\Jetpack\Connection\Utils::filter_register_request_body() |
||
| 5567 | * |
||
| 5568 | * @param array $properties |
||
| 5569 | * @return array amended properties. |
||
| 5570 | */ |
||
| 5571 | public static function filter_register_request_body( $properties ) { |
||
| 5575 | |||
| 5576 | /** |
||
| 5577 | * Filters the token request body to include tracking properties. |
||
| 5578 | * |
||
| 5579 | * @param array $properties |
||
| 5580 | * @return array amended properties. |
||
| 5581 | */ |
||
| 5582 | View Code Duplication | public static function filter_token_request_body( $properties ) { |
|
| 5594 | |||
| 5595 | /** |
||
| 5596 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 5597 | * |
||
| 5598 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 5599 | */ |
||
| 5600 | public static function maybe_set_version_option() { |
||
| 5614 | |||
| 5615 | /* Client Server API */ |
||
| 5616 | |||
| 5617 | /** |
||
| 5618 | * Loads the Jetpack XML-RPC client. |
||
| 5619 | * No longer necessary, as the XML-RPC client will be automagically loaded. |
||
| 5620 | * |
||
| 5621 | * @deprecated since 7.7.0 |
||
| 5622 | */ |
||
| 5623 | public static function load_xml_rpc_client() { |
||
| 5626 | |||
| 5627 | /** |
||
| 5628 | * Resets the saved authentication state in between testing requests. |
||
| 5629 | * |
||
| 5630 | * @deprecated since 8.9.0 |
||
| 5631 | * @see Automattic\Jetpack\Connection\Rest_Authentication::reset_saved_auth_state() |
||
| 5632 | */ |
||
| 5633 | public function reset_saved_auth_state() { |
||
| 5637 | |||
| 5638 | /** |
||
| 5639 | * Verifies the signature of the current request. |
||
| 5640 | * |
||
| 5641 | * @deprecated since 7.7.0 |
||
| 5642 | * @see Automattic\Jetpack\Connection\Manager::verify_xml_rpc_signature() |
||
| 5643 | * |
||
| 5644 | * @return false|array |
||
| 5645 | */ |
||
| 5646 | public function verify_xml_rpc_signature() { |
||
| 5650 | |||
| 5651 | /** |
||
| 5652 | * Verifies the signature of the current request. |
||
| 5653 | * |
||
| 5654 | * This function has side effects and should not be used. Instead, |
||
| 5655 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
| 5656 | * |
||
| 5657 | * @deprecated since 7.7.0 |
||
| 5658 | * @see Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature() |
||
| 5659 | * @internal |
||
| 5660 | */ |
||
| 5661 | private function internal_verify_xml_rpc_signature() { |
||
| 5664 | |||
| 5665 | /** |
||
| 5666 | * Authenticates XML-RPC and other requests from the Jetpack Server. |
||
| 5667 | * |
||
| 5668 | * @deprecated since 7.7.0 |
||
| 5669 | * @see Automattic\Jetpack\Connection\Manager::authenticate_jetpack() |
||
| 5670 | * |
||
| 5671 | * @param \WP_User|mixed $user User object if authenticated. |
||
| 5672 | * @param string $username Username. |
||
| 5673 | * @param string $password Password string. |
||
| 5674 | * @return \WP_User|mixed Authenticated user or error. |
||
| 5675 | */ |
||
| 5676 | View Code Duplication | public function authenticate_jetpack( $user, $username, $password ) { |
|
| 5685 | |||
| 5686 | /** |
||
| 5687 | * Authenticates requests from Jetpack server to WP REST API endpoints. |
||
| 5688 | * Uses the existing XMLRPC request signing implementation. |
||
| 5689 | * |
||
| 5690 | * @deprecated since 8.9.0 |
||
| 5691 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authenticate() |
||
| 5692 | */ |
||
| 5693 | function wp_rest_authenticate( $user ) { |
||
| 5697 | |||
| 5698 | /** |
||
| 5699 | * Report authentication status to the WP REST API. |
||
| 5700 | * |
||
| 5701 | * @deprecated since 8.9.0 |
||
| 5702 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authentication_errors() |
||
| 5703 | * |
||
| 5704 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
| 5705 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
| 5706 | */ |
||
| 5707 | public function wp_rest_authentication_errors( $value ) { |
||
| 5711 | |||
| 5712 | /** |
||
| 5713 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 5714 | * Capture it here so we can verify the signature later. |
||
| 5715 | * |
||
| 5716 | * @deprecated since 7.7.0 |
||
| 5717 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_methods() |
||
| 5718 | * |
||
| 5719 | * @param array $methods XMLRPC methods. |
||
| 5720 | * @return array XMLRPC methods, with the $HTTP_RAW_POST_DATA one. |
||
| 5721 | */ |
||
| 5722 | View Code Duplication | public function xmlrpc_methods( $methods ) { |
|
| 5731 | |||
| 5732 | /** |
||
| 5733 | * Register additional public XMLRPC methods. |
||
| 5734 | * |
||
| 5735 | * @deprecated since 7.7.0 |
||
| 5736 | * @see Automattic\Jetpack\Connection\Manager::public_xmlrpc_methods() |
||
| 5737 | * |
||
| 5738 | * @param array $methods Public XMLRPC methods. |
||
| 5739 | * @return array Public XMLRPC methods, with the getOptions one. |
||
| 5740 | */ |
||
| 5741 | View Code Duplication | public function public_xmlrpc_methods( $methods ) { |
|
| 5750 | |||
| 5751 | /** |
||
| 5752 | * Handles a getOptions XMLRPC method call. |
||
| 5753 | * |
||
| 5754 | * @deprecated since 7.7.0 |
||
| 5755 | * @see Automattic\Jetpack\Connection\Manager::jetpack_getOptions() |
||
| 5756 | * |
||
| 5757 | * @param array $args method call arguments. |
||
| 5758 | * @return array an amended XMLRPC server options array. |
||
| 5759 | */ |
||
| 5760 | View Code Duplication | public function jetpack_getOptions( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 5769 | |||
| 5770 | /** |
||
| 5771 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
| 5772 | * |
||
| 5773 | * @deprecated since 7.7.0 |
||
| 5774 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_options() |
||
| 5775 | * |
||
| 5776 | * @param array $options Standard Core options. |
||
| 5777 | * @return array Amended options. |
||
| 5778 | */ |
||
| 5779 | View Code Duplication | public function xmlrpc_options( $options ) { |
|
| 5788 | |||
| 5789 | /** |
||
| 5790 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 5791 | * SET: state( $key, $value ); |
||
| 5792 | * GET: $value = state( $key ); |
||
| 5793 | * |
||
| 5794 | * @param string $key |
||
| 5795 | * @param string $value |
||
| 5796 | * @param bool $restate private |
||
| 5797 | */ |
||
| 5798 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 5854 | |||
| 5855 | public static function restate() { |
||
| 5858 | |||
| 5859 | /** |
||
| 5860 | * Determines whether the jetpackState[$key] value should be added to the |
||
| 5861 | * cookie. |
||
| 5862 | * |
||
| 5863 | * @param string $key The state key. |
||
| 5864 | * |
||
| 5865 | * @return boolean Whether the value should be added to the cookie. |
||
| 5866 | */ |
||
| 5867 | public static function should_set_cookie( $key ) { |
||
| 5877 | |||
| 5878 | public static function check_privacy( $file ) { |
||
| 5912 | |||
| 5913 | /** |
||
| 5914 | * Helper method for multicall XMLRPC. |
||
| 5915 | * |
||
| 5916 | * @deprecated since 8.9.0 |
||
| 5917 | * @see Automattic\\Jetpack\\Connection\\Xmlrpc_Async_Call::add_call() |
||
| 5918 | * |
||
| 5919 | * @param ...$args Args for the async_call. |
||
| 5920 | */ |
||
| 5921 | public static function xmlrpc_async_call( ...$args ) { |
||
| 5963 | |||
| 5964 | /** |
||
| 5965 | * Serve a WordPress.com static resource via a randomized wp.com subdomain. |
||
| 5966 | * |
||
| 5967 | * @deprecated 9.3.0 Use Assets::staticize_subdomain. |
||
| 5968 | * |
||
| 5969 | * @param string $url WordPress.com static resource URL. |
||
| 5970 | */ |
||
| 5971 | public static function staticize_subdomain( $url ) { |
||
| 5975 | |||
| 5976 | /* JSON API Authorization */ |
||
| 5977 | |||
| 5978 | /** |
||
| 5979 | * Handles the login action for Authorizing the JSON API |
||
| 5980 | */ |
||
| 5981 | function login_form_json_api_authorization() { |
||
| 5990 | |||
| 5991 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 5992 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 6006 | |||
| 6007 | // Make sure the POSTed request is handled by the same action |
||
| 6008 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 6012 | |||
| 6013 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 6014 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 6020 | |||
| 6021 | // Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. |
||
| 6022 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 6026 | |||
| 6027 | static function is_redirect_encoded( $redirect_url ) { |
||
| 6030 | |||
| 6031 | // Add all wordpress.com environments to the safe redirect allowed list. |
||
| 6032 | function allow_wpcom_environments( $domains ) { |
||
| 6039 | |||
| 6040 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 6041 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 6053 | |||
| 6054 | /** |
||
| 6055 | * Verifies the request by checking the signature |
||
| 6056 | * |
||
| 6057 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
| 6058 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
| 6059 | * |
||
| 6060 | * @param null|array $environment |
||
| 6061 | */ |
||
| 6062 | function verify_json_api_authorization_request( $environment = null ) { |
||
| 6184 | |||
| 6185 | function login_message_json_api_authorization( $message ) { |
||
| 6191 | |||
| 6192 | /** |
||
| 6193 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 6194 | */ |
||
| 6195 | public static function get_content_width() { |
||
| 6208 | |||
| 6209 | /** |
||
| 6210 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 6211 | * |
||
| 6212 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 6213 | * |
||
| 6214 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 6215 | */ |
||
| 6216 | public function get_cloud_site_options( $option_names ) { |
||
| 6231 | |||
| 6232 | /** |
||
| 6233 | * Checks if the site is currently in an identity crisis. |
||
| 6234 | * |
||
| 6235 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
| 6236 | */ |
||
| 6237 | public static function check_identity_crisis() { |
||
| 6244 | |||
| 6245 | /** |
||
| 6246 | * Checks whether the home and siteurl specifically are allowed. |
||
| 6247 | * Written so that we don't have re-check $key and $value params every time |
||
| 6248 | * we want to check if this site is allowed, for example in footer.php |
||
| 6249 | * |
||
| 6250 | * @since 3.8.0 |
||
| 6251 | * @return bool True = already allowed False = not on the allowed list. |
||
| 6252 | */ |
||
| 6253 | public static function is_staging_site() { |
||
| 6257 | |||
| 6258 | /** |
||
| 6259 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
| 6260 | * |
||
| 6261 | * @since 4.4.0 |
||
| 6262 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
| 6263 | * |
||
| 6264 | * @return bool |
||
| 6265 | */ |
||
| 6266 | public static function validate_sync_error_idc_option() { |
||
| 6308 | |||
| 6309 | /** |
||
| 6310 | * Normalizes a url by doing three things: |
||
| 6311 | * - Strips protocol |
||
| 6312 | * - Strips www |
||
| 6313 | * - Adds a trailing slash |
||
| 6314 | * |
||
| 6315 | * @since 4.4.0 |
||
| 6316 | * @param string $url |
||
| 6317 | * @return WP_Error|string |
||
| 6318 | */ |
||
| 6319 | public static function normalize_url_protocol_agnostic( $url ) { |
||
| 6329 | |||
| 6330 | /** |
||
| 6331 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
| 6332 | * |
||
| 6333 | * @since 4.4.0 |
||
| 6334 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
| 6335 | * |
||
| 6336 | * @param array $response |
||
| 6337 | * @return array Array of the local urls, wpcom urls, and error code |
||
| 6338 | */ |
||
| 6339 | public static function get_sync_error_idc_option( $response = array() ) { |
||
| 6371 | |||
| 6372 | /** |
||
| 6373 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
| 6374 | * If set to true, the site will be put into staging mode. |
||
| 6375 | * |
||
| 6376 | * @since 4.3.2 |
||
| 6377 | * @return bool |
||
| 6378 | */ |
||
| 6379 | public static function sync_idc_optin() { |
||
| 6397 | |||
| 6398 | /** |
||
| 6399 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 6400 | * |
||
| 6401 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 6402 | */ |
||
| 6403 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 6445 | |||
| 6446 | /** |
||
| 6447 | * If the asset is minified, let's flag .min as the suffix. |
||
| 6448 | * |
||
| 6449 | * Attached to `style_loader_src` filter. |
||
| 6450 | * |
||
| 6451 | * @param string $tag The tag that would link to the external asset. |
||
| 6452 | * @param string $handle The registered handle of the script in question. |
||
| 6453 | * @param string $href The url of the asset in question. |
||
| 6454 | */ |
||
| 6455 | public static function set_suffix_on_min( $src, $handle ) { |
||
| 6471 | |||
| 6472 | /** |
||
| 6473 | * Maybe inlines a stylesheet. |
||
| 6474 | * |
||
| 6475 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 6476 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 6477 | * |
||
| 6478 | * Attached to `style_loader_tag` filter. |
||
| 6479 | * |
||
| 6480 | * @param string $tag The tag that would link to the external asset. |
||
| 6481 | * @param string $handle The registered handle of the script in question. |
||
| 6482 | * |
||
| 6483 | * @return string |
||
| 6484 | */ |
||
| 6485 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 6535 | |||
| 6536 | /** |
||
| 6537 | * Loads a view file from the views |
||
| 6538 | * |
||
| 6539 | * Data passed in with the $data parameter will be available in the |
||
| 6540 | * template file as $data['value'] |
||
| 6541 | * |
||
| 6542 | * @param string $template - Template file to load |
||
| 6543 | * @param array $data - Any data to pass along to the template |
||
| 6544 | * @return boolean - If template file was found |
||
| 6545 | **/ |
||
| 6546 | public function load_view( $template, $data = array() ) { |
||
| 6557 | |||
| 6558 | /** |
||
| 6559 | * Throws warnings for deprecated hooks to be removed from Jetpack that cannot remain in the original place in the code. |
||
| 6560 | */ |
||
| 6561 | public function deprecated_hooks() { |
||
| 6818 | |||
| 6819 | /** |
||
| 6820 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 6821 | * |
||
| 6822 | * Considerations: |
||
| 6823 | * - Normal, relative URLs `feh.png` |
||
| 6824 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 6825 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 6826 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 6827 | * - Domain root relative URLs `/feh.png` |
||
| 6828 | * |
||
| 6829 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 6830 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 6831 | * |
||
| 6832 | * @return mixed|string |
||
| 6833 | */ |
||
| 6834 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 6878 | |||
| 6879 | /** |
||
| 6880 | * This methods removes all of the registered css files on the front end |
||
| 6881 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 6882 | * all the files into one file. |
||
| 6883 | * |
||
| 6884 | * Pros: |
||
| 6885 | * - Uses only ONE css asset connection instead of 15 |
||
| 6886 | * - Saves a minimum of 56k |
||
| 6887 | * - Reduces server load |
||
| 6888 | * - Reduces time to first painted byte |
||
| 6889 | * |
||
| 6890 | * Cons: |
||
| 6891 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 6892 | * should not cause any issues with themes. |
||
| 6893 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 6894 | * jetpack_implode_frontend_css filter for a workaround |
||
| 6895 | * |
||
| 6896 | * For some situations developers may wish to disable css imploding and |
||
| 6897 | * instead operate in legacy mode where each file loads seperately and |
||
| 6898 | * can be edited individually or dequeued. This can be accomplished with |
||
| 6899 | * the following line: |
||
| 6900 | * |
||
| 6901 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 6902 | * |
||
| 6903 | * @since 3.2 |
||
| 6904 | **/ |
||
| 6905 | public function implode_frontend_css( $travis_test = false ) { |
||
| 6962 | |||
| 6963 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 6973 | |||
| 6974 | /** |
||
| 6975 | * @deprecated |
||
| 6976 | * @see Automattic\Jetpack\Assets\add_aync_script |
||
| 6977 | */ |
||
| 6978 | public function script_add_async( $tag, $handle, $src ) { |
||
| 6981 | |||
| 6982 | /* |
||
| 6983 | * Check the heartbeat data |
||
| 6984 | * |
||
| 6985 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 6986 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 6987 | * |
||
| 6988 | * Data will be added to "caution" array, if it either: |
||
| 6989 | * - Out of date Jetpack version |
||
| 6990 | * - Out of date WP version |
||
| 6991 | * - Out of date PHP version |
||
| 6992 | * |
||
| 6993 | * $return array $filtered_data |
||
| 6994 | */ |
||
| 6995 | public static function jetpack_check_heartbeat_data() { |
||
| 7048 | |||
| 7049 | /* |
||
| 7050 | * This method is used to organize all options that can be reset |
||
| 7051 | * without disconnecting Jetpack. |
||
| 7052 | * |
||
| 7053 | * It is used in class.jetpack-cli.php to reset options |
||
| 7054 | * |
||
| 7055 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
| 7056 | * |
||
| 7057 | * @return array of options to delete. |
||
| 7058 | */ |
||
| 7059 | public static function get_jetpack_options_for_reset() { |
||
| 7062 | |||
| 7063 | /* |
||
| 7064 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 7065 | * so we can bring them directly to their site in calypso. |
||
| 7066 | * |
||
| 7067 | * @deprecated 9.2.0 Use Automattic\Jetpack\Status::get_site_suffix |
||
| 7068 | * |
||
| 7069 | * @param string | url |
||
| 7070 | * @return string | url without the guff |
||
| 7071 | */ |
||
| 7072 | public static function build_raw_urls( $url ) { |
||
| 7077 | |||
| 7078 | /** |
||
| 7079 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 7080 | * |
||
| 7081 | * @deprecated 8.8.0 Use Jetpack::add_resource_hints. |
||
| 7082 | * |
||
| 7083 | * @param string|array $urls URLs to hint. |
||
| 7084 | */ |
||
| 7085 | public static function dns_prefetch( $urls = null ) { |
||
| 7091 | |||
| 7092 | public function wp_dashboard_setup() { |
||
| 7130 | |||
| 7131 | /** |
||
| 7132 | * @param mixed $result Value for the user's option |
||
| 7133 | * @return mixed |
||
| 7134 | */ |
||
| 7135 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 7160 | |||
| 7161 | public static function dashboard_widget() { |
||
| 7169 | |||
| 7170 | public static function dashboard_widget_footer() { |
||
| 7238 | |||
| 7239 | /* |
||
| 7240 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 7241 | */ |
||
| 7242 | function jetpack_icon_user_connected( $columns ) { |
||
| 7246 | |||
| 7247 | /* |
||
| 7248 | * Show Jetpack icon if the user is linked. |
||
| 7249 | */ |
||
| 7250 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 7263 | |||
| 7264 | /* |
||
| 7265 | * Style the Jetpack user column |
||
| 7266 | */ |
||
| 7267 | function jetpack_user_col_style() { |
||
| 7286 | |||
| 7287 | /** |
||
| 7288 | * Checks if Akismet is active and working. |
||
| 7289 | * |
||
| 7290 | * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key |
||
| 7291 | * that implied usage of methods present since more recent version. |
||
| 7292 | * See https://github.com/Automattic/jetpack/pull/9585 |
||
| 7293 | * |
||
| 7294 | * @since 5.1.0 |
||
| 7295 | * |
||
| 7296 | * @return bool True = Akismet available. False = Aksimet not available. |
||
| 7297 | */ |
||
| 7298 | public static function is_akismet_active() { |
||
| 7333 | |||
| 7334 | /** |
||
| 7335 | * @deprecated |
||
| 7336 | * |
||
| 7337 | * @see Automattic\Jetpack\Sync\Modules\Users::is_function_in_backtrace |
||
| 7338 | */ |
||
| 7339 | public static function is_function_in_backtrace() { |
||
| 7342 | |||
| 7343 | /** |
||
| 7344 | * Given a minified path, and a non-minified path, will return |
||
| 7345 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
| 7346 | * |
||
| 7347 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
| 7348 | * root Jetpack directory. |
||
| 7349 | * |
||
| 7350 | * @since 5.6.0 |
||
| 7351 | * |
||
| 7352 | * @param string $min_path |
||
| 7353 | * @param string $non_min_path |
||
| 7354 | * @return string The URL to the file |
||
| 7355 | */ |
||
| 7356 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
| 7359 | |||
| 7360 | /** |
||
| 7361 | * Checks for whether Jetpack Backup is enabled. |
||
| 7362 | * Will return true if the state of Backup is anything except "unavailable". |
||
| 7363 | * |
||
| 7364 | * @return bool|int|mixed |
||
| 7365 | */ |
||
| 7366 | public static function is_rewind_enabled() { |
||
| 7386 | |||
| 7387 | /** |
||
| 7388 | * Return Calypso environment value; used for developing Jetpack and pairing |
||
| 7389 | * it with different Calypso enrionments, such as localhost. |
||
| 7390 | * |
||
| 7391 | * @since 7.4.0 |
||
| 7392 | * |
||
| 7393 | * @return string Calypso environment |
||
| 7394 | */ |
||
| 7395 | public static function get_calypso_env() { |
||
| 7410 | |||
| 7411 | /** |
||
| 7412 | * Returns the hostname with protocol for Calypso. |
||
| 7413 | * Used for developing Jetpack with Calypso. |
||
| 7414 | * |
||
| 7415 | * @since 8.4.0 |
||
| 7416 | * |
||
| 7417 | * @return string Calypso host. |
||
| 7418 | */ |
||
| 7419 | public static function get_calypso_host() { |
||
| 7432 | |||
| 7433 | /** |
||
| 7434 | * Handles activating default modules as well general cleanup for the new connection. |
||
| 7435 | * |
||
| 7436 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
| 7437 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
| 7438 | * @param boolean $send_state_messages Whether to send state messages. |
||
| 7439 | * @return void |
||
| 7440 | */ |
||
| 7441 | public static function handle_post_authorization_actions( |
||
| 7469 | |||
| 7470 | /** |
||
| 7471 | * Returns a boolean for whether backups UI should be displayed or not. |
||
| 7472 | * |
||
| 7473 | * @return bool Should backups UI be displayed? |
||
| 7474 | */ |
||
| 7475 | public static function show_backups_ui() { |
||
| 7485 | |||
| 7486 | /* |
||
| 7487 | * Deprecated manage functions |
||
| 7488 | */ |
||
| 7489 | function prepare_manage_jetpack_notice() { |
||
| 7510 | |||
| 7511 | /** |
||
| 7512 | * Clean leftoveruser meta. |
||
| 7513 | * |
||
| 7514 | * Delete Jetpack-related user meta when it is no longer needed. |
||
| 7515 | * |
||
| 7516 | * @since 7.3.0 |
||
| 7517 | * |
||
| 7518 | * @param int $user_id User ID being updated. |
||
| 7519 | */ |
||
| 7520 | public static function user_meta_cleanup( $user_id ) { |
||
| 7535 | |||
| 7536 | /** |
||
| 7537 | * Checks if a Jetpack site is both active and not in offline mode. |
||
| 7538 | * |
||
| 7539 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
| 7540 | * |
||
| 7541 | * @deprecated 8.8.0 |
||
| 7542 | * |
||
| 7543 | * @return bool True if Jetpack is active and not in offline mode. |
||
| 7544 | */ |
||
| 7545 | public static function is_active_and_not_development_mode() { |
||
| 7552 | |||
| 7553 | /** |
||
| 7554 | * Checks if a Jetpack site is both active and not in offline mode. |
||
| 7555 | * |
||
| 7556 | * This is a DRY function to avoid repeating `Jetpack::is_connection_ready && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
| 7557 | * |
||
| 7558 | * @since 8.8.0 |
||
| 7559 | * |
||
| 7560 | * @return bool True if Jetpack is active and not in offline mode. |
||
| 7561 | */ |
||
| 7562 | public static function is_active_and_not_offline_mode() { |
||
| 7568 | |||
| 7569 | /** |
||
| 7570 | * Returns the list of products that we have available for purchase. |
||
| 7571 | */ |
||
| 7572 | public static function get_products_for_purchase() { |
||
| 7666 | } |
||
| 7667 |
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.