Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 53 | class Jetpack { |
||
| 54 | public $xmlrpc_server = null; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var array The handles of styles that are concatenated into jetpack.css. |
||
| 58 | * |
||
| 59 | * When making changes to that list, you must also update concat_list in tools/builder/frontend-css.js. |
||
| 60 | */ |
||
| 61 | public $concatenated_style_handles = array( |
||
| 62 | 'jetpack-carousel', |
||
| 63 | 'grunion.css', |
||
| 64 | 'the-neverending-homepage', |
||
| 65 | 'jetpack_likes', |
||
| 66 | 'jetpack_related-posts', |
||
| 67 | 'sharedaddy', |
||
| 68 | 'jetpack-slideshow', |
||
| 69 | 'presentations', |
||
| 70 | 'quiz', |
||
| 71 | 'jetpack-subscriptions', |
||
| 72 | 'jetpack-responsive-videos-style', |
||
| 73 | 'jetpack-social-menu', |
||
| 74 | 'tiled-gallery', |
||
| 75 | 'jetpack_display_posts_widget', |
||
| 76 | 'gravatar-profile-widget', |
||
| 77 | 'goodreads-widget', |
||
| 78 | 'jetpack_social_media_icons_widget', |
||
| 79 | 'jetpack-top-posts-widget', |
||
| 80 | 'jetpack_image_widget', |
||
| 81 | 'jetpack-my-community-widget', |
||
| 82 | 'jetpack-authors-widget', |
||
| 83 | 'wordads', |
||
| 84 | 'eu-cookie-law-style', |
||
| 85 | 'flickr-widget-style', |
||
| 86 | 'jetpack-search-widget', |
||
| 87 | 'jetpack-simple-payments-widget-style', |
||
| 88 | 'jetpack-widget-social-icons-styles', |
||
| 89 | 'wpcom_instagram_widget', |
||
| 90 | ); |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Contains all assets that have had their URL rewritten to minified versions. |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | static $min_assets = array(); |
||
| 98 | |||
| 99 | public $plugins_to_deactivate = array( |
||
| 100 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 101 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 102 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 103 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 104 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 105 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 106 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 107 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 108 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 109 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 110 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 111 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 112 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 113 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ), |
||
| 114 | ); |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Map of roles we care about, and their corresponding minimum capabilities. |
||
| 118 | * |
||
| 119 | * @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead. |
||
| 120 | * |
||
| 121 | * @access public |
||
| 122 | * @static |
||
| 123 | * |
||
| 124 | * @var array |
||
| 125 | */ |
||
| 126 | public static $capability_translations = array( |
||
| 127 | 'administrator' => 'manage_options', |
||
| 128 | 'editor' => 'edit_others_posts', |
||
| 129 | 'author' => 'publish_posts', |
||
| 130 | 'contributor' => 'edit_posts', |
||
| 131 | 'subscriber' => 'read', |
||
| 132 | ); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 136 | * if the plugins are active. Used by filter_default_modules |
||
| 137 | * |
||
| 138 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 139 | * change `module-slug` and add this to your plugin: |
||
| 140 | * |
||
| 141 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 142 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 143 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 144 | * } |
||
| 145 | * |
||
| 146 | * @var array |
||
| 147 | */ |
||
| 148 | private $conflicting_plugins = array( |
||
| 149 | 'comments' => array( |
||
| 150 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 151 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 152 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 153 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 154 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 155 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 156 | ), |
||
| 157 | 'comment-likes' => array( |
||
| 158 | 'Epoch' => 'epoch/plugincore.php', |
||
| 159 | ), |
||
| 160 | 'contact-form' => array( |
||
| 161 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 162 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 163 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 164 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 165 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 166 | 'Ninja Forms' => 'ninja-forms/ninja-forms.php', |
||
| 167 | ), |
||
| 168 | 'latex' => array( |
||
| 169 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 170 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 171 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 172 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 173 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 174 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 175 | ), |
||
| 176 | 'protect' => array( |
||
| 177 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 178 | 'Captcha' => 'captcha/captcha.php', |
||
| 179 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 180 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 181 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 182 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 183 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 184 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 185 | 'Login Security' => 'login-security/login-security.php', |
||
| 186 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 187 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 188 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 189 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 190 | ), |
||
| 191 | 'random-redirect' => array( |
||
| 192 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 193 | ), |
||
| 194 | 'related-posts' => array( |
||
| 195 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 196 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 197 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 198 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 199 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 200 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 201 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 202 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 203 | ), |
||
| 204 | 'sharedaddy' => array( |
||
| 205 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 206 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 207 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 208 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 209 | ), |
||
| 210 | 'seo-tools' => array( |
||
| 211 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 212 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 213 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 214 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 215 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 216 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 217 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 218 | ), |
||
| 219 | 'verification-tools' => array( |
||
| 220 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 221 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 222 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 223 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 224 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 225 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 226 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 227 | ), |
||
| 228 | 'widget-visibility' => array( |
||
| 229 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 230 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 231 | ), |
||
| 232 | 'sitemaps' => array( |
||
| 233 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 234 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 235 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 236 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 237 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 238 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 239 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 240 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 241 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 242 | 'The SEO Framework' => 'autodescription/autodescription.php', |
||
| 243 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 244 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 245 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 246 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 247 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 248 | 'Rank Math' => 'seo-by-rank-math/rank-math.php', |
||
| 249 | 'Slim SEO' => 'slim-seo/slim-seo.php', |
||
| 250 | ), |
||
| 251 | 'lazy-images' => array( |
||
| 252 | 'Lazy Load' => 'lazy-load/lazy-load.php', |
||
| 253 | 'BJ Lazy Load' => 'bj-lazy-load/bj-lazy-load.php', |
||
| 254 | 'Lazy Load by WP Rocket' => 'rocket-lazy-load/rocket-lazy-load.php', |
||
| 255 | ), |
||
| 256 | ); |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 260 | * |
||
| 261 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
| 262 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 263 | * |
||
| 264 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 265 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 266 | */ |
||
| 267 | private $open_graph_conflicting_plugins = array( |
||
| 268 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 269 | // 2 Click Social Media Buttons |
||
| 270 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 271 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 272 | 'complete-open-graph/complete-open-graph.php', // Complete Open Graph |
||
| 273 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 274 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
| 275 | // Open Graph Meta Tags by Heateor |
||
| 276 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 277 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 278 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 279 | // Facebook Featured Image & OG Meta Tags |
||
| 280 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 281 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 282 | // Facebook Open Graph Meta Tags for WordPress |
||
| 283 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 284 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 285 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 286 | // Fedmich's Facebook Open Graph Meta |
||
| 287 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 288 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 289 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 290 | // NextScripts SNAP |
||
| 291 | 'og-tags/og-tags.php', // OG Tags |
||
| 292 | 'opengraph/opengraph.php', // Open Graph |
||
| 293 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 294 | // Open Graph Protocol Framework |
||
| 295 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 296 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 297 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 298 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 299 | 'sharepress/sharepress.php', // SharePress |
||
| 300 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 301 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 302 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 303 | 'socialize/socialize.php', // Socialize |
||
| 304 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
| 305 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 306 | // Tweet, Like, Google +1 and Share |
||
| 307 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 308 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 309 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 310 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 311 | // WP Facebook Like Send & Open Graph Meta |
||
| 312 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 313 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 314 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 315 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button |
||
| 316 | 'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox |
||
| 317 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
| 318 | 'slim-seo/slim-seo.php', // Slim SEO |
||
| 319 | ); |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 323 | */ |
||
| 324 | private $twitter_cards_conflicting_plugins = array( |
||
| 325 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 326 | // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 327 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 328 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 329 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 330 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 331 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 332 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 333 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 334 | 'wp-to-twitter/wp-to-twitter.php', // WP to Twitter |
||
| 335 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 336 | 'seo-by-rank-math/rank-math.php', // Rank Math. |
||
| 337 | 'slim-seo/slim-seo.php', // Slim SEO |
||
| 338 | ); |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Message to display in admin_notice |
||
| 342 | * |
||
| 343 | * @var string |
||
| 344 | */ |
||
| 345 | public $message = ''; |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Error to display in admin_notice |
||
| 349 | * |
||
| 350 | * @var string |
||
| 351 | */ |
||
| 352 | public $error = ''; |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Modules that need more privacy description. |
||
| 356 | * |
||
| 357 | * @var string |
||
| 358 | */ |
||
| 359 | public $privacy_checks = ''; |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Stats to record once the page loads |
||
| 363 | * |
||
| 364 | * @var array |
||
| 365 | */ |
||
| 366 | public $stats = array(); |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Jetpack_Sync object |
||
| 370 | */ |
||
| 371 | public $sync; |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Verified data for JSON authorization request |
||
| 375 | */ |
||
| 376 | public $json_api_authorization_request = array(); |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @var Automattic\Jetpack\Connection\Manager |
||
| 380 | */ |
||
| 381 | protected $connection_manager; |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @var string Transient key used to prevent multiple simultaneous plugin upgrades |
||
| 385 | */ |
||
| 386 | public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock'; |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Holds an instance of Automattic\Jetpack\A8c_Mc_Stats |
||
| 390 | * |
||
| 391 | * @var Automattic\Jetpack\A8c_Mc_Stats |
||
| 392 | */ |
||
| 393 | public $a8c_mc_stats_instance; |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Constant for login redirect key. |
||
| 397 | * |
||
| 398 | * @var string |
||
| 399 | * @since 8.4.0 |
||
| 400 | */ |
||
| 401 | public static $jetpack_redirect_login = 'jetpack_connect_login_redirect'; |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Holds the singleton instance of this class |
||
| 405 | * |
||
| 406 | * @since 2.3.3 |
||
| 407 | * @var Jetpack |
||
| 408 | */ |
||
| 409 | static $instance = false; |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Singleton |
||
| 413 | * |
||
| 414 | * @static |
||
| 415 | */ |
||
| 416 | public static function init() { |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Must never be called statically |
||
| 427 | */ |
||
| 428 | function plugin_upgrade() { |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Runs upgrade routines that need to have modules loaded. |
||
| 519 | */ |
||
| 520 | static function upgrade_on_load() { |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Saves all the currently active modules to options. |
||
| 553 | * Also fires Action hooks for each newly activated and deactivated module. |
||
| 554 | * |
||
| 555 | * @param $modules Array Array of active modules to be saved in options. |
||
| 556 | * |
||
| 557 | * @return $success bool true for success, false for failure. |
||
|
|
|||
| 558 | */ |
||
| 559 | static function update_active_modules( $modules ) { |
||
| 612 | |||
| 613 | static function delete_active_modules() { |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Adds a hook to plugins_loaded at a priority that's currently the earliest |
||
| 619 | * available. |
||
| 620 | */ |
||
| 621 | public function add_configure_hook() { |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Constructor. Initializes WordPress hooks |
||
| 645 | */ |
||
| 646 | private function __construct() { |
||
| 647 | /* |
||
| 648 | * Check for and alert any deprecated hooks |
||
| 649 | */ |
||
| 650 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 651 | |||
| 652 | // Note how this runs at an earlier plugin_loaded hook intentionally to accomodate for other plugins. |
||
| 653 | add_action( 'plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
| 654 | add_action( 'network_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
| 655 | add_action( 'mu_plugin_loaded', array( $this, 'add_configure_hook' ), 90 ); |
||
| 656 | add_action( 'plugins_loaded', array( $this, 'late_initialization' ), 90 ); |
||
| 657 | |||
| 658 | add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) ); |
||
| 659 | |||
| 660 | add_filter( |
||
| 661 | 'jetpack_signature_check_token', |
||
| 662 | array( __CLASS__, 'verify_onboarding_token' ), |
||
| 663 | 10, |
||
| 664 | 3 |
||
| 665 | ); |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Prepare Gutenberg Editor functionality |
||
| 669 | */ |
||
| 670 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; |
||
| 671 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'init' ) ); |
||
| 672 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) ); |
||
| 673 | add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_extended_blocks' ), 9 ); |
||
| 674 | add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); |
||
| 675 | |||
| 676 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
| 677 | |||
| 678 | // Unlink user before deleting the user from WP.com. |
||
| 679 | add_action( 'deleted_user', array( $this, 'disconnect_user' ), 10, 1 ); |
||
| 680 | add_action( 'remove_user_from_blog', array( $this, 'disconnect_user' ), 10, 1 ); |
||
| 681 | |||
| 682 | add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 ); |
||
| 683 | |||
| 684 | add_filter( 'login_url', array( $this, 'login_url' ), 10, 2 ); |
||
| 685 | add_action( 'login_init', array( $this, 'login_init' ) ); |
||
| 686 | |||
| 687 | // Set up the REST authentication hooks. |
||
| 688 | Connection_Rest_Authentication::init(); |
||
| 689 | |||
| 690 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 691 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 692 | |||
| 693 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 20 ); |
||
| 694 | |||
| 695 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 696 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 697 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 698 | |||
| 699 | // returns HTTPS support status |
||
| 700 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
| 701 | |||
| 702 | add_action( 'wp_ajax_jetpack_connection_banner', array( $this, 'jetpack_connection_banner_callback' ) ); |
||
| 703 | |||
| 704 | add_action( 'wp_ajax_jetpack_recommendations_banner', array( 'Jetpack_Recommendations_Banner', 'ajax_callback' ) ); |
||
| 705 | |||
| 706 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 707 | |||
| 708 | /** |
||
| 709 | * These actions run checks to load additional files. |
||
| 710 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 711 | */ |
||
| 712 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 713 | add_action( 'web_stories_story_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 714 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 715 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 716 | |||
| 717 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 718 | add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 ); |
||
| 719 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 720 | |||
| 721 | add_filter( 'profile_update', array( 'Jetpack', 'user_meta_cleanup' ) ); |
||
| 722 | |||
| 723 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 724 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 725 | |||
| 726 | // A filter to control all just in time messages |
||
| 727 | add_filter( 'jetpack_just_in_time_msgs', '__return_true', 9 ); |
||
| 728 | |||
| 729 | add_filter( 'jetpack_just_in_time_msg_cache', '__return_true', 9 ); |
||
| 730 | |||
| 731 | require_once JETPACK__PLUGIN_DIR . 'class-jetpack-pre-connection-jitms.php'; |
||
| 732 | $jetpack_jitm_messages = ( new Jetpack_Pre_Connection_JITMs() ); |
||
| 733 | add_filter( 'jetpack_pre_connection_jitms', array( $jetpack_jitm_messages, 'add_pre_connection_jitms' ) ); |
||
| 734 | |||
| 735 | /* |
||
| 736 | * If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin. |
||
| 737 | * We should make sure to only do this for front end links. |
||
| 738 | */ |
||
| 739 | if ( self::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) { |
||
| 740 | add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 ); |
||
| 741 | add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 ); |
||
| 742 | |||
| 743 | /* |
||
| 744 | * We'll shortcircuit wp_notify_postauthor and wp_notify_moderator pluggable functions |
||
| 745 | * so they point moderation links on emails to Calypso. |
||
| 746 | */ |
||
| 747 | jetpack_require_lib( 'functions.wp-notify' ); |
||
| 748 | add_filter( 'comment_notification_recipients', 'jetpack_notify_postauthor', 1, 2 ); |
||
| 749 | add_filter( 'notify_moderator', 'jetpack_notify_moderator', 1, 2 ); |
||
| 750 | } |
||
| 751 | |||
| 752 | add_action( |
||
| 753 | 'plugins_loaded', |
||
| 754 | function () { |
||
| 755 | if ( User_Agent_Info::is_mobile_app() ) { |
||
| 756 | add_filter( 'get_edit_post_link', '__return_empty_string' ); |
||
| 757 | } |
||
| 758 | } |
||
| 759 | ); |
||
| 760 | |||
| 761 | // Update the site's Jetpack plan and products from API on heartbeats. |
||
| 762 | add_action( 'jetpack_heartbeat', array( 'Jetpack_Plan', 'refresh_from_wpcom' ) ); |
||
| 763 | |||
| 764 | /** |
||
| 765 | * This is the hack to concatenate all css files into one. |
||
| 766 | * For description and reasoning see the implode_frontend_css method. |
||
| 767 | * |
||
| 768 | * Super late priority so we catch all the registered styles. |
||
| 769 | */ |
||
| 770 | if ( ! is_admin() ) { |
||
| 771 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 772 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 773 | } |
||
| 774 | |||
| 775 | /** |
||
| 776 | * These are sync actions that we need to keep track of for jitms |
||
| 777 | */ |
||
| 778 | add_filter( 'jetpack_sync_before_send_updated_option', array( $this, 'jetpack_track_last_sync_callback' ), 99 ); |
||
| 779 | |||
| 780 | // Actually push the stats on shutdown. |
||
| 781 | if ( ! has_action( 'shutdown', array( $this, 'push_stats' ) ) ) { |
||
| 782 | add_action( 'shutdown', array( $this, 'push_stats' ) ); |
||
| 783 | } |
||
| 784 | |||
| 785 | // After a successful connection. |
||
| 786 | add_action( 'jetpack_site_registered', array( $this, 'activate_default_modules_on_site_register' ) ); |
||
| 787 | |||
| 788 | // Actions for Manager::authorize(). |
||
| 789 | add_action( 'jetpack_authorize_starting', array( $this, 'authorize_starting' ) ); |
||
| 790 | add_action( 'jetpack_authorize_ending_linked', array( $this, 'authorize_ending_linked' ) ); |
||
| 791 | add_action( 'jetpack_authorize_ending_authorized', array( $this, 'authorize_ending_authorized' ) ); |
||
| 792 | |||
| 793 | add_action( 'jetpack_client_authorize_error', array( Jetpack_Client_Server::class, 'client_authorize_error' ) ); |
||
| 794 | add_filter( 'jetpack_client_authorize_already_authorized_url', array( Jetpack_Client_Server::class, 'client_authorize_already_authorized_url' ) ); |
||
| 795 | add_action( 'jetpack_client_authorize_processing', array( Jetpack_Client_Server::class, 'client_authorize_processing' ) ); |
||
| 796 | add_filter( 'jetpack_client_authorize_fallback_url', array( Jetpack_Client_Server::class, 'client_authorize_fallback_url' ) ); |
||
| 797 | |||
| 798 | // Filters for the Manager::get_token() urls and request body. |
||
| 799 | add_filter( 'jetpack_token_redirect_url', array( __CLASS__, 'filter_connect_redirect_url' ) ); |
||
| 800 | add_filter( 'jetpack_token_request_body', array( __CLASS__, 'filter_token_request_body' ) ); |
||
| 801 | |||
| 802 | // Actions for successful reconnect. |
||
| 803 | add_action( 'jetpack_reconnection_completed', array( $this, 'reconnection_completed' ) ); |
||
| 804 | |||
| 805 | // Actions for licensing. |
||
| 806 | Licensing::instance()->initialize(); |
||
| 807 | |||
| 808 | // Filters for Sync Callables. |
||
| 809 | add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ), 10, 1 ); |
||
| 810 | add_filter( 'jetpack_sync_multisite_callable_whitelist', array( $this, 'filter_sync_multisite_callable_whitelist' ), 10, 1 ); |
||
| 811 | |||
| 812 | // Make resources use static domain when possible. |
||
| 813 | add_filter( 'jetpack_static_url', array( 'Automattic\\Jetpack\\Assets', 'staticize_subdomain' ) ); |
||
| 814 | |||
| 815 | // Validate the domain names in Jetpack development versions. |
||
| 816 | add_action( 'jetpack_pre_register', array( get_called_class(), 'registration_check_domains' ) ); |
||
| 817 | } |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Before everything else starts getting initalized, we need to initialize Jetpack using the |
||
| 821 | * Config object. |
||
| 822 | */ |
||
| 823 | public function configure() { |
||
| 824 | $config = new Config(); |
||
| 825 | |||
| 826 | foreach ( |
||
| 827 | array( |
||
| 828 | 'sync', |
||
| 829 | 'jitm', |
||
| 830 | ) |
||
| 831 | as $feature |
||
| 832 | ) { |
||
| 833 | $config->ensure( $feature ); |
||
| 834 | } |
||
| 835 | |||
| 836 | $config->ensure( |
||
| 837 | 'connection', |
||
| 838 | array( |
||
| 839 | 'slug' => 'jetpack', |
||
| 840 | 'name' => 'Jetpack', |
||
| 841 | ) |
||
| 842 | ); |
||
| 843 | |||
| 844 | if ( ! $this->connection_manager ) { |
||
| 845 | $this->connection_manager = new Connection_Manager( 'jetpack' ); |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Filter to activate Jetpack Connection UI. |
||
| 849 | * INTERNAL USE ONLY. |
||
| 850 | * |
||
| 851 | * @since 9.5.0 |
||
| 852 | * |
||
| 853 | * @param bool false Whether to activate the Connection UI. |
||
| 854 | */ |
||
| 855 | if ( apply_filters( 'jetpack_connection_ui_active', false ) ) { |
||
| 856 | Automattic\Jetpack\ConnectionUI\Admin::init(); |
||
| 857 | } |
||
| 858 | } |
||
| 859 | |||
| 860 | /* |
||
| 861 | * Load things that should only be in Network Admin. |
||
| 862 | * |
||
| 863 | * For now blow away everything else until a more full |
||
| 864 | * understanding of what is needed at the network level is |
||
| 865 | * available |
||
| 866 | */ |
||
| 867 | if ( is_multisite() ) { |
||
| 868 | $network = Jetpack_Network::init(); |
||
| 869 | $network->set_connection( $this->connection_manager ); |
||
| 870 | } |
||
| 871 | |||
| 872 | if ( self::is_connection_ready() ) { |
||
| 873 | add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) ); |
||
| 874 | |||
| 875 | Jetpack_Heartbeat::init(); |
||
| 876 | if ( self::is_module_active( 'stats' ) && self::is_module_active( 'search' ) ) { |
||
| 877 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php'; |
||
| 878 | Jetpack_Search_Performance_Logger::init(); |
||
| 879 | } |
||
| 880 | } |
||
| 881 | |||
| 882 | // Initialize remote file upload request handlers. |
||
| 883 | $this->add_remote_request_handlers(); |
||
| 884 | |||
| 885 | /* |
||
| 886 | * Enable enhanced handling of previewing sites in Calypso |
||
| 887 | */ |
||
| 888 | if ( self::is_connection_ready() ) { |
||
| 889 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php'; |
||
| 890 | add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 ); |
||
| 891 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php'; |
||
| 892 | add_action( 'init', array( 'Jetpack_Keyring_Service_Helper', 'init' ), 9, 0 ); |
||
| 893 | } |
||
| 894 | |||
| 895 | if ( ( new Tracking( $this->connection_manager ) )->should_enable_tracking( new Terms_Of_Service(), new Status() ) ) { |
||
| 896 | add_action( 'init', array( new Plugin_Tracking(), 'init' ) ); |
||
| 897 | } else { |
||
| 898 | /** |
||
| 899 | * Initialize tracking right after the user agrees to the terms of service. |
||
| 900 | */ |
||
| 901 | add_action( 'jetpack_agreed_to_terms_of_service', array( new Plugin_Tracking(), 'init' ) ); |
||
| 902 | } |
||
| 903 | } |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Runs on plugins_loaded. Use this to add code that needs to be executed later than other |
||
| 907 | * initialization code. |
||
| 908 | * |
||
| 909 | * @action plugins_loaded |
||
| 910 | */ |
||
| 911 | public function late_initialization() { |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Sets up the XMLRPC request handlers. |
||
| 931 | * |
||
| 932 | * @deprecated since 7.7.0 |
||
| 933 | * @see Automattic\Jetpack\Connection\Manager::setup_xmlrpc_handlers() |
||
| 934 | * |
||
| 935 | * @param array $request_params Incoming request parameters. |
||
| 936 | * @param Boolean $is_active Whether the connection is currently active. |
||
| 937 | * @param Boolean $is_signed Whether the signature check has been successful. |
||
| 938 | * @param Jetpack_XMLRPC_Server $xmlrpc_server (optional) An instance of the server to use instead of instantiating a new one. |
||
| 939 | */ |
||
| 940 | View Code Duplication | public function setup_xmlrpc_handlers( |
|
| 959 | |||
| 960 | /** |
||
| 961 | * Initialize REST API registration connector. |
||
| 962 | * |
||
| 963 | * @deprecated since 7.7.0 |
||
| 964 | * @see Automattic\Jetpack\Connection\Manager::initialize_rest_api_registration_connector() |
||
| 965 | */ |
||
| 966 | View Code Duplication | public function initialize_rest_api_registration_connector() { |
|
| 975 | |||
| 976 | /** |
||
| 977 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
| 978 | * |
||
| 979 | * @param $domains |
||
| 980 | */ |
||
| 981 | function add_wpcom_to_allowed_redirect_hosts( $domains ) { |
||
| 984 | |||
| 985 | /** |
||
| 986 | * Return $domains, with 'wordpress.com' appended. |
||
| 987 | * This is ported over from the manage module, which has been deprecated and baked in here. |
||
| 988 | * |
||
| 989 | * @param $domains |
||
| 990 | * @return array |
||
| 991 | */ |
||
| 992 | function allow_wpcom_domain( $domains ) { |
||
| 999 | |||
| 1000 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
| 1029 | |||
| 1030 | function point_edit_comment_links_to_calypso( $url ) { |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Extend Sync callables with Jetpack Plugin functions. |
||
| 1045 | * |
||
| 1046 | * @param array $callables list of callables. |
||
| 1047 | * |
||
| 1048 | * @return array list of callables. |
||
| 1049 | */ |
||
| 1050 | public function filter_sync_callable_whitelist( $callables ) { |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Extend Sync multisite callables with Jetpack Plugin functions. |
||
| 1078 | * |
||
| 1079 | * @param array $callables list of callables. |
||
| 1080 | * |
||
| 1081 | * @return array list of callables. |
||
| 1082 | */ |
||
| 1083 | public function filter_sync_multisite_callable_whitelist( $callables ) { |
||
| 1098 | |||
| 1099 | function jetpack_track_last_sync_callback( $params ) { |
||
| 1121 | |||
| 1122 | function jetpack_connection_banner_callback() { |
||
| 1136 | |||
| 1137 | /** |
||
| 1138 | * Removes all XML-RPC methods that are not `jetpack.*`. |
||
| 1139 | * Only used in our alternate XML-RPC endpoint, where we want to |
||
| 1140 | * ensure that Core and other plugins' methods are not exposed. |
||
| 1141 | * |
||
| 1142 | * @deprecated since 7.7.0 |
||
| 1143 | * @see Automattic\Jetpack\Connection\Manager::remove_non_jetpack_xmlrpc_methods() |
||
| 1144 | * |
||
| 1145 | * @param array $methods A list of registered WordPress XMLRPC methods. |
||
| 1146 | * @return array Filtered $methods |
||
| 1147 | */ |
||
| 1148 | View Code Duplication | public function remove_non_jetpack_xmlrpc_methods( $methods ) { |
|
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, |
||
| 1160 | * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive |
||
| 1161 | * security/firewall policies, we provide our own alternate XML RPC API endpoint |
||
| 1162 | * which is accessible via a different URI. Most of the below is copied directly |
||
| 1163 | * from /xmlrpc.php so that we're replicating it as closely as possible. |
||
| 1164 | * |
||
| 1165 | * @deprecated since 7.7.0 |
||
| 1166 | * @see Automattic\Jetpack\Connection\Manager::alternate_xmlrpc() |
||
| 1167 | */ |
||
| 1168 | View Code Duplication | public function alternate_xmlrpc() { |
|
| 1177 | |||
| 1178 | /** |
||
| 1179 | * The callback for the JITM ajax requests. |
||
| 1180 | * |
||
| 1181 | * @deprecated since 7.9.0 |
||
| 1182 | */ |
||
| 1183 | function jetpack_jitm_ajax_callback() { |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 1189 | */ |
||
| 1190 | function push_stats() { |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * Sets the Jetpack custom capabilities. |
||
| 1198 | * |
||
| 1199 | * @param string[] $caps Array of the user's capabilities. |
||
| 1200 | * @param string $cap Capability name. |
||
| 1201 | * @param int $user_id The user ID. |
||
| 1202 | * @param array $args Adds the context to the cap. Typically the object ID. |
||
| 1203 | */ |
||
| 1204 | public function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 1239 | |||
| 1240 | /** |
||
| 1241 | * Require a Jetpack authentication. |
||
| 1242 | * |
||
| 1243 | * @deprecated since 7.7.0 |
||
| 1244 | * @see Automattic\Jetpack\Connection\Manager::require_jetpack_authentication() |
||
| 1245 | */ |
||
| 1246 | View Code Duplication | public function require_jetpack_authentication() { |
|
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 1258 | * |
||
| 1259 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 1260 | * @action wp_loaded |
||
| 1261 | * @return null |
||
| 1262 | */ |
||
| 1263 | public function register_assets() { |
||
| 1264 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 1265 | wp_register_script( |
||
| 1266 | 'jetpack-gallery-settings', |
||
| 1267 | Assets::get_file_url_for_environment( '_inc/build/gallery-settings.min.js', '_inc/gallery-settings.js' ), |
||
| 1268 | array( 'media-views' ), |
||
| 1269 | '20121225' |
||
| 1270 | ); |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
||
| 1274 | wp_register_script( |
||
| 1275 | 'jetpack-twitter-timeline', |
||
| 1276 | Assets::get_file_url_for_environment( '_inc/build/twitter-timeline.min.js', '_inc/twitter-timeline.js' ), |
||
| 1277 | array( 'jquery' ), |
||
| 1278 | '4.0.0', |
||
| 1279 | true |
||
| 1280 | ); |
||
| 1281 | } |
||
| 1282 | |||
| 1283 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 1284 | wp_register_script( |
||
| 1285 | 'jetpack-facebook-embed', |
||
| 1286 | Assets::get_file_url_for_environment( '_inc/build/facebook-embed.min.js', '_inc/facebook-embed.js' ), |
||
| 1287 | array(), |
||
| 1288 | null, |
||
| 1289 | true |
||
| 1290 | ); |
||
| 1291 | |||
| 1292 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 1293 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 1294 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 1295 | $fb_app_id = ''; |
||
| 1296 | } |
||
| 1297 | wp_localize_script( |
||
| 1298 | 'jetpack-facebook-embed', |
||
| 1299 | 'jpfbembed', |
||
| 1300 | array( |
||
| 1301 | 'appid' => $fb_app_id, |
||
| 1302 | 'locale' => $this->get_locale(), |
||
| 1303 | ) |
||
| 1304 | ); |
||
| 1305 | } |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 1309 | * the hook may have already fired by this point. |
||
| 1310 | * So, let's just trigger it manually. |
||
| 1311 | */ |
||
| 1312 | require_once JETPACK__PLUGIN_DIR . '_inc/genericons.php'; |
||
| 1313 | jetpack_register_genericons(); |
||
| 1314 | |||
| 1315 | /** |
||
| 1316 | * Register the social logos |
||
| 1317 | */ |
||
| 1318 | require_once JETPACK__PLUGIN_DIR . '_inc/social-logos.php'; |
||
| 1319 | jetpack_register_social_logos(); |
||
| 1320 | |||
| 1321 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) { |
|
| 1322 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 1323 | } |
||
| 1324 | } |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Guess locale from language code. |
||
| 1328 | * |
||
| 1329 | * @param string $lang Language code. |
||
| 1330 | * @return string|bool |
||
| 1331 | */ |
||
| 1332 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Get the locale. |
||
| 1374 | * |
||
| 1375 | * @return string|bool |
||
| 1376 | */ |
||
| 1377 | function get_locale() { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 1389 | * |
||
| 1390 | * @param bool $option |
||
| 1391 | * @return string |
||
| 1392 | */ |
||
| 1393 | public function jetpack_main_network_site_option( $option ) { |
||
| 1396 | /** |
||
| 1397 | * Network Name. |
||
| 1398 | */ |
||
| 1399 | static function network_name( $option = null ) { |
||
| 1403 | /** |
||
| 1404 | * Does the network allow new user and site registrations. |
||
| 1405 | * |
||
| 1406 | * @return string |
||
| 1407 | */ |
||
| 1408 | static function network_allow_new_registrations( $option = null ) { |
||
| 1411 | /** |
||
| 1412 | * Does the network allow admins to add new users. |
||
| 1413 | * |
||
| 1414 | * @return boolian |
||
| 1415 | */ |
||
| 1416 | static function network_add_new_users( $option = null ) { |
||
| 1419 | /** |
||
| 1420 | * File upload psace left per site in MB. |
||
| 1421 | * -1 means NO LIMIT. |
||
| 1422 | * |
||
| 1423 | * @return number |
||
| 1424 | */ |
||
| 1425 | static function network_site_upload_space( $option = null ) { |
||
| 1429 | |||
| 1430 | /** |
||
| 1431 | * Network allowed file types. |
||
| 1432 | * |
||
| 1433 | * @return string |
||
| 1434 | */ |
||
| 1435 | static function network_upload_file_types( $option = null ) { |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Maximum file upload size set by the network. |
||
| 1441 | * |
||
| 1442 | * @return number |
||
| 1443 | */ |
||
| 1444 | static function network_max_upload_file_size( $option = null ) { |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Lets us know if a site allows admins to manage the network. |
||
| 1451 | * |
||
| 1452 | * @return array |
||
| 1453 | */ |
||
| 1454 | static function network_enable_administration_menus( $option = null ) { |
||
| 1457 | |||
| 1458 | /** |
||
| 1459 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
| 1460 | * jetpack_other_linked_admins transient. |
||
| 1461 | * |
||
| 1462 | * @since 4.3.2 |
||
| 1463 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
| 1464 | * |
||
| 1465 | * @param int $user_id The user ID whose role changed. |
||
| 1466 | * @param string $role The new role. |
||
| 1467 | * @param array $old_roles An array of the user's previous roles. |
||
| 1468 | */ |
||
| 1469 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
| 1477 | |||
| 1478 | /** |
||
| 1479 | * Checks to see if there are any other users available to become primary |
||
| 1480 | * Users must both: |
||
| 1481 | * - Be linked to wpcom |
||
| 1482 | * - Be an admin |
||
| 1483 | * |
||
| 1484 | * @return mixed False if no other users are linked, Int if there are. |
||
| 1485 | */ |
||
| 1486 | static function get_other_linked_admins() { |
||
| 1514 | |||
| 1515 | /** |
||
| 1516 | * Return whether we are dealing with a multi network setup or not. |
||
| 1517 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 1518 | * the result is false since when is_main_network_option return false it cases |
||
| 1519 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 1520 | * database which could be set to anything as opposed to what this function returns. |
||
| 1521 | * |
||
| 1522 | * @param bool $option |
||
| 1523 | * |
||
| 1524 | * @return boolean |
||
| 1525 | */ |
||
| 1526 | public function is_main_network_option( $option ) { |
||
| 1530 | |||
| 1531 | /** |
||
| 1532 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 1533 | * |
||
| 1534 | * @param string $option |
||
| 1535 | * @return boolean |
||
| 1536 | */ |
||
| 1537 | public function is_multisite( $option ) { |
||
| 1540 | |||
| 1541 | /** |
||
| 1542 | * Implemented since there is no core is multi network function |
||
| 1543 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 1544 | * |
||
| 1545 | * @since 3.3 |
||
| 1546 | * @return boolean |
||
| 1547 | */ |
||
| 1548 | View Code Duplication | public static function is_multi_network() { |
|
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1566 | * |
||
| 1567 | * @return null |
||
| 1568 | */ |
||
| 1569 | function update_jetpack_main_network_site_option() { |
||
| 1572 | /** |
||
| 1573 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1574 | */ |
||
| 1575 | function update_jetpack_network_settings() { |
||
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Get back if the current site is single user site. |
||
| 1582 | * |
||
| 1583 | * @return bool |
||
| 1584 | */ |
||
| 1585 | View Code Duplication | public static function is_single_user_site() { |
|
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Returns true if the site has file write access false otherwise. |
||
| 1597 | * |
||
| 1598 | * @return string ( '1' | '0' ) |
||
| 1599 | **/ |
||
| 1600 | public static function file_system_write_access() { |
||
| 1620 | |||
| 1621 | /** |
||
| 1622 | * Finds out if a site is using a version control system. |
||
| 1623 | * |
||
| 1624 | * @return string ( '1' | '0' ) |
||
| 1625 | **/ |
||
| 1626 | public static function is_version_controlled() { |
||
| 1630 | |||
| 1631 | /** |
||
| 1632 | * Determines whether the current theme supports featured images or not. |
||
| 1633 | * |
||
| 1634 | * @return string ( '1' | '0' ) |
||
| 1635 | */ |
||
| 1636 | public static function featured_images_enabled() { |
||
| 1640 | |||
| 1641 | /** |
||
| 1642 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
| 1643 | * |
||
| 1644 | * @deprecated 4.7 use get_avatar_url instead. |
||
| 1645 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 1646 | * @param int $size Size of the avatar image |
||
| 1647 | * @param string $default URL to a default image to use if no avatar is available |
||
| 1648 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 1649 | * |
||
| 1650 | * @return array |
||
| 1651 | */ |
||
| 1652 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 1663 | // phpcs:disable WordPress.WP.CapitalPDangit.Misspelled |
||
| 1664 | /** |
||
| 1665 | * jetpack_updates is saved in the following schema: |
||
| 1666 | * |
||
| 1667 | * array ( |
||
| 1668 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1669 | * 'themes' => (int) Number of theme updates available. |
||
| 1670 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1671 | * 'translations' => (int) Number of translation updates available. |
||
| 1672 | * 'total' => (int) Total of all available updates. |
||
| 1673 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1674 | * ) |
||
| 1675 | * |
||
| 1676 | * @return array |
||
| 1677 | */ |
||
| 1678 | public static function get_updates() { |
||
| 1695 | // phpcs:enable |
||
| 1696 | |||
| 1697 | public static function get_update_details() { |
||
| 1705 | |||
| 1706 | public static function refresh_update_data() { |
||
| 1710 | |||
| 1711 | public static function refresh_theme_data() { |
||
| 1714 | |||
| 1715 | /** |
||
| 1716 | * Is Jetpack active? |
||
| 1717 | * The method only checks if there's an existing token for the master user. It doesn't validate the token. |
||
| 1718 | * |
||
| 1719 | * This method is deprecated since 9.6.0. Please use one of the methods provided by the Manager class in the Connection package, |
||
| 1720 | * or Jetpack::is_connection_ready if you want to know when the Jetpack plugin starts considering the connection ready to be used. |
||
| 1721 | * |
||
| 1722 | * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. |
||
| 1723 | * |
||
| 1724 | * @deprecated 9.6.0 |
||
| 1725 | * |
||
| 1726 | * @return bool |
||
| 1727 | */ |
||
| 1728 | public static function is_active() { |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI |
||
| 1734 | * |
||
| 1735 | * This method was introduced just before the release of the possibility to use Jetpack without a user connection, while |
||
| 1736 | * it was available only when no_user_testing_mode was enabled. In the near future, this will return is_connected for all |
||
| 1737 | * users and this option will be available by default for everybody. |
||
| 1738 | * |
||
| 1739 | * @since 9.6.0 |
||
| 1740 | * |
||
| 1741 | * @return bool is the site connection ready to be used? |
||
| 1742 | */ |
||
| 1743 | public static function is_connection_ready() { |
||
| 1749 | |||
| 1750 | /** |
||
| 1751 | * Make an API call to WordPress.com for plan status |
||
| 1752 | * |
||
| 1753 | * @deprecated 7.2.0 Use Jetpack_Plan::refresh_from_wpcom. |
||
| 1754 | * |
||
| 1755 | * @return bool True if plan is updated, false if no update |
||
| 1756 | */ |
||
| 1757 | public static function refresh_active_plan_from_wpcom() { |
||
| 1761 | |||
| 1762 | /** |
||
| 1763 | * Get the plan that this Jetpack site is currently using |
||
| 1764 | * |
||
| 1765 | * @deprecated 7.2.0 Use Jetpack_Plan::get. |
||
| 1766 | * @return array Active Jetpack plan details. |
||
| 1767 | */ |
||
| 1768 | public static function get_active_plan() { |
||
| 1772 | |||
| 1773 | /** |
||
| 1774 | * Determine whether the active plan supports a particular feature |
||
| 1775 | * |
||
| 1776 | * @deprecated 7.2.0 Use Jetpack_Plan::supports. |
||
| 1777 | * @return bool True if plan supports feature, false if not. |
||
| 1778 | */ |
||
| 1779 | public static function active_plan_supports( $feature ) { |
||
| 1783 | |||
| 1784 | /** |
||
| 1785 | * Deprecated: Is Jetpack in development (offline) mode? |
||
| 1786 | * |
||
| 1787 | * This static method is being left here intentionally without the use of _deprecated_function(), as other plugins |
||
| 1788 | * and themes still use it, and we do not want to flood them with notices. |
||
| 1789 | * |
||
| 1790 | * Please use Automattic\Jetpack\Status()->is_offline_mode() instead. |
||
| 1791 | * |
||
| 1792 | * @deprecated since 8.0. |
||
| 1793 | */ |
||
| 1794 | public static function is_development_mode() { |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * Whether the site is currently onboarding or not. |
||
| 1801 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
| 1802 | * |
||
| 1803 | * @since 5.8 |
||
| 1804 | * |
||
| 1805 | * @access public |
||
| 1806 | * @static |
||
| 1807 | * |
||
| 1808 | * @return bool True if the site is currently onboarding, false otherwise |
||
| 1809 | */ |
||
| 1810 | public static function is_onboarding() { |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Determines reason for Jetpack offline mode. |
||
| 1816 | */ |
||
| 1817 | public static function development_mode_trigger_text() { |
||
| 1840 | /** |
||
| 1841 | * Get Jetpack offline mode notice text and notice class. |
||
| 1842 | * |
||
| 1843 | * Mirrors the checks made in Automattic\Jetpack\Status->is_offline_mode |
||
| 1844 | */ |
||
| 1845 | public static function show_development_mode_notice() { |
||
| 1873 | |||
| 1874 | /** |
||
| 1875 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1876 | */ |
||
| 1877 | public static function is_development_version() { |
||
| 1892 | |||
| 1893 | /** |
||
| 1894 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1895 | */ |
||
| 1896 | public static function is_user_connected( $user_id = false ) { |
||
| 1900 | |||
| 1901 | /** |
||
| 1902 | * Get the wpcom user data of the current|specified connected user. |
||
| 1903 | */ |
||
| 1904 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * Get the wpcom email of the current|specified connected user. |
||
| 1911 | */ |
||
| 1912 | public static function get_connected_user_email( $user_id = null ) { |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Get the wpcom email of the master user. |
||
| 1931 | */ |
||
| 1932 | public static function get_master_user_email() { |
||
| 1939 | |||
| 1940 | /** |
||
| 1941 | * Whether the current user is the connection owner. |
||
| 1942 | * |
||
| 1943 | * @deprecated since 7.7 |
||
| 1944 | * |
||
| 1945 | * @return bool Whether the current user is the connection owner. |
||
| 1946 | */ |
||
| 1947 | public function current_user_is_connection_owner() { |
||
| 1951 | |||
| 1952 | /** |
||
| 1953 | * Gets current user IP address. |
||
| 1954 | * |
||
| 1955 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
| 1956 | * |
||
| 1957 | * @return string Current user IP address. |
||
| 1958 | */ |
||
| 1959 | public static function current_user_ip( $check_all_headers = false ) { |
||
| 1979 | |||
| 1980 | /** |
||
| 1981 | * Synchronize connected user role changes |
||
| 1982 | */ |
||
| 1983 | function user_role_change( $user_id ) { |
||
| 1987 | |||
| 1988 | /** |
||
| 1989 | * Loads the currently active modules. |
||
| 1990 | */ |
||
| 1991 | public static function load_modules() { |
||
| 2079 | |||
| 2080 | /** |
||
| 2081 | * Check if Jetpack's REST API compat file should be included |
||
| 2082 | * |
||
| 2083 | * @action plugins_loaded |
||
| 2084 | * @return null |
||
| 2085 | */ |
||
| 2086 | public function check_rest_api_compat() { |
||
| 2100 | |||
| 2101 | /** |
||
| 2102 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 2103 | * traditionally activated or network activated. |
||
| 2104 | * |
||
| 2105 | * @todo Store the result in core's object cache maybe? |
||
| 2106 | */ |
||
| 2107 | public static function get_active_plugins() { |
||
| 2123 | |||
| 2124 | /** |
||
| 2125 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 2126 | * |
||
| 2127 | * @since 3.8.1 |
||
| 2128 | * |
||
| 2129 | * @return array Array of plugin data |
||
| 2130 | */ |
||
| 2131 | public static function get_parsed_plugin_data() { |
||
| 2152 | |||
| 2153 | /** |
||
| 2154 | * Gets and parses theme data to send with the heartbeat data |
||
| 2155 | * |
||
| 2156 | * @since 3.8.1 |
||
| 2157 | * |
||
| 2158 | * @return array Array of theme data |
||
| 2159 | */ |
||
| 2160 | public static function get_parsed_theme_data() { |
||
| 2182 | |||
| 2183 | /** |
||
| 2184 | * Checks whether a specific plugin is active. |
||
| 2185 | * |
||
| 2186 | * We don't want to store these in a static variable, in case |
||
| 2187 | * there are switch_to_blog() calls involved. |
||
| 2188 | */ |
||
| 2189 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 2192 | |||
| 2193 | /** |
||
| 2194 | * Check if Jetpack's Open Graph tags should be used. |
||
| 2195 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 2196 | * |
||
| 2197 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 2198 | * @action plugins_loaded |
||
| 2199 | * @return null |
||
| 2200 | */ |
||
| 2201 | public function check_open_graph() { |
||
| 2228 | |||
| 2229 | /** |
||
| 2230 | * Check if Jetpack's Twitter tags should be used. |
||
| 2231 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 2232 | * |
||
| 2233 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 2234 | * @action plugins_loaded |
||
| 2235 | * @return null |
||
| 2236 | */ |
||
| 2237 | public function check_twitter_tags() { |
||
| 2261 | |||
| 2262 | /** |
||
| 2263 | * Allows plugins to submit security reports. |
||
| 2264 | * |
||
| 2265 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 2266 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 2267 | * @param array $args See definitions above |
||
| 2268 | */ |
||
| 2269 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 2272 | |||
| 2273 | /* Jetpack Options API */ |
||
| 2274 | |||
| 2275 | public static function get_option_names( $type = 'compact' ) { |
||
| 2278 | |||
| 2279 | /** |
||
| 2280 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 2281 | * |
||
| 2282 | * @param string $name Option name |
||
| 2283 | * @param mixed $default (optional) |
||
| 2284 | */ |
||
| 2285 | public static function get_option( $name, $default = false ) { |
||
| 2288 | |||
| 2289 | /** |
||
| 2290 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 2291 | * |
||
| 2292 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 2293 | * @param string $name Option name |
||
| 2294 | * @param mixed $value Option value |
||
| 2295 | */ |
||
| 2296 | public static function update_option( $name, $value ) { |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 2303 | * |
||
| 2304 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 2305 | * @param array $array array( option name => option value, ... ) |
||
| 2306 | */ |
||
| 2307 | public static function update_options( $array ) { |
||
| 2311 | |||
| 2312 | /** |
||
| 2313 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 2314 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 2315 | * |
||
| 2316 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 2317 | * @param string|array $names |
||
| 2318 | */ |
||
| 2319 | public static function delete_option( $names ) { |
||
| 2323 | |||
| 2324 | /** |
||
| 2325 | * Enters a user token into the user_tokens option |
||
| 2326 | * |
||
| 2327 | * @deprecated 8.0 Use Automattic\Jetpack\Connection\Tokens->update_user_token() instead. |
||
| 2328 | * |
||
| 2329 | * @param int $user_id The user id. |
||
| 2330 | * @param string $token The user token. |
||
| 2331 | * @param bool $is_master_user Whether the user is the master user. |
||
| 2332 | * @return bool |
||
| 2333 | */ |
||
| 2334 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 2338 | |||
| 2339 | /** |
||
| 2340 | * Returns an array of all PHP files in the specified absolute path. |
||
| 2341 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 2342 | * |
||
| 2343 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 2344 | * @return array Array of absolute paths to the PHP files. |
||
| 2345 | */ |
||
| 2346 | public static function glob_php( $absolute_path ) { |
||
| 2375 | |||
| 2376 | public static function activate_new_modules( $redirect = false ) { |
||
| 2435 | |||
| 2436 | /** |
||
| 2437 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 2438 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 2439 | * |
||
| 2440 | * @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter. |
||
| 2441 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
| 2442 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
| 2443 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
| 2444 | * |
||
| 2445 | * @return array $modules Array of module slugs |
||
| 2446 | */ |
||
| 2447 | public static function get_available_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
| 2519 | |||
| 2520 | /** |
||
| 2521 | * Get default modules loaded on activation. |
||
| 2522 | * |
||
| 2523 | * @param bool|string $min_version Onlu return modules introduced in this version or later. Default is false, do not filter. |
||
| 2524 | * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. |
||
| 2525 | * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. |
||
| 2526 | * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. |
||
| 2527 | * |
||
| 2528 | * @return array $modules Array of module slugs |
||
| 2529 | */ |
||
| 2530 | public static function get_default_modules( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { |
||
| 2563 | |||
| 2564 | /** |
||
| 2565 | * Checks activated modules during auto-activation to determine |
||
| 2566 | * if any of those modules are being deprecated. If so, close |
||
| 2567 | * them out, and add any replacement modules. |
||
| 2568 | * |
||
| 2569 | * Runs at priority 99 by default. |
||
| 2570 | * |
||
| 2571 | * This is run late, so that it can still activate a module if |
||
| 2572 | * the new module is a replacement for another that the user |
||
| 2573 | * currently has active, even if something at the normal priority |
||
| 2574 | * would kibosh everything. |
||
| 2575 | * |
||
| 2576 | * @since 2.6 |
||
| 2577 | * @uses jetpack_get_default_modules filter |
||
| 2578 | * @param array $modules |
||
| 2579 | * @return array |
||
| 2580 | */ |
||
| 2581 | function handle_deprecated_modules( $modules ) { |
||
| 2608 | |||
| 2609 | /** |
||
| 2610 | * Checks activated plugins during auto-activation to determine |
||
| 2611 | * if any of those plugins are in the list with a corresponding module |
||
| 2612 | * that is not compatible with the plugin. The module will not be allowed |
||
| 2613 | * to auto-activate. |
||
| 2614 | * |
||
| 2615 | * @since 2.6 |
||
| 2616 | * @uses jetpack_get_default_modules filter |
||
| 2617 | * @param array $modules |
||
| 2618 | * @return array |
||
| 2619 | */ |
||
| 2620 | function filter_default_modules( $modules ) { |
||
| 2644 | |||
| 2645 | /** |
||
| 2646 | * Extract a module's slug from its full path. |
||
| 2647 | */ |
||
| 2648 | public static function get_module_slug( $file ) { |
||
| 2651 | |||
| 2652 | /** |
||
| 2653 | * Generate a module's path from its slug. |
||
| 2654 | */ |
||
| 2655 | public static function get_module_path( $slug ) { |
||
| 2666 | |||
| 2667 | /** |
||
| 2668 | * Load module data from module file. Headers differ from WordPress |
||
| 2669 | * plugin headers to avoid them being identified as standalone |
||
| 2670 | * plugins on the WordPress plugins page. |
||
| 2671 | */ |
||
| 2672 | public static function get_module( $module ) { |
||
| 2772 | |||
| 2773 | /** |
||
| 2774 | * Like core's get_file_data implementation, but caches the result. |
||
| 2775 | */ |
||
| 2776 | public static function get_file_data( $file, $headers ) { |
||
| 2809 | |||
| 2810 | /** |
||
| 2811 | * Return translated module tag. |
||
| 2812 | * |
||
| 2813 | * @param string $tag Tag as it appears in each module heading. |
||
| 2814 | * |
||
| 2815 | * @return mixed |
||
| 2816 | */ |
||
| 2817 | public static function translate_module_tag( $tag ) { |
||
| 2820 | |||
| 2821 | /** |
||
| 2822 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2823 | * |
||
| 2824 | * @since 3.9.2 |
||
| 2825 | * |
||
| 2826 | * @param array $modules |
||
| 2827 | * |
||
| 2828 | * @return string|void |
||
| 2829 | */ |
||
| 2830 | public static function get_translated_modules( $modules ) { |
||
| 2843 | |||
| 2844 | /** |
||
| 2845 | * Get a list of activated modules as an array of module slugs. |
||
| 2846 | */ |
||
| 2847 | public static function get_active_modules() { |
||
| 2879 | |||
| 2880 | /** |
||
| 2881 | * Check whether or not a Jetpack module is active. |
||
| 2882 | * |
||
| 2883 | * @param string $module The slug of a Jetpack module. |
||
| 2884 | * @return bool |
||
| 2885 | * |
||
| 2886 | * @static |
||
| 2887 | */ |
||
| 2888 | public static function is_module_active( $module ) { |
||
| 2891 | |||
| 2892 | public static function is_module( $module ) { |
||
| 2895 | |||
| 2896 | /** |
||
| 2897 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2898 | * |
||
| 2899 | * @param bool $catch True to start catching, False to stop. |
||
| 2900 | * |
||
| 2901 | * @static |
||
| 2902 | */ |
||
| 2903 | public static function catch_errors( $catch ) { |
||
| 2916 | |||
| 2917 | /** |
||
| 2918 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2919 | */ |
||
| 2920 | public static function catch_errors_on_shutdown() { |
||
| 2923 | |||
| 2924 | /** |
||
| 2925 | * Rewrite any string to make paths easier to read. |
||
| 2926 | * |
||
| 2927 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
| 2928 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
| 2929 | * |
||
| 2930 | * @param $string |
||
| 2931 | * @return mixed |
||
| 2932 | */ |
||
| 2933 | public static function alias_directories( $string ) { |
||
| 2941 | |||
| 2942 | public static function activate_default_modules( |
||
| 3114 | |||
| 3115 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 3208 | |||
| 3209 | function activate_module_actions( $module ) { |
||
| 3212 | |||
| 3213 | public static function deactivate_module( $module ) { |
||
| 3230 | |||
| 3231 | public static function enable_module_configurable( $module ) { |
||
| 3235 | |||
| 3236 | /** |
||
| 3237 | * Composes a module configure URL. It uses Jetpack settings search as default value |
||
| 3238 | * It is possible to redefine resulting URL by using "jetpack_module_configuration_url_$module" filter |
||
| 3239 | * |
||
| 3240 | * @param string $module Module slug |
||
| 3241 | * @return string $url module configuration URL |
||
| 3242 | */ |
||
| 3243 | public static function module_configuration_url( $module ) { |
||
| 3257 | |||
| 3258 | /* Installation */ |
||
| 3259 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 3299 | |||
| 3300 | /** |
||
| 3301 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 3302 | * |
||
| 3303 | * @static |
||
| 3304 | */ |
||
| 3305 | public static function plugin_activation( $network_wide ) { |
||
| 3325 | |||
| 3326 | public static function get_activation_source( $referer_url ) { |
||
| 3375 | |||
| 3376 | /** |
||
| 3377 | * Runs before bumping version numbers up to a new version |
||
| 3378 | * |
||
| 3379 | * @param string $version Version:timestamp. |
||
| 3380 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
| 3381 | */ |
||
| 3382 | public static function do_version_bump( $version, $old_version ) { |
||
| 3392 | |||
| 3393 | /** |
||
| 3394 | * Sets the display_update_modal state. |
||
| 3395 | */ |
||
| 3396 | public static function set_update_modal_display() { |
||
| 3399 | |||
| 3400 | /** |
||
| 3401 | * Sets the internal version number and activation state. |
||
| 3402 | * |
||
| 3403 | * @static |
||
| 3404 | */ |
||
| 3405 | public static function plugin_initialize() { |
||
| 3422 | |||
| 3423 | /** |
||
| 3424 | * Removes all connection options |
||
| 3425 | * |
||
| 3426 | * @static |
||
| 3427 | */ |
||
| 3428 | public static function plugin_deactivation() { |
||
| 3439 | |||
| 3440 | /** |
||
| 3441 | * Disconnects from the Jetpack servers. |
||
| 3442 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 3443 | * |
||
| 3444 | * @static |
||
| 3445 | */ |
||
| 3446 | public static function disconnect( $update_activated_state = true ) { |
||
| 3492 | |||
| 3493 | /** |
||
| 3494 | * Disconnects the user |
||
| 3495 | * |
||
| 3496 | * @param int $user_id The user ID to disconnect. |
||
| 3497 | */ |
||
| 3498 | public function disconnect_user( $user_id ) { |
||
| 3501 | |||
| 3502 | /** |
||
| 3503 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 3504 | * |
||
| 3505 | * @deprecated since Jetpack 9.7.0 |
||
| 3506 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
| 3507 | * |
||
| 3508 | * @return bool|WP_Error |
||
| 3509 | */ |
||
| 3510 | public static function try_registration() { |
||
| 3511 | _deprecated_function( __METHOD__, 'jetpack-9.7', 'Automattic\\Jetpack\\Connection\\Manager::try_registration' ); |
||
| 3512 | return static::connection()->try_registration(); |
||
| 3513 | } |
||
| 3514 | |||
| 3515 | /** |
||
| 3516 | * Checking the domain names in beta versions. |
||
| 3517 | * If this is a development version, before attempting to connect, let's make sure that the domains are viable. |
||
| 3518 | * |
||
| 3519 | * @param null|\WP_Error $error The domain validation error, or `null` if everything's fine. |
||
| 3520 | * |
||
| 3521 | * @return null|\WP_Error The domain validation error, or `null` if everything's fine. |
||
| 3522 | */ |
||
| 3523 | public static function registration_check_domains( $error ) { |
||
| 3524 | if ( static::is_development_version() && defined( 'PHP_URL_HOST' ) ) { |
||
| 3525 | $domains_to_check = array_unique( |
||
| 3526 | array( |
||
| 3527 | 'siteurl' => wp_parse_url( get_site_url(), PHP_URL_HOST ), |
||
| 3528 | 'homeurl' => wp_parse_url( get_home_url(), PHP_URL_HOST ), |
||
| 3529 | ) |
||
| 3530 | ); |
||
| 3531 | foreach ( $domains_to_check as $domain ) { |
||
| 3532 | $result = static::connection()->is_usable_domain( $domain ); |
||
| 3533 | if ( is_wp_error( $result ) ) { |
||
| 3534 | return $result; |
||
| 3535 | } |
||
| 3536 | } |
||
| 3537 | } |
||
| 3538 | |||
| 3539 | return $error; |
||
| 3540 | } |
||
| 3541 | |||
| 3542 | /** |
||
| 3543 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 3544 | * |
||
| 3545 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 3546 | */ |
||
| 3547 | public static function log( $code, $data = null ) { |
||
| 3548 | // only grab the latest 200 entries |
||
| 3549 | $log = array_slice( Jetpack_Options::get_option( 'log', array() ), -199, 199 ); |
||
| 3550 | |||
| 3551 | // Append our event to the log |
||
| 3552 | $log_entry = array( |
||
| 3553 | 'time' => time(), |
||
| 3554 | 'user_id' => get_current_user_id(), |
||
| 3555 | 'blog_id' => Jetpack_Options::get_option( 'id' ), |
||
| 3556 | 'code' => $code, |
||
| 3557 | ); |
||
| 3558 | // Don't bother storing it unless we've got some. |
||
| 3559 | if ( ! is_null( $data ) ) { |
||
| 3560 | $log_entry['data'] = $data; |
||
| 3561 | } |
||
| 3562 | $log[] = $log_entry; |
||
| 3563 | |||
| 3564 | // Try add_option first, to make sure it's not autoloaded. |
||
| 3565 | // @todo: Add an add_option method to Jetpack_Options |
||
| 3566 | if ( ! add_option( 'jetpack_log', $log, null, 'no' ) ) { |
||
| 3567 | Jetpack_Options::update_option( 'log', $log ); |
||
| 3568 | } |
||
| 3569 | |||
| 3570 | /** |
||
| 3571 | * Fires when Jetpack logs an internal event. |
||
| 3572 | * |
||
| 3573 | * @since 3.0.0 |
||
| 3574 | * |
||
| 3575 | * @param array $log_entry { |
||
| 3576 | * Array of details about the log entry. |
||
| 3577 | * |
||
| 3578 | * @param string time Time of the event. |
||
| 3579 | * @param int user_id ID of the user who trigerred the event. |
||
| 3580 | * @param int blog_id Jetpack Blog ID. |
||
| 3581 | * @param string code Unique name for the event. |
||
| 3582 | * @param string data Data about the event. |
||
| 3583 | * } |
||
| 3584 | */ |
||
| 3585 | do_action( 'jetpack_log_entry', $log_entry ); |
||
| 3586 | } |
||
| 3587 | |||
| 3588 | /** |
||
| 3589 | * Get the internal event log. |
||
| 3590 | * |
||
| 3591 | * @param $event (string) - only return the specific log events |
||
| 3592 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 3593 | * |
||
| 3594 | * @return array of log events || WP_Error for invalid params |
||
| 3595 | */ |
||
| 3596 | public static function get_log( $event = false, $num = false ) { |
||
| 3597 | if ( $event && ! is_string( $event ) ) { |
||
| 3598 | return new WP_Error( __( 'First param must be string or empty', 'jetpack' ) ); |
||
| 3599 | } |
||
| 3600 | |||
| 3601 | if ( $num && ! is_numeric( $num ) ) { |
||
| 3602 | return new WP_Error( __( 'Second param must be numeric or empty', 'jetpack' ) ); |
||
| 3603 | } |
||
| 3604 | |||
| 3605 | $entire_log = Jetpack_Options::get_option( 'log', array() ); |
||
| 3606 | |||
| 3607 | // If nothing set - act as it did before, otherwise let's start customizing the output |
||
| 3608 | if ( ! $num && ! $event ) { |
||
| 3609 | return $entire_log; |
||
| 3610 | } else { |
||
| 3611 | $entire_log = array_reverse( $entire_log ); |
||
| 3612 | } |
||
| 3613 | |||
| 3614 | $custom_log_output = array(); |
||
| 3615 | |||
| 3616 | if ( $event ) { |
||
| 3617 | foreach ( $entire_log as $log_event ) { |
||
| 3618 | if ( $event == $log_event['code'] ) { |
||
| 3619 | $custom_log_output[] = $log_event; |
||
| 3620 | } |
||
| 3621 | } |
||
| 3622 | } else { |
||
| 3623 | $custom_log_output = $entire_log; |
||
| 3624 | } |
||
| 3625 | |||
| 3626 | if ( $num ) { |
||
| 3627 | $custom_log_output = array_slice( $custom_log_output, 0, $num ); |
||
| 3628 | } |
||
| 3629 | |||
| 3630 | return $custom_log_output; |
||
| 3631 | } |
||
| 3632 | |||
| 3633 | /** |
||
| 3634 | * Log modification of important settings. |
||
| 3635 | */ |
||
| 3636 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 3637 | switch ( $option ) { |
||
| 3638 | case 'jetpack_sync_non_public_post_stati': |
||
| 3639 | self::log( $option, $value ); |
||
| 3640 | break; |
||
| 3641 | } |
||
| 3642 | } |
||
| 3643 | |||
| 3644 | /** |
||
| 3645 | * Return stat data for WPCOM sync |
||
| 3646 | */ |
||
| 3647 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
| 3648 | $data = Jetpack_Heartbeat::generate_stats_array(); |
||
| 3649 | |||
| 3650 | if ( $extended ) { |
||
| 3651 | $additional_data = self::get_additional_stat_data(); |
||
| 3652 | $data = array_merge( $data, $additional_data ); |
||
| 3653 | } |
||
| 3654 | |||
| 3655 | if ( $encode ) { |
||
| 3656 | return json_encode( $data ); |
||
| 3657 | } |
||
| 3658 | |||
| 3659 | return $data; |
||
| 3660 | } |
||
| 3661 | |||
| 3662 | /** |
||
| 3663 | * Get additional stat data to sync to WPCOM |
||
| 3664 | */ |
||
| 3665 | public static function get_additional_stat_data( $prefix = '' ) { |
||
| 3666 | $return[ "{$prefix}themes" ] = self::get_parsed_theme_data(); |
||
| 3667 | $return[ "{$prefix}plugins-extra" ] = self::get_parsed_plugin_data(); |
||
| 3668 | $return[ "{$prefix}users" ] = (int) self::get_site_user_count(); |
||
| 3669 | $return[ "{$prefix}site-count" ] = 0; |
||
| 3670 | |||
| 3671 | if ( function_exists( 'get_blog_count' ) ) { |
||
| 3672 | $return[ "{$prefix}site-count" ] = get_blog_count(); |
||
| 3673 | } |
||
| 3674 | return $return; |
||
| 3675 | } |
||
| 3676 | |||
| 3677 | private static function get_site_user_count() { |
||
| 3678 | global $wpdb; |
||
| 3679 | |||
| 3680 | if ( function_exists( 'wp_is_large_network' ) ) { |
||
| 3681 | if ( wp_is_large_network( 'users' ) ) { |
||
| 3682 | return -1; // Not a real value but should tell us that we are dealing with a large network. |
||
| 3683 | } |
||
| 3684 | } |
||
| 3685 | if ( false === ( $user_count = get_transient( 'jetpack_site_user_count' ) ) ) { |
||
| 3686 | // It wasn't there, so regenerate the data and save the transient |
||
| 3687 | $user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities'" ); |
||
| 3688 | set_transient( 'jetpack_site_user_count', $user_count, DAY_IN_SECONDS ); |
||
| 3689 | } |
||
| 3690 | return $user_count; |
||
| 3691 | } |
||
| 3692 | |||
| 3693 | /* Admin Pages */ |
||
| 3694 | |||
| 3695 | function admin_init() { |
||
| 3696 | // If the plugin is not connected, display a connect message. |
||
| 3697 | if ( |
||
| 3698 | // the plugin was auto-activated and needs its candy |
||
| 3699 | Jetpack_Options::get_option_and_ensure_autoload( 'do_activate', '0' ) |
||
| 3700 | || |
||
| 3701 | // the plugin is active, but was never activated. Probably came from a site-wide network activation |
||
| 3702 | ! Jetpack_Options::get_option( 'activated' ) |
||
| 3703 | ) { |
||
| 3704 | self::plugin_initialize(); |
||
| 3705 | } |
||
| 3706 | |||
| 3707 | $is_offline_mode = ( new Status() )->is_offline_mode(); |
||
| 3708 | if ( ! self::is_connection_ready() && ! $is_offline_mode ) { |
||
| 3709 | Jetpack_Connection_Banner::init(); |
||
| 3710 | /** Already documented in automattic/jetpack-connection::src/class-client.php */ |
||
| 3711 | } elseif ( ( false === Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ) ) && ! apply_filters( 'jetpack_client_verify_ssl_certs', false ) ) { |
||
| 3712 | // Upgrade: 1.1 -> 1.1.1 |
||
| 3713 | // Check and see if host can verify the Jetpack servers' SSL certificate |
||
| 3714 | $args = array(); |
||
| 3715 | Client::_wp_remote_request( self::connection()->api_url( 'test' ), $args, true ); |
||
| 3716 | } |
||
| 3717 | |||
| 3718 | Jetpack_Recommendations_Banner::init(); |
||
| 3719 | |||
| 3720 | if ( current_user_can( 'manage_options' ) && ! self::permit_ssl() ) { |
||
| 3721 | add_action( 'jetpack_notices', array( $this, 'alert_auto_ssl_fail' ) ); |
||
| 3722 | } |
||
| 3723 | |||
| 3724 | add_action( 'load-plugins.php', array( $this, 'intercept_plugin_error_scrape_init' ) ); |
||
| 3725 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
||
| 3726 | add_action( 'admin_enqueue_scripts', array( $this, 'deactivate_dialog' ) ); |
||
| 3727 | add_filter( 'plugin_action_links_' . plugin_basename( JETPACK__PLUGIN_DIR . 'jetpack.php' ), array( $this, 'plugin_action_links' ) ); |
||
| 3728 | |||
| 3729 | if ( self::is_connection_ready() || $is_offline_mode ) { |
||
| 3730 | // Artificially throw errors in certain specific cases during plugin activation. |
||
| 3731 | add_action( 'activate_plugin', array( $this, 'throw_error_on_activate_plugin' ) ); |
||
| 3732 | } |
||
| 3733 | |||
| 3734 | // Add custom column in wp-admin/users.php to show whether user is linked. |
||
| 3735 | add_filter( 'manage_users_columns', array( $this, 'jetpack_icon_user_connected' ) ); |
||
| 3736 | add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_user_connected_icon' ), 10, 3 ); |
||
| 3737 | add_action( 'admin_print_styles', array( $this, 'jetpack_user_col_style' ) ); |
||
| 3738 | } |
||
| 3739 | |||
| 3740 | function admin_body_class( $admin_body_class = '' ) { |
||
| 3741 | $classes = explode( ' ', trim( $admin_body_class ) ); |
||
| 3742 | |||
| 3743 | $classes[] = self::is_connection_ready() ? 'jetpack-connected' : 'jetpack-disconnected'; |
||
| 3744 | |||
| 3745 | $admin_body_class = implode( ' ', array_unique( $classes ) ); |
||
| 3746 | return " $admin_body_class "; |
||
| 3747 | } |
||
| 3748 | |||
| 3749 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 3750 | return $admin_body_class . ' jetpack-pagestyles '; |
||
| 3751 | } |
||
| 3752 | |||
| 3753 | /** |
||
| 3754 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 3755 | * This function artificially throws errors for such cases (per a specific list). |
||
| 3756 | * |
||
| 3757 | * @param string $plugin The activated plugin. |
||
| 3758 | */ |
||
| 3759 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 3760 | $active_modules = self::get_active_modules(); |
||
| 3761 | |||
| 3762 | // The Shortlinks module and the Stats plugin conflict, but won't cause errors on activation because of some function_exists() checks. |
||
| 3763 | if ( function_exists( 'stats_get_api_key' ) && in_array( 'shortlinks', $active_modules ) ) { |
||
| 3764 | $throw = false; |
||
| 3765 | |||
| 3766 | // Try and make sure it really was the stats plugin |
||
| 3767 | if ( ! class_exists( 'ReflectionFunction' ) ) { |
||
| 3768 | if ( 'stats.php' == basename( $plugin ) ) { |
||
| 3769 | $throw = true; |
||
| 3770 | } |
||
| 3771 | } else { |
||
| 3772 | $reflection = new ReflectionFunction( 'stats_get_api_key' ); |
||
| 3773 | if ( basename( $plugin ) == basename( $reflection->getFileName() ) ) { |
||
| 3774 | $throw = true; |
||
| 3775 | } |
||
| 3776 | } |
||
| 3777 | |||
| 3778 | if ( $throw ) { |
||
| 3779 | trigger_error( sprintf( __( 'Jetpack contains the most recent version of the old “%1$s” plugin.', 'jetpack' ), 'WordPress.com Stats' ), E_USER_ERROR ); |
||
| 3780 | } |
||
| 3781 | } |
||
| 3782 | } |
||
| 3783 | |||
| 3784 | function intercept_plugin_error_scrape_init() { |
||
| 3785 | add_action( 'check_admin_referer', array( $this, 'intercept_plugin_error_scrape' ), 10, 2 ); |
||
| 3786 | } |
||
| 3787 | |||
| 3788 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 3789 | if ( ! $result ) { |
||
| 3790 | return; |
||
| 3791 | } |
||
| 3792 | |||
| 3793 | foreach ( $this->plugins_to_deactivate as $deactivate_me ) { |
||
| 3794 | if ( "plugin-activation-error_{$deactivate_me[0]}" == $action ) { |
||
| 3795 | self::bail_on_activation( sprintf( __( 'Jetpack contains the most recent version of the old “%1$s” plugin.', 'jetpack' ), $deactivate_me[1] ), false ); |
||
| 3796 | } |
||
| 3797 | } |
||
| 3798 | } |
||
| 3799 | |||
| 3800 | /** |
||
| 3801 | * Register the remote file upload request handlers, if needed. |
||
| 3802 | * |
||
| 3803 | * @access public |
||
| 3804 | */ |
||
| 3805 | public function add_remote_request_handlers() { |
||
| 3806 | // Remote file uploads are allowed only via AJAX requests. |
||
| 3807 | if ( ! is_admin() || ! Constants::get_constant( 'DOING_AJAX' ) ) { |
||
| 3808 | return; |
||
| 3809 | } |
||
| 3810 | |||
| 3811 | // Remote file uploads are allowed only for a set of specific AJAX actions. |
||
| 3812 | $remote_request_actions = array( |
||
| 3813 | 'jetpack_upload_file', |
||
| 3814 | 'jetpack_update_file', |
||
| 3815 | ); |
||
| 3816 | |||
| 3817 | // phpcs:ignore WordPress.Security.NonceVerification |
||
| 3818 | if ( ! isset( $_POST['action'] ) || ! in_array( $_POST['action'], $remote_request_actions, true ) ) { |
||
| 3819 | return; |
||
| 3820 | } |
||
| 3821 | |||
| 3822 | // Require Jetpack authentication for the remote file upload AJAX requests. |
||
| 3823 | if ( ! $this->connection_manager ) { |
||
| 3824 | $this->connection_manager = new Connection_Manager(); |
||
| 3825 | } |
||
| 3826 | |||
| 3827 | $this->connection_manager->require_jetpack_authentication(); |
||
| 3828 | |||
| 3829 | // Register the remote file upload AJAX handlers. |
||
| 3830 | foreach ( $remote_request_actions as $action ) { |
||
| 3831 | add_action( "wp_ajax_nopriv_{$action}", array( $this, 'remote_request_handlers' ) ); |
||
| 3832 | } |
||
| 3833 | } |
||
| 3834 | |||
| 3835 | /** |
||
| 3836 | * Handler for Jetpack remote file uploads. |
||
| 3837 | * |
||
| 3838 | * @access public |
||
| 3839 | */ |
||
| 3840 | public function remote_request_handlers() { |
||
| 3841 | $action = current_filter(); |
||
| 3842 | |||
| 3843 | switch ( current_filter() ) { |
||
| 3844 | case 'wp_ajax_nopriv_jetpack_upload_file': |
||
| 3845 | $response = $this->upload_handler(); |
||
| 3846 | break; |
||
| 3847 | |||
| 3848 | case 'wp_ajax_nopriv_jetpack_update_file': |
||
| 3849 | $response = $this->upload_handler( true ); |
||
| 3850 | break; |
||
| 3851 | default: |
||
| 3852 | $response = new WP_Error( 'unknown_handler', 'Unknown Handler', 400 ); |
||
| 3853 | break; |
||
| 3854 | } |
||
| 3855 | |||
| 3856 | if ( ! $response ) { |
||
| 3857 | $response = new WP_Error( 'unknown_error', 'Unknown Error', 400 ); |
||
| 3858 | } |
||
| 3859 | |||
| 3860 | if ( is_wp_error( $response ) ) { |
||
| 3861 | $status_code = $response->get_error_data(); |
||
| 3862 | $error = $response->get_error_code(); |
||
| 3863 | $error_description = $response->get_error_message(); |
||
| 3864 | |||
| 3865 | if ( ! is_int( $status_code ) ) { |
||
| 3866 | $status_code = 400; |
||
| 3867 | } |
||
| 3868 | |||
| 3869 | status_header( $status_code ); |
||
| 3870 | die( json_encode( (object) compact( 'error', 'error_description' ) ) ); |
||
| 3871 | } |
||
| 3872 | |||
| 3873 | status_header( 200 ); |
||
| 3874 | if ( true === $response ) { |
||
| 3875 | exit; |
||
| 3876 | } |
||
| 3877 | |||
| 3878 | die( json_encode( (object) $response ) ); |
||
| 3879 | } |
||
| 3880 | |||
| 3881 | /** |
||
| 3882 | * Uploads a file gotten from the global $_FILES. |
||
| 3883 | * If `$update_media_item` is true and `post_id` is defined |
||
| 3884 | * the attachment file of the media item (gotten through of the post_id) |
||
| 3885 | * will be updated instead of add a new one. |
||
| 3886 | * |
||
| 3887 | * @param boolean $update_media_item - update media attachment |
||
| 3888 | * @return array - An array describing the uploadind files process |
||
| 3889 | */ |
||
| 3890 | function upload_handler( $update_media_item = false ) { |
||
| 3891 | if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { |
||
| 3892 | return new WP_Error( 405, get_status_header_desc( 405 ), 405 ); |
||
| 3893 | } |
||
| 3894 | |||
| 3895 | $user = wp_authenticate( '', '' ); |
||
| 3896 | if ( ! $user || is_wp_error( $user ) ) { |
||
| 3897 | return new WP_Error( 403, get_status_header_desc( 403 ), 403 ); |
||
| 3898 | } |
||
| 3899 | |||
| 3900 | wp_set_current_user( $user->ID ); |
||
| 3901 | |||
| 3902 | if ( ! current_user_can( 'upload_files' ) ) { |
||
| 3903 | return new WP_Error( 'cannot_upload_files', 'User does not have permission to upload files', 403 ); |
||
| 3904 | } |
||
| 3905 | |||
| 3906 | if ( empty( $_FILES ) ) { |
||
| 3907 | return new WP_Error( 'no_files_uploaded', 'No files were uploaded: nothing to process', 400 ); |
||
| 3908 | } |
||
| 3909 | |||
| 3910 | foreach ( array_keys( $_FILES ) as $files_key ) { |
||
| 3911 | if ( ! isset( $_POST[ "_jetpack_file_hmac_{$files_key}" ] ) ) { |
||
| 3912 | return new WP_Error( 'missing_hmac', 'An HMAC for one or more files is missing', 400 ); |
||
| 3913 | } |
||
| 3914 | } |
||
| 3915 | |||
| 3916 | $media_keys = array_keys( $_FILES['media'] ); |
||
| 3917 | |||
| 3918 | $token = ( new Tokens() )->get_access_token( get_current_user_id() ); |
||
| 3919 | if ( ! $token || is_wp_error( $token ) ) { |
||
| 3920 | return new WP_Error( 'unknown_token', 'Unknown Jetpack token', 403 ); |
||
| 3921 | } |
||
| 3922 | |||
| 3923 | $uploaded_files = array(); |
||
| 3924 | $global_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null; |
||
| 3925 | unset( $GLOBALS['post'] ); |
||
| 3926 | foreach ( $_FILES['media']['name'] as $index => $name ) { |
||
| 3927 | $file = array(); |
||
| 3928 | foreach ( $media_keys as $media_key ) { |
||
| 3929 | $file[ $media_key ] = $_FILES['media'][ $media_key ][ $index ]; |
||
| 3930 | } |
||
| 3931 | |||
| 3932 | list( $hmac_provided, $salt ) = explode( ':', $_POST['_jetpack_file_hmac_media'][ $index ] ); |
||
| 3933 | |||
| 3934 | $hmac_file = hash_hmac_file( 'sha1', $file['tmp_name'], $salt . $token->secret ); |
||
| 3935 | if ( $hmac_provided !== $hmac_file ) { |
||
| 3936 | $uploaded_files[ $index ] = (object) array( |
||
| 3937 | 'error' => 'invalid_hmac', |
||
| 3938 | 'error_description' => 'The corresponding HMAC for this file does not match', |
||
| 3939 | ); |
||
| 3940 | continue; |
||
| 3941 | } |
||
| 3942 | |||
| 3943 | $_FILES['.jetpack.upload.'] = $file; |
||
| 3944 | $post_id = isset( $_POST['post_id'][ $index ] ) ? absint( $_POST['post_id'][ $index ] ) : 0; |
||
| 3945 | if ( ! current_user_can( 'edit_post', $post_id ) ) { |
||
| 3946 | $post_id = 0; |
||
| 3947 | } |
||
| 3948 | |||
| 3949 | if ( $update_media_item ) { |
||
| 3950 | if ( ! isset( $post_id ) || $post_id === 0 ) { |
||
| 3951 | return new WP_Error( 'invalid_input', 'Media ID must be defined.', 400 ); |
||
| 3952 | } |
||
| 3953 | |||
| 3954 | $media_array = $_FILES['media']; |
||
| 3955 | |||
| 3956 | $file_array['name'] = $media_array['name'][0]; |
||
| 3957 | $file_array['type'] = $media_array['type'][0]; |
||
| 3958 | $file_array['tmp_name'] = $media_array['tmp_name'][0]; |
||
| 3959 | $file_array['error'] = $media_array['error'][0]; |
||
| 3960 | $file_array['size'] = $media_array['size'][0]; |
||
| 3961 | |||
| 3962 | $edited_media_item = Jetpack_Media::edit_media_file( $post_id, $file_array ); |
||
| 3963 | |||
| 3964 | if ( is_wp_error( $edited_media_item ) ) { |
||
| 3965 | return $edited_media_item; |
||
| 3966 | } |
||
| 3967 | |||
| 3968 | $response = (object) array( |
||
| 3969 | 'id' => (string) $post_id, |
||
| 3970 | 'file' => (string) $edited_media_item->post_title, |
||
| 3971 | 'url' => (string) wp_get_attachment_url( $post_id ), |
||
| 3972 | 'type' => (string) $edited_media_item->post_mime_type, |
||
| 3973 | 'meta' => (array) wp_get_attachment_metadata( $post_id ), |
||
| 3974 | ); |
||
| 3975 | |||
| 3976 | return (array) array( $response ); |
||
| 3977 | } |
||
| 3978 | |||
| 3979 | $attachment_id = media_handle_upload( |
||
| 3980 | '.jetpack.upload.', |
||
| 3981 | $post_id, |
||
| 3982 | array(), |
||
| 3983 | array( |
||
| 3984 | 'action' => 'jetpack_upload_file', |
||
| 3985 | ) |
||
| 3986 | ); |
||
| 3987 | |||
| 3988 | if ( ! $attachment_id ) { |
||
| 3989 | $uploaded_files[ $index ] = (object) array( |
||
| 3990 | 'error' => 'unknown', |
||
| 3991 | 'error_description' => 'An unknown problem occurred processing the upload on the Jetpack site', |
||
| 3992 | ); |
||
| 3993 | } elseif ( is_wp_error( $attachment_id ) ) { |
||
| 3994 | $uploaded_files[ $index ] = (object) array( |
||
| 3995 | 'error' => 'attachment_' . $attachment_id->get_error_code(), |
||
| 3996 | 'error_description' => $attachment_id->get_error_message(), |
||
| 3997 | ); |
||
| 3998 | } else { |
||
| 3999 | $attachment = get_post( $attachment_id ); |
||
| 4000 | $uploaded_files[ $index ] = (object) array( |
||
| 4001 | 'id' => (string) $attachment_id, |
||
| 4002 | 'file' => $attachment->post_title, |
||
| 4003 | 'url' => wp_get_attachment_url( $attachment_id ), |
||
| 4004 | 'type' => $attachment->post_mime_type, |
||
| 4005 | 'meta' => wp_get_attachment_metadata( $attachment_id ), |
||
| 4006 | ); |
||
| 4007 | // Zip files uploads are not supported unless they are done for installation purposed |
||
| 4008 | // lets delete them in case something goes wrong in this whole process |
||
| 4009 | if ( 'application/zip' === $attachment->post_mime_type ) { |
||
| 4010 | // Schedule a cleanup for 2 hours from now in case of failed install. |
||
| 4011 | wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $attachment_id ) ); |
||
| 4012 | } |
||
| 4013 | } |
||
| 4014 | } |
||
| 4015 | if ( ! is_null( $global_post ) ) { |
||
| 4016 | $GLOBALS['post'] = $global_post; |
||
| 4017 | } |
||
| 4018 | |||
| 4019 | return $uploaded_files; |
||
| 4020 | } |
||
| 4021 | |||
| 4022 | /** |
||
| 4023 | * Add help to the Jetpack page |
||
| 4024 | * |
||
| 4025 | * @since Jetpack (1.2.3) |
||
| 4026 | * @return false if not the Jetpack page |
||
| 4027 | */ |
||
| 4028 | function admin_help() { |
||
| 4029 | $current_screen = get_current_screen(); |
||
| 4030 | |||
| 4031 | // Overview |
||
| 4032 | $current_screen->add_help_tab( |
||
| 4033 | array( |
||
| 4034 | 'id' => 'home', |
||
| 4035 | 'title' => __( 'Home', 'jetpack' ), |
||
| 4036 | 'content' => |
||
| 4037 | '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' . |
||
| 4038 | '<p>' . __( 'Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack' ) . '</p>' . |
||
| 4039 | '<p>' . __( 'On this page, you are able to view the modules available within Jetpack, learn more about them, and activate or deactivate them as needed.', 'jetpack' ) . '</p>', |
||
| 4040 | ) |
||
| 4041 | ); |
||
| 4042 | |||
| 4043 | // Screen Content |
||
| 4044 | if ( current_user_can( 'manage_options' ) ) { |
||
| 4045 | $current_screen->add_help_tab( |
||
| 4046 | array( |
||
| 4047 | 'id' => 'settings', |
||
| 4048 | 'title' => __( 'Settings', 'jetpack' ), |
||
| 4049 | 'content' => |
||
| 4050 | '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' . |
||
| 4051 | '<p>' . __( 'You can activate or deactivate individual Jetpack modules to suit your needs.', 'jetpack' ) . '</p>' . |
||
| 4052 | '<ol>' . |
||
| 4053 | '<li>' . __( 'Each module has an Activate or Deactivate link so you can toggle one individually.', 'jetpack' ) . '</li>' . |
||
| 4054 | '<li>' . __( 'Using the checkboxes next to each module, you can select multiple modules to toggle via the Bulk Actions menu at the top of the list.', 'jetpack' ) . '</li>' . |
||
| 4055 | '</ol>' . |
||
| 4056 | '<p>' . __( 'Using the tools on the right, you can search for specific modules, filter by module categories or which are active, or change the sorting order.', 'jetpack' ) . '</p>', |
||
| 4057 | ) |
||
| 4058 | ); |
||
| 4059 | } |
||
| 4060 | |||
| 4061 | // Help Sidebar |
||
| 4062 | $support_url = Redirect::get_url( 'jetpack-support' ); |
||
| 4063 | $faq_url = Redirect::get_url( 'jetpack-faq' ); |
||
| 4064 | $current_screen->set_help_sidebar( |
||
| 4065 | '<p><strong>' . __( 'For more information:', 'jetpack' ) . '</strong></p>' . |
||
| 4066 | '<p><a href="' . $faq_url . '" rel="noopener noreferrer" target="_blank">' . __( 'Jetpack FAQ', 'jetpack' ) . '</a></p>' . |
||
| 4067 | '<p><a href="' . $support_url . '" rel="noopener noreferrer" target="_blank">' . __( 'Jetpack Support', 'jetpack' ) . '</a></p>' . |
||
| 4068 | '<p><a href="' . self::admin_url( array( 'page' => 'jetpack-debugger' ) ) . '">' . __( 'Jetpack Debugging Center', 'jetpack' ) . '</a></p>' |
||
| 4069 | ); |
||
| 4070 | } |
||
| 4071 | |||
| 4072 | function admin_menu_css() { |
||
| 4073 | wp_enqueue_style( 'jetpack-icons' ); |
||
| 4074 | } |
||
| 4075 | |||
| 4076 | function admin_menu_order() { |
||
| 4077 | return true; |
||
| 4078 | } |
||
| 4079 | |||
| 4080 | function jetpack_menu_order( $menu_order ) { |
||
| 4081 | $jp_menu_order = array(); |
||
| 4082 | |||
| 4083 | foreach ( $menu_order as $index => $item ) { |
||
| 4084 | if ( $item != 'jetpack' ) { |
||
| 4085 | $jp_menu_order[] = $item; |
||
| 4086 | } |
||
| 4087 | |||
| 4088 | if ( $index == 0 ) { |
||
| 4089 | $jp_menu_order[] = 'jetpack'; |
||
| 4090 | } |
||
| 4091 | } |
||
| 4092 | |||
| 4093 | return $jp_menu_order; |
||
| 4094 | } |
||
| 4095 | |||
| 4096 | function admin_banner_styles() { |
||
| 4097 | $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
| 4098 | |||
| 4099 | View Code Duplication | if ( ! wp_style_is( 'jetpack-dops-style' ) ) { |
|
| 4100 | wp_register_style( |
||
| 4101 | 'jetpack-dops-style', |
||
| 4102 | plugins_url( '_inc/build/admin.css', JETPACK__PLUGIN_FILE ), |
||
| 4103 | array(), |
||
| 4104 | JETPACK__VERSION |
||
| 4105 | ); |
||
| 4106 | } |
||
| 4107 | |||
| 4108 | wp_enqueue_style( |
||
| 4109 | 'jetpack', |
||
| 4110 | plugins_url( "css/jetpack-banners{$min}.css", JETPACK__PLUGIN_FILE ), |
||
| 4111 | array( 'jetpack-dops-style' ), |
||
| 4112 | JETPACK__VERSION . '-20121016' |
||
| 4113 | ); |
||
| 4114 | wp_style_add_data( 'jetpack', 'rtl', 'replace' ); |
||
| 4115 | wp_style_add_data( 'jetpack', 'suffix', $min ); |
||
| 4116 | } |
||
| 4117 | |||
| 4118 | function plugin_action_links( $actions ) { |
||
| 4119 | |||
| 4120 | $jetpack_home = array( 'jetpack-home' => sprintf( '<a href="%s">%s</a>', self::admin_url( 'page=jetpack' ), 'Jetpack' ) ); |
||
| 4121 | |||
| 4122 | if ( current_user_can( 'jetpack_manage_modules' ) && ( self::is_connection_ready() || ( new Status() )->is_offline_mode() ) ) { |
||
| 4123 | return array_merge( |
||
| 4124 | $jetpack_home, |
||
| 4125 | array( 'settings' => sprintf( '<a href="%s">%s</a>', self::admin_url( 'page=jetpack#/settings' ), __( 'Settings', 'jetpack' ) ) ), |
||
| 4126 | array( 'support' => sprintf( '<a href="%s">%s</a>', self::admin_url( 'page=jetpack-debugger ' ), __( 'Support', 'jetpack' ) ) ), |
||
| 4127 | $actions |
||
| 4128 | ); |
||
| 4129 | } |
||
| 4130 | |||
| 4131 | return array_merge( $jetpack_home, $actions ); |
||
| 4132 | } |
||
| 4133 | |||
| 4134 | /** |
||
| 4135 | * Adds the deactivation warning modal if there are other active plugins using the connection |
||
| 4136 | * |
||
| 4137 | * @param string $hook The current admin page. |
||
| 4138 | * |
||
| 4139 | * @return void |
||
| 4140 | */ |
||
| 4141 | public function deactivate_dialog( $hook ) { |
||
| 4142 | if ( |
||
| 4143 | 'plugins.php' === $hook |
||
| 4144 | && self::is_connection_ready() |
||
| 4145 | ) { |
||
| 4146 | |||
| 4147 | $active_plugins_using_connection = Connection_Plugin_Storage::get_all(); |
||
| 4148 | |||
| 4149 | if ( count( $active_plugins_using_connection ) > 1 ) { |
||
| 4150 | |||
| 4151 | add_thickbox(); |
||
| 4152 | |||
| 4153 | wp_register_script( |
||
| 4154 | 'jp-tracks', |
||
| 4155 | '//stats.wp.com/w.js', |
||
| 4156 | array(), |
||
| 4157 | gmdate( 'YW' ), |
||
| 4158 | true |
||
| 4159 | ); |
||
| 4160 | |||
| 4161 | $tracking = new Tracking(); |
||
| 4162 | $tracking->register_tracks_scripts(); |
||
| 4163 | |||
| 4164 | wp_enqueue_script( |
||
| 4165 | 'jetpack-deactivate-dialog-js', |
||
| 4166 | Assets::get_file_url_for_environment( |
||
| 4167 | '_inc/build/jetpack-deactivate-dialog.min.js', |
||
| 4168 | '_inc/jetpack-deactivate-dialog.js' |
||
| 4169 | ), |
||
| 4170 | array( 'jquery', 'jp-tracks-functions' ), |
||
| 4171 | JETPACK__VERSION, |
||
| 4172 | true |
||
| 4173 | ); |
||
| 4174 | |||
| 4175 | wp_localize_script( |
||
| 4176 | 'jetpack-deactivate-dialog-js', |
||
| 4177 | 'deactivate_dialog', |
||
| 4178 | array( |
||
| 4179 | 'title' => __( 'Deactivate Jetpack', 'jetpack' ), |
||
| 4180 | 'deactivate_label' => __( 'Disconnect and Deactivate', 'jetpack' ), |
||
| 4181 | 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), |
||
| 4182 | ) |
||
| 4183 | ); |
||
| 4184 | |||
| 4185 | add_action( 'admin_footer', array( $this, 'deactivate_dialog_content' ) ); |
||
| 4186 | |||
| 4187 | wp_enqueue_style( 'jetpack-deactivate-dialog', plugins_url( 'css/jetpack-deactivate-dialog.css', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION ); |
||
| 4188 | } |
||
| 4189 | } |
||
| 4190 | } |
||
| 4191 | |||
| 4192 | /** |
||
| 4193 | * Outputs the content of the deactivation modal |
||
| 4194 | * |
||
| 4195 | * @return void |
||
| 4196 | */ |
||
| 4197 | public function deactivate_dialog_content() { |
||
| 4202 | |||
| 4203 | /** |
||
| 4204 | * Filters the login URL to include the registration flow in case the user isn't logged in. |
||
| 4205 | * |
||
| 4206 | * @param string $login_url The wp-login URL. |
||
| 4207 | * @param string $redirect URL to redirect users after logging in. |
||
| 4208 | * @since Jetpack 8.4 |
||
| 4209 | * @return string |
||
| 4210 | */ |
||
| 4211 | public function login_url( $login_url, $redirect ) { |
||
| 4218 | |||
| 4219 | /** |
||
| 4220 | * Redirects non-authenticated users to authenticate with Calypso if redirect flag is set. |
||
| 4221 | * |
||
| 4222 | * @since Jetpack 8.4 |
||
| 4223 | */ |
||
| 4224 | public function login_init() { |
||
| 4241 | |||
| 4242 | /* |
||
| 4243 | * Registration flow: |
||
| 4244 | * 1 - ::admin_page_load() action=register |
||
| 4245 | * 2 - ::try_registration() |
||
| 4246 | * 3 - ::register() |
||
| 4247 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 4248 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 4249 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 4250 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 4251 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 4252 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 4253 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 4254 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 4255 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 4256 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 4257 | * 5 - user logs in with WP.com account |
||
| 4258 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 4259 | * - Manager::authorize() |
||
| 4260 | * - Manager::get_token() |
||
| 4261 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 4262 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 4263 | * - which responds with access_token, token_type, scope |
||
| 4264 | * - Manager::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 4265 | * - Jetpack::activate_default_modules() |
||
| 4266 | * - Deactivates deprecated plugins |
||
| 4267 | * - Activates all default modules |
||
| 4268 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 4269 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 4270 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 4271 | * Done! |
||
| 4272 | */ |
||
| 4273 | |||
| 4274 | /** |
||
| 4275 | * Handles the page load events for the Jetpack admin page |
||
| 4276 | */ |
||
| 4277 | function admin_page_load() { |
||
| 4593 | |||
| 4594 | function admin_notices() { |
||
| 4719 | |||
| 4720 | /** |
||
| 4721 | * We can't always respond to a signed XML-RPC request with a |
||
| 4722 | * helpful error message. In some circumstances, doing so could |
||
| 4723 | * leak information. |
||
| 4724 | * |
||
| 4725 | * Instead, track that the error occurred via a Jetpack_Option, |
||
| 4726 | * and send that data back in the heartbeat. |
||
| 4727 | * All this does is increment a number, but it's enough to find |
||
| 4728 | * trends. |
||
| 4729 | * |
||
| 4730 | * @param WP_Error $xmlrpc_error The error produced during |
||
| 4731 | * signature validation. |
||
| 4732 | */ |
||
| 4733 | function track_xmlrpc_error( $xmlrpc_error ) { |
||
| 4748 | |||
| 4749 | /** |
||
| 4750 | * Initialize the jetpack stats instance only when needed |
||
| 4751 | * |
||
| 4752 | * @return void |
||
| 4753 | */ |
||
| 4754 | private function initialize_stats() { |
||
| 4759 | |||
| 4760 | /** |
||
| 4761 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 4762 | */ |
||
| 4763 | function stat( $group, $detail ) { |
||
| 4770 | |||
| 4771 | /** |
||
| 4772 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 4773 | */ |
||
| 4774 | function do_stats( $method = '' ) { |
||
| 4785 | |||
| 4786 | /** |
||
| 4787 | * Runs stats code for a one-off, server-side. |
||
| 4788 | * |
||
| 4789 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 4790 | * |
||
| 4791 | * @return bool If it worked. |
||
| 4792 | */ |
||
| 4793 | static function do_server_side_stat( $args ) { |
||
| 4798 | |||
| 4799 | /** |
||
| 4800 | * Builds the stats url. |
||
| 4801 | * |
||
| 4802 | * @param $args array|string The arguments to append to the URL. |
||
| 4803 | * |
||
| 4804 | * @return string The URL to be pinged. |
||
| 4805 | */ |
||
| 4806 | static function build_stats_url( $args ) { |
||
| 4812 | |||
| 4813 | /** |
||
| 4814 | * Builds a URL to the Jetpack connection auth page |
||
| 4815 | * |
||
| 4816 | * @since 3.9.5 |
||
| 4817 | * |
||
| 4818 | * @param bool $raw If true, URL will not be escaped. |
||
| 4819 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 4820 | * If string, will be a custom redirect. |
||
| 4821 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 4822 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
| 4823 | * |
||
| 4824 | * @return string Connect URL |
||
| 4825 | */ |
||
| 4826 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
| 4888 | |||
| 4889 | public static function build_authorize_url( $redirect = false, $iframe = false ) { |
||
| 4917 | |||
| 4918 | /** |
||
| 4919 | * Filters the connection URL parameter array. |
||
| 4920 | * |
||
| 4921 | * @param array $args default URL parameters used by the package. |
||
| 4922 | * @return array the modified URL arguments array. |
||
| 4923 | */ |
||
| 4924 | public static function filter_connect_request_body( $args ) { |
||
| 4954 | |||
| 4955 | /** |
||
| 4956 | * Filters the URL that will process the connection data. It can be different from the URL |
||
| 4957 | * that we send the user to after everything is done. |
||
| 4958 | * |
||
| 4959 | * @param String $processing_url the default redirect URL used by the package. |
||
| 4960 | * @return String the modified URL. |
||
| 4961 | * |
||
| 4962 | * @deprecated since Jetpack 9.5.0 |
||
| 4963 | */ |
||
| 4964 | public static function filter_connect_processing_url( $processing_url ) { |
||
| 4970 | |||
| 4971 | /** |
||
| 4972 | * Filters the redirection URL that is used for connect requests. The redirect |
||
| 4973 | * URL should return the user back to the Jetpack console. |
||
| 4974 | * |
||
| 4975 | * @param String $redirect the default redirect URL used by the package. |
||
| 4976 | * @return String the modified URL. |
||
| 4977 | */ |
||
| 4978 | public static function filter_connect_redirect_url( $redirect ) { |
||
| 4990 | |||
| 4991 | /** |
||
| 4992 | * This action fires at the beginning of the Manager::authorize method. |
||
| 4993 | */ |
||
| 4994 | public static function authorize_starting() { |
||
| 5018 | |||
| 5019 | /** |
||
| 5020 | * This action fires at the end of the Manager::authorize method when a secondary user is |
||
| 5021 | * linked. |
||
| 5022 | */ |
||
| 5023 | public static function authorize_ending_linked() { |
||
| 5027 | |||
| 5028 | /** |
||
| 5029 | * This action fires at the end of the Manager::authorize method when the master user is |
||
| 5030 | * authorized. |
||
| 5031 | * |
||
| 5032 | * @param array $data The request data. |
||
| 5033 | */ |
||
| 5034 | public static function authorize_ending_authorized( $data ) { |
||
| 5054 | |||
| 5055 | /** |
||
| 5056 | * Fires on the jetpack_site_registered hook and acitvates default modules |
||
| 5057 | */ |
||
| 5058 | public static function activate_default_modules_on_site_register() { |
||
| 5073 | |||
| 5074 | /** |
||
| 5075 | * This action fires at the end of the REST_Connector connection_reconnect method when the |
||
| 5076 | * reconnect process is completed. |
||
| 5077 | * Note that this currently only happens when we don't need the user to re-authorize |
||
| 5078 | * their WP.com account, eg in cases where we are restoring a connection with |
||
| 5079 | * unhealthy blog token. |
||
| 5080 | */ |
||
| 5081 | public static function reconnection_completed() { |
||
| 5084 | |||
| 5085 | /** |
||
| 5086 | * Get our assumed site creation date. |
||
| 5087 | * Calculated based on the earlier date of either: |
||
| 5088 | * - Earliest admin user registration date. |
||
| 5089 | * - Earliest date of post of any post type. |
||
| 5090 | * |
||
| 5091 | * @since 7.2.0 |
||
| 5092 | * @deprecated since 7.8.0 |
||
| 5093 | * |
||
| 5094 | * @return string Assumed site creation date and time. |
||
| 5095 | */ |
||
| 5096 | public static function get_assumed_site_creation_date() { |
||
| 5100 | |||
| 5101 | View Code Duplication | public static function apply_activation_source_to_args( &$args ) { |
|
| 5112 | |||
| 5113 | function build_reconnect_url( $raw = false ) { |
||
| 5117 | |||
| 5118 | public static function admin_url( $args = null ) { |
||
| 5123 | |||
| 5124 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 5128 | |||
| 5129 | function dismiss_jetpack_notice() { |
||
| 5146 | |||
| 5147 | public static function sort_modules( $a, $b ) { |
||
| 5154 | |||
| 5155 | function ajax_recheck_ssl() { |
||
| 5165 | |||
| 5166 | /* Client API */ |
||
| 5167 | |||
| 5168 | /** |
||
| 5169 | * Returns the requested Jetpack API URL |
||
| 5170 | * |
||
| 5171 | * @deprecated since 7.7 |
||
| 5172 | * @return string |
||
| 5173 | */ |
||
| 5174 | public static function api_url( $relative_url ) { |
||
| 5179 | |||
| 5180 | /** |
||
| 5181 | * @deprecated 8.0 |
||
| 5182 | * |
||
| 5183 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests. |
||
| 5184 | * But we no longer fix "bad hosts" anyway, outbound HTTPS is required for Jetpack to function. |
||
| 5185 | */ |
||
| 5186 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 5190 | |||
| 5191 | public static function verify_onboarding_token( $token_data, $token, $request_data ) { |
||
| 5236 | |||
| 5237 | /** |
||
| 5238 | * Create a random secret for validating onboarding payload |
||
| 5239 | * |
||
| 5240 | * @return string Secret token |
||
| 5241 | */ |
||
| 5242 | public static function create_onboarding_token() { |
||
| 5250 | |||
| 5251 | /** |
||
| 5252 | * Remove the onboarding token |
||
| 5253 | * |
||
| 5254 | * @return bool True on success, false on failure |
||
| 5255 | */ |
||
| 5256 | public static function invalidate_onboarding_token() { |
||
| 5259 | |||
| 5260 | /** |
||
| 5261 | * Validate an onboarding token for a specific action |
||
| 5262 | * |
||
| 5263 | * @return boolean True if token/action pair is accepted, false if not |
||
| 5264 | */ |
||
| 5265 | public static function validate_onboarding_token_action( $token, $action ) { |
||
| 5283 | |||
| 5284 | /** |
||
| 5285 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 5286 | * |
||
| 5287 | * @since 2.3.3 |
||
| 5288 | * @return boolean |
||
| 5289 | */ |
||
| 5290 | public static function permit_ssl( $force_recheck = false ) { |
||
| 5319 | |||
| 5320 | /* |
||
| 5321 | * Displays an admin_notice, alerting the user that outbound SSL isn't working. |
||
| 5322 | */ |
||
| 5323 | public function alert_auto_ssl_fail() { |
||
| 5377 | |||
| 5378 | /** |
||
| 5379 | * Returns the Jetpack XML-RPC API |
||
| 5380 | * |
||
| 5381 | * @deprecated 8.0 Use Connection_Manager instead. |
||
| 5382 | * @return string |
||
| 5383 | */ |
||
| 5384 | public static function xmlrpc_api_url() { |
||
| 5388 | |||
| 5389 | /** |
||
| 5390 | * Returns the connection manager object. |
||
| 5391 | * |
||
| 5392 | * @return Automattic\Jetpack\Connection\Manager |
||
| 5393 | */ |
||
| 5394 | public static function connection() { |
||
| 5404 | |||
| 5405 | /** |
||
| 5406 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 5407 | * |
||
| 5408 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 5409 | * |
||
| 5410 | * @deprecated 9.5 Use Automattic\Jetpack\Connection\Secrets->generate() instead. |
||
| 5411 | * |
||
| 5412 | * @since 2.6 |
||
| 5413 | * @param String $action The action name. |
||
| 5414 | * @param Integer $user_id The user identifier. |
||
| 5415 | * @param Integer $exp Expiration time in seconds. |
||
| 5416 | * @return array |
||
| 5417 | */ |
||
| 5418 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
| 5422 | |||
| 5423 | public static function get_secrets( $action, $user_id ) { |
||
| 5436 | |||
| 5437 | /** |
||
| 5438 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5439 | * |
||
| 5440 | * Based on local php max_execution_time in php.ini |
||
| 5441 | * |
||
| 5442 | * @since 2.6 |
||
| 5443 | * @return int |
||
| 5444 | * @deprecated |
||
| 5445 | **/ |
||
| 5446 | public function get_remote_query_timeout_limit() { |
||
| 5450 | |||
| 5451 | /** |
||
| 5452 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5453 | * |
||
| 5454 | * Based on local php max_execution_time in php.ini |
||
| 5455 | * |
||
| 5456 | * @since 5.4 |
||
| 5457 | * @return int |
||
| 5458 | **/ |
||
| 5459 | public static function get_max_execution_time() { |
||
| 5468 | |||
| 5469 | /** |
||
| 5470 | * Sets a minimum request timeout, and returns the current timeout |
||
| 5471 | * |
||
| 5472 | * @since 5.4 |
||
| 5473 | **/ |
||
| 5474 | View Code Duplication | public static function set_min_time_limit( $min_timeout ) { |
|
| 5482 | |||
| 5483 | /** |
||
| 5484 | * Takes the response from the Jetpack register new site endpoint and |
||
| 5485 | * verifies it worked properly. |
||
| 5486 | * |
||
| 5487 | * @since 2.6 |
||
| 5488 | * @deprecated since 7.7.0 |
||
| 5489 | * @see Automattic\Jetpack\Connection\Manager::validate_remote_register_response() |
||
| 5490 | **/ |
||
| 5491 | public function validate_remote_register_response() { |
||
| 5494 | |||
| 5495 | /** |
||
| 5496 | * @deprecated since Jetpack 9.7.0 |
||
| 5497 | * @see Automattic\Jetpack\Connection\Manager::try_registration() |
||
| 5498 | * |
||
| 5499 | * @return bool|WP_Error |
||
| 5500 | */ |
||
| 5501 | public static function register() { |
||
| 5502 | _deprecated_function( __METHOD__, 'jetpack-9.7', 'Automattic\\Jetpack\\Connection\\Manager::try_registration' ); |
||
| 5503 | return static::connection()->try_registration( false ); |
||
| 5504 | } |
||
| 5505 | |||
| 5506 | /** |
||
| 5507 | * Filters the registration request body to include tracking properties. |
||
| 5508 | * |
||
| 5509 | * @deprecated since Jetpack 9.7.0 |
||
| 5510 | * @see Automattic\Jetpack\Connection\Utils::filter_register_request_body() |
||
| 5511 | * |
||
| 5512 | * @param array $properties |
||
| 5513 | * @return array amended properties. |
||
| 5514 | */ |
||
| 5515 | public static function filter_register_request_body( $properties ) { |
||
| 5516 | _deprecated_function( __METHOD__, 'jetpack-9.7', 'Automattic\\Jetpack\\Connection\\Utils::filter_register_request_body' ); |
||
| 5517 | return Connection_Utils::filter_register_request_body( $properties ); |
||
| 5518 | } |
||
| 5519 | |||
| 5520 | /** |
||
| 5521 | * Filters the token request body to include tracking properties. |
||
| 5522 | * |
||
| 5523 | * @param array $properties |
||
| 5524 | * @return array amended properties. |
||
| 5525 | */ |
||
| 5526 | View Code Duplication | public static function filter_token_request_body( $properties ) { |
|
| 5538 | |||
| 5539 | /** |
||
| 5540 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 5541 | * |
||
| 5542 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 5543 | */ |
||
| 5544 | public static function maybe_set_version_option() { |
||
| 5558 | |||
| 5559 | /* Client Server API */ |
||
| 5560 | |||
| 5561 | /** |
||
| 5562 | * Loads the Jetpack XML-RPC client. |
||
| 5563 | * No longer necessary, as the XML-RPC client will be automagically loaded. |
||
| 5564 | * |
||
| 5565 | * @deprecated since 7.7.0 |
||
| 5566 | */ |
||
| 5567 | public static function load_xml_rpc_client() { |
||
| 5570 | |||
| 5571 | /** |
||
| 5572 | * Resets the saved authentication state in between testing requests. |
||
| 5573 | * |
||
| 5574 | * @deprecated since 8.9.0 |
||
| 5575 | * @see Automattic\Jetpack\Connection\Rest_Authentication::reset_saved_auth_state() |
||
| 5576 | */ |
||
| 5577 | public function reset_saved_auth_state() { |
||
| 5581 | |||
| 5582 | /** |
||
| 5583 | * Verifies the signature of the current request. |
||
| 5584 | * |
||
| 5585 | * @deprecated since 7.7.0 |
||
| 5586 | * @see Automattic\Jetpack\Connection\Manager::verify_xml_rpc_signature() |
||
| 5587 | * |
||
| 5588 | * @return false|array |
||
| 5589 | */ |
||
| 5590 | public function verify_xml_rpc_signature() { |
||
| 5594 | |||
| 5595 | /** |
||
| 5596 | * Verifies the signature of the current request. |
||
| 5597 | * |
||
| 5598 | * This function has side effects and should not be used. Instead, |
||
| 5599 | * use the memoized version `->verify_xml_rpc_signature()`. |
||
| 5600 | * |
||
| 5601 | * @deprecated since 7.7.0 |
||
| 5602 | * @see Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature() |
||
| 5603 | * @internal |
||
| 5604 | */ |
||
| 5605 | private function internal_verify_xml_rpc_signature() { |
||
| 5608 | |||
| 5609 | /** |
||
| 5610 | * Authenticates XML-RPC and other requests from the Jetpack Server. |
||
| 5611 | * |
||
| 5612 | * @deprecated since 7.7.0 |
||
| 5613 | * @see Automattic\Jetpack\Connection\Manager::authenticate_jetpack() |
||
| 5614 | * |
||
| 5615 | * @param \WP_User|mixed $user User object if authenticated. |
||
| 5616 | * @param string $username Username. |
||
| 5617 | * @param string $password Password string. |
||
| 5618 | * @return \WP_User|mixed Authenticated user or error. |
||
| 5619 | */ |
||
| 5620 | View Code Duplication | public function authenticate_jetpack( $user, $username, $password ) { |
|
| 5629 | |||
| 5630 | /** |
||
| 5631 | * Authenticates requests from Jetpack server to WP REST API endpoints. |
||
| 5632 | * Uses the existing XMLRPC request signing implementation. |
||
| 5633 | * |
||
| 5634 | * @deprecated since 8.9.0 |
||
| 5635 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authenticate() |
||
| 5636 | */ |
||
| 5637 | function wp_rest_authenticate( $user ) { |
||
| 5641 | |||
| 5642 | /** |
||
| 5643 | * Report authentication status to the WP REST API. |
||
| 5644 | * |
||
| 5645 | * @deprecated since 8.9.0 |
||
| 5646 | * @see Automattic\Jetpack\Connection\Rest_Authentication::wp_rest_authentication_errors() |
||
| 5647 | * |
||
| 5648 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
| 5649 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
| 5650 | */ |
||
| 5651 | public function wp_rest_authentication_errors( $value ) { |
||
| 5655 | |||
| 5656 | /** |
||
| 5657 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 5658 | * Capture it here so we can verify the signature later. |
||
| 5659 | * |
||
| 5660 | * @deprecated since 7.7.0 |
||
| 5661 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_methods() |
||
| 5662 | * |
||
| 5663 | * @param array $methods XMLRPC methods. |
||
| 5664 | * @return array XMLRPC methods, with the $HTTP_RAW_POST_DATA one. |
||
| 5665 | */ |
||
| 5666 | View Code Duplication | public function xmlrpc_methods( $methods ) { |
|
| 5675 | |||
| 5676 | /** |
||
| 5677 | * Register additional public XMLRPC methods. |
||
| 5678 | * |
||
| 5679 | * @deprecated since 7.7.0 |
||
| 5680 | * @see Automattic\Jetpack\Connection\Manager::public_xmlrpc_methods() |
||
| 5681 | * |
||
| 5682 | * @param array $methods Public XMLRPC methods. |
||
| 5683 | * @return array Public XMLRPC methods, with the getOptions one. |
||
| 5684 | */ |
||
| 5685 | View Code Duplication | public function public_xmlrpc_methods( $methods ) { |
|
| 5694 | |||
| 5695 | /** |
||
| 5696 | * Handles a getOptions XMLRPC method call. |
||
| 5697 | * |
||
| 5698 | * @deprecated since 7.7.0 |
||
| 5699 | * @see Automattic\Jetpack\Connection\Manager::jetpack_getOptions() |
||
| 5700 | * |
||
| 5701 | * @param array $args method call arguments. |
||
| 5702 | * @return array an amended XMLRPC server options array. |
||
| 5703 | */ |
||
| 5704 | View Code Duplication | public function jetpack_getOptions( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 5713 | |||
| 5714 | /** |
||
| 5715 | * Adds Jetpack-specific options to the output of the XMLRPC options method. |
||
| 5716 | * |
||
| 5717 | * @deprecated since 7.7.0 |
||
| 5718 | * @see Automattic\Jetpack\Connection\Manager::xmlrpc_options() |
||
| 5719 | * |
||
| 5720 | * @param array $options Standard Core options. |
||
| 5721 | * @return array Amended options. |
||
| 5722 | */ |
||
| 5723 | View Code Duplication | public function xmlrpc_options( $options ) { |
|
| 5732 | |||
| 5733 | /** |
||
| 5734 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 5735 | * SET: state( $key, $value ); |
||
| 5736 | * GET: $value = state( $key ); |
||
| 5737 | * |
||
| 5738 | * @param string $key |
||
| 5739 | * @param string $value |
||
| 5740 | * @param bool $restate private |
||
| 5741 | */ |
||
| 5742 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 5798 | |||
| 5799 | public static function restate() { |
||
| 5802 | |||
| 5803 | /** |
||
| 5804 | * Determines whether the jetpackState[$key] value should be added to the |
||
| 5805 | * cookie. |
||
| 5806 | * |
||
| 5807 | * @param string $key The state key. |
||
| 5808 | * |
||
| 5809 | * @return boolean Whether the value should be added to the cookie. |
||
| 5810 | */ |
||
| 5811 | public static function should_set_cookie( $key ) { |
||
| 5821 | |||
| 5822 | public static function check_privacy( $file ) { |
||
| 5856 | |||
| 5857 | /** |
||
| 5858 | * Helper method for multicall XMLRPC. |
||
| 5859 | * |
||
| 5860 | * @deprecated since 8.9.0 |
||
| 5861 | * @see Automattic\\Jetpack\\Connection\\Xmlrpc_Async_Call::add_call() |
||
| 5862 | * |
||
| 5863 | * @param ...$args Args for the async_call. |
||
| 5864 | */ |
||
| 5865 | public static function xmlrpc_async_call( ...$args ) { |
||
| 5907 | |||
| 5908 | /** |
||
| 5909 | * Serve a WordPress.com static resource via a randomized wp.com subdomain. |
||
| 5910 | * |
||
| 5911 | * @deprecated 9.3.0 Use Assets::staticize_subdomain. |
||
| 5912 | * |
||
| 5913 | * @param string $url WordPress.com static resource URL. |
||
| 5914 | */ |
||
| 5915 | public static function staticize_subdomain( $url ) { |
||
| 5919 | |||
| 5920 | /* JSON API Authorization */ |
||
| 5921 | |||
| 5922 | /** |
||
| 5923 | * Handles the login action for Authorizing the JSON API |
||
| 5924 | */ |
||
| 5925 | function login_form_json_api_authorization() { |
||
| 5934 | |||
| 5935 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 5936 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 5950 | |||
| 5951 | // Make sure the POSTed request is handled by the same action |
||
| 5952 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 5956 | |||
| 5957 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 5958 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 5964 | |||
| 5965 | // Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. |
||
| 5966 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 5970 | |||
| 5971 | static function is_redirect_encoded( $redirect_url ) { |
||
| 5974 | |||
| 5975 | // Add all wordpress.com environments to the safe redirect allowed list. |
||
| 5976 | function allow_wpcom_environments( $domains ) { |
||
| 5983 | |||
| 5984 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 5985 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 5997 | |||
| 5998 | /** |
||
| 5999 | * Verifies the request by checking the signature |
||
| 6000 | * |
||
| 6001 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
| 6002 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
| 6003 | * |
||
| 6004 | * @param null|array $environment |
||
| 6005 | */ |
||
| 6006 | function verify_json_api_authorization_request( $environment = null ) { |
||
| 6128 | |||
| 6129 | function login_message_json_api_authorization( $message ) { |
||
| 6135 | |||
| 6136 | /** |
||
| 6137 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 6138 | */ |
||
| 6139 | public static function get_content_width() { |
||
| 6152 | |||
| 6153 | /** |
||
| 6154 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 6155 | * |
||
| 6156 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 6157 | * |
||
| 6158 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 6159 | */ |
||
| 6160 | public function get_cloud_site_options( $option_names ) { |
||
| 6175 | |||
| 6176 | /** |
||
| 6177 | * Checks if the site is currently in an identity crisis. |
||
| 6178 | * |
||
| 6179 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
| 6180 | */ |
||
| 6181 | public static function check_identity_crisis() { |
||
| 6188 | |||
| 6189 | /** |
||
| 6190 | * Checks whether the home and siteurl specifically are allowed. |
||
| 6191 | * Written so that we don't have re-check $key and $value params every time |
||
| 6192 | * we want to check if this site is allowed, for example in footer.php |
||
| 6193 | * |
||
| 6194 | * @since 3.8.0 |
||
| 6195 | * @return bool True = already allowed False = not on the allowed list. |
||
| 6196 | */ |
||
| 6197 | public static function is_staging_site() { |
||
| 6201 | |||
| 6202 | /** |
||
| 6203 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
| 6204 | * |
||
| 6205 | * @since 4.4.0 |
||
| 6206 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
| 6207 | * |
||
| 6208 | * @return bool |
||
| 6209 | */ |
||
| 6210 | public static function validate_sync_error_idc_option() { |
||
| 6252 | |||
| 6253 | /** |
||
| 6254 | * Normalizes a url by doing three things: |
||
| 6255 | * - Strips protocol |
||
| 6256 | * - Strips www |
||
| 6257 | * - Adds a trailing slash |
||
| 6258 | * |
||
| 6259 | * @since 4.4.0 |
||
| 6260 | * @param string $url |
||
| 6261 | * @return WP_Error|string |
||
| 6262 | */ |
||
| 6263 | public static function normalize_url_protocol_agnostic( $url ) { |
||
| 6273 | |||
| 6274 | /** |
||
| 6275 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
| 6276 | * |
||
| 6277 | * @since 4.4.0 |
||
| 6278 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
| 6279 | * |
||
| 6280 | * @param array $response |
||
| 6281 | * @return array Array of the local urls, wpcom urls, and error code |
||
| 6282 | */ |
||
| 6283 | public static function get_sync_error_idc_option( $response = array() ) { |
||
| 6315 | |||
| 6316 | /** |
||
| 6317 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
| 6318 | * If set to true, the site will be put into staging mode. |
||
| 6319 | * |
||
| 6320 | * @since 4.3.2 |
||
| 6321 | * @return bool |
||
| 6322 | */ |
||
| 6323 | public static function sync_idc_optin() { |
||
| 6341 | |||
| 6342 | /** |
||
| 6343 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 6344 | * |
||
| 6345 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 6346 | */ |
||
| 6347 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 6389 | |||
| 6390 | /** |
||
| 6391 | * If the asset is minified, let's flag .min as the suffix. |
||
| 6392 | * |
||
| 6393 | * Attached to `style_loader_src` filter. |
||
| 6394 | * |
||
| 6395 | * @param string $tag The tag that would link to the external asset. |
||
| 6396 | * @param string $handle The registered handle of the script in question. |
||
| 6397 | * @param string $href The url of the asset in question. |
||
| 6398 | */ |
||
| 6399 | public static function set_suffix_on_min( $src, $handle ) { |
||
| 6415 | |||
| 6416 | /** |
||
| 6417 | * Maybe inlines a stylesheet. |
||
| 6418 | * |
||
| 6419 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 6420 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 6421 | * |
||
| 6422 | * Attached to `style_loader_tag` filter. |
||
| 6423 | * |
||
| 6424 | * @param string $tag The tag that would link to the external asset. |
||
| 6425 | * @param string $handle The registered handle of the script in question. |
||
| 6426 | * |
||
| 6427 | * @return string |
||
| 6428 | */ |
||
| 6429 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 6479 | |||
| 6480 | /** |
||
| 6481 | * Loads a view file from the views |
||
| 6482 | * |
||
| 6483 | * Data passed in with the $data parameter will be available in the |
||
| 6484 | * template file as $data['value'] |
||
| 6485 | * |
||
| 6486 | * @param string $template - Template file to load |
||
| 6487 | * @param array $data - Any data to pass along to the template |
||
| 6488 | * @return boolean - If template file was found |
||
| 6489 | **/ |
||
| 6490 | public function load_view( $template, $data = array() ) { |
||
| 6501 | |||
| 6502 | /** |
||
| 6503 | * Throws warnings for deprecated hooks to be removed from Jetpack that cannot remain in the original place in the code. |
||
| 6504 | */ |
||
| 6505 | public function deprecated_hooks() { |
||
| 6762 | |||
| 6763 | /** |
||
| 6764 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 6765 | * |
||
| 6766 | * Considerations: |
||
| 6767 | * - Normal, relative URLs `feh.png` |
||
| 6768 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 6769 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 6770 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 6771 | * - Domain root relative URLs `/feh.png` |
||
| 6772 | * |
||
| 6773 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 6774 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 6775 | * |
||
| 6776 | * @return mixed|string |
||
| 6777 | */ |
||
| 6778 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 6822 | |||
| 6823 | /** |
||
| 6824 | * This methods removes all of the registered css files on the front end |
||
| 6825 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 6826 | * all the files into one file. |
||
| 6827 | * |
||
| 6828 | * Pros: |
||
| 6829 | * - Uses only ONE css asset connection instead of 15 |
||
| 6830 | * - Saves a minimum of 56k |
||
| 6831 | * - Reduces server load |
||
| 6832 | * - Reduces time to first painted byte |
||
| 6833 | * |
||
| 6834 | * Cons: |
||
| 6835 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 6836 | * should not cause any issues with themes. |
||
| 6837 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 6838 | * jetpack_implode_frontend_css filter for a workaround |
||
| 6839 | * |
||
| 6840 | * For some situations developers may wish to disable css imploding and |
||
| 6841 | * instead operate in legacy mode where each file loads seperately and |
||
| 6842 | * can be edited individually or dequeued. This can be accomplished with |
||
| 6843 | * the following line: |
||
| 6844 | * |
||
| 6845 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 6846 | * |
||
| 6847 | * @since 3.2 |
||
| 6848 | **/ |
||
| 6849 | public function implode_frontend_css( $travis_test = false ) { |
||
| 6906 | |||
| 6907 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 6917 | |||
| 6918 | /** |
||
| 6919 | * @deprecated |
||
| 6920 | * @see Automattic\Jetpack\Assets\add_aync_script |
||
| 6921 | */ |
||
| 6922 | public function script_add_async( $tag, $handle, $src ) { |
||
| 6925 | |||
| 6926 | /* |
||
| 6927 | * Check the heartbeat data |
||
| 6928 | * |
||
| 6929 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 6930 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 6931 | * |
||
| 6932 | * Data will be added to "caution" array, if it either: |
||
| 6933 | * - Out of date Jetpack version |
||
| 6934 | * - Out of date WP version |
||
| 6935 | * - Out of date PHP version |
||
| 6936 | * |
||
| 6937 | * $return array $filtered_data |
||
| 6938 | */ |
||
| 6939 | public static function jetpack_check_heartbeat_data() { |
||
| 6992 | |||
| 6993 | /* |
||
| 6994 | * This method is used to organize all options that can be reset |
||
| 6995 | * without disconnecting Jetpack. |
||
| 6996 | * |
||
| 6997 | * It is used in class.jetpack-cli.php to reset options |
||
| 6998 | * |
||
| 6999 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
| 7000 | * |
||
| 7001 | * @return array of options to delete. |
||
| 7002 | */ |
||
| 7003 | public static function get_jetpack_options_for_reset() { |
||
| 7006 | |||
| 7007 | /* |
||
| 7008 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 7009 | * so we can bring them directly to their site in calypso. |
||
| 7010 | * |
||
| 7011 | * @deprecated 9.2.0 Use Automattic\Jetpack\Status::get_site_suffix |
||
| 7012 | * |
||
| 7013 | * @param string | url |
||
| 7014 | * @return string | url without the guff |
||
| 7015 | */ |
||
| 7016 | public static function build_raw_urls( $url ) { |
||
| 7021 | |||
| 7022 | /** |
||
| 7023 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 7024 | * |
||
| 7025 | * @deprecated 8.8.0 Use Jetpack::add_resource_hints. |
||
| 7026 | * |
||
| 7027 | * @param string|array $urls URLs to hint. |
||
| 7028 | */ |
||
| 7029 | public static function dns_prefetch( $urls = null ) { |
||
| 7035 | |||
| 7036 | public function wp_dashboard_setup() { |
||
| 7074 | |||
| 7075 | /** |
||
| 7076 | * @param mixed $result Value for the user's option |
||
| 7077 | * @return mixed |
||
| 7078 | */ |
||
| 7079 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 7104 | |||
| 7105 | public static function dashboard_widget() { |
||
| 7113 | |||
| 7114 | public static function dashboard_widget_footer() { |
||
| 7182 | |||
| 7183 | /* |
||
| 7184 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 7185 | */ |
||
| 7186 | function jetpack_icon_user_connected( $columns ) { |
||
| 7190 | |||
| 7191 | /* |
||
| 7192 | * Show Jetpack icon if the user is linked. |
||
| 7193 | */ |
||
| 7194 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 7207 | |||
| 7208 | /* |
||
| 7209 | * Style the Jetpack user column |
||
| 7210 | */ |
||
| 7211 | function jetpack_user_col_style() { |
||
| 7230 | |||
| 7231 | /** |
||
| 7232 | * Checks if Akismet is active and working. |
||
| 7233 | * |
||
| 7234 | * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key |
||
| 7235 | * that implied usage of methods present since more recent version. |
||
| 7236 | * See https://github.com/Automattic/jetpack/pull/9585 |
||
| 7237 | * |
||
| 7238 | * @since 5.1.0 |
||
| 7239 | * |
||
| 7240 | * @return bool True = Akismet available. False = Aksimet not available. |
||
| 7241 | */ |
||
| 7242 | public static function is_akismet_active() { |
||
| 7277 | |||
| 7278 | /** |
||
| 7279 | * @deprecated |
||
| 7280 | * |
||
| 7281 | * @see Automattic\Jetpack\Sync\Modules\Users::is_function_in_backtrace |
||
| 7282 | */ |
||
| 7283 | public static function is_function_in_backtrace() { |
||
| 7286 | |||
| 7287 | /** |
||
| 7288 | * Given a minified path, and a non-minified path, will return |
||
| 7289 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
| 7290 | * |
||
| 7291 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
| 7292 | * root Jetpack directory. |
||
| 7293 | * |
||
| 7294 | * @since 5.6.0 |
||
| 7295 | * |
||
| 7296 | * @param string $min_path |
||
| 7297 | * @param string $non_min_path |
||
| 7298 | * @return string The URL to the file |
||
| 7299 | */ |
||
| 7300 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
| 7303 | |||
| 7304 | /** |
||
| 7305 | * Checks for whether Jetpack Backup is enabled. |
||
| 7306 | * Will return true if the state of Backup is anything except "unavailable". |
||
| 7307 | * |
||
| 7308 | * @return bool|int|mixed |
||
| 7309 | */ |
||
| 7310 | public static function is_rewind_enabled() { |
||
| 7330 | |||
| 7331 | /** |
||
| 7332 | * Return Calypso environment value; used for developing Jetpack and pairing |
||
| 7333 | * it with different Calypso enrionments, such as localhost. |
||
| 7334 | * |
||
| 7335 | * @since 7.4.0 |
||
| 7336 | * |
||
| 7337 | * @return string Calypso environment |
||
| 7338 | */ |
||
| 7339 | public static function get_calypso_env() { |
||
| 7354 | |||
| 7355 | /** |
||
| 7356 | * Returns the hostname with protocol for Calypso. |
||
| 7357 | * Used for developing Jetpack with Calypso. |
||
| 7358 | * |
||
| 7359 | * @since 8.4.0 |
||
| 7360 | * |
||
| 7361 | * @return string Calypso host. |
||
| 7362 | */ |
||
| 7363 | public static function get_calypso_host() { |
||
| 7376 | |||
| 7377 | /** |
||
| 7378 | * Handles activating default modules as well general cleanup for the new connection. |
||
| 7379 | * |
||
| 7380 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
| 7381 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
| 7382 | * @param boolean $send_state_messages Whether to send state messages. |
||
| 7383 | * @return void |
||
| 7384 | */ |
||
| 7385 | public static function handle_post_authorization_actions( |
||
| 7413 | |||
| 7414 | /** |
||
| 7415 | * Returns a boolean for whether backups UI should be displayed or not. |
||
| 7416 | * |
||
| 7417 | * @return bool Should backups UI be displayed? |
||
| 7418 | */ |
||
| 7419 | public static function show_backups_ui() { |
||
| 7429 | |||
| 7430 | /* |
||
| 7431 | * Deprecated manage functions |
||
| 7432 | */ |
||
| 7433 | function prepare_manage_jetpack_notice() { |
||
| 7454 | |||
| 7455 | /** |
||
| 7456 | * Clean leftoveruser meta. |
||
| 7457 | * |
||
| 7458 | * Delete Jetpack-related user meta when it is no longer needed. |
||
| 7459 | * |
||
| 7460 | * @since 7.3.0 |
||
| 7461 | * |
||
| 7462 | * @param int $user_id User ID being updated. |
||
| 7463 | */ |
||
| 7464 | public static function user_meta_cleanup( $user_id ) { |
||
| 7479 | |||
| 7480 | /** |
||
| 7481 | * Checks if a Jetpack site is both active and not in offline mode. |
||
| 7482 | * |
||
| 7483 | * This is a DRY function to avoid repeating `Jetpack::is_active && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
| 7484 | * |
||
| 7485 | * @deprecated 8.8.0 |
||
| 7486 | * |
||
| 7487 | * @return bool True if Jetpack is active and not in offline mode. |
||
| 7488 | */ |
||
| 7489 | public static function is_active_and_not_development_mode() { |
||
| 7496 | |||
| 7497 | /** |
||
| 7498 | * Checks if a Jetpack site is both active and not in offline mode. |
||
| 7499 | * |
||
| 7500 | * This is a DRY function to avoid repeating `Jetpack::is_connection_ready && ! Automattic\Jetpack\Status->is_offline_mode`. |
||
| 7501 | * |
||
| 7502 | * @since 8.8.0 |
||
| 7503 | * |
||
| 7504 | * @return bool True if Jetpack is active and not in offline mode. |
||
| 7505 | */ |
||
| 7506 | public static function is_active_and_not_offline_mode() { |
||
| 7512 | |||
| 7513 | /** |
||
| 7514 | * Returns the list of products that we have available for purchase. |
||
| 7515 | */ |
||
| 7516 | public static function get_products_for_purchase() { |
||
| 7610 | } |
||
| 7611 |
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.