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 |
||
| 25 | class Jetpack { |
||
| 26 | public $xmlrpc_server = null; |
||
| 27 | |||
| 28 | private $xmlrpc_verification = null; |
||
| 29 | |||
| 30 | public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA'] |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array The handles of styles that are concatenated into jetpack.css |
||
| 34 | */ |
||
| 35 | public $concatenated_style_handles = array( |
||
| 36 | 'jetpack-carousel', |
||
| 37 | 'grunion.css', |
||
| 38 | 'the-neverending-homepage', |
||
| 39 | 'jetpack_likes', |
||
| 40 | 'jetpack_related-posts', |
||
| 41 | 'sharedaddy', |
||
| 42 | 'jetpack-slideshow', |
||
| 43 | 'presentations', |
||
| 44 | 'jetpack-subscriptions', |
||
| 45 | 'jetpack-responsive-videos-style', |
||
| 46 | 'jetpack-social-menu', |
||
| 47 | 'tiled-gallery', |
||
| 48 | 'jetpack_display_posts_widget', |
||
| 49 | 'gravatar-profile-widget', |
||
| 50 | 'goodreads-widget', |
||
| 51 | 'jetpack_social_media_icons_widget', |
||
| 52 | 'jetpack-top-posts-widget', |
||
| 53 | 'jetpack_image_widget', |
||
| 54 | ); |
||
| 55 | |||
| 56 | public $plugins_to_deactivate = array( |
||
| 57 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 58 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 59 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 60 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 61 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
| 62 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 63 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 64 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 65 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 66 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 67 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 68 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 69 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 70 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
| 71 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 72 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
| 73 | ); |
||
| 74 | |||
| 75 | static $capability_translations = array( |
||
|
|
|||
| 76 | 'administrator' => 'manage_options', |
||
| 77 | 'editor' => 'edit_others_posts', |
||
| 78 | 'author' => 'publish_posts', |
||
| 79 | 'contributor' => 'edit_posts', |
||
| 80 | 'subscriber' => 'read', |
||
| 81 | ); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 85 | * if the plugins are active. Used by filter_default_modules |
||
| 86 | * |
||
| 87 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 88 | * change `module-slug` and add this to your plugin: |
||
| 89 | * |
||
| 90 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 91 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 92 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 93 | * } |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | private $conflicting_plugins = array( |
||
| 98 | 'comments' => array( |
||
| 99 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 100 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 101 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 102 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 103 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 104 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 105 | ), |
||
| 106 | 'contact-form' => array( |
||
| 107 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 108 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 109 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 110 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 111 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 112 | ), |
||
| 113 | 'minileven' => array( |
||
| 114 | 'WPtouch' => 'wptouch/wptouch.php', |
||
| 115 | ), |
||
| 116 | 'latex' => array( |
||
| 117 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 118 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 119 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 120 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 121 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 122 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 123 | ), |
||
| 124 | 'protect' => array( |
||
| 125 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 126 | 'Captcha' => 'captcha/captcha.php', |
||
| 127 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 128 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 129 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 130 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 131 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 132 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 133 | 'Login Security' => 'login-security/login-security.php', |
||
| 134 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 135 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 136 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 137 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 138 | ), |
||
| 139 | 'random-redirect' => array( |
||
| 140 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 141 | ), |
||
| 142 | 'related-posts' => array( |
||
| 143 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 144 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 145 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 146 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 147 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 148 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 149 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 150 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 151 | ), |
||
| 152 | 'sharedaddy' => array( |
||
| 153 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 154 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 155 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 156 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 157 | ), |
||
| 158 | 'verification-tools' => array( |
||
| 159 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 160 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 161 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 162 | ), |
||
| 163 | 'widget-visibility' => array( |
||
| 164 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 165 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 166 | ), |
||
| 167 | 'sitemaps' => array( |
||
| 168 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 169 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 170 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 171 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 172 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 173 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 174 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 175 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 176 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 177 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 178 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 179 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 180 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 181 | ), |
||
| 182 | ); |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 186 | * |
||
| 187 | * Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate |
||
| 188 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 189 | * |
||
| 190 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 191 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 192 | */ |
||
| 193 | private $open_graph_conflicting_plugins = array( |
||
| 194 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 195 | // 2 Click Social Media Buttons |
||
| 196 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 197 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 198 | 'autodescription/autodescription.php', // The SEO Framework |
||
| 199 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 200 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
| 201 | // Open Graph Meta Tags by Heateor |
||
| 202 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 203 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 204 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 205 | // Facebook Featured Image & OG Meta Tags |
||
| 206 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 207 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 208 | // Facebook Open Graph Meta Tags for WordPress |
||
| 209 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 210 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 211 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 212 | // Fedmich's Facebook Open Graph Meta |
||
| 213 | 'header-footer/plugin.php', // Header and Footer |
||
| 214 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 215 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 216 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 217 | // NextScripts SNAP |
||
| 218 | 'og-tags/og-tags.php', // OG Tags |
||
| 219 | 'opengraph/opengraph.php', // Open Graph |
||
| 220 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 221 | // Open Graph Protocol Framework |
||
| 222 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 223 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 224 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 225 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 226 | 'sharepress/sharepress.php', // SharePress |
||
| 227 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 228 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 229 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 230 | 'socialize/socialize.php', // Socialize |
||
| 231 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 232 | // Tweet, Like, Google +1 and Share |
||
| 233 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 234 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 235 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 236 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 237 | // WP Facebook Like Send & Open Graph Meta |
||
| 238 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 239 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 240 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 241 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
| 242 | ); |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 246 | */ |
||
| 247 | private $twitter_cards_conflicting_plugins = array( |
||
| 248 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 249 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 250 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 251 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 252 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 253 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 254 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 255 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 256 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 257 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 258 | ); |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Message to display in admin_notice |
||
| 262 | * @var string |
||
| 263 | */ |
||
| 264 | public $message = ''; |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Error to display in admin_notice |
||
| 268 | * @var string |
||
| 269 | */ |
||
| 270 | public $error = ''; |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Modules that need more privacy description. |
||
| 274 | * @var string |
||
| 275 | */ |
||
| 276 | public $privacy_checks = ''; |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Stats to record once the page loads |
||
| 280 | * |
||
| 281 | * @var array |
||
| 282 | */ |
||
| 283 | public $stats = array(); |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Jetpack_Sync object |
||
| 287 | */ |
||
| 288 | public $sync; |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Verified data for JSON authorization request |
||
| 292 | */ |
||
| 293 | public $json_api_authorization_request = array(); |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Holds the singleton instance of this class |
||
| 297 | * @since 2.3.3 |
||
| 298 | * @var Jetpack |
||
| 299 | */ |
||
| 300 | static $instance = false; |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Singleton |
||
| 304 | * @static |
||
| 305 | */ |
||
| 306 | public static function init() { |
||
| 307 | if ( ! self::$instance ) { |
||
| 308 | self::$instance = new Jetpack; |
||
| 309 | |||
| 310 | self::$instance->plugin_upgrade(); |
||
| 311 | } |
||
| 312 | |||
| 313 | return self::$instance; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Must never be called statically |
||
| 318 | */ |
||
| 319 | function plugin_upgrade() { |
||
| 320 | if ( Jetpack::is_active() ) { |
||
| 321 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 322 | if ( JETPACK__VERSION != $version ) { |
||
| 323 | |||
| 324 | // Check which active modules actually exist and remove others from active_modules list |
||
| 325 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
| 326 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
| 327 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
| 328 | Jetpack::update_active_modules( $modules ); |
||
| 329 | } |
||
| 330 | |||
| 331 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
| 332 | |||
| 333 | // Upgrade to 4.3.0 |
||
| 334 | if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) { |
||
| 335 | Jetpack_Options::delete_option( 'identity_crisis_whitelist' ); |
||
| 336 | } |
||
| 337 | |||
| 338 | Jetpack::maybe_set_version_option(); |
||
| 339 | } |
||
| 340 | } |
||
| 341 | } |
||
| 342 | |||
| 343 | static function activate_manage( ) { |
||
| 344 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
| 345 | self::activate_module( 'manage', false, false ); |
||
| 346 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
| 347 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
| 348 | } |
||
| 349 | } |
||
| 350 | |||
| 351 | static function update_active_modules( $modules ) { |
||
| 352 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
| 353 | |||
| 354 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $modules ) ); |
||
| 355 | |||
| 356 | if ( is_array( $modules ) && is_array( $current_modules ) ) { |
||
| 357 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
| 358 | foreach( $new_active_modules as $module ) { |
||
| 359 | /** |
||
| 360 | * Fires when a specific module is activated. |
||
| 361 | * |
||
| 362 | * @since 1.9.0 |
||
| 363 | * |
||
| 364 | * @param string $module Module slug. |
||
| 365 | * @param boolean $success whether the module was activated. @since 4.2 |
||
| 366 | */ |
||
| 367 | do_action( 'jetpack_activate_module', $module, $success ); |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Fires when a module is activated. |
||
| 371 | * The dynamic part of the filter, $module, is the module slug. |
||
| 372 | * |
||
| 373 | * @since 1.9.0 |
||
| 374 | * |
||
| 375 | * @param string $module Module slug. |
||
| 376 | */ |
||
| 377 | do_action( "jetpack_activate_module_$module", $module ); |
||
| 378 | } |
||
| 379 | |||
| 380 | $new_deactive_modules = array_diff( $current_modules, $modules ); |
||
| 381 | foreach( $new_deactive_modules as $module ) { |
||
| 382 | /** |
||
| 383 | * Fired after a module has been deactivated. |
||
| 384 | * |
||
| 385 | * @since 4.2.0 |
||
| 386 | * |
||
| 387 | * @param string $module Module slug. |
||
| 388 | * @param boolean $success whether the module was deactivated. |
||
| 389 | */ |
||
| 390 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
| 391 | /** |
||
| 392 | * Fires when a module is deactivated. |
||
| 393 | * The dynamic part of the filter, $module, is the module slug. |
||
| 394 | * |
||
| 395 | * @since 1.9.0 |
||
| 396 | * |
||
| 397 | * @param string $module Module slug. |
||
| 398 | */ |
||
| 399 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
| 400 | } |
||
| 401 | } |
||
| 402 | |||
| 403 | return $success; |
||
| 404 | } |
||
| 405 | |||
| 406 | static function delete_active_modules() { |
||
| 407 | self::update_active_modules( array() ); |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Constructor. Initializes WordPress hooks |
||
| 412 | */ |
||
| 413 | private function __construct() { |
||
| 414 | /* |
||
| 415 | * Check for and alert any deprecated hooks |
||
| 416 | */ |
||
| 417 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 418 | |||
| 419 | |||
| 420 | /* |
||
| 421 | * Load things that should only be in Network Admin. |
||
| 422 | * |
||
| 423 | * For now blow away everything else until a more full |
||
| 424 | * understanding of what is needed at the network level is |
||
| 425 | * available |
||
| 426 | */ |
||
| 427 | if( is_multisite() ) { |
||
| 428 | Jetpack_Network::init(); |
||
| 429 | } |
||
| 430 | |||
| 431 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
| 432 | |||
| 433 | // Unlink user before deleting the user from .com |
||
| 434 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 435 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 436 | |||
| 437 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
| 438 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
| 439 | |||
| 440 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
| 441 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
| 442 | |||
| 443 | $this->require_jetpack_authentication(); |
||
| 444 | |||
| 445 | if ( Jetpack::is_active() ) { |
||
| 446 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
| 447 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
| 448 | |||
| 449 | $signed = $this->verify_xml_rpc_signature(); |
||
| 450 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
| 451 | // The actual API methods. |
||
| 452 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
| 453 | } else { |
||
| 454 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
| 455 | // active Jetpack connection, so that additional users can link their account. |
||
| 456 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
| 457 | } |
||
| 458 | } else { |
||
| 459 | // The bootstrap API methods. |
||
| 460 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
| 461 | } |
||
| 462 | |||
| 463 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
| 464 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
| 465 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
| 466 | $this->require_jetpack_authentication(); |
||
| 467 | $this->add_remote_request_handlers(); |
||
| 468 | } else { |
||
| 469 | if ( Jetpack::is_active() ) { |
||
| 470 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
| 471 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | if ( Jetpack::is_active() ) { |
||
| 476 | Jetpack_Heartbeat::init(); |
||
| 477 | } |
||
| 478 | |||
| 479 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
| 480 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
| 481 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
| 482 | } |
||
| 483 | |||
| 484 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
| 485 | |||
| 486 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 487 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 488 | |||
| 489 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
| 490 | |||
| 491 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 492 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 493 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 494 | |||
| 495 | // returns HTTPS support status |
||
| 496 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
| 497 | |||
| 498 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
| 499 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
| 500 | |||
| 501 | // JITM AJAX callback function |
||
| 502 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
| 503 | |||
| 504 | // Universal ajax callback for all tracking events triggered via js |
||
| 505 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
| 506 | |||
| 507 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 508 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 509 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 510 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 511 | |||
| 512 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
| 513 | |||
| 514 | /** |
||
| 515 | * These actions run checks to load additional files. |
||
| 516 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 517 | */ |
||
| 518 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 519 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 520 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 521 | |||
| 522 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 523 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 524 | |||
| 525 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
| 526 | |||
| 527 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 528 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 529 | |||
| 530 | // A filter to control all just in time messages |
||
| 531 | add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); |
||
| 532 | |||
| 533 | /** |
||
| 534 | * This is the hack to concatinate all css files into one. |
||
| 535 | * For description and reasoning see the implode_frontend_css method |
||
| 536 | * |
||
| 537 | * Super late priority so we catch all the registered styles |
||
| 538 | */ |
||
| 539 | if( !is_admin() ) { |
||
| 540 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 541 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 542 | } |
||
| 543 | |||
| 544 | } |
||
| 545 | |||
| 546 | function jetpack_admin_ajax_tracks_callback() { |
||
| 547 | // Check for nonce |
||
| 548 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
| 549 | wp_die( 'Permissions check failed.' ); |
||
| 550 | } |
||
| 551 | |||
| 552 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
| 553 | wp_die( 'No valid event name or type.' ); |
||
| 554 | } |
||
| 555 | |||
| 556 | $tracks_data = array(); |
||
| 557 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
| 558 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
| 559 | } |
||
| 560 | |||
| 561 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
| 562 | wp_send_json_success(); |
||
| 563 | wp_die(); |
||
| 564 | } |
||
| 565 | |||
| 566 | /** |
||
| 567 | * The callback for the JITM ajax requests. |
||
| 568 | */ |
||
| 569 | function jetpack_jitm_ajax_callback() { |
||
| 570 | // Check for nonce |
||
| 571 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
| 572 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
| 573 | } |
||
| 574 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
| 575 | $module_slug = $_REQUEST['jitmModule']; |
||
| 576 | Jetpack::log( 'activate', $module_slug ); |
||
| 577 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 578 | Jetpack::state( 'message', 'no_message' ); |
||
| 579 | |||
| 580 | //A Jetpack module is being activated through a JITM, track it |
||
| 581 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
| 582 | $this->do_stats( 'server_side' ); |
||
| 583 | |||
| 584 | wp_send_json_success(); |
||
| 585 | } |
||
| 586 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
| 587 | // get the hide_jitm options array |
||
| 588 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
| 589 | $module_slug = $_REQUEST['jitmModule']; |
||
| 590 | |||
| 591 | if( ! $jetpack_hide_jitm ) { |
||
| 592 | $jetpack_hide_jitm = array( |
||
| 593 | $module_slug => 'hide' |
||
| 594 | ); |
||
| 595 | } else { |
||
| 596 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
| 597 | } |
||
| 598 | |||
| 599 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
| 600 | |||
| 601 | //jitm is being dismissed forever, track it |
||
| 602 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
| 603 | $this->do_stats( 'server_side' ); |
||
| 604 | |||
| 605 | wp_send_json_success(); |
||
| 606 | } |
||
| 607 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
| 608 | $module_slug = $_REQUEST['jitmModule']; |
||
| 609 | |||
| 610 | // User went to WordPress.com, track this |
||
| 611 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
| 612 | $this->do_stats( 'server_side' ); |
||
| 613 | |||
| 614 | wp_send_json_success(); |
||
| 615 | } |
||
| 616 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
| 617 | $track = $_REQUEST['jitmModule']; |
||
| 618 | |||
| 619 | // User is viewing JITM, track it. |
||
| 620 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
| 621 | $this->do_stats( 'server_side' ); |
||
| 622 | |||
| 623 | wp_send_json_success(); |
||
| 624 | } |
||
| 625 | } |
||
| 626 | |||
| 627 | /** |
||
| 628 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 629 | */ |
||
| 630 | function __destruct() { |
||
| 631 | if ( ! empty( $this->stats ) ) { |
||
| 632 | $this->do_stats( 'server_side' ); |
||
| 633 | } |
||
| 634 | } |
||
| 635 | |||
| 636 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 637 | switch( $cap ) { |
||
| 638 | case 'jetpack_connect' : |
||
| 639 | case 'jetpack_reconnect' : |
||
| 640 | if ( Jetpack::is_development_mode() ) { |
||
| 641 | $caps = array( 'do_not_allow' ); |
||
| 642 | break; |
||
| 643 | } |
||
| 644 | /** |
||
| 645 | * Pass through. If it's not development mode, these should match disconnect. |
||
| 646 | * Let users disconnect if it's development mode, just in case things glitch. |
||
| 647 | */ |
||
| 648 | case 'jetpack_disconnect' : |
||
| 649 | /** |
||
| 650 | * In multisite, can individual site admins manage their own connection? |
||
| 651 | * |
||
| 652 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
| 653 | */ |
||
| 654 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
| 655 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
| 656 | /** |
||
| 657 | * We need to update the option name -- it's terribly unclear which |
||
| 658 | * direction the override goes. |
||
| 659 | * |
||
| 660 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
| 661 | */ |
||
| 662 | $caps = array( 'do_not_allow' ); |
||
| 663 | break; |
||
| 664 | } |
||
| 665 | } |
||
| 666 | |||
| 667 | $caps = array( 'manage_options' ); |
||
| 668 | break; |
||
| 669 | case 'jetpack_manage_modules' : |
||
| 670 | case 'jetpack_activate_modules' : |
||
| 671 | case 'jetpack_deactivate_modules' : |
||
| 672 | $caps = array( 'manage_options' ); |
||
| 673 | break; |
||
| 674 | case 'jetpack_configure_modules' : |
||
| 675 | $caps = array( 'manage_options' ); |
||
| 676 | break; |
||
| 677 | case 'jetpack_network_admin_page': |
||
| 678 | case 'jetpack_network_settings_page': |
||
| 679 | $caps = array( 'manage_network_plugins' ); |
||
| 680 | break; |
||
| 681 | case 'jetpack_network_sites_page': |
||
| 682 | $caps = array( 'manage_sites' ); |
||
| 683 | break; |
||
| 684 | case 'jetpack_admin_page' : |
||
| 685 | if ( Jetpack::is_development_mode() ) { |
||
| 686 | $caps = array( 'manage_options' ); |
||
| 687 | break; |
||
| 688 | } else { |
||
| 689 | $caps = array( 'read' ); |
||
| 690 | } |
||
| 691 | break; |
||
| 692 | case 'jetpack_connect_user' : |
||
| 693 | if ( Jetpack::is_development_mode() ) { |
||
| 694 | $caps = array( 'do_not_allow' ); |
||
| 695 | break; |
||
| 696 | } |
||
| 697 | $caps = array( 'read' ); |
||
| 698 | break; |
||
| 699 | } |
||
| 700 | return $caps; |
||
| 701 | } |
||
| 702 | |||
| 703 | function require_jetpack_authentication() { |
||
| 704 | // Don't let anyone authenticate |
||
| 705 | $_COOKIE = array(); |
||
| 706 | remove_all_filters( 'authenticate' ); |
||
| 707 | remove_all_actions( 'wp_login_failed' ); |
||
| 708 | |||
| 709 | if ( Jetpack::is_active() ) { |
||
| 710 | // Allow Jetpack authentication |
||
| 711 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
| 712 | } |
||
| 713 | } |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Load language files |
||
| 717 | * @action plugins_loaded |
||
| 718 | */ |
||
| 719 | public static function plugin_textdomain() { |
||
| 720 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
| 721 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
| 722 | } |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 726 | * |
||
| 727 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 728 | * @action wp_loaded |
||
| 729 | * @return null |
||
| 730 | */ |
||
| 731 | public function register_assets() { |
||
| 732 | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
||
| 733 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
| 734 | } |
||
| 735 | |||
| 736 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
| 737 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
| 738 | } |
||
| 739 | |||
| 740 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 741 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
| 742 | } |
||
| 743 | |||
| 744 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
| 745 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
| 746 | } |
||
| 747 | |||
| 748 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 749 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
| 750 | |||
| 751 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 752 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 753 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 754 | $fb_app_id = ''; |
||
| 755 | } |
||
| 756 | wp_localize_script( |
||
| 757 | 'jetpack-facebook-embed', |
||
| 758 | 'jpfbembed', |
||
| 759 | array( |
||
| 760 | 'appid' => $fb_app_id, |
||
| 761 | 'locale' => $this->get_locale(), |
||
| 762 | ) |
||
| 763 | ); |
||
| 764 | } |
||
| 765 | |||
| 766 | /** |
||
| 767 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 768 | * the hook may have already fired by this point. |
||
| 769 | * So, let's just trigger it manually. |
||
| 770 | */ |
||
| 771 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
| 772 | jetpack_register_genericons(); |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Register the social logos |
||
| 776 | */ |
||
| 777 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
| 778 | jetpack_register_social_logos(); |
||
| 779 | |||
| 780 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
| 781 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 782 | } |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Guess locale from language code. |
||
| 786 | * |
||
| 787 | * @param string $lang Language code. |
||
| 788 | * @return string|bool |
||
| 789 | */ |
||
| 790 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 791 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
| 792 | return 'en_US'; |
||
| 793 | } |
||
| 794 | |||
| 795 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
| 796 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
| 797 | return false; |
||
| 798 | } |
||
| 799 | |||
| 800 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
| 801 | } |
||
| 802 | |||
| 803 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 804 | // WP.com: get_locale() returns 'it' |
||
| 805 | $locale = GP_Locales::by_slug( $lang ); |
||
| 806 | } else { |
||
| 807 | // Jetpack: get_locale() returns 'it_IT'; |
||
| 808 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
| 809 | } |
||
| 810 | |||
| 811 | if ( ! $locale ) { |
||
| 812 | return false; |
||
| 813 | } |
||
| 814 | |||
| 815 | if ( empty( $locale->facebook_locale ) ) { |
||
| 816 | if ( empty( $locale->wp_locale ) ) { |
||
| 817 | return false; |
||
| 818 | } else { |
||
| 819 | // Facebook SDK is smart enough to fall back to en_US if a |
||
| 820 | // locale isn't supported. Since supported Facebook locales |
||
| 821 | // can fall out of sync, we'll attempt to use the known |
||
| 822 | // wp_locale value and rely on said fallback. |
||
| 823 | return $locale->wp_locale; |
||
| 824 | } |
||
| 825 | } |
||
| 826 | |||
| 827 | return $locale->facebook_locale; |
||
| 828 | } |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Get the locale. |
||
| 832 | * |
||
| 833 | * @return string|bool |
||
| 834 | */ |
||
| 835 | function get_locale() { |
||
| 836 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
| 837 | |||
| 838 | if ( ! $locale ) { |
||
| 839 | $locale = 'en_US'; |
||
| 840 | } |
||
| 841 | |||
| 842 | return $locale; |
||
| 843 | } |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Device Pixels support |
||
| 847 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
| 848 | */ |
||
| 849 | function devicepx() { |
||
| 850 | if ( Jetpack::is_active() ) { |
||
| 851 | wp_enqueue_script( 'devicepx', set_url_scheme( 'http://s0.wp.com/wp-content/js/devicepx-jetpack.js' ), array(), gmdate( 'oW' ), true ); |
||
| 852 | } |
||
| 853 | } |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 857 | * @param bool $option |
||
| 858 | * @return string |
||
| 859 | */ |
||
| 860 | public function jetpack_main_network_site_option( $option ) { |
||
| 861 | return network_site_url(); |
||
| 862 | } |
||
| 863 | /** |
||
| 864 | * Network Name. |
||
| 865 | */ |
||
| 866 | static function network_name( $option = null ) { |
||
| 867 | global $current_site; |
||
| 868 | return $current_site->site_name; |
||
| 869 | } |
||
| 870 | /** |
||
| 871 | * Does the network allow new user and site registrations. |
||
| 872 | * @return string |
||
| 873 | */ |
||
| 874 | static function network_allow_new_registrations( $option = null ) { |
||
| 875 | return ( in_array( get_site_option( 'registration' ), array('none', 'user', 'blog', 'all' ) ) ? get_site_option( 'registration') : 'none' ); |
||
| 876 | } |
||
| 877 | /** |
||
| 878 | * Does the network allow admins to add new users. |
||
| 879 | * @return boolian |
||
| 880 | */ |
||
| 881 | static function network_add_new_users( $option = null ) { |
||
| 882 | return (bool) get_site_option( 'add_new_users' ); |
||
| 883 | } |
||
| 884 | /** |
||
| 885 | * File upload psace left per site in MB. |
||
| 886 | * -1 means NO LIMIT. |
||
| 887 | * @return number |
||
| 888 | */ |
||
| 889 | static function network_site_upload_space( $option = null ) { |
||
| 890 | // value in MB |
||
| 891 | return ( get_site_option( 'upload_space_check_disabled' ) ? -1 : get_space_allowed() ); |
||
| 892 | } |
||
| 893 | |||
| 894 | /** |
||
| 895 | * Network allowed file types. |
||
| 896 | * @return string |
||
| 897 | */ |
||
| 898 | static function network_upload_file_types( $option = null ) { |
||
| 899 | return get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ); |
||
| 900 | } |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Maximum file upload size set by the network. |
||
| 904 | * @return number |
||
| 905 | */ |
||
| 906 | static function network_max_upload_file_size( $option = null ) { |
||
| 907 | // value in KB |
||
| 908 | return get_site_option( 'fileupload_maxk', 300 ); |
||
| 909 | } |
||
| 910 | |||
| 911 | /** |
||
| 912 | * Lets us know if a site allows admins to manage the network. |
||
| 913 | * @return array |
||
| 914 | */ |
||
| 915 | static function network_enable_administration_menus( $option = null ) { |
||
| 916 | return get_site_option( 'menu_items' ); |
||
| 917 | } |
||
| 918 | |||
| 919 | /** |
||
| 920 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
| 921 | * jetpack_other_linked_admins transient. |
||
| 922 | * |
||
| 923 | * @param $user_id |
||
| 924 | * @param $role |
||
| 925 | * @param $old_roles |
||
| 926 | */ |
||
| 927 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles ) { |
||
| 928 | if ( 'administrator' == $role || ( is_array( $old_roles ) && in_array( 'administrator', $old_roles ) ) |
||
| 929 | ) { |
||
| 930 | delete_transient( 'jetpack_other_linked_admins' ); |
||
| 931 | } |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Checks to see if there are any other users available to become primary |
||
| 936 | * Users must both: |
||
| 937 | * - Be linked to wpcom |
||
| 938 | * - Be an admin |
||
| 939 | * |
||
| 940 | * @return mixed False if no other users are linked, Int if there are. |
||
| 941 | */ |
||
| 942 | static function get_other_linked_admins() { |
||
| 943 | $other_linked_users = get_transient( 'jetpack_other_linked_admins' ); |
||
| 944 | |||
| 945 | if ( false === $other_linked_users ) { |
||
| 946 | $admins = get_users( array( 'role' => 'administrator' ) ); |
||
| 947 | if ( count( $admins ) > 1 ) { |
||
| 948 | $available = array(); |
||
| 949 | foreach ( $admins as $admin ) { |
||
| 950 | if ( Jetpack::is_user_connected( $admin->ID ) ) { |
||
| 951 | $available[] = $admin->ID; |
||
| 952 | } |
||
| 953 | } |
||
| 954 | |||
| 955 | $count_connected_admins = count( $available ); |
||
| 956 | if ( count( $available ) > 1 ) { |
||
| 957 | $other_linked_users = $count_connected_admins; |
||
| 958 | } else { |
||
| 959 | $other_linked_users = 0; |
||
| 960 | } |
||
| 961 | } else { |
||
| 962 | $other_linked_users = 0; |
||
| 963 | } |
||
| 964 | |||
| 965 | set_transient( 'jetpack_other_linked_admins', $other_linked_users, HOUR_IN_SECONDS ); |
||
| 966 | } |
||
| 967 | |||
| 968 | return ( 0 === $other_linked_users ) ? false : $other_linked_users; |
||
| 969 | } |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Return whether we are dealing with a multi network setup or not. |
||
| 973 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 974 | * the result is false since when is_main_network_option return false it cases |
||
| 975 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 976 | * database which could be set to anything as opposed to what this function returns. |
||
| 977 | * @param bool $option |
||
| 978 | * |
||
| 979 | * @return boolean |
||
| 980 | */ |
||
| 981 | public function is_main_network_option( $option ) { |
||
| 982 | // return '1' or '' |
||
| 983 | return (string) (bool) Jetpack::is_multi_network(); |
||
| 984 | } |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 988 | * |
||
| 989 | * @param string $option |
||
| 990 | * @return boolean |
||
| 991 | */ |
||
| 992 | public function is_multisite( $option ) { |
||
| 993 | return (string) (bool) is_multisite(); |
||
| 994 | } |
||
| 995 | |||
| 996 | /** |
||
| 997 | * Implemented since there is no core is multi network function |
||
| 998 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 999 | * |
||
| 1000 | * @since 3.3 |
||
| 1001 | * @return boolean |
||
| 1002 | */ |
||
| 1003 | public static function is_multi_network() { |
||
| 1004 | global $wpdb; |
||
| 1005 | |||
| 1006 | // if we don't have a multi site setup no need to do any more |
||
| 1007 | if ( ! is_multisite() ) { |
||
| 1008 | return false; |
||
| 1009 | } |
||
| 1010 | |||
| 1011 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
| 1012 | if ( $num_sites > 1 ) { |
||
| 1013 | return true; |
||
| 1014 | } else { |
||
| 1015 | return false; |
||
| 1016 | } |
||
| 1017 | } |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1021 | * @return null |
||
| 1022 | */ |
||
| 1023 | function update_jetpack_main_network_site_option() { |
||
| 1024 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1025 | } |
||
| 1026 | /** |
||
| 1027 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1028 | * |
||
| 1029 | */ |
||
| 1030 | function update_jetpack_network_settings() { |
||
| 1031 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1032 | // Only sync this info for the main network site. |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Get back if the current site is single user site. |
||
| 1037 | * |
||
| 1038 | * @return bool |
||
| 1039 | */ |
||
| 1040 | public static function is_single_user_site() { |
||
| 1041 | global $wpdb; |
||
| 1042 | $some_users = $wpdb->get_var( "select count(*) from (select user_id from $wpdb->usermeta where meta_key = '{$wpdb->prefix}capabilities' LIMIT 2) as someusers" ); |
||
| 1043 | return 1 === (int) $some_users; |
||
| 1044 | } |
||
| 1045 | |||
| 1046 | /** |
||
| 1047 | * Returns true if the site has file write access false otherwise. |
||
| 1048 | * @return string ( '1' | '0' ) |
||
| 1049 | **/ |
||
| 1050 | public static function file_system_write_access() { |
||
| 1051 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
||
| 1052 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
||
| 1053 | } |
||
| 1054 | |||
| 1055 | require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
||
| 1056 | |||
| 1057 | $filesystem_method = get_filesystem_method(); |
||
| 1058 | if ( $filesystem_method === 'direct' ) { |
||
| 1059 | return 1; |
||
| 1060 | } |
||
| 1061 | |||
| 1062 | ob_start(); |
||
| 1063 | $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
||
| 1064 | ob_end_clean(); |
||
| 1065 | if ( $filesystem_credentials_are_stored ) { |
||
| 1066 | return 1; |
||
| 1067 | } |
||
| 1068 | return 0; |
||
| 1069 | } |
||
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Finds out if a site is using a version control system. |
||
| 1073 | * @return string ( '1' | '0' ) |
||
| 1074 | **/ |
||
| 1075 | public static function is_version_controlled() { |
||
| 1076 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); |
||
| 1077 | return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); |
||
| 1078 | } |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Determines whether the current theme supports featured images or not. |
||
| 1082 | * @return string ( '1' | '0' ) |
||
| 1083 | */ |
||
| 1084 | public static function featured_images_enabled() { |
||
| 1085 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1086 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
| 1087 | } |
||
| 1088 | |||
| 1089 | /** |
||
| 1090 | * jetpack_updates is saved in the following schema: |
||
| 1091 | * |
||
| 1092 | * array ( |
||
| 1093 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1094 | * 'themes' => (int) Number of theme updates available. |
||
| 1095 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1096 | * 'translations' => (int) Number of translation updates available. |
||
| 1097 | * 'total' => (int) Total of all available updates. |
||
| 1098 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1099 | * ) |
||
| 1100 | * @return array |
||
| 1101 | */ |
||
| 1102 | public static function get_updates() { |
||
| 1103 | $update_data = wp_get_update_data(); |
||
| 1104 | |||
| 1105 | // Stores the individual update counts as well as the total count. |
||
| 1106 | if ( isset( $update_data['counts'] ) ) { |
||
| 1107 | $updates = $update_data['counts']; |
||
| 1108 | } |
||
| 1109 | |||
| 1110 | // If we need to update WordPress core, let's find the latest version number. |
||
| 1111 | View Code Duplication | if ( ! empty( $updates['wordpress'] ) ) { |
|
| 1112 | $cur = get_preferred_from_update_core(); |
||
| 1113 | if ( isset( $cur->response ) && 'upgrade' === $cur->response ) { |
||
| 1114 | $updates['wp_update_version'] = $cur->current; |
||
| 1115 | } |
||
| 1116 | } |
||
| 1117 | return isset( $updates ) ? $updates : array(); |
||
| 1118 | } |
||
| 1119 | |||
| 1120 | public static function get_update_details() { |
||
| 1121 | $update_details = array( |
||
| 1122 | 'update_core' => get_site_transient( 'update_core' ), |
||
| 1123 | 'update_plugins' => get_site_transient( 'update_plugins' ), |
||
| 1124 | 'update_themes' => get_site_transient( 'update_themes' ), |
||
| 1125 | ); |
||
| 1126 | return $update_details; |
||
| 1127 | } |
||
| 1128 | |||
| 1129 | public static function refresh_update_data() { |
||
| 1130 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1131 | |||
| 1132 | } |
||
| 1133 | |||
| 1134 | public static function refresh_theme_data() { |
||
| 1135 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1136 | } |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * Is Jetpack active? |
||
| 1140 | */ |
||
| 1141 | public static function is_active() { |
||
| 1142 | return (bool) Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
| 1143 | } |
||
| 1144 | |||
| 1145 | /** |
||
| 1146 | * Is Jetpack in development (offline) mode? |
||
| 1147 | */ |
||
| 1148 | public static function is_development_mode() { |
||
| 1149 | $development_mode = false; |
||
| 1150 | |||
| 1151 | if ( defined( 'JETPACK_DEV_DEBUG' ) ) { |
||
| 1152 | $development_mode = JETPACK_DEV_DEBUG; |
||
| 1153 | } |
||
| 1154 | |||
| 1155 | elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
| 1156 | $development_mode = true; |
||
| 1157 | } |
||
| 1158 | /** |
||
| 1159 | * Filters Jetpack's development mode. |
||
| 1160 | * |
||
| 1161 | * @see https://jetpack.com/support/development-mode/ |
||
| 1162 | * |
||
| 1163 | * @since 2.2.1 |
||
| 1164 | * |
||
| 1165 | * @param bool $development_mode Is Jetpack's development mode active. |
||
| 1166 | */ |
||
| 1167 | return apply_filters( 'jetpack_development_mode', $development_mode ); |
||
| 1168 | } |
||
| 1169 | |||
| 1170 | /** |
||
| 1171 | * Get Jetpack development mode notice text and notice class. |
||
| 1172 | * |
||
| 1173 | * Mirrors the checks made in Jetpack::is_development_mode |
||
| 1174 | * |
||
| 1175 | */ |
||
| 1176 | public static function show_development_mode_notice() { |
||
| 1177 | if ( Jetpack::is_development_mode() ) { |
||
| 1178 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
| 1179 | $notice = sprintf( |
||
| 1180 | /* translators: %s is a URL */ |
||
| 1181 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), |
||
| 1182 | 'https://jetpack.com/support/development-mode/' |
||
| 1183 | ); |
||
| 1184 | } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
| 1185 | $notice = sprintf( |
||
| 1186 | /* translators: %s is a URL */ |
||
| 1187 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), |
||
| 1188 | 'https://jetpack.com/support/development-mode/' |
||
| 1189 | ); |
||
| 1190 | } else { |
||
| 1191 | $notice = sprintf( |
||
| 1192 | /* translators: %s is a URL */ |
||
| 1193 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), |
||
| 1194 | 'https://jetpack.com/support/development-mode/' |
||
| 1195 | ); |
||
| 1196 | } |
||
| 1197 | |||
| 1198 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1199 | } |
||
| 1200 | |||
| 1201 | // Throw up a notice if using a development version and as for feedback. |
||
| 1202 | if ( Jetpack::is_development_version() ) { |
||
| 1203 | /* translators: %s is a URL */ |
||
| 1204 | $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.com/contact-support/beta-group/' ); |
||
| 1205 | |||
| 1206 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1207 | } |
||
| 1208 | // Throw up a notice if using staging mode |
||
| 1209 | if ( Jetpack::is_staging_site() ) { |
||
| 1210 | /* translators: %s is a URL */ |
||
| 1211 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); |
||
| 1212 | |||
| 1213 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1214 | } |
||
| 1215 | } |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1219 | */ |
||
| 1220 | public static function is_development_version() { |
||
| 1221 | /** |
||
| 1222 | * Allows filtering whether this is a development version of Jetpack. |
||
| 1223 | * |
||
| 1224 | * This filter is especially useful for tests. |
||
| 1225 | * |
||
| 1226 | * @since 4.3.0 |
||
| 1227 | * |
||
| 1228 | * @param bool $development_version Is this a develoment version of Jetpack? |
||
| 1229 | */ |
||
| 1230 | return (bool) apply_filters( |
||
| 1231 | 'jetpack_development_version', |
||
| 1232 | ! preg_match( '/^\d+(\.\d+)+$/', JETPACK__VERSION ) |
||
| 1233 | ); |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1238 | */ |
||
| 1239 | public static function is_user_connected( $user_id = false ) { |
||
| 1240 | $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); |
||
| 1241 | if ( ! $user_id ) { |
||
| 1242 | return false; |
||
| 1243 | } |
||
| 1244 | |||
| 1245 | return (bool) Jetpack_Data::get_access_token( $user_id ); |
||
| 1246 | } |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Get the wpcom user data of the current|specified connected user. |
||
| 1250 | */ |
||
| 1251 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1252 | if ( ! $user_id ) { |
||
| 1253 | $user_id = get_current_user_id(); |
||
| 1254 | } |
||
| 1255 | |||
| 1256 | $transient_key = "jetpack_connected_user_data_$user_id"; |
||
| 1257 | |||
| 1258 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
||
| 1259 | return $cached_user_data; |
||
| 1260 | } |
||
| 1261 | |||
| 1262 | Jetpack::load_xml_rpc_client(); |
||
| 1263 | $xml = new Jetpack_IXR_Client( array( |
||
| 1264 | 'user_id' => $user_id, |
||
| 1265 | ) ); |
||
| 1266 | $xml->query( 'wpcom.getUser' ); |
||
| 1267 | if ( ! $xml->isError() ) { |
||
| 1268 | $user_data = $xml->getResponse(); |
||
| 1269 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
||
| 1270 | return $user_data; |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | return false; |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * Get the wpcom email of the current|specified connected user. |
||
| 1278 | */ |
||
| 1279 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Get the wpcom email of the master user. |
||
| 1296 | */ |
||
| 1297 | public static function get_master_user_email() { |
||
| 1304 | |||
| 1305 | function current_user_is_connection_owner() { |
||
| 1309 | |||
| 1310 | /** |
||
| 1311 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
| 1312 | */ |
||
| 1313 | function extra_oembed_providers() { |
||
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Synchronize connected user role changes |
||
| 1324 | */ |
||
| 1325 | function user_role_change( $user_id ) { |
||
| 1326 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Users::user_role_change()' ); |
||
| 1327 | Jetpack_Sync_Users::user_role_change( $user_id ); |
||
| 1328 | } |
||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Loads the currently active modules. |
||
| 1332 | */ |
||
| 1333 | public static function load_modules() { |
||
| 1334 | if ( ! self::is_active() && !self::is_development_mode() ) { |
||
| 1335 | if ( ! is_multisite() || ! get_site_option( 'jetpack_protect_active' ) ) { |
||
| 1336 | return; |
||
| 1337 | } |
||
| 1338 | } |
||
| 1339 | |||
| 1340 | $version = Jetpack_Options::get_option( 'version' ); |
||
| 1341 | View Code Duplication | if ( ! $version ) { |
|
| 1342 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
| 1343 | /** This action is documented in class.jetpack.php */ |
||
| 1344 | do_action( 'updating_jetpack_version', $version, false ); |
||
| 1345 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
| 1346 | } |
||
| 1347 | list( $version ) = explode( ':', $version ); |
||
| 1348 | |||
| 1349 | $modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) ); |
||
| 1350 | |||
| 1351 | $modules_data = array(); |
||
| 1352 | |||
| 1353 | // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check. |
||
| 1354 | if ( version_compare( $version, JETPACK__VERSION, '<' ) ) { |
||
| 1355 | $updated_modules = array(); |
||
| 1356 | foreach ( $modules as $module ) { |
||
| 1357 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
| 1358 | if ( ! isset( $modules_data[ $module ]['changed'] ) ) { |
||
| 1359 | continue; |
||
| 1360 | } |
||
| 1361 | |||
| 1362 | if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) { |
||
| 1363 | continue; |
||
| 1364 | } |
||
| 1417 | |||
| 1418 | /** |
||
| 1419 | * Check if Jetpack's REST API compat file should be included |
||
| 1420 | * @action plugins_loaded |
||
| 1421 | * @return null |
||
| 1422 | */ |
||
| 1423 | public function check_rest_api_compat() { |
||
| 1439 | |||
| 1440 | /** |
||
| 1441 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 1442 | * traditionally activated or network activated. |
||
| 1443 | * |
||
| 1444 | * @todo Store the result in core's object cache maybe? |
||
| 1445 | */ |
||
| 1446 | public static function get_active_plugins() { |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 1465 | * |
||
| 1466 | * @since 3.8.1 |
||
| 1467 | * |
||
| 1468 | * @return array Array of plugin data |
||
| 1469 | */ |
||
| 1470 | public static function get_parsed_plugin_data() { |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Gets and parses theme data to send with the heartbeat data |
||
| 1494 | * |
||
| 1495 | * @since 3.8.1 |
||
| 1496 | * |
||
| 1497 | * @return array Array of theme data |
||
| 1498 | */ |
||
| 1499 | public static function get_parsed_theme_data() { |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * Checks whether a specific plugin is active. |
||
| 1524 | * |
||
| 1525 | * We don't want to store these in a static variable, in case |
||
| 1526 | * there are switch_to_blog() calls involved. |
||
| 1527 | */ |
||
| 1528 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 1531 | |||
| 1532 | /** |
||
| 1533 | * Check if Jetpack's Open Graph tags should be used. |
||
| 1534 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 1535 | * |
||
| 1536 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1537 | * @action plugins_loaded |
||
| 1538 | * @return null |
||
| 1539 | */ |
||
| 1540 | public function check_open_graph() { |
||
| 1567 | |||
| 1568 | /** |
||
| 1569 | * Check if Jetpack's Twitter tags should be used. |
||
| 1570 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 1571 | * |
||
| 1572 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1573 | * @action plugins_loaded |
||
| 1574 | * @return null |
||
| 1575 | */ |
||
| 1576 | public function check_twitter_tags() { |
||
| 1600 | |||
| 1601 | /** |
||
| 1602 | * Allows plugins to submit security reports. |
||
| 1603 | * |
||
| 1604 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 1605 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 1606 | * @param array $args See definitions above |
||
| 1607 | */ |
||
| 1608 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 1611 | |||
| 1612 | /* Jetpack Options API */ |
||
| 1613 | |||
| 1614 | public static function get_option_names( $type = 'compact' ) { |
||
| 1617 | |||
| 1618 | /** |
||
| 1619 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 1620 | * |
||
| 1621 | * @param string $name Option name |
||
| 1622 | * @param mixed $default (optional) |
||
| 1623 | */ |
||
| 1624 | public static function get_option( $name, $default = false ) { |
||
| 1627 | |||
| 1628 | /** |
||
| 1629 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
| 1630 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
| 1631 | * $name must be a registered option name. |
||
| 1632 | */ |
||
| 1633 | public static function create_nonce( $name ) { |
||
| 1647 | |||
| 1648 | /** |
||
| 1649 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 1650 | * |
||
| 1651 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 1652 | * @param string $name Option name |
||
| 1653 | * @param mixed $value Option value |
||
| 1654 | */ |
||
| 1655 | public static function update_option( $name, $value ) { |
||
| 1659 | |||
| 1660 | /** |
||
| 1661 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 1662 | * |
||
| 1663 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 1664 | * @param array $array array( option name => option value, ... ) |
||
| 1665 | */ |
||
| 1666 | public static function update_options( $array ) { |
||
| 1670 | |||
| 1671 | /** |
||
| 1672 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 1673 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 1674 | * |
||
| 1675 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 1676 | * @param string|array $names |
||
| 1677 | */ |
||
| 1678 | public static function delete_option( $names ) { |
||
| 1682 | |||
| 1683 | /** |
||
| 1684 | * Enters a user token into the user_tokens option |
||
| 1685 | * |
||
| 1686 | * @param int $user_id |
||
| 1687 | * @param string $token |
||
| 1688 | * return bool |
||
| 1689 | */ |
||
| 1690 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * Returns an array of all PHP files in the specified absolute path. |
||
| 1707 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 1708 | * |
||
| 1709 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 1710 | * @return array Array of absolute paths to the PHP files. |
||
| 1711 | */ |
||
| 1712 | public static function glob_php( $absolute_path ) { |
||
| 1741 | |||
| 1742 | public static function activate_new_modules( $redirect = false ) { |
||
| 1800 | |||
| 1801 | /** |
||
| 1802 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 1803 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 1804 | */ |
||
| 1805 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Default modules loaded on activation. |
||
| 1865 | */ |
||
| 1866 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 1897 | |||
| 1898 | /** |
||
| 1899 | * Checks activated modules during auto-activation to determine |
||
| 1900 | * if any of those modules are being deprecated. If so, close |
||
| 1901 | * them out, and add any replacement modules. |
||
| 1902 | * |
||
| 1903 | * Runs at priority 99 by default. |
||
| 1904 | * |
||
| 1905 | * This is run late, so that it can still activate a module if |
||
| 1906 | * the new module is a replacement for another that the user |
||
| 1907 | * currently has active, even if something at the normal priority |
||
| 1908 | * would kibosh everything. |
||
| 1909 | * |
||
| 1910 | * @since 2.6 |
||
| 1911 | * @uses jetpack_get_default_modules filter |
||
| 1912 | * @param array $modules |
||
| 1913 | * @return array |
||
| 1914 | */ |
||
| 1915 | function handle_deprecated_modules( $modules ) { |
||
| 1941 | |||
| 1942 | /** |
||
| 1943 | * Checks activated plugins during auto-activation to determine |
||
| 1944 | * if any of those plugins are in the list with a corresponding module |
||
| 1945 | * that is not compatible with the plugin. The module will not be allowed |
||
| 1946 | * to auto-activate. |
||
| 1947 | * |
||
| 1948 | * @since 2.6 |
||
| 1949 | * @uses jetpack_get_default_modules filter |
||
| 1950 | * @param array $modules |
||
| 1951 | * @return array |
||
| 1952 | */ |
||
| 1953 | function filter_default_modules( $modules ) { |
||
| 1977 | |||
| 1978 | /** |
||
| 1979 | * Extract a module's slug from its full path. |
||
| 1980 | */ |
||
| 1981 | public static function get_module_slug( $file ) { |
||
| 1984 | |||
| 1985 | /** |
||
| 1986 | * Generate a module's path from its slug. |
||
| 1987 | */ |
||
| 1988 | public static function get_module_path( $slug ) { |
||
| 1991 | |||
| 1992 | /** |
||
| 1993 | * Load module data from module file. Headers differ from WordPress |
||
| 1994 | * plugin headers to avoid them being identified as standalone |
||
| 1995 | * plugins on the WordPress plugins page. |
||
| 1996 | */ |
||
| 1997 | public static function get_module( $module ) { |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Like core's get_file_data implementation, but caches the result. |
||
| 2083 | */ |
||
| 2084 | public static function get_file_data( $file, $headers ) { |
||
| 2105 | |||
| 2106 | /** |
||
| 2107 | * Return translated module tag. |
||
| 2108 | * |
||
| 2109 | * @param string $tag Tag as it appears in each module heading. |
||
| 2110 | * |
||
| 2111 | * @return mixed |
||
| 2112 | */ |
||
| 2113 | public static function translate_module_tag( $tag ) { |
||
| 2116 | |||
| 2117 | /** |
||
| 2118 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2119 | * |
||
| 2120 | * @since 3.9.2 |
||
| 2121 | * |
||
| 2122 | * @param array $modules |
||
| 2123 | * |
||
| 2124 | * @return string|void |
||
| 2125 | */ |
||
| 2126 | public static function get_translated_modules( $modules ) { |
||
| 2139 | |||
| 2140 | /** |
||
| 2141 | * Get a list of activated modules as an array of module slugs. |
||
| 2142 | */ |
||
| 2143 | public static function get_active_modules() { |
||
| 2160 | |||
| 2161 | /** |
||
| 2162 | * Check whether or not a Jetpack module is active. |
||
| 2163 | * |
||
| 2164 | * @param string $module The slug of a Jetpack module. |
||
| 2165 | * @return bool |
||
| 2166 | * |
||
| 2167 | * @static |
||
| 2168 | */ |
||
| 2169 | public static function is_module_active( $module ) { |
||
| 2172 | |||
| 2173 | public static function is_module( $module ) { |
||
| 2176 | |||
| 2177 | /** |
||
| 2178 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2179 | * |
||
| 2180 | * @param bool $catch True to start catching, False to stop. |
||
| 2181 | * |
||
| 2182 | * @static |
||
| 2183 | */ |
||
| 2184 | public static function catch_errors( $catch ) { |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2200 | */ |
||
| 2201 | public static function catch_errors_on_shutdown() { |
||
| 2204 | |||
| 2205 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
| 2322 | |||
| 2323 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 2407 | |||
| 2408 | function activate_module_actions( $module ) { |
||
| 2411 | |||
| 2412 | public static function deactivate_module( $module ) { |
||
| 2439 | |||
| 2440 | public static function enable_module_configurable( $module ) { |
||
| 2444 | |||
| 2445 | public static function module_configuration_url( $module ) { |
||
| 2449 | |||
| 2450 | public static function module_configuration_load( $module, $method ) { |
||
| 2454 | |||
| 2455 | public static function module_configuration_head( $module, $method ) { |
||
| 2459 | |||
| 2460 | public static function module_configuration_screen( $module, $method ) { |
||
| 2464 | |||
| 2465 | public static function module_configuration_activation_screen( $module, $method ) { |
||
| 2469 | |||
| 2470 | /* Installation */ |
||
| 2471 | |||
| 2472 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 2512 | |||
| 2513 | /** |
||
| 2514 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 2515 | * @static |
||
| 2516 | */ |
||
| 2517 | public static function plugin_activation( $network_wide ) { |
||
| 2529 | /** |
||
| 2530 | * Runs before bumping version numbers up to a new version |
||
| 2531 | * @param (string) $version Version:timestamp |
||
| 2532 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
| 2533 | * @return null [description] |
||
| 2534 | */ |
||
| 2535 | public static function do_version_bump( $version, $old_version ) { |
||
| 2542 | |||
| 2543 | /** |
||
| 2544 | * Sets the internal version number and activation state. |
||
| 2545 | * @static |
||
| 2546 | */ |
||
| 2547 | public static function plugin_initialize() { |
||
| 2563 | |||
| 2564 | /** |
||
| 2565 | * Removes all connection options |
||
| 2566 | * @static |
||
| 2567 | */ |
||
| 2568 | public static function plugin_deactivation( ) { |
||
| 2577 | |||
| 2578 | /** |
||
| 2579 | * Disconnects from the Jetpack servers. |
||
| 2580 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 2581 | * @static |
||
| 2582 | */ |
||
| 2583 | public static function disconnect( $update_activated_state = true ) { |
||
| 2633 | |||
| 2634 | /** |
||
| 2635 | * Unlinks the current user from the linked WordPress.com user |
||
| 2636 | */ |
||
| 2637 | public static function unlink_user( $user_id = null ) { |
||
| 2668 | |||
| 2669 | /** |
||
| 2670 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 2671 | */ |
||
| 2672 | public static function try_registration() { |
||
| 2697 | |||
| 2698 | /** |
||
| 2699 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 2700 | * |
||
| 2701 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 2702 | */ |
||
| 2703 | public static function log( $code, $data = null ) { |
||
| 2743 | |||
| 2744 | /** |
||
| 2745 | * Get the internal event log. |
||
| 2746 | * |
||
| 2747 | * @param $event (string) - only return the specific log events |
||
| 2748 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 2749 | * |
||
| 2750 | * @return array of log events || WP_Error for invalid params |
||
| 2751 | */ |
||
| 2752 | public static function get_log( $event = false, $num = false ) { |
||
| 2788 | |||
| 2789 | /** |
||
| 2790 | * Log modification of important settings. |
||
| 2791 | */ |
||
| 2792 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 2799 | |||
| 2800 | /** |
||
| 2801 | * Return stat data for WPCOM sync |
||
| 2802 | */ |
||
| 2803 | public static function get_stat_data( $encode = true ) { |
||
| 2815 | |||
| 2816 | /** |
||
| 2817 | * Get additional stat data to sync to WPCOM |
||
| 2818 | */ |
||
| 2819 | public static function get_additional_stat_data( $prefix = '' ) { |
||
| 2831 | |||
| 2832 | /* Admin Pages */ |
||
| 2833 | |||
| 2834 | function admin_init() { |
||
| 2888 | |||
| 2889 | function admin_body_class( $admin_body_class = '' ) { |
||
| 2897 | |||
| 2898 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 2901 | |||
| 2902 | function prepare_connect_notice() { |
||
| 2910 | /** |
||
| 2911 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
| 2912 | * |
||
| 2913 | * @return null |
||
| 2914 | */ |
||
| 2915 | function prepare_manage_jetpack_notice() { |
||
| 2920 | |||
| 2921 | function manage_activate_screen() { |
||
| 2924 | /** |
||
| 2925 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 2926 | * This function artificially throws errors for such cases (whitelisted). |
||
| 2927 | * |
||
| 2928 | * @param string $plugin The activated plugin. |
||
| 2929 | */ |
||
| 2930 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 2954 | |||
| 2955 | function intercept_plugin_error_scrape_init() { |
||
| 2958 | |||
| 2959 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 2970 | |||
| 2971 | function add_remote_request_handlers() { |
||
| 2974 | |||
| 2975 | function remote_request_handlers() { |
||
| 3009 | |||
| 3010 | function upload_handler() { |
||
| 3095 | |||
| 3096 | /** |
||
| 3097 | * Add help to the Jetpack page |
||
| 3098 | * |
||
| 3099 | * @since Jetpack (1.2.3) |
||
| 3100 | * @return false if not the Jetpack page |
||
| 3101 | */ |
||
| 3102 | function admin_help() { |
||
| 3143 | |||
| 3144 | function admin_menu_css() { |
||
| 3147 | |||
| 3148 | function admin_menu_order() { |
||
| 3151 | |||
| 3152 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
| 3167 | |||
| 3168 | function admin_head() { |
||
| 3173 | |||
| 3174 | View Code Duplication | function admin_banner_styles() { |
|
| 3181 | |||
| 3182 | function plugin_action_links( $actions ) { |
||
| 3197 | |||
| 3198 | function admin_connect_notice() { |
||
| 3233 | |||
| 3234 | /** |
||
| 3235 | * This is the first banner |
||
| 3236 | * It should be visible only to user that can update the option |
||
| 3237 | * Are not connected |
||
| 3238 | * |
||
| 3239 | * @return null |
||
| 3240 | */ |
||
| 3241 | function admin_jetpack_manage_notice() { |
||
| 3276 | |||
| 3277 | /** |
||
| 3278 | * Returns the url that the user clicks to remove the notice for the big banner |
||
| 3279 | * @return (string) |
||
| 3280 | */ |
||
| 3281 | function opt_out_jetpack_manage_url() { |
||
| 3285 | /** |
||
| 3286 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
| 3287 | * @return (string) |
||
| 3288 | */ |
||
| 3289 | function opt_in_jetpack_manage_url() { |
||
| 3292 | |||
| 3293 | function opt_in_jetpack_manage_notice() { |
||
| 3303 | /** |
||
| 3304 | * Determines whether to show the notice of not true = display notice |
||
| 3305 | * @return (bool) |
||
| 3306 | */ |
||
| 3307 | function can_display_jetpack_manage_notice() { |
||
| 3329 | |||
| 3330 | function network_connect_notice() { |
||
| 3339 | |||
| 3340 | /* |
||
| 3341 | * Registration flow: |
||
| 3342 | * 1 - ::admin_page_load() action=register |
||
| 3343 | * 2 - ::try_registration() |
||
| 3344 | * 3 - ::register() |
||
| 3345 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 3346 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 3347 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 3348 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 3349 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 3350 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 3351 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 3352 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 3353 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 3354 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 3355 | * 5 - user logs in with WP.com account |
||
| 3356 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 3357 | * - Jetpack_Client_Server::authorize() |
||
| 3358 | * - Jetpack_Client_Server::get_token() |
||
| 3359 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 3360 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 3361 | * - which responds with access_token, token_type, scope |
||
| 3362 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 3363 | * - Jetpack::activate_default_modules() |
||
| 3364 | * - Deactivates deprecated plugins |
||
| 3365 | * - Activates all default modules |
||
| 3366 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 3367 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 3368 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 3369 | * Done! |
||
| 3370 | */ |
||
| 3371 | |||
| 3372 | /** |
||
| 3373 | * Handles the page load events for the Jetpack admin page |
||
| 3374 | */ |
||
| 3375 | function admin_page_load() { |
||
| 3601 | |||
| 3602 | function admin_notices() { |
||
| 3699 | |||
| 3700 | /** |
||
| 3701 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 3702 | */ |
||
| 3703 | function stat( $group, $detail ) { |
||
| 3708 | |||
| 3709 | /** |
||
| 3710 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 3711 | */ |
||
| 3712 | function do_stats( $method = '' ) { |
||
| 3727 | |||
| 3728 | /** |
||
| 3729 | * Runs stats code for a one-off, server-side. |
||
| 3730 | * |
||
| 3731 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 3732 | * |
||
| 3733 | * @return bool If it worked. |
||
| 3734 | */ |
||
| 3735 | static function do_server_side_stat( $args ) { |
||
| 3745 | |||
| 3746 | /** |
||
| 3747 | * Builds the stats url. |
||
| 3748 | * |
||
| 3749 | * @param $args array|string The arguments to append to the URL. |
||
| 3750 | * |
||
| 3751 | * @return string The URL to be pinged. |
||
| 3752 | */ |
||
| 3753 | static function build_stats_url( $args ) { |
||
| 3773 | |||
| 3774 | static function translate_current_user_to_role() { |
||
| 3783 | |||
| 3784 | static function translate_role_to_cap( $role ) { |
||
| 3791 | |||
| 3792 | static function sign_role( $role ) { |
||
| 3804 | |||
| 3805 | |||
| 3806 | /** |
||
| 3807 | * Builds a URL to the Jetpack connection auth page |
||
| 3808 | * |
||
| 3809 | * @since 3.9.5 |
||
| 3810 | * |
||
| 3811 | * @param bool $raw If true, URL will not be escaped. |
||
| 3812 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 3813 | * If string, will be a custom redirect. |
||
| 3814 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 3815 | * |
||
| 3816 | * @return string Connect URL |
||
| 3817 | */ |
||
| 3818 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
| 3892 | |||
| 3893 | function build_reconnect_url( $raw = false ) { |
||
| 3897 | |||
| 3898 | public static function admin_url( $args = null ) { |
||
| 3903 | |||
| 3904 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 3908 | |||
| 3909 | function dismiss_jetpack_notice() { |
||
| 3983 | |||
| 3984 | function debugger_page() { |
||
| 3992 | |||
| 3993 | public static function admin_screen_configure_module( $module_id ) { |
||
| 4045 | |||
| 4046 | /** |
||
| 4047 | * Display link to activate the module to see the settings screen. |
||
| 4048 | * @param string $module_id |
||
| 4049 | * @return null |
||
| 4050 | */ |
||
| 4051 | public static function display_activate_module_link( $module_id ) { |
||
| 4103 | |||
| 4104 | public static function sort_modules( $a, $b ) { |
||
| 4110 | |||
| 4111 | function ajax_recheck_ssl() { |
||
| 4119 | |||
| 4120 | /* Client API */ |
||
| 4121 | |||
| 4122 | /** |
||
| 4123 | * Returns the requested Jetpack API URL |
||
| 4124 | * |
||
| 4125 | * @return string |
||
| 4126 | */ |
||
| 4127 | public static function api_url( $relative_url ) { |
||
| 4130 | |||
| 4131 | /** |
||
| 4132 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
| 4133 | */ |
||
| 4134 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 4150 | |||
| 4151 | /** |
||
| 4152 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 4153 | * |
||
| 4154 | * @since 2.3.3 |
||
| 4155 | * @return boolean |
||
| 4156 | */ |
||
| 4157 | public static function permit_ssl( $force_recheck = false ) { |
||
| 4199 | |||
| 4200 | /* |
||
| 4201 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
| 4202 | */ |
||
| 4203 | public function alert_auto_ssl_fail() { |
||
| 4252 | |||
| 4253 | /** |
||
| 4254 | * Returns the Jetpack XML-RPC API |
||
| 4255 | * |
||
| 4256 | * @return string |
||
| 4257 | */ |
||
| 4258 | public static function xmlrpc_api_url() { |
||
| 4262 | |||
| 4263 | /** |
||
| 4264 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 4265 | * |
||
| 4266 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 4267 | * |
||
| 4268 | * @since 2.6 |
||
| 4269 | * @return array |
||
| 4270 | */ |
||
| 4271 | public function generate_secrets( $action, $exp = 600 ) { |
||
| 4279 | |||
| 4280 | /** |
||
| 4281 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 4282 | * |
||
| 4283 | * Based on local php max_execution_time in php.ini |
||
| 4284 | * |
||
| 4285 | * @since 2.6 |
||
| 4286 | * @return int |
||
| 4287 | **/ |
||
| 4288 | public function get_remote_query_timeout_limit() { |
||
| 4294 | |||
| 4295 | |||
| 4296 | /** |
||
| 4297 | * Takes the response from the Jetpack register new site endpoint and |
||
| 4298 | * verifies it worked properly. |
||
| 4299 | * |
||
| 4300 | * @since 2.6 |
||
| 4301 | * @return true or Jetpack_Error |
||
| 4302 | **/ |
||
| 4303 | public function validate_remote_register_response( $response ) { |
||
| 4338 | /** |
||
| 4339 | * @return bool|WP_Error |
||
| 4340 | */ |
||
| 4341 | public static function register() { |
||
| 4438 | |||
| 4439 | /** |
||
| 4440 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 4441 | * |
||
| 4442 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 4443 | */ |
||
| 4444 | public static function maybe_set_version_option() { |
||
| 4458 | |||
| 4459 | /* Client Server API */ |
||
| 4460 | |||
| 4461 | /** |
||
| 4462 | * Loads the Jetpack XML-RPC client |
||
| 4463 | */ |
||
| 4464 | public static function load_xml_rpc_client() { |
||
| 4468 | |||
| 4469 | function verify_xml_rpc_signature() { |
||
| 4567 | |||
| 4568 | /** |
||
| 4569 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 4570 | */ |
||
| 4571 | function authenticate_jetpack( $user, $username, $password ) { |
||
| 4594 | |||
| 4595 | function add_nonce( $timestamp, $nonce ) { |
||
| 4633 | |||
| 4634 | /** |
||
| 4635 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 4636 | * Capture it here so we can verify the signature later. |
||
| 4637 | */ |
||
| 4638 | function xmlrpc_methods( $methods ) { |
||
| 4642 | |||
| 4643 | function public_xmlrpc_methods( $methods ) { |
||
| 4649 | |||
| 4650 | function jetpack_getOptions( $args ) { |
||
| 4690 | |||
| 4691 | function xmlrpc_options( $options ) { |
||
| 4709 | |||
| 4710 | public static function clean_nonces( $all = false ) { |
||
| 4735 | |||
| 4736 | /** |
||
| 4737 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 4738 | * SET: state( $key, $value ); |
||
| 4739 | * GET: $value = state( $key ); |
||
| 4740 | * |
||
| 4741 | * @param string $key |
||
| 4742 | * @param string $value |
||
| 4743 | * @param bool $restate private |
||
| 4744 | */ |
||
| 4745 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 4795 | |||
| 4796 | public static function restate() { |
||
| 4799 | |||
| 4800 | public static function check_privacy( $file ) { |
||
| 4835 | |||
| 4836 | /** |
||
| 4837 | * Helper method for multicall XMLRPC. |
||
| 4838 | */ |
||
| 4839 | public static function xmlrpc_async_call() { |
||
| 4881 | |||
| 4882 | public static function staticize_subdomain( $url ) { |
||
| 4917 | |||
| 4918 | /* JSON API Authorization */ |
||
| 4919 | |||
| 4920 | /** |
||
| 4921 | * Handles the login action for Authorizing the JSON API |
||
| 4922 | */ |
||
| 4923 | function login_form_json_api_authorization() { |
||
| 4932 | |||
| 4933 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 4934 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 4947 | |||
| 4948 | // Make sure the POSTed request is handled by the same action |
||
| 4949 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 4953 | |||
| 4954 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 4955 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 4961 | |||
| 4962 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
| 4963 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 4967 | |||
| 4968 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 4969 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 4981 | |||
| 4982 | // Verifies the request by checking the signature |
||
| 4983 | function verify_json_api_authorization_request() { |
||
| 5062 | |||
| 5063 | function login_message_json_api_authorization( $message ) { |
||
| 5069 | |||
| 5070 | /** |
||
| 5071 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 5072 | */ |
||
| 5073 | public static function get_content_width() { |
||
| 5084 | |||
| 5085 | /** |
||
| 5086 | * Centralize the function here until it gets added to core. |
||
| 5087 | * |
||
| 5088 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 5089 | * @param int $size Size of the avatar image |
||
| 5090 | * @param string $default URL to a default image to use if no avatar is available |
||
| 5091 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 5092 | * |
||
| 5093 | * @return array First element is the URL, second is the class. |
||
| 5094 | */ |
||
| 5095 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 5123 | |||
| 5124 | /** |
||
| 5125 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 5126 | * |
||
| 5127 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 5128 | * |
||
| 5129 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 5130 | */ |
||
| 5131 | public function get_cloud_site_options( $option_names ) { |
||
| 5147 | |||
| 5148 | /** |
||
| 5149 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
| 5150 | * |
||
| 5151 | * @return array An array of options to check. |
||
| 5152 | */ |
||
| 5153 | public static function identity_crisis_options_to_check() { |
||
| 5159 | |||
| 5160 | /** |
||
| 5161 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
| 5162 | * |
||
| 5163 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
| 5164 | * |
||
| 5165 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
| 5166 | */ |
||
| 5167 | public static function check_identity_crisis( $force_recheck = false ) { |
||
| 5232 | |||
| 5233 | /** |
||
| 5234 | * Checks whether a value is already whitelisted. |
||
| 5235 | * |
||
| 5236 | * @param string $key The option name that we're checking the value for. |
||
| 5237 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
| 5238 | * |
||
| 5239 | * @return bool Whether the value is whitelisted. |
||
| 5240 | */ |
||
| 5241 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
| 5248 | |||
| 5249 | /** |
||
| 5250 | * Checks whether the home and siteurl specifically are whitelisted |
||
| 5251 | * Written so that we don't have re-check $key and $value params every time |
||
| 5252 | * we want to check if this site is whitelisted, for example in footer.php |
||
| 5253 | * |
||
| 5254 | * @since 3.8.0 |
||
| 5255 | * @return bool True = already whitelisted False = not whitelisted |
||
| 5256 | */ |
||
| 5257 | public static function is_staging_site() { |
||
| 5311 | |||
| 5312 | /** |
||
| 5313 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
| 5314 | * If set to true, the site will be put into staging mode. |
||
| 5315 | * |
||
| 5316 | * @since 4.4.0 |
||
| 5317 | * @return bool |
||
| 5318 | */ |
||
| 5319 | public static function sync_idc_optin() { |
||
| 5320 | /** |
||
| 5321 | * Allows sites to optin to IDC mitigation which blocks the site from syncing to WordPress.com when the home |
||
| 5322 | * URL or site URL do not match what WordPress.com expects. |
||
| 5323 | * The default value is either false, or the value of JETPACK_SYNC_IDC_OPTIN constant if set |
||
| 5324 | * |
||
| 5325 | * @since 4.4.0 |
||
| 5326 | * |
||
| 5327 | * @param bool |
||
| 5328 | */ |
||
| 5329 | $default = ( defined( 'JETPACK_SYNC_IDC_OPTIN' ) ) ? JETPACK_SYNC_IDC_OPTIN : false; |
||
| 5330 | return apply_filters( 'jetpack_sync_idc_optin', $default ); |
||
| 5331 | } |
||
| 5332 | |||
| 5333 | /** |
||
| 5334 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 5335 | * |
||
| 5336 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 5337 | */ |
||
| 5338 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 5373 | |||
| 5374 | /** |
||
| 5375 | * Maybe inlines a stylesheet. |
||
| 5376 | * |
||
| 5377 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 5378 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 5379 | * |
||
| 5380 | * Attached to `style_loader_tag` filter. |
||
| 5381 | * |
||
| 5382 | * @param string $tag The tag that would link to the external asset. |
||
| 5383 | * @param string $handle The registered handle of the script in question. |
||
| 5384 | * |
||
| 5385 | * @return string |
||
| 5386 | */ |
||
| 5387 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 5437 | |||
| 5438 | /** |
||
| 5439 | * Loads a view file from the views |
||
| 5440 | * |
||
| 5441 | * Data passed in with the $data parameter will be available in the |
||
| 5442 | * template file as $data['value'] |
||
| 5443 | * |
||
| 5444 | * @param string $template - Template file to load |
||
| 5445 | * @param array $data - Any data to pass along to the template |
||
| 5446 | * @return boolean - If template file was found |
||
| 5447 | **/ |
||
| 5448 | public function load_view( $template, $data = array() ) { |
||
| 5459 | |||
| 5460 | /** |
||
| 5461 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
| 5462 | */ |
||
| 5463 | public function deprecated_hooks() { |
||
| 5505 | |||
| 5506 | /** |
||
| 5507 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 5508 | * |
||
| 5509 | * Considerations: |
||
| 5510 | * - Normal, relative URLs `feh.png` |
||
| 5511 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 5512 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 5513 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 5514 | * - Domain root relative URLs `/feh.png` |
||
| 5515 | * |
||
| 5516 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 5517 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 5518 | * |
||
| 5519 | * @return mixed|string |
||
| 5520 | */ |
||
| 5521 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 5565 | |||
| 5566 | /** |
||
| 5567 | * This method checks to see if SSL is required by the site in |
||
| 5568 | * order to visit it in some way other than only setting the |
||
| 5569 | * https value in the home or siteurl values. |
||
| 5570 | * |
||
| 5571 | * @since 3.2 |
||
| 5572 | * @return boolean |
||
| 5573 | **/ |
||
| 5574 | private function is_ssl_required_to_visit_site() { |
||
| 5583 | |||
| 5584 | /** |
||
| 5585 | * This methods removes all of the registered css files on the front end |
||
| 5586 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 5587 | * all the files into one file. |
||
| 5588 | * |
||
| 5589 | * Pros: |
||
| 5590 | * - Uses only ONE css asset connection instead of 15 |
||
| 5591 | * - Saves a minimum of 56k |
||
| 5592 | * - Reduces server load |
||
| 5593 | * - Reduces time to first painted byte |
||
| 5594 | * |
||
| 5595 | * Cons: |
||
| 5596 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 5597 | * should not cause any issues with themes. |
||
| 5598 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 5599 | * jetpack_implode_frontend_css filter for a workaround |
||
| 5600 | * |
||
| 5601 | * For some situations developers may wish to disable css imploding and |
||
| 5602 | * instead operate in legacy mode where each file loads seperately and |
||
| 5603 | * can be edited individually or dequeued. This can be accomplished with |
||
| 5604 | * the following line: |
||
| 5605 | * |
||
| 5606 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 5607 | * |
||
| 5608 | * @since 3.2 |
||
| 5609 | **/ |
||
| 5610 | public function implode_frontend_css( $travis_test = false ) { |
||
| 5662 | |||
| 5663 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 5673 | |||
| 5674 | /* |
||
| 5675 | * Check the heartbeat data |
||
| 5676 | * |
||
| 5677 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 5678 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 5679 | * |
||
| 5680 | * Data will be added to "caution" array, if it either: |
||
| 5681 | * - Out of date Jetpack version |
||
| 5682 | * - Out of date WP version |
||
| 5683 | * - Out of date PHP version |
||
| 5684 | * |
||
| 5685 | * $return array $filtered_data |
||
| 5686 | */ |
||
| 5687 | public static function jetpack_check_heartbeat_data() { |
||
| 5740 | |||
| 5741 | |||
| 5742 | /* |
||
| 5743 | * This method is used to organize all options that can be reset |
||
| 5744 | * without disconnecting Jetpack. |
||
| 5745 | * |
||
| 5746 | * It is used in class.jetpack-cli.php to reset options |
||
| 5747 | * |
||
| 5748 | * @return array of options to delete. |
||
| 5749 | */ |
||
| 5750 | public static function get_jetpack_options_for_reset() { |
||
| 5817 | |||
| 5818 | /** |
||
| 5819 | * Check if an option of a Jetpack module has been updated. |
||
| 5820 | * |
||
| 5821 | * If any module option has been updated before Jump Start has been dismissed, |
||
| 5822 | * update the 'jumpstart' option so we can hide Jump Start. |
||
| 5823 | * |
||
| 5824 | * @param string $option_name |
||
| 5825 | * |
||
| 5826 | * @return bool |
||
| 5827 | */ |
||
| 5828 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
| 5849 | |||
| 5850 | /* |
||
| 5851 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 5852 | * so we can bring them directly to their site in calypso. |
||
| 5853 | * |
||
| 5854 | * @param string | url |
||
| 5855 | * @return string | url without the guff |
||
| 5856 | */ |
||
| 5857 | public static function build_raw_urls( $url ) { |
||
| 5863 | |||
| 5864 | /** |
||
| 5865 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 5866 | * |
||
| 5867 | * @param mixed $new_urls |
||
| 5868 | */ |
||
| 5869 | public static function dns_prefetch( $new_urls = null ) { |
||
| 5886 | |||
| 5887 | public function wp_dashboard_setup() { |
||
| 5915 | |||
| 5916 | /** |
||
| 5917 | * @param mixed $result Value for the user's option |
||
| 5918 | * @return mixed |
||
| 5919 | */ |
||
| 5920 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 5945 | |||
| 5946 | public static function dashboard_widget() { |
||
| 5954 | |||
| 5955 | public static function dashboard_widget_footer() { |
||
| 5988 | |||
| 5989 | public function dashboard_widget_connect_to_wpcom() { |
||
| 6011 | |||
| 6012 | /* |
||
| 6013 | * A graceful transition to using Core's site icon. |
||
| 6014 | * |
||
| 6015 | * All of the hard work has already been done with the image |
||
| 6016 | * in all_done_page(). All that needs to be done now is update |
||
| 6017 | * the option and display proper messaging. |
||
| 6018 | * |
||
| 6019 | * @todo remove when WP 4.3 is minimum |
||
| 6020 | * |
||
| 6021 | * @since 3.6.1 |
||
| 6022 | * |
||
| 6023 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
| 6024 | */ |
||
| 6025 | public static function jetpack_site_icon_available_in_core() { |
||
| 6060 | |||
| 6061 | /** |
||
| 6062 | * Return string containing the Jetpack logo. |
||
| 6063 | * |
||
| 6064 | * @since 3.9.0 |
||
| 6065 | * |
||
| 6066 | * @return string |
||
| 6067 | */ |
||
| 6068 | public static function get_jp_emblem() { |
||
| 6071 | |||
| 6072 | /* |
||
| 6073 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 6074 | */ |
||
| 6075 | function jetpack_icon_user_connected( $columns ) { |
||
| 6079 | |||
| 6080 | /* |
||
| 6081 | * Show Jetpack icon if the user is linked. |
||
| 6082 | */ |
||
| 6083 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 6095 | |||
| 6096 | /* |
||
| 6097 | * Style the Jetpack user column |
||
| 6098 | */ |
||
| 6099 | function jetpack_user_col_style() { |
||
| 6112 | |||
| 6113 | } |
||
| 6114 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.