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 |
||
| 50 | class Jetpack { |
||
| 51 | public $xmlrpc_server = null; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var array The handles of styles that are concatenated into jetpack.css. |
||
| 55 | * |
||
| 56 | * When making changes to that list, you must also update concat_list in tools/builder/frontend-css.js. |
||
| 57 | */ |
||
| 58 | public $concatenated_style_handles = array( |
||
| 59 | 'jetpack-carousel', |
||
| 60 | 'grunion.css', |
||
| 61 | 'the-neverending-homepage', |
||
| 62 | 'jetpack_likes', |
||
| 63 | 'jetpack_related-posts', |
||
| 64 | 'sharedaddy', |
||
| 65 | 'jetpack-slideshow', |
||
| 66 | 'presentations', |
||
| 67 | 'quiz', |
||
| 68 | 'jetpack-subscriptions', |
||
| 69 | 'jetpack-responsive-videos-style', |
||
| 70 | 'jetpack-social-menu', |
||
| 71 | 'tiled-gallery', |
||
| 72 | 'jetpack_display_posts_widget', |
||
| 73 | 'gravatar-profile-widget', |
||
| 74 | 'goodreads-widget', |
||
| 75 | 'jetpack_social_media_icons_widget', |
||
| 76 | 'jetpack-top-posts-widget', |
||
| 77 | 'jetpack_image_widget', |
||
| 78 | 'jetpack-my-community-widget', |
||
| 79 | 'jetpack-authors-widget', |
||
| 80 | 'wordads', |
||
| 81 | 'eu-cookie-law-style', |
||
| 82 | 'flickr-widget-style', |
||
| 83 | 'jetpack-search-widget', |
||
| 84 | 'jetpack-simple-payments-widget-style', |
||
| 85 | 'jetpack-widget-social-icons-styles', |
||
| 86 | 'wpcom_instagram_widget', |
||
| 87 | ); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Contains all assets that have had their URL rewritten to minified versions. |
||
| 91 | * |
||
| 92 | * @var array |
||
| 93 | */ |
||
| 94 | static $min_assets = array(); |
||
| 95 | |||
| 96 | public $plugins_to_deactivate = array( |
||
| 97 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 98 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 99 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 100 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 101 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 102 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 103 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 104 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 105 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 106 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 107 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 108 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 109 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 110 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ), |
||
| 111 | ); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Map of roles we care about, and their corresponding minimum capabilities. |
||
| 115 | * |
||
| 116 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead. |
||
| 117 | * |
||
| 118 | * @access public |
||
| 119 | * @static |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | */ |
||
| 123 | public static $capability_translations = array( |
||
| 124 | 'administrator' => 'manage_options', |
||
| 125 | 'editor' => 'edit_others_posts', |
||
| 126 | 'author' => 'publish_posts', |
||
| 127 | 'contributor' => 'edit_posts', |
||
| 128 | 'subscriber' => 'read', |
||
| 129 | ); |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 133 | * if the plugins are active. Used by filter_default_modules |
||
| 134 | * |
||
| 135 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 136 | * change `module-slug` and add this to your plugin: |
||
| 137 | * |
||
| 138 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 139 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 140 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 141 | * } |
||
| 142 | * |
||
| 143 | * @var array |
||
| 144 | */ |
||
| 145 | private $conflicting_plugins = array( |
||
| 146 | 'comments' => array( |
||
| 147 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 148 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 149 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 150 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 151 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 152 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 153 | ), |
||
| 154 | 'comment-likes' => array( |
||
| 155 | 'Epoch' => 'epoch/plugincore.php', |
||
| 156 | ), |
||
| 157 | 'contact-form' => array( |
||
| 158 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 159 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 160 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 161 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 162 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 163 | 'Ninja Forms' => 'ninja-forms/ninja-forms.php', |
||
| 164 | ), |
||
| 165 | 'latex' => array( |
||
| 166 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 167 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 168 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 169 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 170 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 171 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 172 | ), |
||
| 173 | 'protect' => array( |
||
| 174 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 175 | 'Captcha' => 'captcha/captcha.php', |
||
| 176 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 177 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 178 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 179 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 180 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 181 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 182 | 'Login Security' => 'login-security/login-security.php', |
||
| 183 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 184 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 185 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 186 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 187 | ), |
||
| 188 | 'random-redirect' => array( |
||
| 189 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 190 | ), |
||
| 191 | 'related-posts' => array( |
||
| 192 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 193 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 194 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 195 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 196 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 197 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 198 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 199 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 200 | ), |
||
| 201 | 'sharedaddy' => array( |
||
| 202 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 203 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 204 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 205 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 206 | ), |
||
| 207 | 'seo-tools' => array( |
||
| 208 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 209 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 210 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 211 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 212 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 213 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 214 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 215 | ), |
||
| 216 | 'verification-tools' => array( |
||
| 217 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 218 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 219 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 220 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 221 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 222 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 223 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 224 | ), |
||
| 225 | 'widget-visibility' => array( |
||
| 226 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 227 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 228 | ), |
||
| 229 | 'sitemaps' => array( |
||
| 230 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 231 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 232 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 233 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 234 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 235 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 236 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 237 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 238 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 239 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 240 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 241 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 242 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 243 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 244 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 245 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 246 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 247 | ), |
||
| 248 | 'lazy-images' => array( |
||
| 249 | 'Lazy Load' => 'lazy-load/lazy-load.php', |
||
| 250 | 'BJ Lazy Load' => 'bj-lazy-load/bj-lazy-load.php', |
||
| 251 | 'Lazy Load by WP Rocket' => 'rocket-lazy-load/rocket-lazy-load.php', |
||
| 252 | ), |
||
| 253 | ); |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 257 | * |
||
| 258 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
| 259 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 260 | * |
||
| 261 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 262 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 263 | */ |
||
| 264 | private $open_graph_conflicting_plugins = array( |
||
| 265 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 266 | // 2 Click Social Media Buttons |
||
| 267 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 268 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 269 | 'complete-open-graph/complete-open-graph.php', // Complete Open Graph |
||
| 270 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 271 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
| 272 | // Open Graph Meta Tags by Heateor |
||
| 273 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 274 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 275 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 276 | // Facebook Featured Image & OG Meta Tags |
||
| 277 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 278 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 279 | // Facebook Open Graph Meta Tags for WordPress |
||
| 280 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 281 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 282 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 283 | // Fedmich's Facebook Open Graph Meta |
||
| 284 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 285 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 286 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 287 | // NextScripts SNAP |
||
| 288 | 'og-tags/og-tags.php', // OG Tags |
||
| 289 | 'opengraph/opengraph.php', // Open Graph |
||
| 290 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 291 | // Open Graph Protocol Framework |
||
| 292 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 293 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 294 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 295 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 296 | 'sharepress/sharepress.php', // SharePress |
||
| 297 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 298 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 299 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 300 | 'socialize/socialize.php', // Socialize |
||
| 301 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
| 302 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 303 | // Tweet, Like, Google +1 and Share |
||
| 304 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 305 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 306 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 307 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 308 | // WP Facebook Like Send & Open Graph Meta |
||
| 309 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 310 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 311 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 312 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button |
||
| 313 | 'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox |
||
| 314 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
| 315 | 'slim-seo/slim-seo.php', // Slim SEO |
||
| 316 | ); |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 320 | */ |
||
| 321 | private $twitter_cards_conflicting_plugins = array( |
||
| 322 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 323 | // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 324 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 325 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 326 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 327 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 328 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 329 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 330 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 331 | 'wp-to-twitter/wp-to-twitter.php', // WP to Twitter |
||
| 332 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 333 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
| 334 | 'slim-seo/slim-seo.php', // Slim SEO |
||
| 335 | ); |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Message to display in admin_notice |
||
| 339 | * |
||
| 340 | * @var string |
||
| 341 | */ |
||
| 342 | public $message = ''; |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Error to display in admin_notice |
||
| 346 | * |
||
| 347 | * @var string |
||
| 348 | */ |
||
| 349 | public $error = ''; |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Modules that need more privacy description. |
||
| 353 | * |
||
| 354 | * @var string |
||
| 355 | */ |
||
| 356 | public $privacy_checks = ''; |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Stats to record once the page loads |
||
| 360 | * |
||
| 361 | * @var array |
||
| 362 | */ |
||
| 363 | public $stats = array(); |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Jetpack_Sync object |
||
| 367 | */ |
||
| 368 | public $sync; |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Verified data for JSON authorization request |
||
| 372 | */ |
||
| 373 | public $json_api_authorization_request = array(); |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @var Automattic\Jetpack\Connection\Manager |
||
| 377 | */ |
||
| 378 | protected $connection_manager; |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @var string Transient key used to prevent multiple simultaneous plugin upgrades |
||
| 382 | */ |
||
| 383 | public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock'; |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Holds an instance of Automattic\Jetpack\A8c_Mc_Stats |
||
| 387 | * |
||
| 388 | * @var Automattic\Jetpack\A8c_Mc_Stats |
||
| 389 | */ |
||
| 390 | public $a8c_mc_stats_instance; |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Constant for login redirect key. |
||
| 394 | * |
||
| 395 | * @var string |
||
| 396 | * @since 8.4.0 |
||
| 397 | */ |
||
| 398 | public static $jetpack_redirect_login = 'jetpack_connect_login_redirect'; |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Holds the singleton instance of this class |
||
| 402 | * |
||
| 403 | * @since 2.3.3 |
||
| 404 | * @var Jetpack |
||
| 405 | */ |
||
| 406 | static $instance = false; |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Singleton |
||
| 410 | * |
||
| 411 | * @static |
||
| 412 | */ |
||
| 413 | public static function init() { |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Must never be called statically |
||
| 424 | */ |
||
| 425 | function plugin_upgrade() { |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Runs upgrade routines that need to have modules loaded. |
||
| 516 | */ |
||
| 517 | static function upgrade_on_load() { |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Saves all the currently active modules to options. |
||
| 550 | * Also fires Action hooks for each newly activated and deactivated module. |
||
| 551 | * |
||
| 552 | * @param $modules Array Array of active modules to be saved in options. |
||
| 553 | * |
||
| 554 | * @return $success bool true for success, false for failure. |
||
|
|
|||
| 555 | */ |
||
| 556 | static function update_active_modules( $modules ) { |
||
| 609 | |||
| 610 | static function delete_active_modules() { |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Adds a hook to plugins_loaded at a priority that's currently the earliest |
||
| 616 | * available. |
||
| 617 | */ |
||
| 618 | public function add_configure_hook() { |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Constructor. Initializes WordPress hooks |
||
| 642 | */ |
||
| 643 | private function __construct() { |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Before everything else starts getting initalized, we need to initialize Jetpack using the |
||
| 807 | * Config object. |
||
| 808 | */ |
||
| 809 | public function configure() { |
||
| 893 | |||
| 894 | /** |
||
| 895 | * Runs on plugins_loaded. Use this to add code that needs to be executed later than other |
||
| 896 | * initialization code. |
||
| 897 | * |
||
| 898 | * @action plugins_loaded |
||
| 899 | */ |
||
| 900 | public function late_initialization() { |
||
| 917 | |||
| 918 | /** |
||
| 919 | * Sets up the XMLRPC request handlers. |
||
| 920 | * |
||
| 921 | * @deprecated since 7.7.0 |
||
| 922 | * @see Automattic\Jetpack\Connection\Manager::setup_xmlrpc_handlers() |
||
| 923 | * |
||
| 924 | * @param array $request_params Incoming request parameters. |
||
| 925 | * @param Boolean $is_active Whether the connection is currently active. |
||
| 926 | * @param Boolean $is_signed Whether the signature check has been successful. |
||
| 927 | * @param Jetpack_XMLRPC_Server $xmlrpc_server (optional) An instance of the server to use instead of instantiating a new one. |
||
| 928 | */ |
||
| 929 | View Code Duplication | public function setup_xmlrpc_handlers( |
|
| 948 | |||
| 949 | /** |
||
| 950 | * Initialize REST API registration connector. |
||
| 951 | * |
||
| 952 | * @deprecated since 7.7.0 |
||
| 953 | * @see Automattic\Jetpack\Connection\Manager::initialize_rest_api_registration_connector() |
||
| 954 | */ |
||
| 955 | View Code Duplication | public function initialize_rest_api_registration_connector() { |
|
| 964 | |||
| 965 | /** |
||
| 966 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
| 967 | * |
||
| 968 | * @param $domains |
||
| 969 | */ |
||
| 970 | function add_wpcom_to_allowed_redirect_hosts( $domains ) { |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Return $domains, with 'wordpress.com' appended. |
||
| 976 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
| 977 | * |
||
| 978 | * @param $domains |
||
| 979 | * @return array |
||
| 980 | */ |
||
| 981 | function allow_wpcom_domain( $domains ) { |
||
| 988 | |||
| 989 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
| 1018 | |||
| 1019 | function point_edit_comment_links_to_calypso( $url ) { |
||
| 1031 | |||
| 1032 | /** |
||
| 1033 | * Extend callables with Jetpack Plugin functions. |
||
| 1034 | * |
||
| 1035 | * @param array $callables list of callables. |
||
| 1036 | * |
||
| 1037 | * @return array list of callables. |
||
| 1038 | */ |
||
| 1039 | public function filter_sync_callable_whitelist( $callables ) { |
||
| 1064 | |||
| 1065 | function jetpack_track_last_sync_callback( $params ) { |
||
| 1087 | |||
| 1088 | function jetpack_connection_banner_callback() { |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
| 1105 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
| 1106 | * ensure that Core and other plugins' methods are not exposed. |
||
| 1107 | * |
||
| 1108 | * @deprecated since 7.7.0 |
||
| 1109 | * @see Automattic\Jetpack\Connection\Manager::remove_non_jetpack_xmlrpc_methods() |
||
| 1110 | * |
||
| 1111 | * @param array $methods A list of registered WordPress XMLRPC methods. |
||
| 1112 | * @return array Filtered $methods |
||
| 1113 | */ |
||
| 1114 | View Code Duplication | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
|
| 1123 | |||
| 1124 | /** |
||
| 1125 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
| 1126 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
| 1127 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
| 1128 | * which is accessible via a different URI. Most of the below is copied directly |
||
| 1129 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
| 1130 | * |
||
| 1131 | * @deprecated since 7.7.0 |
||
| 1132 | * @see Automattic\Jetpack\Connection\Manager::alternate_xmlrpc() |
||
| 1133 | */ |
||
| 1134 | View Code Duplication | public function alternate_xmlrpc() { |
|
| 1143 | |||
| 1144 | /** |
||
| 1145 | * The callback for the JITM ajax requests. |
||
| 1146 | * |
||
| 1147 | * @deprecated since 7.9.0 |
||
| 1148 | */ |
||
| 1149 | function jetpack_jitm_ajax_callback() { |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 1155 | */ |
||
| 1156 | function push_stats() { |
||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Sets the Jetpack custom capabilities. |
||
| 1164 | * |
||
| 1165 | * @param string[] $caps Array of the user's capabilities. |
||
| 1166 | * @param string $cap Capability name. |
||
| 1167 | * @param int $user_id The user ID. |
||
| 1168 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
| 1169 | */ |
||
| 1170 | public function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 1205 | |||
| 1206 | /** |
||
| 1207 | * Require a Jetpack authentication. |
||
| 1208 | * |
||
| 1209 | * @deprecated since 7.7.0 |
||
| 1210 | * @see Automattic\Jetpack\Connection\Manager::require_jetpack_authentication() |
||
| 1211 | */ |
||
| 1212 | View Code Duplication | public function require_jetpack_authentication() { |
|
| 1221 | |||
| 1222 | /** |
||
| 1223 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 1224 | * |
||
| 1225 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 1226 | * @action wp_loaded |
||
| 1227 | * @return null |
||
| 1228 | */ |
||
| 1229 | public function register_assets() { |
||
| 1230 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 1231 | wp_register_script( |
||
| 1232 | 'jetpack-gallery-settings', |
||
| 1233 | Assets::get_file_url_for_environment( '_inc/build/gallery-settings.min.js', '_inc/gallery-settings.js' ), |
||
| 1234 | array( 'media-views' ), |
||
| 1235 | '20121225' |
||
| 1236 | ); |
||
| 1237 | } |
||
| 1238 | |||
| 1239 | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
||
| 1240 | wp_register_script( |
||
| 1241 | 'jetpack-twitter-timeline', |
||
| 1242 | Assets::get_file_url_for_environment( '_inc/build/twitter-timeline.min.js', '_inc/twitter-timeline.js' ), |
||
| 1243 | array( 'jquery' ), |
||
| 1244 | '4.0.0', |
||
| 1245 | true |
||
| 1246 | ); |
||
| 1247 | } |
||
| 1248 | |||
| 1249 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 1250 | wp_register_script( |
||
| 1251 | 'jetpack-facebook-embed', |
||
| 1252 | Assets::get_file_url_for_environment( '_inc/build/facebook-embed.min.js', '_inc/facebook-embed.js' ), |
||
| 1253 | array(), |
||
| 1254 | null, |
||
| 1255 | true |
||
| 1256 | ); |
||
| 1257 | |||
| 1258 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 1259 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 1260 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 1261 | $fb_app_id = ''; |
||
| 1262 | } |
||
| 1263 | wp_localize_script( |
||
| 1264 | 'jetpack-facebook-embed', |
||
| 1265 | 'jpfbembed', |
||
| 1266 | array( |
||
| 1267 | 'appid' => $fb_app_id, |
||
| 1268 | 'locale' => $this->get_locale(), |
||
| 1269 | ) |
||
| 1270 | ); |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 1275 | * the hook may have already fired by this point. |
||
| 1276 | * So, let's just trigger it manually. |
||
| 1277 | */ |
||
| 1278 | require_once JETPACK__PLUGIN_DIR . '_inc/genericons.php'; |
||
| 1279 | jetpack_register_genericons(); |
||
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Register the social logos |
||
| 1283 | */ |
||
| 1284 | require_once JETPACK__PLUGIN_DIR . '_inc/social-logos.php'; |
||
| 1285 | jetpack_register_social_logos(); |
||
| 1286 | |||
| 1287 | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) { |
||
| 1288 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 1289 | } |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Guess locale from language code. |
||
| 1294 | * |
||
| 1295 | * @param string $lang Language code. |
||
| 1296 | * @return string|bool |
||
| 1297 | */ |
||
| 1298 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 1337 | |||
| 1338 | /** |
||
| 1339 | * Get the locale. |
||
| 1340 | * |
||
| 1341 | * @return string|bool |
||
| 1342 | */ |
||
| 1343 | function get_locale() { |
||
| 1352 | |||
| 1353 | /** |
||
| 1354 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 1355 | * |
||
| 1356 | * @param bool $option |
||
| 1357 | * @return string |
||
| 1358 | */ |
||
| 1359 | public function jetpack_main_network_site_option( $option ) { |
||
| 1362 | /** |
||
| 1363 | * Network Name. |
||
| 1364 | */ |
||
| 1365 | static function network_name( $option = null ) { |
||
| 1369 | /** |
||
| 1370 | * Does the network allow new user and site registrations. |
||
| 1371 | * |
||
| 1372 | * @return string |
||
| 1373 | */ |
||
| 1374 | static function network_allow_new_registrations( $option = null ) { |
||
| 1377 | /** |
||
| 1378 | * Does the network allow admins to add new users. |
||
| 1379 | * |
||
| 1380 | * @return boolian |
||
| 1381 | */ |
||
| 1382 | static function network_add_new_users( $option = null ) { |
||
| 1385 | /** |
||
| 1386 | * File upload psace left per site in MB. |
||
| 1387 | * -1 means NO LIMIT. |
||
| 1388 | * |
||
| 1389 | * @return number |
||
| 1390 | */ |
||
| 1391 | static function network_site_upload_space( $option = null ) { |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Network allowed file types. |
||
| 1398 | * |
||
| 1399 | * @return string |
||
| 1400 | */ |
||
| 1401 | static function network_upload_file_types( $option = null ) { |
||
| 1404 | |||
| 1405 | /** |
||
| 1406 | * Maximum file upload size set by the network. |
||
| 1407 | * |
||
| 1408 | * @return number |
||
| 1409 | */ |
||
| 1410 | static function network_max_upload_file_size( $option = null ) { |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Lets us know if a site allows admins to manage the network. |
||
| 1417 | * |
||
| 1418 | * @return array |
||
| 1419 | */ |
||
| 1420 | static function network_enable_administration_menus( $option = null ) { |
||
| 1423 | |||
| 1424 | /** |
||
| 1425 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
| 1426 | * jetpack_other_linked_admins transient. |
||
| 1427 | * |
||
| 1428 | * @since 4.3.2 |
||
| 1429 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
| 1430 | * |
||
| 1431 | * @param int $user_id The user ID whose role changed. |
||
| 1432 | * @param string $role The new role. |
||
| 1433 | * @param array $old_roles An array of the user's previous roles. |
||
| 1434 | */ |
||
| 1435 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Checks to see if there are any other users available to become primary |
||
| 1446 | * Users must both: |
||
| 1447 | * - Be linked to wpcom |
||
| 1448 | * - Be an admin |
||
| 1449 | * |
||
| 1450 | * @return mixed False if no other users are linked, Int if there are. |
||
| 1451 | */ |
||
| 1452 | static function get_other_linked_admins() { |
||
| 1480 | |||
| 1481 | /** |
||
| 1482 | * Return whether we are dealing with a multi network setup or not. |
||
| 1483 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 1484 | * the result is false since when is_main_network_option return false it cases |
||
| 1485 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 1486 | * database which could be set to anything as opposed to what this function returns. |
||
| 1487 | * |
||
| 1488 | * @param bool $option |
||
| 1489 | * |
||
| 1490 | * @return boolean |
||
| 1491 | */ |
||
| 1492 | public function is_main_network_option( $option ) { |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 1499 | * |
||
| 1500 | * @param string $option |
||
| 1501 | * @return boolean |
||
| 1502 | */ |
||
| 1503 | public function is_multisite( $option ) { |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Implemented since there is no core is multi network function |
||
| 1509 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 1510 | * |
||
| 1511 | * @since 3.3 |
||
| 1512 | * @return boolean |
||
| 1513 | */ |
||
| 1514 | View Code Duplication | public static function is_multi_network() { |
|
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1532 | * |
||
| 1533 | * @return null |
||
| 1534 | */ |
||
| 1535 | function update_jetpack_main_network_site_option() { |
||
| 1538 | /** |
||
| 1539 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1540 | */ |
||
| 1541 | function update_jetpack_network_settings() { |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * Get back if the current site is single user site. |
||
| 1548 | * |
||
| 1549 | * @return bool |
||
| 1550 | */ |
||
| 1551 | View Code Duplication | public static function is_single_user_site() { |
|
| 1560 | |||
| 1561 | /** |
||
| 1562 | * Returns true if the site has file write access false otherwise. |
||
| 1563 | * |
||
| 1564 | * @return string ( '1' | '0' ) |
||
| 1565 | **/ |
||
| 1566 | public static function file_system_write_access() { |
||
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Finds out if a site is using a version control system. |
||
| 1589 | * |
||
| 1590 | * @return string ( '1' | '0' ) |
||
| 1591 | **/ |
||
| 1592 | public static function is_version_controlled() { |
||
| 1596 | |||
| 1597 | /** |
||
| 1598 | * Determines whether the current theme supports featured images or not. |
||
| 1599 | * |
||
| 1600 | * @return string ( '1' | '0' ) |
||
| 1601 | */ |
||
| 1602 | public static function featured_images_enabled() { |
||
| 1606 | |||
| 1607 | /** |
||
| 1608 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
| 1609 | * |
||
| 1610 | * @deprecated 4.7 use get_avatar_url instead. |
||
| 1611 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 1612 | * @param int $size Size of the avatar image |
||
| 1613 | * @param string $default URL to a default image to use if no avatar is available |
||
| 1614 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 1615 | * |
||
| 1616 | * @return array |
||
| 1617 | */ |
||
| 1618 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 1629 | // phpcs:disable WordPress.WP.CapitalPDangit.Misspelled |
||
| 1630 | /** |
||
| 1631 | * jetpack_updates is saved in the following schema: |
||
| 1632 | * |
||
| 1633 | * array ( |
||
| 1634 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1635 | * 'themes' => (int) Number of theme updates available. |
||
| 1636 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1637 | * 'translations' => (int) Number of translation updates available. |
||
| 1638 | * 'total' => (int) Total of all available updates. |
||
| 1639 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1640 | * ) |
||
| 1641 | * |
||
| 1642 | * @return array |
||
| 1643 | */ |
||
| 1644 | public static function get_updates() { |
||
| 1661 | // phpcs:enable |
||
| 1662 | |||
| 1663 | public static function get_update_details() { |
||
| 1671 | |||
| 1672 | public static function refresh_update_data() { |
||
| 1676 | |||
| 1677 | public static function refresh_theme_data() { |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Is Jetpack active? |
||
| 1683 | * The method only checks if there's an existing token for the master user. It doesn't validate the token. |
||
| 1684 | * |
||
| 1685 | * @return bool |
||
| 1686 | */ |
||
| 1687 | public static function is_active() { |
||
| 1690 | |||
| 1691 | /** |
||
| 1692 | * Make an API call to WordPress.com for plan status |
||
| 1693 | * |
||
| 1694 | * @deprecated 7.2.0 Use Jetpack_Plan::refresh_from_wpcom. |
||
| 1695 | * |
||
| 1696 | * @return bool True if plan is updated, false if no update |
||
| 1697 | */ |
||
| 1698 | public static function refresh_active_plan_from_wpcom() { |
||
| 1702 | |||
| 1703 | /** |
||
| 1704 | * Get the plan that this Jetpack site is currently using |
||
| 1705 | * |
||
| 1706 | * @deprecated 7.2.0 Use Jetpack_Plan::get. |
||
| 1707 | * @return array Active Jetpack plan details. |
||
| 1708 | */ |
||
| 1709 | public static function get_active_plan() { |
||
| 1713 | |||
| 1714 | /** |
||
| 1715 | * Determine whether the active plan supports a particular feature |
||
| 1716 | * |
||
| 1717 | * @deprecated 7.2.0 Use Jetpack_Plan::supports. |
||
| 1718 | * @return bool True if plan supports feature, false if not. |
||
| 1719 | */ |
||
| 1720 | public static function active_plan_supports( $feature ) { |
||
| 1724 | |||
| 1725 | /** |
||
| 1726 | * Deprecated: Is Jetpack in development (offline) mode? |
||
| 1727 | * |
||
| 1728 | * This static method is being left here intentionally without the use of _deprecated_function(), as other plugins |
||
| 1729 | * and themes still use it, and we do not want to flood them with notices. |
||
| 1730 | * |
||
| 1731 | * Please use Automattic\Jetpack\Status()->is_offline_mode() instead. |
||
| 1732 | * |
||
| 1733 | * @deprecated since 8.0. |
||
| 1734 | */ |
||
| 1735 | public static function is_development_mode() { |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Whether the site is currently onboarding or not. |
||
| 1741 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
| 1742 | * |
||
| 1743 | * @since 5.8 |
||
| 1744 | * |
||
| 1745 | * @access public |
||
| 1746 | * @static |
||
| 1747 | * |
||
| 1748 | * @return bool True if the site is currently onboarding, false otherwise |
||
| 1749 | */ |
||
| 1750 | public static function is_onboarding() { |
||
| 1753 | |||
| 1754 | /** |
||
| 1755 | * Determines reason for Jetpack offline mode. |
||
| 1756 | */ |
||
| 1757 | public static function development_mode_trigger_text() { |
||
| 1780 | /** |
||
| 1781 | * Get Jetpack offline mode notice text and notice class. |
||
| 1782 | * |
||
| 1783 | * Mirrors the checks made in Automattic\Jetpack\Status->is_offline_mode |
||
| 1784 | */ |
||
| 1785 | public static function show_development_mode_notice() { |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1816 | */ |
||
| 1817 | public static function is_development_version() { |
||
| 1832 | |||
| 1833 | /** |
||
| 1834 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1835 | */ |
||
| 1836 | public static function is_user_connected( $user_id = false ) { |
||
| 1840 | |||
| 1841 | /** |
||
| 1842 | * Get the wpcom user data of the current|specified connected user. |
||
| 1843 | */ |
||
| 1844 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1848 | |||
| 1849 | /** |
||
| 1850 | * Get the wpcom email of the current|specified connected user. |
||
| 1851 | */ |
||
| 1852 | public static function get_connected_user_email( $user_id = null ) { |
||
| 1868 | |||
| 1869 | /** |
||
| 1870 | * Get the wpcom email of the master user. |
||
| 1871 | */ |
||
| 1872 | public static function get_master_user_email() { |
||
| 1879 | |||
| 1880 | /** |
||
| 1881 | * Whether the current user is the connection owner. |
||
| 1882 | * |
||
| 1883 | * @deprecated since 7.7 |
||
| 1884 | * |
||
| 1885 | * @return bool Whether the current user is the connection owner. |
||
| 1886 | */ |
||
| 1887 | public function current_user_is_connection_owner() { |
||
| 1891 | |||
| 1892 | /** |
||
| 1893 | * Gets current user IP address. |
||
| 1894 | * |
||
| 1895 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
| 1896 | * |
||
| 1897 | * @return string Current user IP address. |
||
| 1898 | */ |
||
| 1899 | public static function current_user_ip( $check_all_headers = false ) { |
||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Synchronize connected user role changes |
||
| 1922 | */ |
||
| 1923 | function user_role_change( $user_id ) { |
||
| 1927 | |||
| 1928 | /** |
||
| 1929 | * Loads the currently active modules. |
||
| 1930 | */ |
||
| 1931 | public static function load_modules() { |
||
| 2019 | |||
| 2020 | /** |
||
| 2021 | * Check if Jetpack's REST API compat file should be included |
||
| 2022 | * |
||
| 2023 | * @action plugins_loaded |
||
| 2024 | * @return null |
||
| 2025 | */ |
||
| 2026 | public function check_rest_api_compat() { |
||
| 2040 | |||
| 2041 | /** |
||
| 2042 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 2043 | * traditionally activated or network activated. |
||
| 2044 | * |
||
| 2045 | * @todo Store the result in core's object cache maybe? |
||
| 2046 | */ |
||
| 2047 | public static function get_active_plugins() { |
||
| 2063 | |||
| 2064 | /** |
||
| 2065 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 2066 | * |
||
| 2067 | * @since 3.8.1 |
||
| 2068 | * |
||
| 2069 | * @return array Array of plugin data |
||
| 2070 | */ |
||
| 2071 | public static function get_parsed_plugin_data() { |
||
| 2092 | |||
| 2093 | /** |
||
| 2094 | * Gets and parses theme data to send with the heartbeat data |
||
| 2095 | * |
||
| 2096 | * @since 3.8.1 |
||
| 2097 | * |
||
| 2098 | * @return array Array of theme data |
||
| 2099 | */ |
||
| 2100 | public static function get_parsed_theme_data() { |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * Checks whether a specific plugin is active. |
||
| 2125 | * |
||
| 2126 | * We don't want to store these in a static variable, in case |
||
| 2127 | * there are switch_to_blog() calls involved. |
||
| 2128 | */ |
||
| 2129 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 2132 | |||
| 2133 | /** |
||
| 2134 | * Check if Jetpack's Open Graph tags should be used. |
||
| 2135 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 2136 | * |
||
| 2137 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 2138 | * @action plugins_loaded |
||
| 2139 | * @return null |
||
| 2140 | */ |
||
| 2141 | public function check_open_graph() { |
||
| 2168 | |||
| 2169 | /** |
||
| 2170 | * Check if Jetpack's Twitter tags should be used. |
||
| 2171 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 2172 | * |
||
| 2173 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 2174 | * @action plugins_loaded |
||
| 2175 | * @return null |
||
| 2176 | */ |
||
| 2177 | public function check_twitter_tags() { |
||
| 2201 | |||
| 2202 | /** |
||
| 2203 | * Allows plugins to submit security reports. |
||
| 2204 | * |
||
| 2205 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 2206 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 2207 | * @param array $args See definitions above |
||
| 2208 | */ |
||
| 2209 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 2212 | |||
| 2213 | /* Jetpack Options API */ |
||
| 2214 | |||
| 2215 | public static function get_option_names( $type = 'compact' ) { |
||
| 2218 | |||
| 2219 | /** |
||
| 2220 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 2221 | * |
||
| 2222 | * @param string $name Option name |
||
| 2223 | * @param mixed $default (optional) |
||
| 2224 | */ |
||
| 2225 | public static function get_option( $name, $default = false ) { |
||
| 2228 | |||
| 2229 | /** |
||
| 2230 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 2231 | * |
||
| 2232 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 2233 | * @param string $name Option name |
||
| 2234 | * @param mixed $value Option value |
||
| 2235 | */ |
||
| 2236 | public static function update_option( $name, $value ) { |
||
| 2240 | |||
| 2241 | /** |
||
| 2242 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 2243 | * |
||
| 2244 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 2245 | * @param array $array array( option name => option value, ... ) |
||
| 2246 | */ |
||
| 2247 | public static function update_options( $array ) { |
||
| 2251 | |||
| 2252 | /** |
||
| 2253 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 2254 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 2255 | * |
||
| 2256 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 2257 | * @param string|array $names |
||
| 2258 | */ |
||
| 2259 | public static function delete_option( $names ) { |
||
| 2263 | |||
| 2264 | /** |
||
| 2265 | * @deprecated 8.0 Use Automattic\Jetpack\Connection\Utils::update_user_token() instead. |
||
| 2266 | * |
||
| 2267 | * Enters a user token into the user_tokens option |
||
| 2268 | * |
||
| 2269 | * @param int $user_id The user id. |
||
| 2270 | * @param string $token The user token. |
||
| 2271 | * @param bool $is_master_user Whether the user is the master user. |
||
| 2272 | * @return bool |
||
| 2273 | */ |
||
| 2274 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 2278 | |||
| 2279 | /** |
||
| 2280 | * Returns an array of all PHP files in the specified absolute path. |
||
| 2281 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 2282 | * |
||
| 2283 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 2284 | * @return array Array of absolute paths to the PHP files. |
||
| 2285 | */ |
||
| 2286 | public static function glob_php( $absolute_path ) { |
||
| 2315 | |||
| 2316 | public static function activate_new_modules( $redirect = false ) { |
||
| 2375 | |||
| 2376 | /** |
||
| 2377 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 2378 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 2379 | */ |
||
| 2380 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 2440 | |||
| 2441 | /** |
||
| 2442 | * Default modules loaded on activation. |
||
| 2443 | */ |
||
| 2444 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 2475 | |||
| 2476 | /** |
||
| 2477 | * Checks activated modules during auto-activation to determine |
||
| 2478 | * if any of those modules are being deprecated. If so, close |
||
| 2479 | * them out, and add any replacement modules. |
||
| 2480 | * |
||
| 2481 | * Runs at priority 99 by default. |
||
| 2482 | * |
||
| 2483 | * This is run late, so that it can still activate a module if |
||
| 2484 | * the new module is a replacement for another that the user |
||
| 2485 | * currently has active, even if something at the normal priority |
||
| 2486 | * would kibosh everything. |
||
| 2487 | * |
||
| 2488 | * @since 2.6 |
||
| 2489 | * @uses jetpack_get_default_modules filter |
||
| 2490 | * @param array $modules |
||
| 2491 | * @return array |
||
| 2492 | */ |
||
| 2493 | function handle_deprecated_modules( $modules ) { |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Checks activated plugins during auto-activation to determine |
||
| 2523 | * if any of those plugins are in the list with a corresponding module |
||
| 2524 | * that is not compatible with the plugin. The module will not be allowed |
||
| 2525 | * to auto-activate. |
||
| 2526 | * |
||
| 2527 | * @since 2.6 |
||
| 2528 | * @uses jetpack_get_default_modules filter |
||
| 2529 | * @param array $modules |
||
| 2530 | * @return array |
||
| 2531 | */ |
||
| 2532 | function filter_default_modules( $modules ) { |
||
| 2556 | |||
| 2557 | /** |
||
| 2558 | * Extract a module's slug from its full path. |
||
| 2559 | */ |
||
| 2560 | public static function get_module_slug( $file ) { |
||
| 2563 | |||
| 2564 | /** |
||
| 2565 | * Generate a module's path from its slug. |
||
| 2566 | */ |
||
| 2567 | public static function get_module_path( $slug ) { |
||
| 2578 | |||
| 2579 | /** |
||
| 2580 | * Load module data from module file. Headers differ from WordPress |
||
| 2581 | * plugin headers to avoid them being identified as standalone |
||
| 2582 | * plugins on the WordPress plugins page. |
||
| 2583 | */ |
||
| 2584 | public static function get_module( $module ) { |
||
| 2585 | $headers = array( |
||
| 2586 | 'name' => 'Module Name', |
||
| 2587 | 'description' => 'Module Description', |
||
| 2588 | 'sort' => 'Sort Order', |
||
| 2589 | 'recommendation_order' => 'Recommendation Order', |
||
| 2590 | 'introduced' => 'First Introduced', |
||
| 2591 | 'changed' => 'Major Changes In', |
||
| 2592 | 'deactivate' => 'Deactivate', |
||
| 2593 | 'free' => 'Free', |
||
| 2594 | 'requires_connection' => 'Requires Connection', |
||
| 2595 | 'requires_user_connection' => 'Requires User Connection', |
||
| 2596 | 'auto_activate' => 'Auto Activate', |
||
| 2597 | 'module_tags' => 'Module Tags', |
||
| 2598 | 'feature' => 'Feature', |
||
| 2599 | 'additional_search_queries' => 'Additional Search Queries', |
||
| 2600 | 'plan_classes' => 'Plans', |
||
| 2601 | ); |
||
| 2602 | |||
| 2603 | $file = self::get_module_path( self::get_module_slug( $module ) ); |
||
| 2604 | |||
| 2605 | $mod = self::get_file_data( $file, $headers ); |
||
| 2606 | if ( empty( $mod['name'] ) ) { |
||
| 2607 | return false; |
||
| 2608 | } |
||
| 2609 | |||
| 2610 | $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort']; |
||
| 2611 | $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order']; |
||
| 2612 | $mod['deactivate'] = empty( $mod['deactivate'] ); |
||
| 2613 | $mod['free'] = empty( $mod['free'] ); |
||
| 2614 | $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' === $mod['requires_connection'] ) ? false : true; |
||
| 2615 | $mod['requires_user_connection'] = ( empty( $mod['requires_user_connection'] ) || 'No' === $mod['requires_user_connection'] ) ? false : true; |
||
| 2616 | |||
| 2617 | if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ) ) ) { |
||
| 2618 | $mod['auto_activate'] = 'No'; |
||
| 2619 | } else { |
||
| 2620 | $mod['auto_activate'] = (string) $mod['auto_activate']; |
||
| 2621 | } |
||
| 2622 | |||
| 2623 | if ( $mod['module_tags'] ) { |
||
| 2624 | $mod['module_tags'] = explode( ',', $mod['module_tags'] ); |
||
| 2625 | $mod['module_tags'] = array_map( 'trim', $mod['module_tags'] ); |
||
| 2626 | $mod['module_tags'] = array_map( array( __CLASS__, 'translate_module_tag' ), $mod['module_tags'] ); |
||
| 2627 | } else { |
||
| 2628 | $mod['module_tags'] = array( self::translate_module_tag( 'Other' ) ); |
||
| 2629 | } |
||
| 2630 | |||
| 2631 | View Code Duplication | if ( $mod['plan_classes'] ) { |
|
| 2632 | $mod['plan_classes'] = explode( ',', $mod['plan_classes'] ); |
||
| 2633 | $mod['plan_classes'] = array_map( 'strtolower', array_map( 'trim', $mod['plan_classes'] ) ); |
||
| 2634 | } else { |
||
| 2635 | $mod['plan_classes'] = array( 'free' ); |
||
| 2636 | } |
||
| 2637 | |||
| 2638 | View Code Duplication | if ( $mod['feature'] ) { |
|
| 2639 | $mod['feature'] = explode( ',', $mod['feature'] ); |
||
| 2640 | $mod['feature'] = array_map( 'trim', $mod['feature'] ); |
||
| 2641 | } else { |
||
| 2642 | $mod['feature'] = array( self::translate_module_tag( 'Other' ) ); |
||
| 2643 | } |
||
| 2644 | |||
| 2645 | /** |
||
| 2646 | * Filters the feature array on a module. |
||
| 2647 | * |
||
| 2648 | * This filter allows you to control where each module is filtered: Recommended, |
||
| 2649 | * and the default "Other" listing. |
||
| 2650 | * |
||
| 2651 | * @since 3.5.0 |
||
| 2652 | * |
||
| 2653 | * @param array $mod['feature'] The areas to feature this module: |
||
| 2654 | * 'Recommended' shows on the main Jetpack admin screen. |
||
| 2655 | * 'Other' should be the default if no other value is in the array. |
||
| 2656 | * @param string $module The slug of the module, e.g. sharedaddy. |
||
| 2657 | * @param array $mod All the currently assembled module data. |
||
| 2658 | */ |
||
| 2659 | $mod['feature'] = apply_filters( 'jetpack_module_feature', $mod['feature'], $module, $mod ); |
||
| 2660 | |||
| 2661 | /** |
||
| 2662 | * Filter the returned data about a module. |
||
| 2663 | * |
||
| 2664 | * This filter allows overriding any info about Jetpack modules. It is dangerous, |
||
| 2665 | * so please be careful. |
||
| 2666 | * |
||
| 2667 | * @since 3.6.0 |
||
| 2668 | * |
||
| 2669 | * @param array $mod The details of the requested module. |
||
| 2670 | * @param string $module The slug of the module, e.g. sharedaddy |
||
| 2671 | * @param string $file The path to the module source file. |
||
| 2672 | */ |
||
| 2673 | return apply_filters( 'jetpack_get_module', $mod, $module, $file ); |
||
| 2674 | } |
||
| 2675 | |||
| 2676 | /** |
||
| 2677 | * Like core's get_file_data implementation, but caches the result. |
||
| 2678 | */ |
||
| 2679 | public static function get_file_data( $file, $headers ) { |
||
| 2680 | // Get just the filename from $file (i.e. exclude full path) so that a consistent hash is generated |
||
| 2681 | $file_name = basename( $file ); |
||
| 2682 | |||
| 2683 | $cache_key = 'jetpack_file_data_' . JETPACK__VERSION; |
||
| 2684 | |||
| 2685 | $file_data_option = get_transient( $cache_key ); |
||
| 2686 | |||
| 2687 | if ( ! is_array( $file_data_option ) ) { |
||
| 2688 | delete_transient( $cache_key ); |
||
| 2689 | $file_data_option = false; |
||
| 2690 | } |
||
| 2691 | |||
| 2692 | if ( false === $file_data_option ) { |
||
| 2693 | $file_data_option = array(); |
||
| 2694 | } |
||
| 2695 | |||
| 2696 | $key = md5( $file_name . serialize( $headers ) ); |
||
| 2697 | $refresh_cache = is_admin() && isset( $_GET['page'] ) && 'jetpack' === substr( $_GET['page'], 0, 7 ); |
||
| 2698 | |||
| 2699 | // If we don't need to refresh the cache, and already have the value, short-circuit! |
||
| 2700 | if ( ! $refresh_cache && isset( $file_data_option[ $key ] ) ) { |
||
| 2701 | return $file_data_option[ $key ]; |
||
| 2702 | } |
||
| 2703 | |||
| 2704 | $data = get_file_data( $file, $headers ); |
||
| 2705 | |||
| 2706 | $file_data_option[ $key ] = $data; |
||
| 2707 | |||
| 2708 | set_transient( $cache_key, $file_data_option, 29 * DAY_IN_SECONDS ); |
||
| 2709 | |||
| 2710 | return $data; |
||
| 2711 | } |
||
| 2712 | |||
| 2713 | /** |
||
| 2714 | * Return translated module tag. |
||
| 2715 | * |
||
| 2716 | * @param string $tag Tag as it appears in each module heading. |
||
| 2717 | * |
||
| 2718 | * @return mixed |
||
| 2719 | */ |
||
| 2720 | public static function translate_module_tag( $tag ) { |
||
| 2721 | return jetpack_get_module_i18n_tag( $tag ); |
||
| 2722 | } |
||
| 2723 | |||
| 2724 | /** |
||
| 2725 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2726 | * |
||
| 2727 | * @since 3.9.2 |
||
| 2728 | * |
||
| 2729 | * @param array $modules |
||
| 2730 | * |
||
| 2731 | * @return string|void |
||
| 2732 | */ |
||
| 2733 | public static function get_translated_modules( $modules ) { |
||
| 2734 | foreach ( $modules as $index => $module ) { |
||
| 2735 | $i18n_module = jetpack_get_module_i18n( $module['module'] ); |
||
| 2736 | if ( isset( $module['name'] ) ) { |
||
| 2737 | $modules[ $index ]['name'] = $i18n_module['name']; |
||
| 2738 | } |
||
| 2739 | if ( isset( $module['description'] ) ) { |
||
| 2740 | $modules[ $index ]['description'] = $i18n_module['description']; |
||
| 2741 | $modules[ $index ]['short_description'] = $i18n_module['description']; |
||
| 2742 | } |
||
| 2743 | } |
||
| 2744 | return $modules; |
||
| 2745 | } |
||
| 2746 | |||
| 2747 | /** |
||
| 2748 | * Get a list of activated modules as an array of module slugs. |
||
| 2749 | */ |
||
| 2750 | public static function get_active_modules() { |
||
| 2751 | $active = Jetpack_Options::get_option( 'active_modules' ); |
||
| 2752 | |||
| 2753 | if ( ! is_array( $active ) ) { |
||
| 2754 | $active = array(); |
||
| 2755 | } |
||
| 2756 | |||
| 2757 | if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) { |
||
| 2758 | $active[] = 'vaultpress'; |
||
| 2759 | } else { |
||
| 2760 | $active = array_diff( $active, array( 'vaultpress' ) ); |
||
| 2761 | } |
||
| 2762 | |||
| 2763 | // If protect is active on the main site of a multisite, it should be active on all sites. |
||
| 2764 | if ( ! in_array( 'protect', $active ) && is_multisite() && get_site_option( 'jetpack_protect_active' ) ) { |
||
| 2765 | $active[] = 'protect'; |
||
| 2766 | } |
||
| 2767 | |||
| 2768 | /** |
||
| 2769 | * Allow filtering of the active modules. |
||
| 2770 | * |
||
| 2771 | * Gives theme and plugin developers the power to alter the modules that |
||
| 2772 | * are activated on the fly. |
||
| 2773 | * |
||
| 2774 | * @since 5.8.0 |
||
| 2775 | * |
||
| 2776 | * @param array $active Array of active module slugs. |
||
| 2777 | */ |
||
| 2778 | $active = apply_filters( 'jetpack_active_modules', $active ); |
||
| 2779 | |||
| 2780 | return array_unique( $active ); |
||
| 2781 | } |
||
| 2782 | |||
| 2783 | /** |
||
| 2784 | * Check whether or not a Jetpack module is active. |
||
| 2785 | * |
||
| 2786 | * @param string $module The slug of a Jetpack module. |
||
| 2787 | * @return bool |
||
| 2788 | * |
||
| 2789 | * @static |
||
| 2790 | */ |
||
| 2791 | public static function is_module_active( $module ) { |
||
| 2792 | return in_array( $module, self::get_active_modules() ); |
||
| 2793 | } |
||
| 2794 | |||
| 2795 | public static function is_module( $module ) { |
||
| 2796 | return ! empty( $module ) && ! validate_file( $module, self::get_available_modules() ); |
||
| 2797 | } |
||
| 2798 | |||
| 2799 | /** |
||
| 2800 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2801 | * |
||
| 2802 | * @param bool $catch True to start catching, False to stop. |
||
| 2803 | * |
||
| 2804 | * @static |
||
| 2805 | */ |
||
| 2806 | public static function catch_errors( $catch ) { |
||
| 2807 | static $display_errors, $error_reporting; |
||
| 2808 | |||
| 2809 | if ( $catch ) { |
||
| 2810 | $display_errors = @ini_set( 'display_errors', 1 ); |
||
| 2811 | $error_reporting = @error_reporting( E_ALL ); |
||
| 2812 | add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
| 2813 | } else { |
||
| 2814 | @ini_set( 'display_errors', $display_errors ); |
||
| 2815 | @error_reporting( $error_reporting ); |
||
| 2816 | remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
| 2817 | } |
||
| 2818 | } |
||
| 2819 | |||
| 2820 | /** |
||
| 2821 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2822 | */ |
||
| 2823 | public static function catch_errors_on_shutdown() { |
||
| 2824 | self::state( 'php_errors', self::alias_directories( ob_get_clean() ) ); |
||
| 2825 | } |
||
| 2826 | |||
| 2827 | /** |
||
| 2828 | * Rewrite any string to make paths easier to read. |
||
| 2829 | * |
||
| 2830 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
| 2831 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
| 2832 | * |
||
| 2833 | * @param $string |
||
| 2834 | * @return mixed |
||
| 2835 | */ |
||
| 2836 | public static function alias_directories( $string ) { |
||
| 2837 | // ABSPATH has a trailing slash. |
||
| 2838 | $string = str_replace( ABSPATH, 'ABSPATH/', $string ); |
||
| 2839 | // WP_CONTENT_DIR does not have a trailing slash. |
||
| 2840 | $string = str_replace( WP_CONTENT_DIR, 'WP_CONTENT_DIR', $string ); |
||
| 2841 | |||
| 2842 | return $string; |
||
| 2843 | } |
||
| 2844 | |||
| 2845 | public static function activate_default_modules( |
||
| 2846 | $min_version = false, |
||
| 2847 | $max_version = false, |
||
| 2848 | $other_modules = array(), |
||
| 2849 | $redirect = null, |
||
| 2850 | $send_state_messages = null |
||
| 2851 | ) { |
||
| 2852 | $jetpack = self::init(); |
||
| 2853 | |||
| 2854 | if ( is_null( $redirect ) ) { |
||
| 2855 | if ( |
||
| 2856 | ( defined( 'REST_REQUEST' ) && REST_REQUEST ) |
||
| 2857 | || |
||
| 2858 | ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
||
| 2859 | || |
||
| 2860 | ( defined( 'WP_CLI' ) && WP_CLI ) |
||
| 2861 | || |
||
| 2862 | ( defined( 'DOING_CRON' ) && DOING_CRON ) |
||
| 2863 | || |
||
| 2864 | ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
||
| 2865 | ) { |
||
| 2866 | $redirect = false; |
||
| 2867 | } elseif ( is_admin() ) { |
||
| 2868 | $redirect = true; |
||
| 2869 | } else { |
||
| 2870 | $redirect = false; |
||
| 2871 | } |
||
| 2872 | } |
||
| 2873 | |||
| 2874 | if ( is_null( $send_state_messages ) ) { |
||
| 2875 | $send_state_messages = current_user_can( 'jetpack_activate_modules' ); |
||
| 2876 | } |
||
| 2877 | |||
| 2878 | $modules = self::get_default_modules( $min_version, $max_version ); |
||
| 2879 | $modules = array_merge( $other_modules, $modules ); |
||
| 2880 | |||
| 2881 | // Look for standalone plugins and disable if active. |
||
| 2882 | |||
| 2883 | $to_deactivate = array(); |
||
| 2884 | foreach ( $modules as $module ) { |
||
| 2885 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
| 2886 | $to_deactivate[ $module ] = $jetpack->plugins_to_deactivate[ $module ]; |
||
| 2887 | } |
||
| 2888 | } |
||
| 2889 | |||
| 2890 | $deactivated = array(); |
||
| 2891 | foreach ( $to_deactivate as $module => $deactivate_me ) { |
||
| 2892 | list( $probable_file, $probable_title ) = $deactivate_me; |
||
| 2893 | if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) { |
||
| 2894 | $deactivated[] = $module; |
||
| 2895 | } |
||
| 2896 | } |
||
| 2897 | |||
| 2898 | if ( $deactivated ) { |
||
| 2899 | if ( $send_state_messages ) { |
||
| 2900 | self::state( 'deactivated_plugins', join( ',', $deactivated ) ); |
||
| 2901 | } |
||
| 2902 | |||
| 2903 | if ( $redirect ) { |
||
| 2904 | $url = add_query_arg( |
||
| 2905 | array( |
||
| 2906 | 'action' => 'activate_default_modules', |
||
| 2907 | '_wpnonce' => wp_create_nonce( 'activate_default_modules' ), |
||
| 2908 | ), |
||
| 2909 | add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), self::admin_url( 'page=jetpack' ) ) |
||
| 2910 | ); |
||
| 2911 | wp_safe_redirect( $url ); |
||
| 2912 | exit; |
||
| 2913 | } |
||
| 2914 | } |
||
| 2915 | |||
| 2916 | /** |
||
| 2917 | * Fires before default modules are activated. |
||
| 2918 | * |
||
| 2919 | * @since 1.9.0 |
||
| 2920 | * |
||
| 2921 | * @param string $min_version Minimum version number required to use modules. |
||
| 2922 | * @param string $max_version Maximum version number required to use modules. |
||
| 2923 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
| 2924 | */ |
||
| 2925 | do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
| 2926 | |||
| 2927 | // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating |
||
| 2928 | if ( $send_state_messages ) { |
||
| 2929 | self::restate(); |
||
| 2930 | self::catch_errors( true ); |
||
| 2931 | } |
||
| 2932 | |||
| 2933 | $active = self::get_active_modules(); |
||
| 2934 | |||
| 2935 | foreach ( $modules as $module ) { |
||
| 2936 | if ( did_action( "jetpack_module_loaded_$module" ) ) { |
||
| 2937 | $active[] = $module; |
||
| 2938 | self::update_active_modules( $active ); |
||
| 2939 | continue; |
||
| 2940 | } |
||
| 2941 | |||
| 2942 | if ( $send_state_messages && in_array( $module, $active ) ) { |
||
| 2943 | $module_info = self::get_module( $module ); |
||
| 2944 | View Code Duplication | if ( ! $module_info['deactivate'] ) { |
|
| 2945 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
| 2946 | if ( $active_state = self::state( $state ) ) { |
||
| 2947 | $active_state = explode( ',', $active_state ); |
||
| 2948 | } else { |
||
| 2949 | $active_state = array(); |
||
| 2950 | } |
||
| 2951 | $active_state[] = $module; |
||
| 2952 | self::state( $state, implode( ',', $active_state ) ); |
||
| 2953 | } |
||
| 2954 | continue; |
||
| 2955 | } |
||
| 2956 | |||
| 2957 | $file = self::get_module_path( $module ); |
||
| 2958 | if ( ! file_exists( $file ) ) { |
||
| 2959 | continue; |
||
| 2960 | } |
||
| 2961 | |||
| 2962 | // we'll override this later if the plugin can be included without fatal error |
||
| 2963 | if ( $redirect ) { |
||
| 2964 | wp_safe_redirect( self::admin_url( 'page=jetpack' ) ); |
||
| 2965 | } |
||
| 2966 | |||
| 2967 | if ( $send_state_messages ) { |
||
| 2968 | self::state( 'error', 'module_activation_failed' ); |
||
| 2969 | self::state( 'module', $module ); |
||
| 2970 | } |
||
| 2971 | |||
| 2972 | ob_start(); |
||
| 2973 | require_once $file; |
||
| 2974 | |||
| 2975 | $active[] = $module; |
||
| 2976 | |||
| 2977 | View Code Duplication | if ( $send_state_messages ) { |
|
| 2978 | |||
| 2979 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
| 2980 | if ( $active_state = self::state( $state ) ) { |
||
| 2981 | $active_state = explode( ',', $active_state ); |
||
| 2982 | } else { |
||
| 2983 | $active_state = array(); |
||
| 2984 | } |
||
| 2985 | $active_state[] = $module; |
||
| 2986 | self::state( $state, implode( ',', $active_state ) ); |
||
| 2987 | } |
||
| 2988 | |||
| 2989 | self::update_active_modules( $active ); |
||
| 2990 | |||
| 2991 | ob_end_clean(); |
||
| 2992 | } |
||
| 2993 | |||
| 2994 | if ( $send_state_messages ) { |
||
| 2995 | self::state( 'error', false ); |
||
| 2996 | self::state( 'module', false ); |
||
| 2997 | } |
||
| 2998 | |||
| 2999 | self::catch_errors( false ); |
||
| 3000 | /** |
||
| 3001 | * Fires when default modules are activated. |
||
| 3002 | * |
||
| 3003 | * @since 1.9.0 |
||
| 3004 | * |
||
| 3005 | * @param string $min_version Minimum version number required to use modules. |
||
| 3006 | * @param string $max_version Maximum version number required to use modules. |
||
| 3007 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
| 3008 | */ |
||
| 3009 | do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
| 3010 | } |
||
| 3011 | |||
| 3012 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 3013 | /** |
||
| 3014 | * Fires before a module is activated. |
||
| 3015 | * |
||
| 3016 | * @since 2.6.0 |
||
| 3017 | * |
||
| 3018 | * @param string $module Module slug. |
||
| 3019 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
| 3020 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
| 3021 | */ |
||
| 3022 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
| 3023 | |||
| 3024 | $jetpack = self::init(); |
||
| 3025 | |||
| 3026 | if ( ! strlen( $module ) ) { |
||
| 3027 | return false; |
||
| 3028 | } |
||
| 3029 | |||
| 3030 | if ( ! self::is_module( $module ) ) { |
||
| 3031 | return false; |
||
| 3032 | } |
||
| 3033 | |||
| 3034 | // If it's already active, then don't do it again |
||
| 3035 | $active = self::get_active_modules(); |
||
| 3036 | foreach ( $active as $act ) { |
||
| 3037 | if ( $act == $module ) { |
||
| 3038 | return true; |
||
| 3039 | } |
||
| 3040 | } |
||
| 3041 | |||
| 3042 | $module_data = self::get_module( $module ); |
||
| 3043 | |||
| 3044 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
| 3045 | if ( ! self::is_active() ) { |
||
| 3046 | if ( ! $is_offline_mode && ! self::is_onboarding() ) { |
||
| 3047 | return false; |
||
| 3048 | } |
||
| 3049 | |||
| 3050 | // If we're not connected but in offline mode, make sure the module doesn't require a connection. |
||
| 3051 | if ( $is_offline_mode && $module_data['requires_connection'] ) { |
||
| 3052 | return false; |
||
| 3053 | } |
||
| 3054 | } |
||
| 3055 | |||
| 3056 | // Check and see if the old plugin is active |
||
| 3057 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
| 3058 | // Deactivate the old plugin |
||
| 3059 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
| 3060 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
| 3061 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
| 3062 | self::state( 'deactivated_plugins', $module ); |
||
| 3063 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
| 3064 | exit; |
||
| 3065 | } |
||
| 3066 | } |
||
| 3067 | |||
| 3068 | // Protect won't work with mis-configured IPs |
||
| 3069 | if ( 'protect' === $module ) { |
||
| 3070 | include_once JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php'; |
||
| 3071 | if ( ! jetpack_protect_get_ip() ) { |
||
| 3072 | self::state( 'message', 'protect_misconfigured_ip' ); |
||
| 3073 | return false; |
||
| 3074 | } |
||
| 3075 | } |
||
| 3076 | |||
| 3077 | if ( ! Jetpack_Plan::supports( $module ) ) { |
||
| 3078 | return false; |
||
| 3079 | } |
||
| 3080 | |||
| 3081 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
| 3082 | self::state( 'module', $module ); |
||
| 3083 | self::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
| 3084 | |||
| 3085 | self::catch_errors( true ); |
||
| 3086 | ob_start(); |
||
| 3087 | require self::get_module_path( $module ); |
||
| 3088 | /** This action is documented in class.jetpack.php */ |
||
| 3089 | do_action( 'jetpack_activate_module', $module ); |
||
| 3090 | $active[] = $module; |
||
| 3091 | self::update_active_modules( $active ); |
||
| 3092 | |||
| 3093 | self::state( 'error', false ); // the override |
||
| 3094 | ob_end_clean(); |
||
| 3095 | self::catch_errors( false ); |
||
| 3096 | |||
| 3097 | if ( $redirect ) { |
||
| 3098 | wp_safe_redirect( self::admin_url( 'page=jetpack' ) ); |
||
| 3099 | } |
||
| 3100 | if ( $exit ) { |
||
| 3101 | exit; |
||
| 3102 | } |
||
| 3103 | return true; |
||
| 3104 | } |
||
| 3105 | |||
| 3106 | function activate_module_actions( $module ) { |
||
| 3107 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 3108 | } |
||
| 3109 | |||
| 3110 | public static function deactivate_module( $module ) { |
||
| 3111 | /** |
||
| 3112 | * Fires when a module is deactivated. |
||
| 3113 | * |
||
| 3114 | * @since 1.9.0 |
||
| 3115 | * |
||
| 3116 | * @param string $module Module slug. |
||
| 3117 | */ |
||
| 3118 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
| 3119 | |||
| 3120 | $jetpack = self::init(); |
||
| 3121 | |||
| 3122 | $active = self::get_active_modules(); |
||
| 3123 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
| 3124 | |||
| 3125 | return self::update_active_modules( $new ); |
||
| 3126 | } |
||
| 3127 | |||
| 3128 | public static function enable_module_configurable( $module ) { |
||
| 3129 | $module = self::get_module_slug( $module ); |
||
| 3130 | add_filter( 'jetpack_module_configurable_' . $module, '__return_true' ); |
||
| 3131 | } |
||
| 3132 | |||
| 3133 | /** |
||
| 3134 | * Composes a module configure URL. It uses Jetpack settings search as default value |
||
| 3135 | * It is possible to redefine resulting URL by using "jetpack_module_configuration_url_$module" filter |
||
| 3136 | * |
||
| 3137 | * @param string $module Module slug |
||
| 3138 | * @return string $url module configuration URL |
||
| 3139 | */ |
||
| 3140 | public static function module_configuration_url( $module ) { |
||
| 3141 | $module = self::get_module_slug( $module ); |
||
| 3142 | $default_url = self::admin_url() . "#/settings?term=$module"; |
||
| 3143 | /** |
||
| 3144 | * Allows to modify configure_url of specific module to be able to redirect to some custom location. |
||
| 3145 | * |
||
| 3146 | * @since 6.9.0 |
||
| 3147 | * |
||
| 3148 | * @param string $default_url Default url, which redirects to jetpack settings page. |
||
| 3149 | */ |
||
| 3150 | $url = apply_filters( 'jetpack_module_configuration_url_' . $module, $default_url ); |
||
| 3151 | |||
| 3152 | return $url; |
||
| 3153 | } |
||
| 3154 | |||
| 3155 | /* Installation */ |
||
| 3156 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 3157 | ?> |
||
| 3158 | <!doctype html> |
||
| 3159 | <html> |
||
| 3160 | <head> |
||
| 3161 | <meta charset="<?php bloginfo( 'charset' ); ?>"> |
||
| 3162 | <style> |
||
| 3163 | * { |
||
| 3164 | text-align: center; |
||
| 3165 | margin: 0; |
||
| 3166 | padding: 0; |
||
| 3167 | font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; |
||
| 3168 | } |
||
| 3169 | p { |
||
| 3170 | margin-top: 1em; |
||
| 3171 | font-size: 18px; |
||
| 3172 | } |
||
| 3173 | </style> |
||
| 3174 | <body> |
||
| 3175 | <p><?php echo esc_html( $message ); ?></p> |
||
| 3176 | </body> |
||
| 3177 | </html> |
||
| 3178 | <?php |
||
| 3179 | if ( $deactivate ) { |
||
| 3180 | $plugins = get_option( 'active_plugins' ); |
||
| 3181 | $jetpack = plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ); |
||
| 3182 | $update = false; |
||
| 3183 | foreach ( $plugins as $i => $plugin ) { |
||
| 3184 | if ( $plugin === $jetpack ) { |
||
| 3185 | $plugins[ $i ] = false; |
||
| 3186 | $update = true; |
||
| 3187 | } |
||
| 3188 | } |
||
| 3189 | |||
| 3190 | if ( $update ) { |
||
| 3191 | update_option( 'active_plugins', array_filter( $plugins ) ); |
||
| 3192 | } |
||
| 3193 | } |
||
| 3194 | exit; |
||
| 3195 | } |
||
| 3196 | |||
| 3197 | /** |
||
| 3198 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 3199 | * |
||
| 3200 | * @static |
||
| 3201 | */ |
||
| 3202 | public static function plugin_activation( $network_wide ) { |
||
| 3203 | Jetpack_Options::update_option( 'activated', 1 ); |
||
| 3204 | |||
| 3205 | if ( version_compare( $GLOBALS['wp_version'], JETPACK__MINIMUM_WP_VERSION, '<' ) ) { |
||
| 3206 | self::bail_on_activation( sprintf( __( 'Jetpack requires WordPress version %s or later.', 'jetpack' ), JETPACK__MINIMUM_WP_VERSION ) ); |
||
| 3207 | } |
||
| 3208 | |||
| 3209 | if ( $network_wide ) { |
||
| 3210 | self::state( 'network_nag', true ); |
||
| 3211 | } |
||
| 3212 | |||
| 3213 | // For firing one-off events (notices) immediately after activation |
||
| 3214 | set_transient( 'activated_jetpack', true, 0.1 * MINUTE_IN_SECONDS ); |
||
| 3215 | |||
| 3216 | update_option( 'jetpack_activation_source', self::get_activation_source( wp_get_referer() ) ); |
||
| 3217 | |||
| 3218 | Health::on_jetpack_activated(); |
||
| 3219 | |||
| 3220 | self::plugin_initialize(); |
||
| 3221 | } |
||
| 3222 | |||
| 3223 | public static function get_activation_source( $referer_url ) { |
||
| 3224 | |||
| 3225 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
||
| 3226 | return array( 'wp-cli', null ); |
||
| 3227 | } |
||
| 3228 | |||
| 3229 | $referer = wp_parse_url( $referer_url ); |
||
| 3230 | |||
| 3231 | $source_type = 'unknown'; |
||
| 3232 | $source_query = null; |
||
| 3233 | |||
| 3234 | if ( ! is_array( $referer ) ) { |
||
| 3235 | return array( $source_type, $source_query ); |
||
| 3236 | } |
||
| 3237 | |||
| 3238 | $plugins_path = wp_parse_url( admin_url( 'plugins.php' ), PHP_URL_PATH ); |
||
| 3239 | $plugins_install_path = wp_parse_url( admin_url( 'plugin-install.php' ), PHP_URL_PATH );// /wp-admin/plugin-install.php |
||
| 3240 | |||
| 3241 | if ( isset( $referer['query'] ) ) { |
||
| 3242 | parse_str( $referer['query'], $query_parts ); |
||
| 3243 | } else { |
||
| 3244 | $query_parts = array(); |
||
| 3245 | } |
||
| 3246 | |||
| 3247 | if ( $plugins_path === $referer['path'] ) { |
||
| 3248 | $source_type = 'list'; |
||
| 3249 | } elseif ( $plugins_install_path === $referer['path'] ) { |
||
| 3250 | $tab = isset( $query_parts['tab'] ) ? $query_parts['tab'] : 'featured'; |
||
| 3251 | switch ( $tab ) { |
||
| 3252 | case 'popular': |
||
| 3253 | $source_type = 'popular'; |
||
| 3254 | break; |
||
| 3255 | case 'recommended': |
||
| 3256 | $source_type = 'recommended'; |
||
| 3257 | break; |
||
| 3258 | case 'favorites': |
||
| 3259 | $source_type = 'favorites'; |
||
| 3260 | break; |
||
| 3261 | case 'search': |
||
| 3262 | $source_type = 'search-' . ( isset( $query_parts['type'] ) ? $query_parts['type'] : 'term' ); |
||
| 3263 | $source_query = isset( $query_parts['s'] ) ? $query_parts['s'] : null; |
||
| 3264 | break; |
||
| 3265 | default: |
||
| 3266 | $source_type = 'featured'; |
||
| 3267 | } |
||
| 3268 | } |
||
| 3269 | |||
| 3270 | return array( $source_type, $source_query ); |
||
| 3271 | } |
||
| 3272 | |||
| 3273 | /** |
||
| 3274 | * Runs before bumping version numbers up to a new version |
||
| 3275 | * |
||
| 3276 | * @param string $version Version:timestamp. |
||
| 3277 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
| 3278 | */ |
||
| 3279 | public static function do_version_bump( $version, $old_version ) { |
||
| 3280 | if ( $old_version ) { // For existing Jetpack installations. |
||
| 3281 | |||
| 3282 | // If a front end page is visited after the update, the 'wp' action will fire. |
||
| 3283 | add_action( 'wp', 'Jetpack::set_update_modal_display' ); |
||
| 3284 | |||
| 3285 | // If an admin page is visited after the update, the 'current_screen' action will fire. |
||
| 3286 | add_action( 'current_screen', 'Jetpack::set_update_modal_display' ); |
||
| 3287 | } |
||
| 3288 | } |
||
| 3289 | |||
| 3290 | /** |
||
| 3291 | * Sets the display_update_modal state. |
||
| 3292 | */ |
||
| 3293 | public static function set_update_modal_display() { |
||
| 3294 | self::state( 'display_update_modal', true ); |
||
| 3295 | } |
||
| 3296 | |||
| 3297 | /** |
||
| 3298 | * Sets the internal version number and activation state. |
||
| 3299 | * |
||
| 3300 | * @static |
||
| 3301 | */ |
||
| 3302 | public static function plugin_initialize() { |
||
| 3303 | if ( ! Jetpack_Options::get_option( 'activated' ) ) { |
||
| 3304 | Jetpack_Options::update_option( 'activated', 2 ); |
||
| 3305 | } |
||
| 3306 | |||
| 3307 | View Code Duplication | if ( ! Jetpack_Options::get_option( 'version' ) ) { |
|
| 3308 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
| 3309 | /** This action is documented in class.jetpack.php */ |
||
| 3310 | do_action( 'updating_jetpack_version', $version, false ); |
||
| 3311 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
| 3312 | } |
||
| 3313 | |||
| 3314 | self::load_modules(); |
||
| 3315 | |||
| 3316 | Jetpack_Options::delete_option( 'do_activate' ); |
||
| 3317 | Jetpack_Options::delete_option( 'dismissed_connection_banner' ); |
||
| 3318 | } |
||
| 3319 | |||
| 3320 | /** |
||
| 3321 | * Removes all connection options |
||
| 3322 | * |
||
| 3323 | * @static |
||
| 3324 | */ |
||
| 3325 | public static function plugin_deactivation() { |
||
| 3326 | require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
||
| 3327 | $tracking = new Tracking(); |
||
| 3328 | $tracking->record_user_event( 'deactivate_plugin', array() ); |
||
| 3329 | if ( is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
| 3330 | Jetpack_Network::init()->deactivate(); |
||
| 3331 | } else { |
||
| 3332 | self::disconnect( false ); |
||
| 3333 | // Jetpack_Heartbeat::init()->deactivate(); |
||
| 3334 | } |
||
| 3335 | } |
||
| 3336 | |||
| 3337 | /** |
||
| 3338 | * Disconnects from the Jetpack servers. |
||
| 3339 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 3340 | * |
||
| 3341 | * @static |
||
| 3342 | */ |
||
| 3343 | public static function disconnect( $update_activated_state = true ) { |
||
| 3344 | wp_clear_scheduled_hook( 'jetpack_clean_nonces' ); |
||
| 3345 | |||
| 3346 | $connection = self::connection(); |
||
| 3347 | $connection->clean_nonces( true ); |
||
| 3348 | |||
| 3349 | // If the site is in an IDC because sync is not allowed, |
||
| 3350 | // let's make sure to not disconnect the production site. |
||
| 3351 | if ( ! self::validate_sync_error_idc_option() ) { |
||
| 3352 | $tracking = new Tracking(); |
||
| 3353 | $tracking->record_user_event( 'disconnect_site', array() ); |
||
| 3354 | |||
| 3355 | $connection->disconnect_site_wpcom( true ); |
||
| 3356 | } |
||
| 3357 | |||
| 3358 | $connection->delete_all_connection_tokens( true ); |
||
| 3359 | Jetpack_IDC::clear_all_idc_options(); |
||
| 3360 | |||
| 3361 | if ( $update_activated_state ) { |
||
| 3362 | Jetpack_Options::update_option( 'activated', 4 ); |
||
| 3363 | } |
||
| 3364 | |||
| 3365 | if ( $jetpack_unique_connection = Jetpack_Options::get_option( 'unique_connection' ) ) { |
||
| 3366 | // Check then record unique disconnection if site has never been disconnected previously |
||
| 3367 | if ( - 1 == $jetpack_unique_connection['disconnected'] ) { |
||
| 3368 | $jetpack_unique_connection['disconnected'] = 1; |
||
| 3369 | } else { |
||
| 3370 | if ( 0 == $jetpack_unique_connection['disconnected'] ) { |
||
| 3371 | // track unique disconnect |
||
| 3372 | $jetpack = self::init(); |
||
| 3373 | |||
| 3374 | $jetpack->stat( 'connections', 'unique-disconnect' ); |
||
| 3375 | $jetpack->do_stats( 'server_side' ); |
||
| 3376 | } |
||
| 3377 | // increment number of times disconnected |
||
| 3378 | $jetpack_unique_connection['disconnected'] += 1; |
||
| 3379 | } |
||
| 3380 | |||
| 3381 | Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection ); |
||
| 3382 | } |
||
| 3383 | |||
| 3384 | // Delete all the sync related data. Since it could be taking up space. |
||
| 3385 | Sender::get_instance()->uninstall(); |
||
| 3386 | |||
| 3387 | } |
||
| 3388 | |||
| 3389 | /** |
||
| 3390 | * Unlinks the current user from the linked WordPress.com user. |
||
| 3391 | * |
||
| 3392 | * @deprecated since 7.7 |
||
| 3393 | * @see Automattic\Jetpack\Connection\Manager::disconnect_user() |
||
| 3394 | * |
||
| 3395 | * @param Integer $user_id the user identifier. |
||
| 3396 | * @return Boolean Whether the disconnection of the user was successful. |
||
| 3397 | */ |
||
| 3398 | public static function unlink_user( $user_id = null ) { |
||
| 3399 | _deprecated_function( __METHOD__, 'jetpack-7.7', 'Automattic\\Jetpack\\Connection\\Manager::disconnect_user' ); |
||
| 3400 | return Connection_Manager::disconnect_user( $user_id ); |
||
| 3401 | } |
||
| 3402 | |||
| 3403 | /** |
||
| 3404 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 3405 | */ |
||
| 3406 | public static function try_registration() { |
||
| 3407 | $terms_of_service = new Terms_Of_Service(); |
||
| 3408 | // The user has agreed to the TOS at some point by now. |
||
| 3409 | $terms_of_service->agree(); |
||
| 3410 | |||
| 3411 | // Let's get some testing in beta versions and such. |
||
| 3412 | if ( self::is_development_version() && defined( 'PHP_URL_HOST' ) ) { |
||
| 3413 | // Before attempting to connect, let's make sure that the domains are viable. |
||
| 3414 | $domains_to_check = array_unique( |
||
| 3415 | array( |
||
| 3416 | 'siteurl' => wp_parse_url( get_site_url(), PHP_URL_HOST ), |
||
| 3417 | 'homeurl' => wp_parse_url( get_home_url(), PHP_URL_HOST ), |
||
| 3418 | ) |
||
| 3419 | ); |
||
| 3420 | foreach ( $domains_to_check as $domain ) { |
||
| 3421 | $result = self::connection()->is_usable_domain( $domain ); |
||
| 3422 | if ( is_wp_error( $result ) ) { |
||
| 3423 | return $result; |
||
| 3424 | } |
||
| 3425 | } |
||
| 3426 | } |
||
| 3427 | |||
| 3428 | $result = self::register(); |
||
| 3429 | |||
| 3430 | // If there was an error with registration and the site was not registered, record this so we can show a message. |
||
| 3431 | if ( ! $result || is_wp_error( $result ) ) { |
||
| 3432 | return $result; |
||
| 3433 | } else { |
||
| 3434 | return true; |
||
| 3435 | } |
||
| 3436 | } |
||
| 3437 | |||
| 3438 | /** |
||
| 3439 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 3440 | * |
||
| 3441 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 3442 | */ |
||
| 3443 | public static function log( $code, $data = null ) { |
||
| 3444 | // only grab the latest 200 entries |
||
| 3445 | $log = array_slice( Jetpack_Options::get_option( 'log', array() ), -199, 199 ); |
||
| 3446 | |||
| 3447 | // Append our event to the log |
||
| 3448 | $log_entry = array( |
||
| 3449 | 'time' => time(), |
||
| 3450 | 'user_id' => get_current_user_id(), |
||
| 3451 | 'blog_id' => Jetpack_Options::get_option( 'id' ), |
||
| 3452 | 'code' => $code, |
||
| 3453 | ); |
||
| 3454 | // Don't bother storing it unless we've got some. |
||
| 3455 | if ( ! is_null( $data ) ) { |
||
| 3456 | $log_entry['data'] = $data; |
||
| 3457 | } |
||
| 3458 | $log[] = $log_entry; |
||
| 3459 | |||
| 3460 | // Try add_option first, to make sure it's not autoloaded. |
||
| 3461 | // @todo: Add an add_option method to Jetpack_Options |
||
| 3462 | if ( ! add_option( 'jetpack_log', $log, null, 'no' ) ) { |
||
| 3463 | Jetpack_Options::update_option( 'log', $log ); |
||
| 3464 | } |
||
| 3465 | |||
| 3466 | /** |
||
| 3467 | * Fires when Jetpack logs an internal event. |
||
| 3468 | * |
||
| 3469 | * @since 3.0.0 |
||
| 3470 | * |
||
| 3471 | * @param array $log_entry { |
||
| 3472 | * Array of details about the log entry. |
||
| 3473 | * |
||
| 3474 | * @param string time Time of the event. |
||
| 3475 | * @param int user_id ID of the user who trigerred the event. |
||
| 3476 | * @param int blog_id Jetpack Blog ID. |
||
| 3477 | * @param string code Unique name for the event. |
||
| 3478 | * @param string data Data about the event. |
||
| 3479 | * } |
||
| 3480 | */ |
||
| 3481 | do_action( 'jetpack_log_entry', $log_entry ); |
||
| 3482 | } |
||
| 3483 | |||
| 3484 | /** |
||
| 3485 | * Get the internal event log. |
||
| 3486 | * |
||
| 3487 | * @param $event (string) - only return the specific log events |
||
| 3488 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 3489 | * |
||
| 3490 | * @return array of log events || WP_Error for invalid params |
||
| 3491 | */ |
||
| 3492 | public static function get_log( $event = false, $num = false ) { |
||
| 3493 | if ( $event && ! is_string( $event ) ) { |
||
| 3494 | return new WP_Error( __( 'First param must be string or empty', 'jetpack' ) ); |
||
| 3495 | } |
||
| 3496 | |||
| 3497 | if ( $num && ! is_numeric( $num ) ) { |
||
| 3498 | return new WP_Error( __( 'Second param must be numeric or empty', 'jetpack' ) ); |
||
| 3499 | } |
||
| 3500 | |||
| 3501 | $entire_log = Jetpack_Options::get_option( 'log', array() ); |
||
| 3502 | |||
| 3503 | // If nothing set - act as it did before, otherwise let's start customizing the output |
||
| 3504 | if ( ! $num && ! $event ) { |
||
| 3505 | return $entire_log; |
||
| 3506 | } else { |
||
| 3507 | $entire_log = array_reverse( $entire_log ); |
||
| 3508 | } |
||
| 3509 | |||
| 3510 | $custom_log_output = array(); |
||
| 3511 | |||
| 3512 | if ( $event ) { |
||
| 3513 | foreach ( $entire_log as $log_event ) { |
||
| 3514 | if ( $event == $log_event['code'] ) { |
||
| 3515 | $custom_log_output[] = $log_event; |
||
| 3516 | } |
||
| 3517 | } |
||
| 3518 | } else { |
||
| 3519 | $custom_log_output = $entire_log; |
||
| 3520 | } |
||
| 3521 | |||
| 3522 | if ( $num ) { |
||
| 3523 | $custom_log_output = array_slice( $custom_log_output, 0, $num ); |
||
| 3524 | } |
||
| 3525 | |||
| 3526 | return $custom_log_output; |
||
| 3527 | } |
||
| 3528 | |||
| 3529 | /** |
||
| 3530 | * Log modification of important settings. |
||
| 3531 | */ |
||
| 3532 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 3533 | switch ( $option ) { |
||
| 3534 | case 'jetpack_sync_non_public_post_stati': |
||
| 3535 | self::log( $option, $value ); |
||
| 3536 | break; |
||
| 3537 | } |
||
| 3538 | } |
||
| 3539 | |||
| 3540 | /** |
||
| 3541 | * Return stat data for WPCOM sync |
||
| 3542 | */ |
||
| 3543 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
| 3544 | $data = Jetpack_Heartbeat::generate_stats_array(); |
||
| 3545 | |||
| 3546 | if ( $extended ) { |
||
| 3547 | $additional_data = self::get_additional_stat_data(); |
||
| 3548 | $data = array_merge( $data, $additional_data ); |
||
| 3549 | } |
||
| 3550 | |||
| 3551 | if ( $encode ) { |
||
| 3552 | return json_encode( $data ); |
||
| 3553 | } |
||
| 3554 | |||
| 3555 | return $data; |
||
| 3556 | } |
||
| 3557 | |||
| 3558 | /** |
||
| 3559 | * Get additional stat data to sync to WPCOM |
||
| 3560 | */ |
||
| 3561 | public static function get_additional_stat_data( $prefix = '' ) { |
||
| 3562 | $return[ "{$prefix}themes" ] = self::get_parsed_theme_data(); |
||
| 3563 | $return[ "{$prefix}plugins-extra" ] = self::get_parsed_plugin_data(); |
||
| 3564 | $return[ "{$prefix}users" ] = (int) self::get_site_user_count(); |
||
| 3565 | $return[ "{$prefix}site-count" ] = 0; |
||
| 3566 | |||
| 3567 | if ( function_exists( 'get_blog_count' ) ) { |
||
| 3568 | $return[ "{$prefix}site-count" ] = get_blog_count(); |
||
| 3569 | } |
||
| 3570 | return $return; |
||
| 3571 | } |
||
| 3572 | |||
| 3573 | private static function get_site_user_count() { |
||
| 3574 | global $wpdb; |
||
| 3575 | |||
| 3576 | if ( function_exists( 'wp_is_large_network' ) ) { |
||
| 3577 | if ( wp_is_large_network( 'users' ) ) { |
||
| 3578 | return -1; // Not a real value but should tell us that we are dealing with a large network. |
||
| 3579 | } |
||
| 3580 | } |
||
| 3581 | if ( false === ( $user_count = get_transient( 'jetpack_site_user_count' ) ) ) { |
||
| 3582 | // It wasn't there, so regenerate the data and save the transient |
||
| 3583 | $user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities'" ); |
||
| 3584 | set_transient( 'jetpack_site_user_count', $user_count, DAY_IN_SECONDS ); |
||
| 3585 | } |
||
| 3586 | return $user_count; |
||
| 3587 | } |
||
| 3588 | |||
| 3589 | /* Admin Pages */ |
||
| 3590 | |||
| 3591 | function admin_init() { |
||
| 3592 | // If the plugin is not connected, display a connect message. |
||
| 3593 | if ( |
||
| 3594 | // the plugin was auto-activated and needs its candy |
||
| 3595 | Jetpack_Options::get_option_and_ensure_autoload( 'do_activate', '0' ) |
||
| 3596 | || |
||
| 3597 | // the plugin is active, but was never activated. Probably came from a site-wide network activation |
||
| 3598 | ! Jetpack_Options::get_option( 'activated' ) |
||
| 3599 | ) { |
||
| 3600 | self::plugin_initialize(); |
||
| 3601 | } |
||
| 3602 | |||
| 3603 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
| 3604 | if ( ! self::is_active() && ! $is_offline_mode ) { |
||
| 3605 | Jetpack_Connection_Banner::init(); |
||
| 3606 | /** Already documented in automattic/jetpack-connection::src/class-client.php */ |
||
| 3607 | } elseif ( ( false === Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ) ) && ! apply_filters( 'jetpack_client_verify_ssl_certs', false ) ) { |
||
| 3608 | // Upgrade: 1.1 -> 1.1.1 |
||
| 3609 | // Check and see if host can verify the Jetpack servers' SSL certificate |
||
| 3610 | $args = array(); |
||
| 3611 | Client::_wp_remote_request( self::connection()->api_url( 'test' ), $args, true ); |
||
| 3612 | } |
||
| 3613 | |||
| 3614 | Jetpack_Recommendations_Banner::init(); |
||
| 3615 | |||
| 3616 | if ( current_user_can( 'manage_options' ) && ! self::permit_ssl() ) { |
||
| 3617 | add_action( 'jetpack_notices', array( $this, 'alert_auto_ssl_fail' ) ); |
||
| 3618 | } |
||
| 3619 | |||
| 3620 | add_action( 'load-plugins.php', array( $this, 'intercept_plugin_error_scrape_init' ) ); |
||
| 3621 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
||
| 3622 | add_action( 'admin_enqueue_scripts', array( $this, 'deactivate_dialog' ) ); |
||
| 3623 | add_filter( 'plugin_action_links_' . plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ), array( $this, 'plugin_action_links' ) ); |
||
| 3624 | |||
| 3625 | if ( self::is_active() || $is_offline_mode ) { |
||
| 3626 | // Artificially throw errors in certain specific cases during plugin activation. |
||
| 3627 | add_action( 'activate_plugin', array( $this, 'throw_error_on_activate_plugin' ) ); |
||
| 3628 | } |
||
| 3629 | |||
| 3630 | // Add custom column in wp-admin/users.php to show whether user is linked. |
||
| 3631 | add_filter( 'manage_users_columns', array( $this, 'jetpack_icon_user_connected' ) ); |
||
| 3632 | add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_user_connected_icon' ), 10, 3 ); |
||
| 3633 | add_action( 'admin_print_styles', array( $this, 'jetpack_user_col_style' ) ); |
||
| 3634 | } |
||
| 3635 | |||
| 3636 | function admin_body_class( $admin_body_class = '' ) { |
||
| 3644 | |||
| 3645 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 3648 | |||
| 3649 | /** |
||
| 3650 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 3651 | * This function artificially throws errors for such cases (per a specific list). |
||
| 3652 | * |
||
| 3653 | * @param string $plugin The activated plugin. |
||
| 3654 | */ |
||
| 3655 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 3679 | |||
| 3680 | function intercept_plugin_error_scrape_init() { |
||
| 3683 | |||
| 3684 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 3695 | |||
| 3696 | /** |
||
| 3697 | * Register the remote file upload request handlers, if needed. |
||
| 3698 | * |
||
| 3699 | * @access public |
||
| 3700 | */ |
||
| 3701 | public function add_remote_request_handlers() { |
||
| 3730 | |||
| 3731 | /** |
||
| 3732 | * Handler for Jetpack remote file uploads. |
||
| 3733 | * |
||
| 3734 | * @access public |
||
| 3735 | */ |
||
| 3736 | public function remote_request_handlers() { |
||
| 3776 | |||
| 3777 | /** |
||
| 3778 | * Uploads a file gotten from the global $_FILES. |
||
| 3779 | * If `$update_media_item` is true and `post_id` is defined |
||
| 3780 | * the attachment file of the media item (gotten through of the post_id) |
||
| 3781 | * will be updated instead of add a new one. |
||
| 3782 | * |
||
| 3783 | * @param boolean $update_media_item - update media attachment |
||
| 3784 | * @return array - An array describing the uploadind files process |
||
| 3785 | */ |
||
| 3786 | function upload_handler( $update_media_item = false ) { |
||
| 3917 | |||
| 3918 | /** |
||
| 3919 | * Add help to the Jetpack page |
||
| 3920 | * |
||
| 3921 | * @since Jetpack (1.2.3) |
||
| 3922 | * @return false if not the Jetpack page |
||
| 3923 | */ |
||
| 3924 | function admin_help() { |
||
| 3967 | |||
| 3968 | function admin_menu_css() { |
||
| 3971 | |||
| 3972 | function admin_menu_order() { |
||
| 3975 | |||
| 3976 | function jetpack_menu_order( $menu_order ) { |
||
| 3991 | |||
| 3992 | function admin_banner_styles() { |
||
| 3993 | $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
| 3994 | |||
| 3995 | if ( ! wp_style_is( 'jetpack-dops-style' ) ) { |
||
| 3996 | wp_register_style( |
||
| 3997 | 'jetpack-dops-style', |
||
| 3998 | plugins_url( '_inc/build/admin.css', JETPACK__PLUGIN_FILE ), |
||
| 3999 | array(), |
||
| 4000 | JETPACK__VERSION |
||
| 4001 | ); |
||
| 4002 | } |
||
| 4003 | |||
| 4004 | wp_enqueue_style( |
||
| 4005 | 'jetpack', |
||
| 4006 | plugins_url( "css/jetpack-banners{$min}.css", JETPACK__PLUGIN_FILE ), |
||
| 4007 | array( 'jetpack-dops-style' ), |
||
| 4008 | JETPACK__VERSION . '-20121016' |
||
| 4009 | ); |
||
| 4010 | wp_style_add_data( 'jetpack', 'rtl', 'replace' ); |
||
| 4011 | wp_style_add_data( 'jetpack', 'suffix', $min ); |
||
| 4012 | } |
||
| 4013 | |||
| 4014 | function plugin_action_links( $actions ) { |
||
| 4029 | |||
| 4030 | /** |
||
| 4031 | * Adds the deactivation warning modal if there are other active plugins using the connection |
||
| 4032 | * |
||
| 4033 | * @param string $hook The current admin page. |
||
| 4034 | * |
||
| 4035 | * @return void |
||
| 4036 | */ |
||
| 4037 | public function deactivate_dialog( $hook ) { |
||
| 4092 | |||
| 4093 | /** |
||
| 4094 | * Outputs the content of the deactivation modal |
||
| 4095 | * |
||
| 4096 | * @return void |
||
| 4097 | */ |
||
| 4098 | public function deactivate_dialog_content() { |
||
| 4103 | |||
| 4104 | /** |
||
| 4105 | * Filters the login URL to include the registration flow in case the user isn't logged in. |
||
| 4106 | * |
||
| 4107 | * @param string $login_url The wp-login URL. |
||
| 4108 | * @param string $redirect URL to redirect users after logging in. |
||
| 4109 | * @since Jetpack 8.4 |
||
| 4110 | * @return string |
||
| 4111 | */ |
||
| 4112 | public function login_url( $login_url, $redirect ) { |
||
| 4119 | |||
| 4120 | /** |
||
| 4121 | * Redirects non-authenticated users to authenticate with Calypso if redirect flag is set. |
||
| 4122 | * |
||
| 4123 | * @since Jetpack 8.4 |
||
| 4124 | */ |
||
| 4125 | public function login_init() { |
||
| 4142 | |||
| 4143 | /* |
||
| 4144 | * Registration flow: |
||
| 4145 | * 1 - ::admin_page_load() action=register |
||
| 4146 | * 2 - ::try_registration() |
||
| 4147 | * 3 - ::register() |
||
| 4148 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 4149 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 4150 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 4151 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 4152 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 4153 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 4154 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 4155 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 4156 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 4157 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 4158 | * 5 - user logs in with WP.com account |
||
| 4159 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 4160 | * - Manager::authorize() |
||
| 4161 | * - Manager::get_token() |
||
| 4162 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 4163 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 4164 | * - which responds with access_token, token_type, scope |
||
| 4165 | * - Manager::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 4166 | * - Jetpack::activate_default_modules() |
||
| 4167 | * - Deactivates deprecated plugins |
||
| 4168 | * - Activates all default modules |
||
| 4169 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 4170 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 4171 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 4172 | * Done! |
||
| 4173 | */ |
||
| 4174 | |||
| 4175 | /** |
||
| 4176 | * Handles the page load events for the Jetpack admin page |
||
| 4177 | */ |
||
| 4178 | function admin_page_load() { |
||
| 4494 | |||
| 4495 | function admin_notices() { |
||
| 4620 | |||
| 4621 | /** |
||
| 4622 | * We can't always respond to a signed XML-RPC request with a |
||
| 4623 | * helpful error message. In some circumstances, doing so could |
||
| 4624 | * leak information. |
||
| 4625 | * |
||
| 4626 | * Instead, track that the error occurred via a Jetpack_Option, |
||
| 4627 | * and send that data back in the heartbeat. |
||
| 4628 | * All this does is increment a number, but it's enough to find |
||
| 4629 | * trends. |
||
| 4630 | * |
||
| 4631 | * @param WP_Error $xmlrpc_error The error produced during |
||
| 4632 | * signature validation. |
||
| 4633 | */ |
||
| 4634 | function track_xmlrpc_error( $xmlrpc_error ) { |
||
| 4649 | |||
| 4650 | /** |
||
| 4651 | * Initialize the jetpack stats instance only when needed |
||
| 4652 | * |
||
| 4653 | * @return void |
||
| 4654 | */ |
||
| 4655 | private function initialize_stats() { |
||
| 4660 | |||
| 4661 | /** |
||
| 4662 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 4663 | */ |
||
| 4664 | function stat( $group, $detail ) { |
||
| 4671 | |||
| 4672 | /** |
||
| 4673 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 4674 | */ |
||
| 4675 | function do_stats( $method = '' ) { |
||
| 4686 | |||
| 4687 | /** |
||
| 4688 | * Runs stats code for a one-off, server-side. |
||
| 4689 | * |
||
| 4690 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 4691 | * |
||
| 4692 | * @return bool If it worked. |
||
| 4693 | */ |
||
| 4694 | static function do_server_side_stat( $args ) { |
||
| 4699 | |||
| 4700 | /** |
||
| 4701 | * Builds the stats url. |
||
| 4702 | * |
||
| 4703 | * @param $args array|string The arguments to append to the URL. |
||
| 4704 | * |
||
| 4705 | * @return string The URL to be pinged. |
||
| 4706 | */ |
||
| 4707 | static function build_stats_url( $args ) { |
||
| 4713 | |||
| 4714 | /** |
||
| 4715 | * Get the role of the current user. |
||
| 4716 | * |
||
| 4717 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::translate_current_user_to_role() instead. |
||
| 4718 | * |
||
| 4719 | * @access public |
||
| 4720 | * @static |
||
| 4721 | * |
||
| 4722 | * @return string|boolean Current user's role, false if not enough capabilities for any of the roles. |
||
| 4723 | */ |
||
| 4724 | public static function translate_current_user_to_role() { |
||
| 4730 | |||
| 4731 | /** |
||
| 4732 | * Get the role of a particular user. |
||
| 4733 | * |
||
| 4734 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::translate_user_to_role() instead. |
||
| 4735 | * |
||
| 4736 | * @access public |
||
| 4737 | * @static |
||
| 4738 | * |
||
| 4739 | * @param \WP_User $user User object. |
||
| 4740 | * @return string|boolean User's role, false if not enough capabilities for any of the roles. |
||
| 4741 | */ |
||
| 4742 | public static function translate_user_to_role( $user ) { |
||
| 4748 | |||
| 4749 | /** |
||
| 4750 | * Get the minimum capability for a role. |
||
| 4751 | * |
||
| 4752 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::translate_role_to_cap() instead. |
||
| 4753 | * |
||
| 4754 | * @access public |
||
| 4755 | * @static |
||
| 4756 | * |
||
| 4757 | * @param string $role Role name. |
||
| 4758 | * @return string|boolean Capability, false if role isn't mapped to any capabilities. |
||
| 4759 | */ |
||
| 4760 | public static function translate_role_to_cap( $role ) { |
||
| 4766 | |||
| 4767 | /** |
||
| 4768 | * Sign a user role with the master access token. |
||
| 4769 | * If not specified, will default to the current user. |
||
| 4770 | * |
||
| 4771 | * @deprecated since 7.7 |
||
| 4772 | * @see Automattic\Jetpack\Connection\Manager::sign_role() |
||
| 4773 | * |
||
| 4774 | * @access public |
||
| 4775 | * @static |
||
| 4776 | * |
||
| 4777 | * @param string $role User role. |
||
| 4778 | * @param int $user_id ID of the user. |
||
| 4779 | * @return string Signed user role. |
||
| 4780 | */ |
||
| 4781 | public static function sign_role( $role, $user_id = null ) { |
||
| 4785 | |||
| 4786 | /** |
||
| 4787 | * Builds a URL to the Jetpack connection auth page |
||
| 4788 | * |
||
| 4789 | * @since 3.9.5 |
||
| 4790 | * |
||
| 4791 | * @param bool $raw If true, URL will not be escaped. |
||
| 4792 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 4793 | * If string, will be a custom redirect. |
||
| 4794 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 4795 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
| 4796 | * |
||
| 4797 | * @return string Connect URL |
||
| 4798 | */ |
||
| 4799 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
| 4861 | |||
| 4862 | public static function build_authorize_url( $redirect = false, $iframe = false ) { |
||
| 4890 | |||
| 4891 | /** |
||
| 4892 | * Filters the connection URL parameter array. |
||
| 4893 | * |
||
| 4894 | * @param array $args default URL parameters used by the package. |
||
| 4895 | * @return array the modified URL arguments array. |
||
| 4896 | */ |
||
| 4897 | public static function filter_connect_request_body( $args ) { |
||
| 4927 | |||
| 4928 | /** |
||
| 4929 | * Filters the URL that will process the connection data. It can be different from the URL |
||
| 4930 | * that we send the user to after everything is done. |
||
| 4931 | * |
||
| 4932 | * @param String $processing_url the default redirect URL used by the package. |
||
| 4933 | * @return String the modified URL. |
||
| 4934 | * |
||
| 4935 | * @deprecated since Jetpack 9.5.0 |
||
| 4936 | */ |
||
| 4937 | public static function filter_connect_processing_url( $processing_url ) { |
||
| 4943 | |||
| 4944 | /** |
||
| 4945 | * Filters the redirection URL that is used for connect requests. The redirect |
||
| 4946 | * URL should return the user back to the Jetpack console. |
||
| 4947 | * |
||
| 4948 | * @param String $redirect the default redirect URL used by the package. |
||
| 4949 | * @return String the modified URL. |
||
| 4950 | */ |
||
| 4951 | public static function filter_connect_redirect_url( $redirect ) { |
||
| 4963 | |||
| 4964 | /** |
||
| 4965 | * This action fires at the beginning of the Manager::authorize method. |
||
| 4966 | */ |
||
| 4967 | public static function authorize_starting() { |
||
| 4991 | |||
| 4992 | /** |
||
| 4993 | * This action fires at the end of the Manager::authorize method when a secondary user is |
||
| 4994 | * linked. |
||
| 4995 | */ |
||
| 4996 | public static function authorize_ending_linked() { |
||
| 5000 | |||
| 5001 | /** |
||
| 5002 | * This action fires at the end of the Manager::authorize method when the master user is |
||
| 5003 | * authorized. |
||
| 5004 | * |
||
| 5005 | * @param array $data The request data. |
||
| 5006 | */ |
||
| 5007 | public static function authorize_ending_authorized( $data ) { |
||
| 5027 | |||
| 5028 | /** |
||
| 5029 | * This action fires at the end of the REST_Connector connection_reconnect method when the |
||
| 5030 | * reconnect process is completed. |
||
| 5031 | * Note that this currently only happens when we don't need the user to re-authorize |
||
| 5032 | * their WP.com account, eg in cases where we are restoring a connection with |
||
| 5033 | * unhealthy blog token. |
||
| 5034 | */ |
||
| 5035 | public static function reconnection_completed() { |
||
| 5038 | |||
| 5039 | /** |
||
| 5040 | * Get our assumed site creation date. |
||
| 5041 | * Calculated based on the earlier date of either: |
||
| 5042 | * - Earliest admin user registration date. |
||
| 5043 | * - Earliest date of post of any post type. |
||
| 5044 | * |
||
| 5045 | * @since 7.2.0 |
||
| 5046 | * @deprecated since 7.8.0 |
||
| 5047 | * |
||
| 5048 | * @return string Assumed site creation date and time. |
||
| 5049 | */ |
||
| 5050 | public static function get_assumed_site_creation_date() { |
||
| 5054 | |||
| 5055 | View Code Duplication | public static function apply_activation_source_to_args( &$args ) { |
|
| 5066 | |||
| 5067 | function build_reconnect_url( $raw = false ) { |
||
| 5071 | |||
| 5072 | public static function admin_url( $args = null ) { |
||
| 5077 | |||
| 5078 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 5082 | |||
| 5083 | function dismiss_jetpack_notice() { |
||
| 5100 | |||
| 5101 | public static function sort_modules( $a, $b ) { |
||
| 5108 | |||
| 5109 | function ajax_recheck_ssl() { |
||
| 5119 | |||
| 5120 | /* Client API */ |
||
| 5121 | |||
| 5122 | /** |
||
| 5123 | * Returns the requested Jetpack API URL |
||
| 5124 | * |
||
| 5125 | * @deprecated since 7.7 |
||
| 5126 | * @return string |
||
| 5127 | */ |
||
| 5128 | public static function api_url( $relative_url ) { |
||
| 5133 | |||
| 5134 | /** |
||
| 5135 | * @deprecated 8.0 |
||
| 5136 | * |
||
| 5137 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. |
||
| 5138 | * But we no longer fix "bad hosts" anyway, outbound HTTPS is required for Jetpack to function. |
||
| 5139 | */ |
||
| 5140 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 5144 | |||
| 5145 | public static function verify_onboarding_token( $token_data, $token, $request_data ) { |
||
| 5190 | |||
| 5191 | /** |
||
| 5192 | * Create a random secret for validating onboarding payload |
||
| 5193 | * |
||
| 5194 | * @return string Secret token |
||
| 5195 | */ |
||
| 5196 | public static function create_onboarding_token() { |
||
| 5204 | |||
| 5205 | /** |
||
| 5206 | * Remove the onboarding token |
||
| 5207 | * |
||
| 5208 | * @return bool True on success, false on failure |
||
| 5209 | */ |
||
| 5210 | public static function invalidate_onboarding_token() { |
||
| 5213 | |||
| 5214 | /** |
||
| 5215 | * Validate an onboarding token for a specific action |
||
| 5216 | * |
||
| 5217 | * @return boolean True if token/action pair is accepted, false if not |
||
| 5218 | */ |
||
| 5219 | public static function validate_onboarding_token_action( $token, $action ) { |
||
| 5237 | |||
| 5238 | /** |
||
| 5239 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 5240 | * |
||
| 5241 | * @since 2.3.3 |
||
| 5242 | * @return boolean |
||
| 5243 | */ |
||
| 5244 | public static function permit_ssl( $force_recheck = false ) { |
||
| 5273 | |||
| 5274 | /* |
||
| 5275 | * Displays an admin_notice, alerting the user that outbound SSL isn't working. |
||
| 5276 | */ |
||
| 5277 | public function alert_auto_ssl_fail() { |
||
| 5331 | |||
| 5332 | /** |
||
| 5333 | * Returns the Jetpack XML-RPC API |
||
| 5334 | * |
||
| 5335 | * @deprecated 8.0 Use Connection_Manager instead. |
||
| 5336 | * @return string |
||
| 5337 | */ |
||
| 5338 | public static function xmlrpc_api_url() { |
||
| 5342 | |||
| 5343 | /** |
||
| 5344 | * Returns the connection manager object. |
||
| 5345 | * |
||
| 5346 | * @return Automattic\Jetpack\Connection\Manager |
||
| 5347 | */ |
||
| 5348 | public static function connection() { |
||
| 5358 | |||
| 5359 | /** |
||
| 5360 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 5361 | * |
||
| 5362 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 5363 | * |
||
| 5364 | * @since 2.6 |
||
| 5365 | * @param String $action The action name. |
||
| 5366 | * @param Integer $user_id The user identifier. |
||
| 5367 | * @param Integer $exp Expiration time in seconds. |
||
| 5368 | * @return array |
||
| 5369 | */ |
||
| 5370 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
| 5373 | |||
| 5374 | public static function get_secrets( $action, $user_id ) { |
||
| 5387 | |||
| 5388 | /** |
||
| 5389 | * @deprecated 7.5 Use Connection_Manager instead. |
||
| 5390 | * |
||
| 5391 | * @param $action |
||
| 5392 | * @param $user_id |
||
| 5393 | */ |
||
| 5394 | public static function delete_secrets( $action, $user_id ) { |
||
| 5397 | |||
| 5398 | /** |
||
| 5399 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5400 | * |
||
| 5401 | * Based on local php max_execution_time in php.ini |
||
| 5402 | * |
||
| 5403 | * @since 2.6 |
||
| 5404 | * @return int |
||
| 5405 | * @deprecated |
||
| 5406 | **/ |
||
| 5407 | public function get_remote_query_timeout_limit() { |
||
| 5411 | |||
| 5412 | /** |
||
| 5413 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5414 | * |
||
| 5415 | * Based on local php max_execution_time in php.ini |
||
| 5416 | * |
||
| 5417 | * @since 5.4 |
||
| 5418 | * @return int |
||
| 5419 | **/ |
||
| 5420 | public static function get_max_execution_time() { |
||
| 5429 | |||
| 5430 | /** |
||
| 5431 | * Sets a minimum request timeout, and returns the current timeout |
||
| 5432 | * |
||
| 5433 | * @since 5.4 |
||
| 5434 | **/ |
||
| 5435 | View Code Duplication | public static function set_min_time_limit( $min_timeout ) { |
|
| 5443 | |||
| 5444 | /** |
||
| 5445 | * Takes the response from the Jetpack register new site endpoint and |
||
| 5446 | * verifies it worked properly. |
||
| 5447 | * |
||
| 5448 | * @since 2.6 |
||
| 5449 | * @deprecated since 7.7.0 |
||
| 5450 | * @see Automattic\Jetpack\Connection\Manager::validate_remote_register_response() |
||
| 5451 | **/ |
||
| 5452 | public function validate_remote_register_response() { |
||
| 5455 | |||
| 5456 | /** |
||
| 5457 | * @return bool|WP_Error |
||
| 5458 | */ |
||
| 5459 | public static function register() { |
||
| 5476 | |||
| 5477 | /** |
||
| 5478 | * Filters the registration request body to include tracking properties. |
||
| 5479 | * |
||
| 5480 | * @param array $properties |
||
| 5481 | * @return array amended properties. |
||
| 5482 | */ |
||
| 5483 | View Code Duplication | public static function filter_register_request_body( $properties ) { |
|
| 5495 | |||
| 5496 | /** |
||
| 5497 | * Filters the token request body to include tracking properties. |
||
| 5498 | * |
||
| 5499 | * @param array $properties |
||
| 5500 | * @return array amended properties. |
||
| 5501 | */ |
||
| 5502 | View Code Duplication | public static function filter_token_request_body( $properties ) { |
|
| 5514 | |||
| 5515 | /** |
||
| 5516 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 5517 | * |
||
| 5518 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 5519 | */ |
||
| 5520 | public static function maybe_set_version_option() { |
||
| 5534 | |||
| 5535 | /* Client Server API */ |
||
| 5536 | |||
| 5537 | /** |
||
| 5538 | * Loads the Jetpack XML-RPC client. |
||
| 5539 | * No longer necessary, as the XML-RPC client will be automagically loaded. |
||
| 5540 | * |
||
| 5541 | * @deprecated since 7.7.0 |
||
| 5542 | */ |
||
| 5543 | public static function load_xml_rpc_client() { |
||
| 5546 | |||
| 5547 | /** |
||
| 5548 | * Resets the saved authentication state in between testing requests. |
||
| 5549 | * |
||
| 5550 | * @deprecated since 8.9.0 |
||
| 5551 | * @see Automattic\Jetpack\Connection\Rest_Authentication::reset_saved_auth_state() |
||
| 5552 | */ |
||
| 5553 | public function reset_saved_auth_state() { |
||
| 5557 | |||
| 5558 | /** |
||
| 5559 | * Verifies the signature of the current request. |
||
| 5560 | * |
||
| 5561 | * @deprecated since 7.7.0 |
||
| 5562 | * @see Automattic\Jetpack\Connection\Manager::verify_xml_rpc_signature() |
||
| 5563 | * |
||
| 5564 | * @return false|array |
||
| 5565 | */ |
||
| 5566 | public function verify_xml_rpc_signature() { |
||
| 5570 | |||
| 5571 | /** |
||
| 5572 | * Verifies the signature of the current request. |
||
| 5573 | * |
||
| 5574 | * This function has side effects and should not be used. Instead, |
||
| 5575 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
| 5576 | * |
||
| 5577 | * @deprecated since 7.7.0 |
||
| 5578 | * @see Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature() |
||
| 5579 | * @internal |
||
| 5580 | */ |
||
| 5581 | private function internal_verify_xml_rpc_signature() { |
||
| 5584 | |||
| 5585 | /** |
||
| 5586 | * Authenticates XML-RPC and other requests from the Jetpack Server. |
||
| 5587 | * |
||
| 5588 | * @deprecated since 7.7.0 |
||
| 5589 | * @see Automattic\Jetpack\Connection\Manager::authenticate_jetpack() |
||
| 5590 | * |
||
| 5591 | * @param \WP_User|mixed $user User object if authenticated. |
||
| 5592 | * @param string $username Username. |
||
| 5593 | * @param string $password Password string. |
||
| 5594 | * @return \WP_User|mixed Authenticated user or error. |
||
| 5595 | */ |
||
| 5596 | View Code Duplication | public function authenticate_jetpack( $user, $username, $password ) { |
|
| 5605 | |||
| 5606 | /** |
||
| 5607 | * Authenticates requests from Jetpack server to WP REST API endpoints. |
||
| 5608 | * Uses the existing XMLRPC request signing implementation. |
||
| 5609 | * |
||
| 5610 | * @deprecated since 8.9.0 |
||
| 5611 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authenticate() |
||
| 5612 | */ |
||
| 5613 | function wp_rest_authenticate( $user ) { |
||
| 5617 | |||
| 5618 | /** |
||
| 5619 | * Report authentication status to the WP REST API. |
||
| 5620 | * |
||
| 5621 | * @deprecated since 8.9.0 |
||
| 5622 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authentication_errors() |
||
| 5623 | * |
||
| 5624 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
| 5625 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
| 5626 | */ |
||
| 5627 | public function wp_rest_authentication_errors( $value ) { |
||
| 5631 | |||
| 5632 | /** |
||
| 5633 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 5634 | * Capture it here so we can verify the signature later. |
||
| 5635 | * |
||
| 5636 | * @deprecated since 7.7.0 |
||
| 5637 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_methods() |
||
| 5638 | * |
||
| 5639 | * @param array $methods XMLRPC methods. |
||
| 5640 | * @return array XMLRPC methods, with the $HTTP_RAW_POST_DATA one. |
||
| 5641 | */ |
||
| 5642 | View Code Duplication | public function xmlrpc_methods( $methods ) { |
|
| 5651 | |||
| 5652 | /** |
||
| 5653 | * Register additional public XMLRPC methods. |
||
| 5654 | * |
||
| 5655 | * @deprecated since 7.7.0 |
||
| 5656 | * @see Automattic\Jetpack\Connection\Manager::public_xmlrpc_methods() |
||
| 5657 | * |
||
| 5658 | * @param array $methods Public XMLRPC methods. |
||
| 5659 | * @return array Public XMLRPC methods, with the getOptions one. |
||
| 5660 | */ |
||
| 5661 | View Code Duplication | public function public_xmlrpc_methods( $methods ) { |
|
| 5670 | |||
| 5671 | /** |
||
| 5672 | * Handles a getOptions XMLRPC method call. |
||
| 5673 | * |
||
| 5674 | * @deprecated since 7.7.0 |
||
| 5675 | * @see Automattic\Jetpack\Connection\Manager::jetpack_getOptions() |
||
| 5676 | * |
||
| 5677 | * @param array $args method call arguments. |
||
| 5678 | * @return array an amended XMLRPC server options array. |
||
| 5679 | */ |
||
| 5680 | View Code Duplication | public function jetpack_getOptions( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 5689 | |||
| 5690 | /** |
||
| 5691 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
| 5692 | * |
||
| 5693 | * @deprecated since 7.7.0 |
||
| 5694 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_options() |
||
| 5695 | * |
||
| 5696 | * @param array $options Standard Core options. |
||
| 5697 | * @return array Amended options. |
||
| 5698 | */ |
||
| 5699 | View Code Duplication | public function xmlrpc_options( $options ) { |
|
| 5708 | |||
| 5709 | /** |
||
| 5710 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 5711 | * SET: state( $key, $value ); |
||
| 5712 | * GET: $value = state( $key ); |
||
| 5713 | * |
||
| 5714 | * @param string $key |
||
| 5715 | * @param string $value |
||
| 5716 | * @param bool $restate private |
||
| 5717 | */ |
||
| 5718 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 5774 | |||
| 5775 | public static function restate() { |
||
| 5778 | |||
| 5779 | /** |
||
| 5780 | * Determines whether the jetpackState[$key] value should be added to the |
||
| 5781 | * cookie. |
||
| 5782 | * |
||
| 5783 | * @param string $key The state key. |
||
| 5784 | * |
||
| 5785 | * @return boolean Whether the value should be added to the cookie. |
||
| 5786 | */ |
||
| 5787 | public static function should_set_cookie( $key ) { |
||
| 5797 | |||
| 5798 | public static function check_privacy( $file ) { |
||
| 5832 | |||
| 5833 | /** |
||
| 5834 | * Helper method for multicall XMLRPC. |
||
| 5835 | * |
||
| 5836 | * @deprecated since 8.9.0 |
||
| 5837 | * @see Automattic\\Jetpack\\Connection\\Xmlrpc_Async_Call::add_call() |
||
| 5838 | * |
||
| 5839 | * @param ...$args Args for the async_call. |
||
| 5840 | */ |
||
| 5841 | public static function xmlrpc_async_call( ...$args ) { |
||
| 5883 | |||
| 5884 | /** |
||
| 5885 | * Serve a WordPress.com static resource via a randomized wp.com subdomain. |
||
| 5886 | * |
||
| 5887 | * @deprecated 9.3.0 Use Assets::staticize_subdomain. |
||
| 5888 | * |
||
| 5889 | * @param string $url WordPress.com static resource URL. |
||
| 5890 | */ |
||
| 5891 | public static function staticize_subdomain( $url ) { |
||
| 5895 | |||
| 5896 | /* JSON API Authorization */ |
||
| 5897 | |||
| 5898 | /** |
||
| 5899 | * Handles the login action for Authorizing the JSON API |
||
| 5900 | */ |
||
| 5901 | function login_form_json_api_authorization() { |
||
| 5910 | |||
| 5911 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 5912 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 5926 | |||
| 5927 | // Make sure the POSTed request is handled by the same action |
||
| 5928 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 5932 | |||
| 5933 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 5934 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 5940 | |||
| 5941 | // Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. |
||
| 5942 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 5946 | |||
| 5947 | static function is_redirect_encoded( $redirect_url ) { |
||
| 5950 | |||
| 5951 | // Add all wordpress.com environments to the safe redirect allowed list. |
||
| 5952 | function allow_wpcom_environments( $domains ) { |
||
| 5959 | |||
| 5960 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 5961 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 5973 | |||
| 5974 | /** |
||
| 5975 | * Verifies the request by checking the signature |
||
| 5976 | * |
||
| 5977 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
| 5978 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
| 5979 | * |
||
| 5980 | * @param null|array $environment |
||
| 5981 | */ |
||
| 5982 | function verify_json_api_authorization_request( $environment = null ) { |
||
| 6103 | |||
| 6104 | function login_message_json_api_authorization( $message ) { |
||
| 6110 | |||
| 6111 | /** |
||
| 6112 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 6113 | */ |
||
| 6114 | public static function get_content_width() { |
||
| 6127 | |||
| 6128 | /** |
||
| 6129 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 6130 | * |
||
| 6131 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 6132 | * |
||
| 6133 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 6134 | */ |
||
| 6135 | public function get_cloud_site_options( $option_names ) { |
||
| 6150 | |||
| 6151 | /** |
||
| 6152 | * Checks if the site is currently in an identity crisis. |
||
| 6153 | * |
||
| 6154 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
| 6155 | */ |
||
| 6156 | public static function check_identity_crisis() { |
||
| 6163 | |||
| 6164 | /** |
||
| 6165 | * Checks whether the home and siteurl specifically are allowed. |
||
| 6166 | * Written so that we don't have re-check $key and $value params every time |
||
| 6167 | * we want to check if this site is allowed, for example in footer.php |
||
| 6168 | * |
||
| 6169 | * @since 3.8.0 |
||
| 6170 | * @return bool True = already allowed False = not on the allowed list. |
||
| 6171 | */ |
||
| 6172 | public static function is_staging_site() { |
||
| 6176 | |||
| 6177 | /** |
||
| 6178 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
| 6179 | * |
||
| 6180 | * @since 4.4.0 |
||
| 6181 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
| 6182 | * |
||
| 6183 | * @return bool |
||
| 6184 | */ |
||
| 6185 | public static function validate_sync_error_idc_option() { |
||
| 6227 | |||
| 6228 | /** |
||
| 6229 | * Normalizes a url by doing three things: |
||
| 6230 | * - Strips protocol |
||
| 6231 | * - Strips www |
||
| 6232 | * - Adds a trailing slash |
||
| 6233 | * |
||
| 6234 | * @since 4.4.0 |
||
| 6235 | * @param string $url |
||
| 6236 | * @return WP_Error|string |
||
| 6237 | */ |
||
| 6238 | public static function normalize_url_protocol_agnostic( $url ) { |
||
| 6239 | $parsed_url = wp_parse_url( trailingslashit( esc_url_raw( $url ) ) ); |
||
| 6240 | if ( ! $parsed_url || empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) ) { |
||
| 6241 | return new WP_Error( 'cannot_parse_url', sprintf( esc_html__( 'Cannot parse URL %s', 'jetpack' ), $url ) ); |
||
| 6242 | } |
||
| 6243 | |||
| 6244 | // Strip www and protocols |
||
| 6245 | $url = preg_replace( '/^www\./i', '', $parsed_url['host'] . $parsed_url['path'] ); |
||
| 6246 | return $url; |
||
| 6247 | } |
||
| 6248 | |||
| 6249 | /** |
||
| 6250 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
| 6251 | * |
||
| 6252 | * @since 4.4.0 |
||
| 6253 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
| 6254 | * |
||
| 6255 | * @param array $response |
||
| 6256 | * @return array Array of the local urls, wpcom urls, and error code |
||
| 6257 | */ |
||
| 6258 | public static function get_sync_error_idc_option( $response = array() ) { |
||
| 6290 | |||
| 6291 | /** |
||
| 6292 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
| 6293 | * If set to true, the site will be put into staging mode. |
||
| 6294 | * |
||
| 6295 | * @since 4.3.2 |
||
| 6296 | * @return bool |
||
| 6297 | */ |
||
| 6298 | public static function sync_idc_optin() { |
||
| 6316 | |||
| 6317 | /** |
||
| 6318 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 6319 | * |
||
| 6320 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 6321 | */ |
||
| 6322 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 6364 | |||
| 6365 | /** |
||
| 6366 | * If the asset is minified, let's flag .min as the suffix. |
||
| 6367 | * |
||
| 6368 | * Attached to `style_loader_src` filter. |
||
| 6369 | * |
||
| 6370 | * @param string $tag The tag that would link to the external asset. |
||
| 6371 | * @param string $handle The registered handle of the script in question. |
||
| 6372 | * @param string $href The url of the asset in question. |
||
| 6373 | */ |
||
| 6374 | public static function set_suffix_on_min( $src, $handle ) { |
||
| 6390 | |||
| 6391 | /** |
||
| 6392 | * Maybe inlines a stylesheet. |
||
| 6393 | * |
||
| 6394 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 6395 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 6396 | * |
||
| 6397 | * Attached to `style_loader_tag` filter. |
||
| 6398 | * |
||
| 6399 | * @param string $tag The tag that would link to the external asset. |
||
| 6400 | * @param string $handle The registered handle of the script in question. |
||
| 6401 | * |
||
| 6402 | * @return string |
||
| 6403 | */ |
||
| 6404 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 6454 | |||
| 6455 | /** |
||
| 6456 | * Loads a view file from the views |
||
| 6457 | * |
||
| 6458 | * Data passed in with the $data parameter will be available in the |
||
| 6459 | * template file as $data['value'] |
||
| 6460 | * |
||
| 6461 | * @param string $template - Template file to load |
||
| 6462 | * @param array $data - Any data to pass along to the template |
||
| 6463 | * @return boolean - If template file was found |
||
| 6464 | **/ |
||
| 6465 | public function load_view( $template, $data = array() ) { |
||
| 6476 | |||
| 6477 | /** |
||
| 6478 | * Throws warnings for deprecated hooks to be removed from Jetpack that cannot remain in the original place in the code. |
||
| 6479 | */ |
||
| 6480 | public function deprecated_hooks() { |
||
| 6737 | |||
| 6738 | /** |
||
| 6739 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 6740 | * |
||
| 6741 | * Considerations: |
||
| 6742 | * - Normal, relative URLs `feh.png` |
||
| 6743 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 6744 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 6745 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 6746 | * - Domain root relative URLs `/feh.png` |
||
| 6747 | * |
||
| 6748 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 6749 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 6750 | * |
||
| 6751 | * @return mixed|string |
||
| 6752 | */ |
||
| 6753 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 6797 | |||
| 6798 | /** |
||
| 6799 | * This methods removes all of the registered css files on the front end |
||
| 6800 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 6801 | * all the files into one file. |
||
| 6802 | * |
||
| 6803 | * Pros: |
||
| 6804 | * - Uses only ONE css asset connection instead of 15 |
||
| 6805 | * - Saves a minimum of 56k |
||
| 6806 | * - Reduces server load |
||
| 6807 | * - Reduces time to first painted byte |
||
| 6808 | * |
||
| 6809 | * Cons: |
||
| 6810 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 6811 | * should not cause any issues with themes. |
||
| 6812 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 6813 | * jetpack_implode_frontend_css filter for a workaround |
||
| 6814 | * |
||
| 6815 | * For some situations developers may wish to disable css imploding and |
||
| 6816 | * instead operate in legacy mode where each file loads seperately and |
||
| 6817 | * can be edited individually or dequeued. This can be accomplished with |
||
| 6818 | * the following line: |
||
| 6819 | * |
||
| 6820 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 6821 | * |
||
| 6822 | * @since 3.2 |
||
| 6823 | **/ |
||
| 6824 | public function implode_frontend_css( $travis_test = false ) { |
||
| 6881 | |||
| 6882 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 6892 | |||
| 6893 | /** |
||
| 6894 | * @deprecated |
||
| 6895 | * @see Automattic\Jetpack\Assets\add_aync_script |
||
| 6896 | */ |
||
| 6897 | public function script_add_async( $tag, $handle, $src ) { |
||
| 6900 | |||
| 6901 | /* |
||
| 6902 | * Check the heartbeat data |
||
| 6903 | * |
||
| 6904 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 6905 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 6906 | * |
||
| 6907 | * Data will be added to "caution" array, if it either: |
||
| 6908 | * - Out of date Jetpack version |
||
| 6909 | * - Out of date WP version |
||
| 6910 | * - Out of date PHP version |
||
| 6911 | * |
||
| 6912 | * $return array $filtered_data |
||
| 6913 | */ |
||
| 6914 | public static function jetpack_check_heartbeat_data() { |
||
| 6967 | |||
| 6968 | /* |
||
| 6969 | * This method is used to organize all options that can be reset |
||
| 6970 | * without disconnecting Jetpack. |
||
| 6971 | * |
||
| 6972 | * It is used in class.jetpack-cli.php to reset options |
||
| 6973 | * |
||
| 6974 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
| 6975 | * |
||
| 6976 | * @return array of options to delete. |
||
| 6977 | */ |
||
| 6978 | public static function get_jetpack_options_for_reset() { |
||
| 6981 | |||
| 6982 | /* |
||
| 6983 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 6984 | * so we can bring them directly to their site in calypso. |
||
| 6985 | * |
||
| 6986 | * @deprecated 9.2.0 Use Automattic\Jetpack\Status::get_site_suffix |
||
| 6987 | * |
||
| 6988 | * @param string | url |
||
| 6989 | * @return string | url without the guff |
||
| 6990 | */ |
||
| 6991 | public static function build_raw_urls( $url ) { |
||
| 6996 | |||
| 6997 | /** |
||
| 6998 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 6999 | * |
||
| 7000 | * @deprecated 8.8.0 Use Jetpack::add_resource_hints. |
||
| 7001 | * |
||
| 7002 | * @param string|array $urls URLs to hint. |
||
| 7003 | */ |
||
| 7004 | public static function dns_prefetch( $urls = null ) { |
||
| 7010 | |||
| 7011 | public function wp_dashboard_setup() { |
||
| 7049 | |||
| 7050 | /** |
||
| 7051 | * @param mixed $result Value for the user's option |
||
| 7052 | * @return mixed |
||
| 7053 | */ |
||
| 7054 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 7079 | |||
| 7080 | public static function dashboard_widget() { |
||
| 7088 | |||
| 7089 | public static function dashboard_widget_footer() { |
||
| 7157 | |||
| 7158 | /* |
||
| 7159 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 7160 | */ |
||
| 7161 | function jetpack_icon_user_connected( $columns ) { |
||
| 7165 | |||
| 7166 | /* |
||
| 7167 | * Show Jetpack icon if the user is linked. |
||
| 7168 | */ |
||
| 7169 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 7182 | |||
| 7183 | /* |
||
| 7184 | * Style the Jetpack user column |
||
| 7185 | */ |
||
| 7186 | function jetpack_user_col_style() { |
||
| 7205 | |||
| 7206 | /** |
||
| 7207 | * Checks if Akismet is active and working. |
||
| 7208 | * |
||
| 7209 | * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key |
||
| 7210 | * that implied usage of methods present since more recent version. |
||
| 7211 | * See https://github.com/Automattic/jetpack/pull/9585 |
||
| 7212 | * |
||
| 7213 | * @since 5.1.0 |
||
| 7214 | * |
||
| 7215 | * @return bool True = Akismet available. False = Aksimet not available. |
||
| 7216 | */ |
||
| 7217 | public static function is_akismet_active() { |
||
| 7252 | |||
| 7253 | /** |
||
| 7254 | * @deprecated |
||
| 7255 | * |
||
| 7256 | * @see Automattic\Jetpack\Sync\Modules\Users::is_function_in_backtrace |
||
| 7257 | */ |
||
| 7258 | public static function is_function_in_backtrace() { |
||
| 7261 | |||
| 7262 | /** |
||
| 7263 | * Given a minified path, and a non-minified path, will return |
||
| 7264 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
| 7265 | * |
||
| 7266 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
| 7267 | * root Jetpack directory. |
||
| 7268 | * |
||
| 7269 | * @since 5.6.0 |
||
| 7270 | * |
||
| 7271 | * @param string $min_path |
||
| 7272 | * @param string $non_min_path |
||
| 7273 | * @return string The URL to the file |
||
| 7274 | */ |
||
| 7275 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
| 7278 | |||
| 7279 | /** |
||
| 7280 | * Checks for whether Jetpack Backup is enabled. |
||
| 7281 | * Will return true if the state of Backup is anything except "unavailable". |
||
| 7282 | * |
||
| 7283 | * @return bool|int|mixed |
||
| 7284 | */ |
||
| 7285 | public static function is_rewind_enabled() { |
||
| 7304 | |||
| 7305 | /** |
||
| 7306 | * Return Calypso environment value; used for developing Jetpack and pairing |
||
| 7307 | * it with different Calypso enrionments, such as localhost. |
||
| 7308 | * |
||
| 7309 | * @since 7.4.0 |
||
| 7310 | * |
||
| 7311 | * @return string Calypso environment |
||
| 7312 | */ |
||
| 7313 | public static function get_calypso_env() { |
||
| 7328 | |||
| 7329 | /** |
||
| 7330 | * Returns the hostname with protocol for Calypso. |
||
| 7331 | * Used for developing Jetpack with Calypso. |
||
| 7332 | * |
||
| 7333 | * @since 8.4.0 |
||
| 7334 | * |
||
| 7335 | * @return string Calypso host. |
||
| 7336 | */ |
||
| 7337 | public static function get_calypso_host() { |
||
| 7350 | |||
| 7351 | /** |
||
| 7352 | * Handles activating default modules as well general cleanup for the new connection. |
||
| 7353 | * |
||
| 7354 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
| 7355 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
| 7356 | * @param boolean $send_state_messages Whether to send state messages. |
||
| 7357 | * @return void |
||
| 7358 | */ |
||
| 7359 | public static function handle_post_authorization_actions( |
||
| 7383 | |||
| 7384 | /** |
||
| 7385 | * Returns a boolean for whether backups UI should be displayed or not. |
||
| 7386 | * |
||
| 7387 | * @return bool Should backups UI be displayed? |
||
| 7388 | */ |
||
| 7389 | public static function show_backups_ui() { |
||
| 7399 | |||
| 7400 | /* |
||
| 7401 | * Deprecated manage functions |
||
| 7402 | */ |
||
| 7403 | function prepare_manage_jetpack_notice() { |
||
| 7424 | |||
| 7425 | /** |
||
| 7426 | * Clean leftoveruser meta. |
||
| 7427 | * |
||
| 7428 | * Delete Jetpack-related user meta when it is no longer needed. |
||
| 7429 | * |
||
| 7430 | * @since 7.3.0 |
||
| 7431 | * |
||
| 7432 | * @param int $user_id User ID being updated. |
||
| 7433 | */ |
||
| 7434 | public static function user_meta_cleanup( $user_id ) { |
||
| 7449 | |||
| 7450 | /** |
||
| 7451 | * Checks if a Jetpack site is both active and not in offline mode. |
||
| 7452 | * |
||
| 7453 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
| 7454 | * |
||
| 7455 | * @deprecated 8.8.0 |
||
| 7456 | * |
||
| 7457 | * @return bool True if Jetpack is active and not in offline mode. |
||
| 7458 | */ |
||
| 7459 | public static function is_active_and_not_development_mode() { |
||
| 7466 | |||
| 7467 | /** |
||
| 7468 | * Checks if a Jetpack site is both active and not in offline mode. |
||
| 7469 | * |
||
| 7470 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
| 7471 | * |
||
| 7472 | * @since 8.8.0 |
||
| 7473 | * |
||
| 7474 | * @return bool True if Jetpack is active and not in offline mode. |
||
| 7475 | */ |
||
| 7476 | public static function is_active_and_not_offline_mode() { |
||
| 7482 | |||
| 7483 | /** |
||
| 7484 | * Returns the list of products that we have available for purchase. |
||
| 7485 | */ |
||
| 7486 | public static function get_products_for_purchase() { |
||
| 7580 | } |
||
| 7581 |
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.