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 | 'tiled-gallery', |
||
| 46 | 'widget-conditions', |
||
| 47 | 'jetpack_display_posts_widget', |
||
| 48 | 'gravatar-profile-widget', |
||
| 49 | 'widget-grid-and-list', |
||
| 50 | 'jetpack-widgets', |
||
| 51 | 'goodreads-widget', |
||
| 52 | 'jetpack_social_media_icons_widget', |
||
| 53 | ); |
||
| 54 | |||
| 55 | public $plugins_to_deactivate = array( |
||
| 56 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 57 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 58 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 59 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 60 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
| 61 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 62 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 63 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 64 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 65 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 66 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 67 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 68 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 69 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
| 70 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 71 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
| 72 | ); |
||
| 73 | |||
| 74 | static $capability_translations = array( |
||
|
|
|||
| 75 | 'administrator' => 'manage_options', |
||
| 76 | 'editor' => 'edit_others_posts', |
||
| 77 | 'author' => 'publish_posts', |
||
| 78 | 'contributor' => 'edit_posts', |
||
| 79 | 'subscriber' => 'read', |
||
| 80 | ); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 84 | * if the plugins are active. Used by filter_default_modules |
||
| 85 | * |
||
| 86 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 87 | * change `module-slug` and add this to your plugin: |
||
| 88 | * |
||
| 89 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 90 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 91 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 92 | * } |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | private $conflicting_plugins = array( |
||
| 97 | 'comments' => array( |
||
| 98 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 99 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 100 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 101 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 102 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 103 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 104 | ), |
||
| 105 | 'contact-form' => array( |
||
| 106 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 107 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 108 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 109 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 110 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 111 | ), |
||
| 112 | 'minileven' => array( |
||
| 113 | 'WPtouch' => 'wptouch/wptouch.php', |
||
| 114 | ), |
||
| 115 | 'latex' => array( |
||
| 116 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 117 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 118 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 119 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 120 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 121 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 122 | ), |
||
| 123 | 'protect' => array( |
||
| 124 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 125 | 'Captcha' => 'captcha/captcha.php', |
||
| 126 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 127 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 128 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 129 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 130 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 131 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 132 | 'Login Security' => 'login-security/login-security.php', |
||
| 133 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 134 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 135 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 136 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 137 | ), |
||
| 138 | 'random-redirect' => array( |
||
| 139 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 140 | ), |
||
| 141 | 'related-posts' => array( |
||
| 142 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 143 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 144 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 145 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 146 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 147 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 148 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 149 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 150 | ), |
||
| 151 | 'sharedaddy' => array( |
||
| 152 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 153 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 154 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 155 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 156 | ), |
||
| 157 | 'verification-tools' => array( |
||
| 158 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 159 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 160 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 161 | ), |
||
| 162 | 'widget-visibility' => array( |
||
| 163 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 164 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 165 | ), |
||
| 166 | 'sitemaps' => array( |
||
| 167 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 168 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 169 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 170 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 171 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 172 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 173 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 174 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 175 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 176 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 177 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 178 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 179 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 180 | ), |
||
| 181 | ); |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 185 | * |
||
| 186 | * Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate |
||
| 187 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 188 | * |
||
| 189 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 190 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 191 | */ |
||
| 192 | private $open_graph_conflicting_plugins = array( |
||
| 193 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 194 | // 2 Click Social Media Buttons |
||
| 195 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 196 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 197 | 'autodescription/autodescription.php', // The SEO Framework |
||
| 198 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 199 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 200 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 201 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 202 | // Facebook Featured Image & OG Meta Tags |
||
| 203 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 204 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 205 | // Facebook Open Graph Meta Tags for WordPress |
||
| 206 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 207 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 208 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 209 | // Fedmich's Facebook Open Graph Meta |
||
| 210 | 'header-footer/plugin.php', // Header and Footer |
||
| 211 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 212 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 213 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 214 | // NextScripts SNAP |
||
| 215 | 'opengraph/opengraph.php', // Open Graph |
||
| 216 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 217 | // Open Graph Protocol Framework |
||
| 218 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 219 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 220 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 221 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 222 | 'sharepress/sharepress.php', // SharePress |
||
| 223 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 224 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 225 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 226 | 'socialize/socialize.php', // Socialize |
||
| 227 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 228 | // Tweet, Like, Google +1 and Share |
||
| 229 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 230 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 231 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 232 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 233 | // WP Facebook Like Send & Open Graph Meta |
||
| 234 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 235 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 236 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 237 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
| 238 | ); |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 242 | */ |
||
| 243 | private $twitter_cards_conflicting_plugins = array( |
||
| 244 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 245 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 246 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 247 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 248 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 249 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 250 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 251 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 252 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 253 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 254 | ); |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Message to display in admin_notice |
||
| 258 | * @var string |
||
| 259 | */ |
||
| 260 | public $message = ''; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Error to display in admin_notice |
||
| 264 | * @var string |
||
| 265 | */ |
||
| 266 | public $error = ''; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Modules that need more privacy description. |
||
| 270 | * @var string |
||
| 271 | */ |
||
| 272 | public $privacy_checks = ''; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Stats to record once the page loads |
||
| 276 | * |
||
| 277 | * @var array |
||
| 278 | */ |
||
| 279 | public $stats = array(); |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Jetpack_Sync object |
||
| 283 | */ |
||
| 284 | public $sync; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Verified data for JSON authorization request |
||
| 288 | */ |
||
| 289 | public $json_api_authorization_request = array(); |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Holds the singleton instance of this class |
||
| 293 | * @since 2.3.3 |
||
| 294 | * @var Jetpack |
||
| 295 | */ |
||
| 296 | static $instance = false; |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Singleton |
||
| 300 | * @static |
||
| 301 | */ |
||
| 302 | public static function init() { |
||
| 303 | if ( ! self::$instance ) { |
||
| 304 | self::$instance = new Jetpack; |
||
| 305 | |||
| 306 | self::$instance->plugin_upgrade(); |
||
| 307 | } |
||
| 308 | |||
| 309 | return self::$instance; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Must never be called statically |
||
| 314 | */ |
||
| 315 | function plugin_upgrade() { |
||
| 316 | if ( Jetpack::is_active() ) { |
||
| 317 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 318 | if ( JETPACK__VERSION != $version ) { |
||
| 319 | |||
| 320 | // Check which active modules actually exist and remove others from active_modules list |
||
| 321 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
| 322 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
| 323 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
| 324 | Jetpack::update_active_modules( $modules ); |
||
| 325 | } |
||
| 326 | |||
| 327 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
| 328 | Jetpack::maybe_set_version_option(); |
||
| 329 | } |
||
| 330 | } |
||
| 331 | } |
||
| 332 | |||
| 333 | static function activate_manage( ) { |
||
| 334 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
| 335 | self::activate_module( 'manage', false, false ); |
||
| 336 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
| 337 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
| 338 | } |
||
| 339 | } |
||
| 340 | |||
| 341 | static function update_active_modules( $modules ) { |
||
| 342 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
| 343 | |||
| 344 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $modules ) ); |
||
| 345 | |||
| 346 | if ( is_array( $modules ) && is_array( $current_modules ) ) { |
||
| 347 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
| 348 | foreach( $new_active_modules as $module ) { |
||
| 349 | /** |
||
| 350 | * Fires when a specific module is activated. |
||
| 351 | * |
||
| 352 | * @since 1.9.0 |
||
| 353 | * |
||
| 354 | * @param string $module Module slug. |
||
| 355 | * @param boolean $success whether the module was activated. @since 4.2 |
||
| 356 | */ |
||
| 357 | do_action( 'jetpack_activate_module', $module, $success ); |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Fires when a module is activated. |
||
| 361 | * The dynamic part of the filter, $module, is the module slug. |
||
| 362 | * |
||
| 363 | * @since 1.9.0 |
||
| 364 | * |
||
| 365 | * @param string $module Module slug. |
||
| 366 | */ |
||
| 367 | do_action( "jetpack_activate_module_$module", $module ); |
||
| 368 | } |
||
| 369 | |||
| 370 | $new_deactive_modules = array_diff( $current_modules, $modules ); |
||
| 371 | foreach( $new_deactive_modules as $module ) { |
||
| 372 | /** |
||
| 373 | * Fired after a module has been deactivated. |
||
| 374 | * |
||
| 375 | * @since 4.2.0 |
||
| 376 | * |
||
| 377 | * @param string $module Module slug. |
||
| 378 | * @param boolean $success whether the module was deactivated. |
||
| 379 | */ |
||
| 380 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
| 381 | /** |
||
| 382 | * Fires when a module is deactivated. |
||
| 383 | * The dynamic part of the filter, $module, is the module slug. |
||
| 384 | * |
||
| 385 | * @since 1.9.0 |
||
| 386 | * |
||
| 387 | * @param string $module Module slug. |
||
| 388 | */ |
||
| 389 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
| 390 | } |
||
| 391 | } |
||
| 392 | |||
| 393 | return $success; |
||
| 394 | } |
||
| 395 | |||
| 396 | static function delete_active_modules() { |
||
| 397 | self::update_active_modules( array() ); |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Constructor. Initializes WordPress hooks |
||
| 402 | */ |
||
| 403 | private function __construct() { |
||
| 404 | /* |
||
| 405 | * Check for and alert any deprecated hooks |
||
| 406 | */ |
||
| 407 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 408 | |||
| 409 | |||
| 410 | /* |
||
| 411 | * Load things that should only be in Network Admin. |
||
| 412 | * |
||
| 413 | * For now blow away everything else until a more full |
||
| 414 | * understanding of what is needed at the network level is |
||
| 415 | * available |
||
| 416 | */ |
||
| 417 | if( is_multisite() ) { |
||
| 418 | Jetpack_Network::init(); |
||
| 419 | } |
||
| 420 | |||
| 421 | // Unlink user before deleting the user from .com |
||
| 422 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 423 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 424 | |||
| 425 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
| 426 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
| 427 | |||
| 428 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
| 429 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
| 430 | |||
| 431 | $this->require_jetpack_authentication(); |
||
| 432 | |||
| 433 | if ( Jetpack::is_active() ) { |
||
| 434 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
| 435 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
| 436 | |||
| 437 | $signed = $this->verify_xml_rpc_signature(); |
||
| 438 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
| 439 | // The actual API methods. |
||
| 440 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
| 441 | } else { |
||
| 442 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
| 443 | // active Jetpack connection, so that additional users can link their account. |
||
| 444 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
| 445 | } |
||
| 446 | } else { |
||
| 447 | // The bootstrap API methods. |
||
| 448 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
| 449 | } |
||
| 450 | |||
| 451 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
| 452 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
| 453 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
| 454 | $this->require_jetpack_authentication(); |
||
| 455 | $this->add_remote_request_handlers(); |
||
| 456 | } else { |
||
| 457 | if ( Jetpack::is_active() ) { |
||
| 458 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
| 459 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | if ( Jetpack::is_active() ) { |
||
| 464 | Jetpack_Heartbeat::init(); |
||
| 465 | } |
||
| 466 | |||
| 467 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
| 468 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
| 469 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
| 470 | } |
||
| 471 | |||
| 472 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
| 473 | |||
| 474 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 475 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 476 | |||
| 477 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
| 478 | |||
| 479 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 480 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 481 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 482 | |||
| 483 | // returns HTTPS support status |
||
| 484 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
| 485 | |||
| 486 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
| 487 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
| 488 | |||
| 489 | // Identity Crisis AJAX callback function |
||
| 490 | add_action( 'wp_ajax_jetpack_resolve_identity_crisis', array( $this, 'resolve_identity_crisis_ajax_callback' ) ); |
||
| 491 | |||
| 492 | // JITM AJAX callback function |
||
| 493 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
| 494 | |||
| 495 | add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) ); |
||
| 496 | add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) ); |
||
| 497 | |||
| 498 | // Universal ajax callback for all tracking events triggered via js |
||
| 499 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
| 500 | |||
| 501 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 502 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 503 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 504 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 505 | |||
| 506 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
| 507 | |||
| 508 | /** |
||
| 509 | * These actions run checks to load additional files. |
||
| 510 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 511 | */ |
||
| 512 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 513 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 514 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 515 | |||
| 516 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 517 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 518 | |||
| 519 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
| 520 | |||
| 521 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 522 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 523 | |||
| 524 | // A filter to control all just in time messages |
||
| 525 | add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); |
||
| 526 | |||
| 527 | /** |
||
| 528 | * This is the hack to concatinate all css files into one. |
||
| 529 | * For description and reasoning see the implode_frontend_css method |
||
| 530 | * |
||
| 531 | * Super late priority so we catch all the registered styles |
||
| 532 | */ |
||
| 533 | if( !is_admin() ) { |
||
| 534 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 535 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 536 | } |
||
| 537 | |||
| 538 | } |
||
| 539 | |||
| 540 | function jetpack_admin_ajax_tracks_callback() { |
||
| 541 | // Check for nonce |
||
| 542 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
| 543 | wp_die( 'Permissions check failed.' ); |
||
| 544 | } |
||
| 545 | |||
| 546 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
| 547 | wp_die( 'No valid event name or type.' ); |
||
| 548 | } |
||
| 549 | |||
| 550 | $tracks_data = array(); |
||
| 551 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
| 552 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
| 553 | } |
||
| 554 | |||
| 555 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
| 556 | wp_send_json_success(); |
||
| 557 | wp_die(); |
||
| 558 | } |
||
| 559 | |||
| 560 | function jetpack_admin_ajax_callback() { |
||
| 561 | // Check for nonce |
||
| 562 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) || ! current_user_can( 'jetpack_manage_modules' ) ) { |
|
| 563 | wp_die( 'permissions check failed' ); |
||
| 564 | } |
||
| 565 | |||
| 566 | if ( isset( $_REQUEST['toggleModule'] ) && 'nux-toggle-module' == $_REQUEST['toggleModule'] ) { |
||
| 567 | $slug = $_REQUEST['thisModuleSlug']; |
||
| 568 | |||
| 569 | if ( ! in_array( $slug, Jetpack::get_available_modules() ) ) { |
||
| 570 | wp_die( 'That is not a Jetpack module slug' ); |
||
| 571 | } |
||
| 572 | |||
| 573 | if ( Jetpack::is_module_active( $slug ) ) { |
||
| 574 | Jetpack::deactivate_module( $slug ); |
||
| 575 | } else { |
||
| 576 | Jetpack::activate_module( $slug, false, false ); |
||
| 577 | } |
||
| 578 | |||
| 579 | $modules = Jetpack_Admin::init()->get_modules(); |
||
| 580 | echo json_encode( $modules[ $slug ] ); |
||
| 581 | |||
| 582 | exit; |
||
| 583 | } |
||
| 584 | |||
| 585 | wp_die(); |
||
| 586 | } |
||
| 587 | |||
| 588 | /* |
||
| 589 | * Sometimes we need to refresh the data, |
||
| 590 | * especially if the page is visited via a 'history' |
||
| 591 | * event like back/forward |
||
| 592 | */ |
||
| 593 | function jetpack_admin_ajax_refresh_data() { |
||
| 594 | // Check for nonce |
||
| 595 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) ) { |
|
| 596 | wp_die( 'permissions check failed' ); |
||
| 597 | } |
||
| 598 | |||
| 599 | if ( isset( $_REQUEST['refreshData'] ) && 'refresh' == $_REQUEST['refreshData'] ) { |
||
| 600 | $modules = Jetpack_Admin::init()->get_modules(); |
||
| 601 | echo json_encode( $modules ); |
||
| 602 | exit; |
||
| 603 | } |
||
| 604 | |||
| 605 | wp_die(); |
||
| 606 | } |
||
| 607 | |||
| 608 | /** |
||
| 609 | * The callback for the JITM ajax requests. |
||
| 610 | */ |
||
| 611 | function jetpack_jitm_ajax_callback() { |
||
| 612 | // Check for nonce |
||
| 613 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
| 614 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
| 615 | } |
||
| 616 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
| 617 | $module_slug = $_REQUEST['jitmModule']; |
||
| 618 | Jetpack::log( 'activate', $module_slug ); |
||
| 619 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 620 | Jetpack::state( 'message', 'no_message' ); |
||
| 621 | |||
| 622 | //A Jetpack module is being activated through a JITM, track it |
||
| 623 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
| 624 | $this->do_stats( 'server_side' ); |
||
| 625 | |||
| 626 | wp_send_json_success(); |
||
| 627 | } |
||
| 628 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
| 629 | // get the hide_jitm options array |
||
| 630 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
| 631 | $module_slug = $_REQUEST['jitmModule']; |
||
| 632 | |||
| 633 | if( ! $jetpack_hide_jitm ) { |
||
| 634 | $jetpack_hide_jitm = array( |
||
| 635 | $module_slug => 'hide' |
||
| 636 | ); |
||
| 637 | } else { |
||
| 638 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
| 639 | } |
||
| 640 | |||
| 641 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
| 642 | |||
| 643 | //jitm is being dismissed forever, track it |
||
| 644 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
| 645 | $this->do_stats( 'server_side' ); |
||
| 646 | |||
| 647 | wp_send_json_success(); |
||
| 648 | } |
||
| 649 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
| 650 | $module_slug = $_REQUEST['jitmModule']; |
||
| 651 | |||
| 652 | // User went to WordPress.com, track this |
||
| 653 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
| 654 | $this->do_stats( 'server_side' ); |
||
| 655 | |||
| 656 | wp_send_json_success(); |
||
| 657 | } |
||
| 658 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
| 659 | $track = $_REQUEST['jitmModule']; |
||
| 660 | |||
| 661 | // User is viewing JITM, track it. |
||
| 662 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
| 663 | $this->do_stats( 'server_side' ); |
||
| 664 | |||
| 665 | wp_send_json_success(); |
||
| 666 | } |
||
| 667 | } |
||
| 668 | |||
| 669 | /** |
||
| 670 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 671 | */ |
||
| 672 | function __destruct() { |
||
| 673 | if ( ! empty( $this->stats ) ) { |
||
| 674 | $this->do_stats( 'server_side' ); |
||
| 675 | } |
||
| 676 | } |
||
| 677 | |||
| 678 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 679 | switch( $cap ) { |
||
| 680 | case 'jetpack_connect' : |
||
| 681 | case 'jetpack_reconnect' : |
||
| 682 | if ( Jetpack::is_development_mode() ) { |
||
| 683 | $caps = array( 'do_not_allow' ); |
||
| 684 | break; |
||
| 685 | } |
||
| 686 | /** |
||
| 687 | * Pass through. If it's not development mode, these should match disconnect. |
||
| 688 | * Let users disconnect if it's development mode, just in case things glitch. |
||
| 689 | */ |
||
| 690 | case 'jetpack_disconnect' : |
||
| 691 | /** |
||
| 692 | * In multisite, can individual site admins manage their own connection? |
||
| 693 | * |
||
| 694 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
| 695 | */ |
||
| 696 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
| 697 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
| 698 | /** |
||
| 699 | * We need to update the option name -- it's terribly unclear which |
||
| 700 | * direction the override goes. |
||
| 701 | * |
||
| 702 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
| 703 | */ |
||
| 704 | $caps = array( 'do_not_allow' ); |
||
| 705 | break; |
||
| 706 | } |
||
| 707 | } |
||
| 708 | |||
| 709 | $caps = array( 'manage_options' ); |
||
| 710 | break; |
||
| 711 | case 'jetpack_manage_modules' : |
||
| 712 | case 'jetpack_activate_modules' : |
||
| 713 | case 'jetpack_deactivate_modules' : |
||
| 714 | $caps = array( 'manage_options' ); |
||
| 715 | break; |
||
| 716 | case 'jetpack_configure_modules' : |
||
| 717 | $caps = array( 'manage_options' ); |
||
| 718 | break; |
||
| 719 | case 'jetpack_network_admin_page': |
||
| 720 | case 'jetpack_network_settings_page': |
||
| 721 | $caps = array( 'manage_network_plugins' ); |
||
| 722 | break; |
||
| 723 | case 'jetpack_network_sites_page': |
||
| 724 | $caps = array( 'manage_sites' ); |
||
| 725 | break; |
||
| 726 | case 'jetpack_admin_page' : |
||
| 727 | if ( Jetpack::is_development_mode() ) { |
||
| 728 | $caps = array( 'manage_options' ); |
||
| 729 | break; |
||
| 730 | } else { |
||
| 731 | $caps = array( 'read' ); |
||
| 732 | } |
||
| 733 | break; |
||
| 734 | case 'jetpack_connect_user' : |
||
| 735 | if ( Jetpack::is_development_mode() ) { |
||
| 736 | $caps = array( 'do_not_allow' ); |
||
| 737 | break; |
||
| 738 | } |
||
| 739 | $caps = array( 'read' ); |
||
| 740 | break; |
||
| 741 | } |
||
| 742 | return $caps; |
||
| 743 | } |
||
| 744 | |||
| 745 | function require_jetpack_authentication() { |
||
| 746 | // Don't let anyone authenticate |
||
| 747 | $_COOKIE = array(); |
||
| 748 | remove_all_filters( 'authenticate' ); |
||
| 749 | remove_all_actions( 'wp_login_failed' ); |
||
| 750 | |||
| 751 | if ( Jetpack::is_active() ) { |
||
| 752 | // Allow Jetpack authentication |
||
| 753 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
| 754 | } |
||
| 755 | } |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Load language files |
||
| 759 | * @action plugins_loaded |
||
| 760 | */ |
||
| 761 | public static function plugin_textdomain() { |
||
| 762 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
| 763 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
| 764 | } |
||
| 765 | |||
| 766 | /** |
||
| 767 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 768 | * |
||
| 769 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 770 | * @action wp_loaded |
||
| 771 | * @return null |
||
| 772 | */ |
||
| 773 | public function register_assets() { |
||
| 774 | View Code Duplication | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
|
| 775 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
| 776 | } |
||
| 777 | |||
| 778 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
| 779 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
| 780 | } |
||
| 781 | |||
| 782 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 783 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
| 784 | } |
||
| 785 | |||
| 786 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
| 787 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
| 788 | } |
||
| 789 | |||
| 790 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 791 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
| 792 | |||
| 793 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 794 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 795 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 796 | $fb_app_id = ''; |
||
| 797 | } |
||
| 798 | wp_localize_script( |
||
| 799 | 'jetpack-facebook-embed', |
||
| 800 | 'jpfbembed', |
||
| 801 | array( |
||
| 802 | 'appid' => $fb_app_id, |
||
| 803 | 'locale' => $this->get_locale(), |
||
| 804 | ) |
||
| 805 | ); |
||
| 806 | } |
||
| 807 | |||
| 808 | /** |
||
| 809 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 810 | * the hook may have already fired by this point. |
||
| 811 | * So, let's just trigger it manually. |
||
| 812 | */ |
||
| 813 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
| 814 | jetpack_register_genericons(); |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Register the social logos |
||
| 818 | */ |
||
| 819 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
| 820 | jetpack_register_social_logos(); |
||
| 821 | |||
| 822 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
| 823 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 824 | } |
||
| 825 | |||
| 826 | /** |
||
| 827 | * Guess locale from language code. |
||
| 828 | * |
||
| 829 | * @param string $lang Language code. |
||
| 830 | * @return string|bool |
||
| 831 | */ |
||
| 832 | function guess_locale_from_lang( $lang ) { |
||
| 833 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
| 834 | return 'en_US'; |
||
| 835 | } |
||
| 836 | |||
| 837 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
| 838 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
| 839 | return false; |
||
| 840 | } |
||
| 841 | |||
| 842 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
| 843 | } |
||
| 844 | |||
| 845 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 846 | // WP.com: get_locale() returns 'it' |
||
| 847 | $locale = GP_Locales::by_slug( $lang ); |
||
| 848 | } else { |
||
| 849 | // Jetpack: get_locale() returns 'it_IT'; |
||
| 850 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
| 851 | } |
||
| 852 | |||
| 853 | if ( ! $locale ) { |
||
| 854 | return false; |
||
| 855 | } |
||
| 856 | |||
| 857 | if ( empty( $locale->facebook_locale ) ) { |
||
| 858 | if ( empty( $locale->wp_locale ) ) { |
||
| 859 | return false; |
||
| 860 | } else { |
||
| 861 | // Facebook SDK is smart enough to fall back to en_US if a |
||
| 862 | // locale isn't supported. Since supported Facebook locales |
||
| 863 | // can fall out of sync, we'll attempt to use the known |
||
| 864 | // wp_locale value and rely on said fallback. |
||
| 865 | return $locale->wp_locale; |
||
| 866 | } |
||
| 867 | } |
||
| 868 | |||
| 869 | return $locale->facebook_locale; |
||
| 870 | } |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Get the locale. |
||
| 874 | * |
||
| 875 | * @return string|bool |
||
| 876 | */ |
||
| 877 | function get_locale() { |
||
| 878 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
| 879 | |||
| 880 | if ( ! $locale ) { |
||
| 881 | $locale = 'en_US'; |
||
| 882 | } |
||
| 883 | |||
| 884 | return $locale; |
||
| 885 | } |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Device Pixels support |
||
| 889 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
| 890 | */ |
||
| 891 | function devicepx() { |
||
| 892 | if ( Jetpack::is_active() ) { |
||
| 893 | wp_enqueue_script( 'devicepx', set_url_scheme( 'http://s0.wp.com/wp-content/js/devicepx-jetpack.js' ), array(), gmdate( 'oW' ), true ); |
||
| 894 | } |
||
| 895 | } |
||
| 896 | |||
| 897 | /** |
||
| 898 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 899 | * @param bool $option |
||
| 900 | * @return string |
||
| 901 | */ |
||
| 902 | public function jetpack_main_network_site_option( $option ) { |
||
| 903 | return network_site_url(); |
||
| 904 | } |
||
| 905 | /** |
||
| 906 | * Network Name. |
||
| 907 | */ |
||
| 908 | static function network_name( $option = null ) { |
||
| 909 | global $current_site; |
||
| 910 | return $current_site->site_name; |
||
| 911 | } |
||
| 912 | /** |
||
| 913 | * Does the network allow new user and site registrations. |
||
| 914 | * @return string |
||
| 915 | */ |
||
| 916 | static function network_allow_new_registrations( $option = null ) { |
||
| 917 | return ( in_array( get_site_option( 'registration' ), array('none', 'user', 'blog', 'all' ) ) ? get_site_option( 'registration') : 'none' ); |
||
| 918 | } |
||
| 919 | /** |
||
| 920 | * Does the network allow admins to add new users. |
||
| 921 | * @return boolian |
||
| 922 | */ |
||
| 923 | static function network_add_new_users( $option = null ) { |
||
| 924 | return (bool) get_site_option( 'add_new_users' ); |
||
| 925 | } |
||
| 926 | /** |
||
| 927 | * File upload psace left per site in MB. |
||
| 928 | * -1 means NO LIMIT. |
||
| 929 | * @return number |
||
| 930 | */ |
||
| 931 | static function network_site_upload_space( $option = null ) { |
||
| 932 | // value in MB |
||
| 933 | return ( get_site_option( 'upload_space_check_disabled' ) ? -1 : get_space_allowed() ); |
||
| 934 | } |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Network allowed file types. |
||
| 938 | * @return string |
||
| 939 | */ |
||
| 940 | static function network_upload_file_types( $option = null ) { |
||
| 941 | return get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ); |
||
| 942 | } |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Maximum file upload size set by the network. |
||
| 946 | * @return number |
||
| 947 | */ |
||
| 948 | static function network_max_upload_file_size( $option = null ) { |
||
| 949 | // value in KB |
||
| 950 | return get_site_option( 'fileupload_maxk', 300 ); |
||
| 951 | } |
||
| 952 | |||
| 953 | /** |
||
| 954 | * Lets us know if a site allows admins to manage the network. |
||
| 955 | * @return array |
||
| 956 | */ |
||
| 957 | static function network_enable_administration_menus( $option = null ) { |
||
| 958 | return get_site_option( 'menu_items' ); |
||
| 959 | } |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Return whether we are dealing with a multi network setup or not. |
||
| 963 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 964 | * the result is false since when is_main_network_option return false it cases |
||
| 965 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 966 | * database which could be set to anything as opposed to what this function returns. |
||
| 967 | * @param bool $option |
||
| 968 | * |
||
| 969 | * @return boolean |
||
| 970 | */ |
||
| 971 | public function is_main_network_option( $option ) { |
||
| 972 | // return '1' or '' |
||
| 973 | return (string) (bool) Jetpack::is_multi_network(); |
||
| 974 | } |
||
| 975 | |||
| 976 | /** |
||
| 977 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 978 | * |
||
| 979 | * @param string $option |
||
| 980 | * @return boolean |
||
| 981 | */ |
||
| 982 | public function is_multisite( $option ) { |
||
| 983 | return (string) (bool) is_multisite(); |
||
| 984 | } |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Implemented since there is no core is multi network function |
||
| 988 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 989 | * |
||
| 990 | * @since 3.3 |
||
| 991 | * @return boolean |
||
| 992 | */ |
||
| 993 | public static function is_multi_network() { |
||
| 994 | global $wpdb; |
||
| 995 | |||
| 996 | // if we don't have a multi site setup no need to do any more |
||
| 997 | if ( ! is_multisite() ) { |
||
| 998 | return false; |
||
| 999 | } |
||
| 1000 | |||
| 1001 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
| 1002 | if ( $num_sites > 1 ) { |
||
| 1003 | return true; |
||
| 1004 | } else { |
||
| 1005 | return false; |
||
| 1006 | } |
||
| 1007 | } |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1011 | * @return null |
||
| 1012 | */ |
||
| 1013 | function update_jetpack_main_network_site_option() { |
||
| 1014 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1015 | } |
||
| 1016 | /** |
||
| 1017 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1018 | * |
||
| 1019 | */ |
||
| 1020 | function update_jetpack_network_settings() { |
||
| 1021 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1022 | // Only sync this info for the main network site. |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Get back if the current site is single user site. |
||
| 1027 | * |
||
| 1028 | * @return bool |
||
| 1029 | */ |
||
| 1030 | public static function is_single_user_site() { |
||
| 1031 | $user_query = new WP_User_Query( array( |
||
| 1032 | 'blog_id' => get_current_blog_id(), |
||
| 1033 | 'fields' => 'ID', |
||
| 1034 | 'number' => 2 |
||
| 1035 | ) ); |
||
| 1036 | return 1 === (int) $user_query->get_total(); |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Returns true if the site has file write access false otherwise. |
||
| 1041 | * @return string ( '1' | '0' ) |
||
| 1042 | **/ |
||
| 1043 | public static function file_system_write_access() { |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Finds out if a site is using a version control system. |
||
| 1066 | * @return string ( '1' | '0' ) |
||
| 1067 | **/ |
||
| 1068 | public static function is_version_controlled() { |
||
| 1069 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); |
||
| 1070 | return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); |
||
| 1071 | } |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Determines whether the current theme supports featured images or not. |
||
| 1075 | * @return string ( '1' | '0' ) |
||
| 1076 | */ |
||
| 1077 | public static function featured_images_enabled() { |
||
| 1078 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1079 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * jetpack_updates is saved in the following schema: |
||
| 1084 | * |
||
| 1085 | * array ( |
||
| 1086 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1087 | * 'themes' => (int) Number of theme updates available. |
||
| 1088 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1089 | * 'translations' => (int) Number of translation updates available. |
||
| 1090 | * 'total' => (int) Total of all available updates. |
||
| 1091 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1092 | * ) |
||
| 1093 | * @return array |
||
| 1094 | */ |
||
| 1095 | public static function get_updates() { |
||
| 1112 | |||
| 1113 | public static function get_update_details() { |
||
| 1121 | |||
| 1122 | public static function refresh_update_data() { |
||
| 1126 | |||
| 1127 | public static function refresh_theme_data() { |
||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Is Jetpack active? |
||
| 1133 | */ |
||
| 1134 | public static function is_active() { |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * Is Jetpack in development (offline) mode? |
||
| 1140 | */ |
||
| 1141 | public static function is_development_mode() { |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Get Jetpack development mode notice text and notice class. |
||
| 1165 | * |
||
| 1166 | * Mirrors the checks made in Jetpack::is_development_mode |
||
| 1167 | * |
||
| 1168 | */ |
||
| 1169 | public static function show_development_mode_notice() { |
||
| 1209 | |||
| 1210 | /** |
||
| 1211 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1212 | */ |
||
| 1213 | public static function is_development_version() { |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1219 | */ |
||
| 1220 | public static function is_user_connected( $user_id = false ) { |
||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * Get the wpcom user data of the current|specified connected user. |
||
| 1231 | */ |
||
| 1232 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1233 | if ( ! $user_id ) { |
||
| 1234 | $user_id = get_current_user_id(); |
||
| 1235 | } |
||
| 1236 | |||
| 1237 | $transient_key = "jetpack_connected_user_data_$user_id"; |
||
| 1238 | |||
| 1239 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
||
| 1240 | return $cached_user_data; |
||
| 1241 | } |
||
| 1242 | |||
| 1243 | Jetpack::load_xml_rpc_client(); |
||
| 1244 | $xml = new Jetpack_IXR_Client( array( |
||
| 1245 | 'user_id' => $user_id, |
||
| 1246 | ) ); |
||
| 1247 | $xml->query( 'wpcom.getUser' ); |
||
| 1248 | if ( ! $xml->isError() ) { |
||
| 1249 | $user_data = $xml->getResponse(); |
||
| 1250 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
||
| 1251 | return $user_data; |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | return false; |
||
| 1255 | } |
||
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Get the wpcom email of the current|specified connected user. |
||
| 1259 | */ |
||
| 1260 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
| 1274 | |||
| 1275 | /** |
||
| 1276 | * Get the wpcom email of the master user. |
||
| 1277 | */ |
||
| 1278 | public static function get_master_user_email() { |
||
| 1285 | |||
| 1286 | function current_user_is_connection_owner() { |
||
| 1290 | |||
| 1291 | /** |
||
| 1292 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
| 1293 | */ |
||
| 1294 | function extra_oembed_providers() { |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Synchronize connected user role changes |
||
| 1305 | */ |
||
| 1306 | function user_role_change( $user_id ) { |
||
| 1310 | |||
| 1311 | /** |
||
| 1312 | * Loads the currently active modules. |
||
| 1313 | */ |
||
| 1314 | public static function load_modules() { |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Check if Jetpack's REST API compat file should be included |
||
| 1401 | * @action plugins_loaded |
||
| 1402 | * @return null |
||
| 1403 | */ |
||
| 1404 | public function check_rest_api_compat() { |
||
| 1420 | |||
| 1421 | /** |
||
| 1422 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 1423 | * traditionally activated or network activated. |
||
| 1424 | * |
||
| 1425 | * @todo Store the result in core's object cache maybe? |
||
| 1426 | */ |
||
| 1427 | public static function get_active_plugins() { |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 1446 | * |
||
| 1447 | * @since 3.8.1 |
||
| 1448 | * |
||
| 1449 | * @return array Array of plugin data |
||
| 1450 | */ |
||
| 1451 | public static function get_parsed_plugin_data() { |
||
| 1472 | |||
| 1473 | /** |
||
| 1474 | * Gets and parses theme data to send with the heartbeat data |
||
| 1475 | * |
||
| 1476 | * @since 3.8.1 |
||
| 1477 | * |
||
| 1478 | * @return array Array of theme data |
||
| 1479 | */ |
||
| 1480 | public static function get_parsed_theme_data() { |
||
| 1502 | |||
| 1503 | /** |
||
| 1504 | * Checks whether a specific plugin is active. |
||
| 1505 | * |
||
| 1506 | * We don't want to store these in a static variable, in case |
||
| 1507 | * there are switch_to_blog() calls involved. |
||
| 1508 | */ |
||
| 1509 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Check if Jetpack's Open Graph tags should be used. |
||
| 1515 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 1516 | * |
||
| 1517 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1518 | * @action plugins_loaded |
||
| 1519 | * @return null |
||
| 1520 | */ |
||
| 1521 | public function check_open_graph() { |
||
| 1548 | |||
| 1549 | /** |
||
| 1550 | * Check if Jetpack's Twitter tags should be used. |
||
| 1551 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 1552 | * |
||
| 1553 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1554 | * @action plugins_loaded |
||
| 1555 | * @return null |
||
| 1556 | */ |
||
| 1557 | public function check_twitter_tags() { |
||
| 1581 | |||
| 1582 | /** |
||
| 1583 | * Allows plugins to submit security reports. |
||
| 1584 | * |
||
| 1585 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 1586 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 1587 | * @param array $args See definitions above |
||
| 1588 | */ |
||
| 1589 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 1592 | |||
| 1593 | /* Jetpack Options API */ |
||
| 1594 | |||
| 1595 | public static function get_option_names( $type = 'compact' ) { |
||
| 1598 | |||
| 1599 | /** |
||
| 1600 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 1601 | * |
||
| 1602 | * @param string $name Option name |
||
| 1603 | * @param mixed $default (optional) |
||
| 1604 | */ |
||
| 1605 | public static function get_option( $name, $default = false ) { |
||
| 1608 | |||
| 1609 | /** |
||
| 1610 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
| 1611 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
| 1612 | * $name must be a registered option name. |
||
| 1613 | */ |
||
| 1614 | public static function create_nonce( $name ) { |
||
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 1631 | * |
||
| 1632 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 1633 | * @param string $name Option name |
||
| 1634 | * @param mixed $value Option value |
||
| 1635 | */ |
||
| 1636 | public static function update_option( $name, $value ) { |
||
| 1640 | |||
| 1641 | /** |
||
| 1642 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 1643 | * |
||
| 1644 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 1645 | * @param array $array array( option name => option value, ... ) |
||
| 1646 | */ |
||
| 1647 | public static function update_options( $array ) { |
||
| 1651 | |||
| 1652 | /** |
||
| 1653 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 1654 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 1655 | * |
||
| 1656 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 1657 | * @param string|array $names |
||
| 1658 | */ |
||
| 1659 | public static function delete_option( $names ) { |
||
| 1663 | |||
| 1664 | /** |
||
| 1665 | * Enters a user token into the user_tokens option |
||
| 1666 | * |
||
| 1667 | * @param int $user_id |
||
| 1668 | * @param string $token |
||
| 1669 | * return bool |
||
| 1670 | */ |
||
| 1671 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 1685 | |||
| 1686 | /** |
||
| 1687 | * Returns an array of all PHP files in the specified absolute path. |
||
| 1688 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 1689 | * |
||
| 1690 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 1691 | * @return array Array of absolute paths to the PHP files. |
||
| 1692 | */ |
||
| 1693 | public static function glob_php( $absolute_path ) { |
||
| 1722 | |||
| 1723 | public static function activate_new_modules( $redirect = false ) { |
||
| 1781 | |||
| 1782 | /** |
||
| 1783 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 1784 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 1785 | */ |
||
| 1786 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 1843 | |||
| 1844 | /** |
||
| 1845 | * Default modules loaded on activation. |
||
| 1846 | */ |
||
| 1847 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 1878 | |||
| 1879 | /** |
||
| 1880 | * Checks activated modules during auto-activation to determine |
||
| 1881 | * if any of those modules are being deprecated. If so, close |
||
| 1882 | * them out, and add any replacement modules. |
||
| 1883 | * |
||
| 1884 | * Runs at priority 99 by default. |
||
| 1885 | * |
||
| 1886 | * This is run late, so that it can still activate a module if |
||
| 1887 | * the new module is a replacement for another that the user |
||
| 1888 | * currently has active, even if something at the normal priority |
||
| 1889 | * would kibosh everything. |
||
| 1890 | * |
||
| 1891 | * @since 2.6 |
||
| 1892 | * @uses jetpack_get_default_modules filter |
||
| 1893 | * @param array $modules |
||
| 1894 | * @return array |
||
| 1895 | */ |
||
| 1896 | function handle_deprecated_modules( $modules ) { |
||
| 1922 | |||
| 1923 | /** |
||
| 1924 | * Checks activated plugins during auto-activation to determine |
||
| 1925 | * if any of those plugins are in the list with a corresponding module |
||
| 1926 | * that is not compatible with the plugin. The module will not be allowed |
||
| 1927 | * to auto-activate. |
||
| 1928 | * |
||
| 1929 | * @since 2.6 |
||
| 1930 | * @uses jetpack_get_default_modules filter |
||
| 1931 | * @param array $modules |
||
| 1932 | * @return array |
||
| 1933 | */ |
||
| 1934 | function filter_default_modules( $modules ) { |
||
| 1958 | |||
| 1959 | /** |
||
| 1960 | * Extract a module's slug from its full path. |
||
| 1961 | */ |
||
| 1962 | public static function get_module_slug( $file ) { |
||
| 1965 | |||
| 1966 | /** |
||
| 1967 | * Generate a module's path from its slug. |
||
| 1968 | */ |
||
| 1969 | public static function get_module_path( $slug ) { |
||
| 1972 | |||
| 1973 | /** |
||
| 1974 | * Load module data from module file. Headers differ from WordPress |
||
| 1975 | * plugin headers to avoid them being identified as standalone |
||
| 1976 | * plugins on the WordPress plugins page. |
||
| 1977 | */ |
||
| 1978 | public static function get_module( $module ) { |
||
| 2061 | |||
| 2062 | /** |
||
| 2063 | * Like core's get_file_data implementation, but caches the result. |
||
| 2064 | */ |
||
| 2065 | public static function get_file_data( $file, $headers ) { |
||
| 2086 | |||
| 2087 | /** |
||
| 2088 | * Return translated module tag. |
||
| 2089 | * |
||
| 2090 | * @param string $tag Tag as it appears in each module heading. |
||
| 2091 | * |
||
| 2092 | * @return mixed |
||
| 2093 | */ |
||
| 2094 | public static function translate_module_tag( $tag ) { |
||
| 2097 | |||
| 2098 | /** |
||
| 2099 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2100 | * |
||
| 2101 | * @since 3.9.2 |
||
| 2102 | * |
||
| 2103 | * @param array $modules |
||
| 2104 | * |
||
| 2105 | * @return string|void |
||
| 2106 | */ |
||
| 2107 | public static function get_translated_modules( $modules ) { |
||
| 2120 | |||
| 2121 | /** |
||
| 2122 | * Get a list of activated modules as an array of module slugs. |
||
| 2123 | */ |
||
| 2124 | public static function get_active_modules() { |
||
| 2141 | |||
| 2142 | /** |
||
| 2143 | * Check whether or not a Jetpack module is active. |
||
| 2144 | * |
||
| 2145 | * @param string $module The slug of a Jetpack module. |
||
| 2146 | * @return bool |
||
| 2147 | * |
||
| 2148 | * @static |
||
| 2149 | */ |
||
| 2150 | public static function is_module_active( $module ) { |
||
| 2153 | |||
| 2154 | public static function is_module( $module ) { |
||
| 2157 | |||
| 2158 | /** |
||
| 2159 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2160 | * |
||
| 2161 | * @param bool $catch True to start catching, False to stop. |
||
| 2162 | * |
||
| 2163 | * @static |
||
| 2164 | */ |
||
| 2165 | public static function catch_errors( $catch ) { |
||
| 2178 | |||
| 2179 | /** |
||
| 2180 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2181 | */ |
||
| 2182 | public static function catch_errors_on_shutdown() { |
||
| 2185 | |||
| 2186 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
| 2187 | $jetpack = Jetpack::init(); |
||
| 2188 | |||
| 2189 | $modules = Jetpack::get_default_modules( $min_version, $max_version ); |
||
| 2190 | $modules = array_merge( $other_modules, $modules ); |
||
| 2191 | |||
| 2192 | // Look for standalone plugins and disable if active. |
||
| 2193 | |||
| 2194 | $to_deactivate = array(); |
||
| 2195 | foreach ( $modules as $module ) { |
||
| 2196 | if ( isset( $jetpack->plugins_to_deactivate[$module] ) ) { |
||
| 2197 | $to_deactivate[$module] = $jetpack->plugins_to_deactivate[$module]; |
||
| 2198 | } |
||
| 2199 | } |
||
| 2200 | |||
| 2201 | $deactivated = array(); |
||
| 2202 | foreach ( $to_deactivate as $module => $deactivate_me ) { |
||
| 2203 | list( $probable_file, $probable_title ) = $deactivate_me; |
||
| 2204 | if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) { |
||
| 2205 | $deactivated[] = $module; |
||
| 2206 | } |
||
| 2207 | } |
||
| 2208 | |||
| 2209 | if ( $deactivated && $redirect ) { |
||
| 2210 | Jetpack::state( 'deactivated_plugins', join( ',', $deactivated ) ); |
||
| 2211 | |||
| 2212 | $url = add_query_arg( |
||
| 2213 | array( |
||
| 2214 | 'action' => 'activate_default_modules', |
||
| 2215 | '_wpnonce' => wp_create_nonce( 'activate_default_modules' ), |
||
| 2216 | ), |
||
| 2217 | add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), Jetpack::admin_url( 'page=jetpack' ) ) |
||
| 2218 | ); |
||
| 2219 | wp_safe_redirect( $url ); |
||
| 2220 | exit; |
||
| 2221 | } |
||
| 2222 | |||
| 2223 | /** |
||
| 2224 | * Fires before default modules are activated. |
||
| 2225 | * |
||
| 2226 | * @since 1.9.0 |
||
| 2227 | * |
||
| 2228 | * @param string $min_version Minimum version number required to use modules. |
||
| 2229 | * @param string $max_version Maximum version number required to use modules. |
||
| 2230 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
| 2231 | */ |
||
| 2232 | do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
| 2233 | |||
| 2234 | // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating |
||
| 2235 | Jetpack::restate(); |
||
| 2236 | Jetpack::catch_errors( true ); |
||
| 2237 | |||
| 2238 | $active = Jetpack::get_active_modules(); |
||
| 2239 | |||
| 2240 | foreach ( $modules as $module ) { |
||
| 2241 | if ( did_action( "jetpack_module_loaded_$module" ) ) { |
||
| 2242 | $active[] = $module; |
||
| 2243 | self::update_active_modules( $active ); |
||
| 2244 | continue; |
||
| 2245 | } |
||
| 2246 | |||
| 2247 | if ( in_array( $module, $active ) ) { |
||
| 2248 | $module_info = Jetpack::get_module( $module ); |
||
| 2249 | if ( ! $module_info['deactivate'] ) { |
||
| 2250 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
| 2251 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
| 2252 | $active_state = explode( ',', $active_state ); |
||
| 2253 | } else { |
||
| 2254 | $active_state = array(); |
||
| 2255 | } |
||
| 2256 | $active_state[] = $module; |
||
| 2257 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
| 2258 | } |
||
| 2259 | continue; |
||
| 2260 | } |
||
| 2261 | |||
| 2262 | $file = Jetpack::get_module_path( $module ); |
||
| 2263 | if ( ! file_exists( $file ) ) { |
||
| 2264 | continue; |
||
| 2265 | } |
||
| 2266 | |||
| 2267 | // we'll override this later if the plugin can be included without fatal error |
||
| 2268 | if ( $redirect ) { |
||
| 2269 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 2270 | } |
||
| 2271 | Jetpack::state( 'error', 'module_activation_failed' ); |
||
| 2272 | Jetpack::state( 'module', $module ); |
||
| 2273 | ob_start(); |
||
| 2274 | require $file; |
||
| 2275 | |||
| 2276 | $active[] = $module; |
||
| 2277 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
| 2278 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
| 2279 | $active_state = explode( ',', $active_state ); |
||
| 2280 | } else { |
||
| 2281 | $active_state = array(); |
||
| 2282 | } |
||
| 2283 | $active_state[] = $module; |
||
| 2284 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
| 2285 | Jetpack::update_active_modules( $active ); |
||
| 2286 | |||
| 2287 | ob_end_clean(); |
||
| 2288 | } |
||
| 2289 | Jetpack::state( 'error', false ); |
||
| 2290 | Jetpack::state( 'module', false ); |
||
| 2291 | Jetpack::catch_errors( false ); |
||
| 2292 | /** |
||
| 2293 | * Fires when default modules are activated. |
||
| 2294 | * |
||
| 2295 | * @since 1.9.0 |
||
| 2296 | * |
||
| 2297 | * @param string $min_version Minimum version number required to use modules. |
||
| 2298 | * @param string $max_version Maximum version number required to use modules. |
||
| 2299 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
| 2300 | */ |
||
| 2301 | do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
| 2302 | } |
||
| 2303 | |||
| 2304 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 2305 | /** |
||
| 2306 | * Fires before a module is activated. |
||
| 2307 | * |
||
| 2308 | * @since 2.6.0 |
||
| 2309 | * |
||
| 2310 | * @param string $module Module slug. |
||
| 2311 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
| 2312 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
| 2313 | */ |
||
| 2314 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
| 2315 | |||
| 2316 | $jetpack = Jetpack::init(); |
||
| 2317 | |||
| 2318 | if ( ! strlen( $module ) ) |
||
| 2319 | return false; |
||
| 2320 | |||
| 2321 | if ( ! Jetpack::is_module( $module ) ) |
||
| 2322 | return false; |
||
| 2323 | |||
| 2324 | // If it's already active, then don't do it again |
||
| 2325 | $active = Jetpack::get_active_modules(); |
||
| 2326 | foreach ( $active as $act ) { |
||
| 2327 | if ( $act == $module ) |
||
| 2328 | return true; |
||
| 2329 | } |
||
| 2330 | |||
| 2331 | $module_data = Jetpack::get_module( $module ); |
||
| 2332 | |||
| 2333 | if ( ! Jetpack::is_active() ) { |
||
| 2334 | if ( !Jetpack::is_development_mode() ) |
||
| 2335 | return false; |
||
| 2336 | |||
| 2337 | // If we're not connected but in development mode, make sure the module doesn't require a connection |
||
| 2338 | if ( Jetpack::is_development_mode() && $module_data['requires_connection'] ) |
||
| 2339 | return false; |
||
| 2340 | } |
||
| 2341 | |||
| 2342 | // Check and see if the old plugin is active |
||
| 2343 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
| 2344 | // Deactivate the old plugin |
||
| 2345 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
| 2346 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
| 2347 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
| 2348 | Jetpack::state( 'deactivated_plugins', $module ); |
||
| 2349 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
| 2350 | exit; |
||
| 2351 | } |
||
| 2352 | } |
||
| 2353 | |||
| 2354 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
| 2355 | Jetpack::state( 'module', $module ); |
||
| 2356 | Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
| 2357 | |||
| 2358 | Jetpack::catch_errors( true ); |
||
| 2359 | ob_start(); |
||
| 2360 | require Jetpack::get_module_path( $module ); |
||
| 2361 | |||
| 2362 | $active[] = $module; |
||
| 2363 | Jetpack::update_active_modules( $active ); |
||
| 2364 | |||
| 2365 | Jetpack::state( 'error', false ); // the override |
||
| 2366 | ob_end_clean(); |
||
| 2367 | Jetpack::catch_errors( false ); |
||
| 2368 | |||
| 2369 | // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. |
||
| 2370 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
| 2371 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
| 2372 | |||
| 2373 | //Jump start is being dismissed send data to MC Stats |
||
| 2374 | $jetpack->stat( 'jumpstart', 'manual,'.$module ); |
||
| 2375 | |||
| 2376 | $jetpack->do_stats( 'server_side' ); |
||
| 2377 | } |
||
| 2378 | |||
| 2379 | if ( $redirect ) { |
||
| 2380 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 2381 | } |
||
| 2382 | if ( $exit ) { |
||
| 2383 | exit; |
||
| 2384 | } |
||
| 2385 | return true; |
||
| 2386 | } |
||
| 2387 | |||
| 2388 | function activate_module_actions( $module ) { |
||
| 2389 | _deprecated_function( __METHOD__, 'jeptack-4.2' ); |
||
| 2390 | } |
||
| 2391 | |||
| 2392 | public static function deactivate_module( $module ) { |
||
| 2393 | /** |
||
| 2394 | * Fires when a module is deactivated. |
||
| 2395 | * |
||
| 2396 | * @since 1.9.0 |
||
| 2397 | * |
||
| 2398 | * @param string $module Module slug. |
||
| 2399 | */ |
||
| 2400 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
| 2401 | |||
| 2402 | $jetpack = Jetpack::init(); |
||
| 2403 | |||
| 2404 | $active = Jetpack::get_active_modules(); |
||
| 2405 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
| 2406 | |||
| 2407 | // A flag for Jump Start so it's not shown again. |
||
| 2408 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
| 2409 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
| 2410 | |||
| 2411 | //Jump start is being dismissed send data to MC Stats |
||
| 2412 | $jetpack->stat( 'jumpstart', 'manual,deactivated-'.$module ); |
||
| 2413 | |||
| 2414 | $jetpack->do_stats( 'server_side' ); |
||
| 2415 | } |
||
| 2416 | |||
| 2417 | return self::update_active_modules( $new ); |
||
| 2418 | } |
||
| 2419 | |||
| 2420 | public static function enable_module_configurable( $module ) { |
||
| 2424 | |||
| 2425 | public static function module_configuration_url( $module ) { |
||
| 2429 | |||
| 2430 | public static function module_configuration_load( $module, $method ) { |
||
| 2434 | |||
| 2435 | public static function module_configuration_head( $module, $method ) { |
||
| 2439 | |||
| 2440 | public static function module_configuration_screen( $module, $method ) { |
||
| 2444 | |||
| 2445 | public static function module_configuration_activation_screen( $module, $method ) { |
||
| 2449 | |||
| 2450 | /* Installation */ |
||
| 2451 | |||
| 2452 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 2492 | |||
| 2493 | /** |
||
| 2494 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 2495 | * @static |
||
| 2496 | */ |
||
| 2497 | public static function plugin_activation( $network_wide ) { |
||
| 2509 | /** |
||
| 2510 | * Runs before bumping version numbers up to a new version |
||
| 2511 | * @param (string) $version Version:timestamp |
||
| 2512 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
| 2513 | * @return null [description] |
||
| 2514 | */ |
||
| 2515 | public static function do_version_bump( $version, $old_version ) { |
||
| 2522 | |||
| 2523 | /** |
||
| 2524 | * Sets the internal version number and activation state. |
||
| 2525 | * @static |
||
| 2526 | */ |
||
| 2527 | public static function plugin_initialize() { |
||
| 2543 | |||
| 2544 | /** |
||
| 2545 | * Removes all connection options |
||
| 2546 | * @static |
||
| 2547 | */ |
||
| 2548 | public static function plugin_deactivation( ) { |
||
| 2557 | |||
| 2558 | /** |
||
| 2559 | * Disconnects from the Jetpack servers. |
||
| 2560 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 2561 | * @static |
||
| 2562 | */ |
||
| 2563 | public static function disconnect( $update_activated_state = true ) { |
||
| 2613 | |||
| 2614 | /** |
||
| 2615 | * Unlinks the current user from the linked WordPress.com user |
||
| 2616 | */ |
||
| 2617 | public static function unlink_user( $user_id = null ) { |
||
| 2648 | |||
| 2649 | /** |
||
| 2650 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 2651 | */ |
||
| 2652 | public static function try_registration() { |
||
| 2677 | |||
| 2678 | /** |
||
| 2679 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 2680 | * |
||
| 2681 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 2682 | */ |
||
| 2683 | public static function log( $code, $data = null ) { |
||
| 2723 | |||
| 2724 | /** |
||
| 2725 | * Get the internal event log. |
||
| 2726 | * |
||
| 2727 | * @param $event (string) - only return the specific log events |
||
| 2728 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 2729 | * |
||
| 2730 | * @return array of log events || WP_Error for invalid params |
||
| 2731 | */ |
||
| 2732 | public static function get_log( $event = false, $num = false ) { |
||
| 2768 | |||
| 2769 | /** |
||
| 2770 | * Log modification of important settings. |
||
| 2771 | */ |
||
| 2772 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 2779 | |||
| 2780 | /** |
||
| 2781 | * Return stat data for WPCOM sync |
||
| 2782 | */ |
||
| 2783 | function get_stat_data() { |
||
| 2789 | |||
| 2790 | /** |
||
| 2791 | * Get additional stat data to sync to WPCOM |
||
| 2792 | */ |
||
| 2793 | function get_additional_stat_data( $prefix = '' ) { |
||
| 2803 | |||
| 2804 | /* Admin Pages */ |
||
| 2805 | |||
| 2806 | function admin_init() { |
||
| 2860 | |||
| 2861 | function admin_body_class( $admin_body_class = '' ) { |
||
| 2869 | |||
| 2870 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 2873 | |||
| 2874 | function prepare_connect_notice() { |
||
| 2882 | /** |
||
| 2883 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
| 2884 | * |
||
| 2885 | * @return null |
||
| 2886 | */ |
||
| 2887 | function prepare_manage_jetpack_notice() { |
||
| 2892 | |||
| 2893 | function manage_activate_screen() { |
||
| 2896 | /** |
||
| 2897 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 2898 | * This function artificially throws errors for such cases (whitelisted). |
||
| 2899 | * |
||
| 2900 | * @param string $plugin The activated plugin. |
||
| 2901 | */ |
||
| 2902 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 2926 | |||
| 2927 | function intercept_plugin_error_scrape_init() { |
||
| 2930 | |||
| 2931 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 2942 | |||
| 2943 | function add_remote_request_handlers() { |
||
| 2946 | |||
| 2947 | function remote_request_handlers() { |
||
| 2981 | |||
| 2982 | function upload_handler() { |
||
| 3067 | |||
| 3068 | /** |
||
| 3069 | * Add help to the Jetpack page |
||
| 3070 | * |
||
| 3071 | * @since Jetpack (1.2.3) |
||
| 3072 | * @return false if not the Jetpack page |
||
| 3073 | */ |
||
| 3074 | function admin_help() { |
||
| 3115 | |||
| 3116 | function admin_menu_css() { |
||
| 3119 | |||
| 3120 | function admin_menu_order() { |
||
| 3123 | |||
| 3124 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
| 3139 | |||
| 3140 | function admin_head() { |
||
| 3145 | |||
| 3146 | View Code Duplication | function admin_banner_styles() { |
|
| 3153 | |||
| 3154 | function admin_scripts() { |
||
| 3167 | |||
| 3168 | function plugin_action_links( $actions ) { |
||
| 3183 | |||
| 3184 | function admin_connect_notice() { |
||
| 3219 | |||
| 3220 | /** |
||
| 3221 | * This is the first banner |
||
| 3222 | * It should be visible only to user that can update the option |
||
| 3223 | * Are not connected |
||
| 3224 | * |
||
| 3225 | * @return null |
||
| 3226 | */ |
||
| 3227 | function admin_jetpack_manage_notice() { |
||
| 3262 | |||
| 3263 | /** |
||
| 3264 | * Returns the url that the user clicks to remove the notice for the big banner |
||
| 3265 | * @return (string) |
||
| 3266 | */ |
||
| 3267 | function opt_out_jetpack_manage_url() { |
||
| 3271 | /** |
||
| 3272 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
| 3273 | * @return (string) |
||
| 3274 | */ |
||
| 3275 | function opt_in_jetpack_manage_url() { |
||
| 3278 | |||
| 3279 | function opt_in_jetpack_manage_notice() { |
||
| 3289 | /** |
||
| 3290 | * Determines whether to show the notice of not true = display notice |
||
| 3291 | * @return (bool) |
||
| 3292 | */ |
||
| 3293 | function can_display_jetpack_manage_notice() { |
||
| 3315 | |||
| 3316 | function network_connect_notice() { |
||
| 3325 | |||
| 3326 | /* |
||
| 3327 | * Registration flow: |
||
| 3328 | * 1 - ::admin_page_load() action=register |
||
| 3329 | * 2 - ::try_registration() |
||
| 3330 | * 3 - ::register() |
||
| 3331 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 3332 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 3333 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 3334 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 3335 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 3336 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 3337 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 3338 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 3339 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 3340 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 3341 | * 5 - user logs in with WP.com account |
||
| 3342 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 3343 | * - Jetpack_Client_Server::authorize() |
||
| 3344 | * - Jetpack_Client_Server::get_token() |
||
| 3345 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 3346 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 3347 | * - which responds with access_token, token_type, scope |
||
| 3348 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 3349 | * - Jetpack::activate_default_modules() |
||
| 3350 | * - Deactivates deprecated plugins |
||
| 3351 | * - Activates all default modules |
||
| 3352 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 3353 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 3354 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 3355 | * Done! |
||
| 3356 | */ |
||
| 3357 | |||
| 3358 | /** |
||
| 3359 | * Handles the page load events for the Jetpack admin page |
||
| 3360 | */ |
||
| 3361 | function admin_page_load() { |
||
| 3587 | |||
| 3588 | function admin_notices() { |
||
| 3685 | |||
| 3686 | /** |
||
| 3687 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 3688 | */ |
||
| 3689 | function stat( $group, $detail ) { |
||
| 3694 | |||
| 3695 | /** |
||
| 3696 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 3697 | */ |
||
| 3698 | function do_stats( $method = '' ) { |
||
| 3713 | |||
| 3714 | /** |
||
| 3715 | * Runs stats code for a one-off, server-side. |
||
| 3716 | * |
||
| 3717 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 3718 | * |
||
| 3719 | * @return bool If it worked. |
||
| 3720 | */ |
||
| 3721 | static function do_server_side_stat( $args ) { |
||
| 3731 | |||
| 3732 | /** |
||
| 3733 | * Builds the stats url. |
||
| 3734 | * |
||
| 3735 | * @param $args array|string The arguments to append to the URL. |
||
| 3736 | * |
||
| 3737 | * @return string The URL to be pinged. |
||
| 3738 | */ |
||
| 3739 | static function build_stats_url( $args ) { |
||
| 3759 | |||
| 3760 | static function translate_current_user_to_role() { |
||
| 3769 | |||
| 3770 | static function translate_role_to_cap( $role ) { |
||
| 3777 | |||
| 3778 | static function sign_role( $role ) { |
||
| 3790 | |||
| 3791 | |||
| 3792 | /** |
||
| 3793 | * Builds a URL to the Jetpack connection auth page |
||
| 3794 | * |
||
| 3795 | * @since 3.9.5 |
||
| 3796 | * |
||
| 3797 | * @param bool $raw If true, URL will not be escaped. |
||
| 3798 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 3799 | * If string, will be a custom redirect. |
||
| 3800 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 3801 | * |
||
| 3802 | * @return string Connect URL |
||
| 3803 | */ |
||
| 3804 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
| 3878 | |||
| 3879 | function build_reconnect_url( $raw = false ) { |
||
| 3883 | |||
| 3884 | public static function admin_url( $args = null ) { |
||
| 3889 | |||
| 3890 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 3894 | |||
| 3895 | function dismiss_jetpack_notice() { |
||
| 3969 | |||
| 3970 | function debugger_page() { |
||
| 3978 | |||
| 3979 | public static function admin_screen_configure_module( $module_id ) { |
||
| 4031 | |||
| 4032 | /** |
||
| 4033 | * Display link to activate the module to see the settings screen. |
||
| 4034 | * @param string $module_id |
||
| 4035 | * @return null |
||
| 4036 | */ |
||
| 4037 | public static function display_activate_module_link( $module_id ) { |
||
| 4089 | |||
| 4090 | public static function sort_modules( $a, $b ) { |
||
| 4096 | |||
| 4097 | function ajax_recheck_ssl() { |
||
| 4105 | |||
| 4106 | /* Client API */ |
||
| 4107 | |||
| 4108 | /** |
||
| 4109 | * Returns the requested Jetpack API URL |
||
| 4110 | * |
||
| 4111 | * @return string |
||
| 4112 | */ |
||
| 4113 | public static function api_url( $relative_url ) { |
||
| 4116 | |||
| 4117 | /** |
||
| 4118 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
| 4119 | */ |
||
| 4120 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 4136 | |||
| 4137 | /** |
||
| 4138 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 4139 | * |
||
| 4140 | * @since 2.3.3 |
||
| 4141 | * @return boolean |
||
| 4142 | */ |
||
| 4143 | public static function permit_ssl( $force_recheck = false ) { |
||
| 4185 | |||
| 4186 | /* |
||
| 4187 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
| 4188 | */ |
||
| 4189 | public function alert_auto_ssl_fail() { |
||
| 4238 | |||
| 4239 | /** |
||
| 4240 | * Returns the Jetpack XML-RPC API |
||
| 4241 | * |
||
| 4242 | * @return string |
||
| 4243 | */ |
||
| 4244 | public static function xmlrpc_api_url() { |
||
| 4248 | |||
| 4249 | /** |
||
| 4250 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 4251 | * |
||
| 4252 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 4253 | * |
||
| 4254 | * @since 2.6 |
||
| 4255 | * @return array |
||
| 4256 | */ |
||
| 4257 | public function generate_secrets( $action, $exp = 600 ) { |
||
| 4265 | |||
| 4266 | /** |
||
| 4267 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 4268 | * |
||
| 4269 | * Based on local php max_execution_time in php.ini |
||
| 4270 | * |
||
| 4271 | * @since 2.6 |
||
| 4272 | * @return int |
||
| 4273 | **/ |
||
| 4274 | public function get_remote_query_timeout_limit() { |
||
| 4280 | |||
| 4281 | |||
| 4282 | /** |
||
| 4283 | * Takes the response from the Jetpack register new site endpoint and |
||
| 4284 | * verifies it worked properly. |
||
| 4285 | * |
||
| 4286 | * @since 2.6 |
||
| 4287 | * @return true or Jetpack_Error |
||
| 4288 | **/ |
||
| 4289 | public function validate_remote_register_response( $response ) { |
||
| 4324 | /** |
||
| 4325 | * @return bool|WP_Error |
||
| 4326 | */ |
||
| 4327 | public static function register() { |
||
| 4424 | |||
| 4425 | /** |
||
| 4426 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 4427 | * |
||
| 4428 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 4429 | */ |
||
| 4430 | public static function maybe_set_version_option() { |
||
| 4431 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 4432 | if ( JETPACK__VERSION != $version ) { |
||
| 4433 | Jetpack_Options::update_option( 'version', JETPACK__VERSION . ':' . time() ); |
||
| 4434 | |||
| 4435 | if ( version_compare( JETPACK__VERSION, $version, '>' ) ) { |
||
| 4436 | /** This action is documented in class.jetpack.php */ |
||
| 4437 | do_action( 'updating_jetpack_version', JETPACK__VERSION, $version ); |
||
| 4438 | } |
||
| 4439 | |||
| 4440 | return true; |
||
| 4441 | } |
||
| 4442 | return false; |
||
| 4443 | } |
||
| 4444 | |||
| 4445 | /* Client Server API */ |
||
| 4446 | |||
| 4447 | /** |
||
| 4448 | * Loads the Jetpack XML-RPC client |
||
| 4449 | */ |
||
| 4450 | public static function load_xml_rpc_client() { |
||
| 4454 | |||
| 4455 | function verify_xml_rpc_signature() { |
||
| 4553 | |||
| 4554 | /** |
||
| 4555 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 4556 | */ |
||
| 4557 | function authenticate_jetpack( $user, $username, $password ) { |
||
| 4580 | |||
| 4581 | function add_nonce( $timestamp, $nonce ) { |
||
| 4619 | |||
| 4620 | /** |
||
| 4621 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 4622 | * Capture it here so we can verify the signature later. |
||
| 4623 | */ |
||
| 4624 | function xmlrpc_methods( $methods ) { |
||
| 4628 | |||
| 4629 | function public_xmlrpc_methods( $methods ) { |
||
| 4635 | |||
| 4636 | function jetpack_getOptions( $args ) { |
||
| 4676 | |||
| 4677 | function xmlrpc_options( $options ) { |
||
| 4695 | |||
| 4696 | public static function clean_nonces( $all = false ) { |
||
| 4721 | |||
| 4722 | /** |
||
| 4723 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 4724 | * SET: state( $key, $value ); |
||
| 4725 | * GET: $value = state( $key ); |
||
| 4726 | * |
||
| 4727 | * @param string $key |
||
| 4728 | * @param string $value |
||
| 4729 | * @param bool $restate private |
||
| 4730 | */ |
||
| 4731 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 4781 | |||
| 4782 | public static function restate() { |
||
| 4785 | |||
| 4786 | public static function check_privacy( $file ) { |
||
| 4821 | |||
| 4822 | /** |
||
| 4823 | * Helper method for multicall XMLRPC. |
||
| 4824 | */ |
||
| 4825 | public static function xmlrpc_async_call() { |
||
| 4867 | |||
| 4868 | public static function staticize_subdomain( $url ) { |
||
| 4903 | |||
| 4904 | /* JSON API Authorization */ |
||
| 4905 | |||
| 4906 | /** |
||
| 4907 | * Handles the login action for Authorizing the JSON API |
||
| 4908 | */ |
||
| 4909 | function login_form_json_api_authorization() { |
||
| 4918 | |||
| 4919 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 4920 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 4933 | |||
| 4934 | // Make sure the POSTed request is handled by the same action |
||
| 4935 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 4939 | |||
| 4940 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 4941 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 4947 | |||
| 4948 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
| 4949 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 4953 | |||
| 4954 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 4955 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 4967 | |||
| 4968 | // Verifies the request by checking the signature |
||
| 4969 | function verify_json_api_authorization_request() { |
||
| 5048 | |||
| 5049 | function login_message_json_api_authorization( $message ) { |
||
| 5055 | |||
| 5056 | /** |
||
| 5057 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 5058 | */ |
||
| 5059 | public static function get_content_width() { |
||
| 5070 | |||
| 5071 | /** |
||
| 5072 | * Centralize the function here until it gets added to core. |
||
| 5073 | * |
||
| 5074 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 5075 | * @param int $size Size of the avatar image |
||
| 5076 | * @param string $default URL to a default image to use if no avatar is available |
||
| 5077 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 5078 | * |
||
| 5079 | * @return array First element is the URL, second is the class. |
||
| 5080 | */ |
||
| 5081 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 5109 | |||
| 5110 | /** |
||
| 5111 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 5112 | * |
||
| 5113 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 5114 | * |
||
| 5115 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 5116 | */ |
||
| 5117 | public function get_cloud_site_options( $option_names ) { |
||
| 5133 | |||
| 5134 | /** |
||
| 5135 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
| 5136 | * |
||
| 5137 | * @return array An array of options to check. |
||
| 5138 | */ |
||
| 5139 | public static function identity_crisis_options_to_check() { |
||
| 5145 | |||
| 5146 | /** |
||
| 5147 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
| 5148 | * |
||
| 5149 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
| 5150 | * |
||
| 5151 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
| 5152 | */ |
||
| 5153 | public static function check_identity_crisis( $force_recheck = false ) { |
||
| 5219 | |||
| 5220 | /* |
||
| 5221 | * Resolve ID crisis |
||
| 5222 | * |
||
| 5223 | * If the URL has changed, but the rest of the options are the same (i.e. blog/user tokens) |
||
| 5224 | * The user has the option to update the shadow site with the new URL before a new |
||
| 5225 | * token is created. |
||
| 5226 | * |
||
| 5227 | * @param $key : Which option to sync. null defautlts to home and siteurl |
||
| 5228 | */ |
||
| 5229 | public static function resolve_identity_crisis( $key = null ) { |
||
| 5249 | |||
| 5250 | /* |
||
| 5251 | * Whitelist URL |
||
| 5252 | * |
||
| 5253 | * Ignore the URL differences between the blog and the shadow site. |
||
| 5254 | */ |
||
| 5255 | public static function whitelist_current_url() { |
||
| 5263 | |||
| 5264 | /* |
||
| 5265 | * Ajax callbacks for ID crisis resolutions |
||
| 5266 | * |
||
| 5267 | * Things that could happen here: |
||
| 5268 | * - site_migrated : Update the URL on the shadow blog to match new domain |
||
| 5269 | * - whitelist : Ignore the URL difference |
||
| 5270 | * - default : Error message |
||
| 5271 | */ |
||
| 5272 | public static function resolve_identity_crisis_ajax_callback() { |
||
| 5312 | |||
| 5313 | /** |
||
| 5314 | * Adds a value to the whitelist for the specified key. |
||
| 5315 | * |
||
| 5316 | * @param string $key The option name that we're whitelisting the value for. |
||
| 5317 | * @param string $value The value that we're intending to add to the whitelist. |
||
| 5318 | * |
||
| 5319 | * @return bool Whether the value was added to the whitelist, or false if it was already there. |
||
| 5320 | */ |
||
| 5321 | public static function whitelist_identity_crisis_value( $key, $value ) { |
||
| 5335 | |||
| 5336 | /** |
||
| 5337 | * Checks whether a value is already whitelisted. |
||
| 5338 | * |
||
| 5339 | * @param string $key The option name that we're checking the value for. |
||
| 5340 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
| 5341 | * |
||
| 5342 | * @return bool Whether the value is whitelisted. |
||
| 5343 | */ |
||
| 5344 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
| 5351 | |||
| 5352 | /** |
||
| 5353 | * Checks whether the home and siteurl specifically are whitelisted |
||
| 5354 | * Written so that we don't have re-check $key and $value params every time |
||
| 5355 | * we want to check if this site is whitelisted, for example in footer.php |
||
| 5356 | * |
||
| 5357 | * @return bool True = already whitelisted False = not whitelisted |
||
| 5358 | */ |
||
| 5359 | public static function is_staging_site() { |
||
| 5360 | $is_staging = false; |
||
| 5361 | |||
| 5362 | $current_whitelist = Jetpack_Options::get_option( 'identity_crisis_whitelist' ); |
||
| 5363 | if ( $current_whitelist && ! get_transient( 'jetpack_checked_is_staging' ) ) { |
||
| 5364 | $options_to_check = Jetpack::identity_crisis_options_to_check(); |
||
| 5365 | $cloud_options = Jetpack::init()->get_cloud_site_options( $options_to_check ); |
||
| 5366 | |||
| 5367 | foreach ( $cloud_options as $cloud_key => $cloud_value ) { |
||
| 5368 | if ( self::is_identity_crisis_value_whitelisted( $cloud_key, $cloud_value ) ) { |
||
| 5369 | $is_staging = true; |
||
| 5370 | break; |
||
| 5371 | } |
||
| 5372 | } |
||
| 5373 | // set a flag so we don't check again for an hour |
||
| 5374 | set_transient( 'jetpack_checked_is_staging', 1, HOUR_IN_SECONDS ); |
||
| 5375 | } |
||
| 5376 | $known_staging = array( |
||
| 5377 | 'urls' => array( |
||
| 5378 | '#\.staging\.wpengine\.com$#i', // WP Engine |
||
| 5379 | ), |
||
| 5380 | 'constants' => array( |
||
| 5381 | 'IS_WPE_SNAPSHOT', // WP Engine |
||
| 5382 | 'KINSTA_DEV_ENV', // Kinsta.com |
||
| 5383 | 'WPSTAGECOACH_STAGING', // WP Stagecoach |
||
| 5384 | 'JETPACK_STAGING_MODE', // Generic |
||
| 5385 | ) |
||
| 5386 | ); |
||
| 5387 | /** |
||
| 5388 | * Filters the flags of known staging sites. |
||
| 5389 | * |
||
| 5390 | * @since 3.9.0 |
||
| 5391 | * |
||
| 5392 | * @param array $known_staging { |
||
| 5393 | * An array of arrays that each are used to check if the current site is staging. |
||
| 5394 | * @type array $urls URLs of staging sites in regex to check against site_url. |
||
| 5395 | * @type array $constants PHP constants of known staging/developement environments. |
||
| 5396 | * } |
||
| 5397 | */ |
||
| 5398 | $known_staging = apply_filters( 'jetpack_known_staging', $known_staging ); |
||
| 5399 | |||
| 5400 | if ( isset( $known_staging['urls'] ) ) { |
||
| 5401 | foreach ( $known_staging['urls'] as $url ){ |
||
| 5402 | if ( preg_match( $url, site_url() ) ) { |
||
| 5403 | $is_staging = true; |
||
| 5404 | break; |
||
| 5405 | } |
||
| 5406 | } |
||
| 5407 | } |
||
| 5408 | |||
| 5409 | if ( isset( $known_staging['constants'] ) ) { |
||
| 5410 | foreach ( $known_staging['constants'] as $constant ) { |
||
| 5411 | if ( defined( $constant ) && constant( $constant ) ) { |
||
| 5412 | $is_staging = true; |
||
| 5413 | } |
||
| 5414 | } |
||
| 5415 | } |
||
| 5416 | |||
| 5417 | /** |
||
| 5418 | * Filters is_staging_site check. |
||
| 5419 | * |
||
| 5420 | * @since 3.9.0 |
||
| 5421 | * |
||
| 5422 | * @param bool $is_staging If the current site is a staging site. |
||
| 5423 | */ |
||
| 5424 | return apply_filters( 'jetpack_is_staging_site', $is_staging ); |
||
| 5425 | } |
||
| 5426 | |||
| 5427 | public function identity_crisis_js( $nonce ) { |
||
| 5497 | |||
| 5498 | /** |
||
| 5499 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 5500 | * |
||
| 5501 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 5502 | */ |
||
| 5503 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 5538 | |||
| 5539 | /** |
||
| 5540 | * Maybe inlines a stylesheet. |
||
| 5541 | * |
||
| 5542 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 5543 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 5544 | * |
||
| 5545 | * Attached to `style_loader_tag` filter. |
||
| 5546 | * |
||
| 5547 | * @param string $tag The tag that would link to the external asset. |
||
| 5548 | * @param string $handle The registered handle of the script in question. |
||
| 5549 | * |
||
| 5550 | * @return string |
||
| 5551 | */ |
||
| 5552 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 5602 | |||
| 5603 | /** |
||
| 5604 | * Loads a view file from the views |
||
| 5605 | * |
||
| 5606 | * Data passed in with the $data parameter will be available in the |
||
| 5607 | * template file as $data['value'] |
||
| 5608 | * |
||
| 5609 | * @param string $template - Template file to load |
||
| 5610 | * @param array $data - Any data to pass along to the template |
||
| 5611 | * @return boolean - If template file was found |
||
| 5612 | **/ |
||
| 5613 | public function load_view( $template, $data = array() ) { |
||
| 5624 | |||
| 5625 | /** |
||
| 5626 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
| 5627 | */ |
||
| 5628 | public function deprecated_hooks() { |
||
| 5670 | |||
| 5671 | /** |
||
| 5672 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 5673 | * |
||
| 5674 | * Considerations: |
||
| 5675 | * - Normal, relative URLs `feh.png` |
||
| 5676 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 5677 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 5678 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 5679 | * - Domain root relative URLs `/feh.png` |
||
| 5680 | * |
||
| 5681 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 5682 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 5683 | * |
||
| 5684 | * @return mixed|string |
||
| 5685 | */ |
||
| 5686 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 5730 | |||
| 5731 | /** |
||
| 5732 | * This method checks to see if SSL is required by the site in |
||
| 5733 | * order to visit it in some way other than only setting the |
||
| 5734 | * https value in the home or siteurl values. |
||
| 5735 | * |
||
| 5736 | * @since 3.2 |
||
| 5737 | * @return boolean |
||
| 5738 | **/ |
||
| 5739 | private function is_ssl_required_to_visit_site() { |
||
| 5740 | global $wp_version; |
||
| 5741 | $ssl = is_ssl(); |
||
| 5742 | |||
| 5743 | if ( force_ssl_admin() ) { |
||
| 5744 | $ssl = true; |
||
| 5745 | } |
||
| 5746 | return $ssl; |
||
| 5747 | } |
||
| 5748 | |||
| 5749 | /** |
||
| 5750 | * This methods removes all of the registered css files on the front end |
||
| 5751 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 5752 | * all the files into one file. |
||
| 5753 | * |
||
| 5754 | * Pros: |
||
| 5755 | * - Uses only ONE css asset connection instead of 15 |
||
| 5756 | * - Saves a minimum of 56k |
||
| 5757 | * - Reduces server load |
||
| 5758 | * - Reduces time to first painted byte |
||
| 5759 | * |
||
| 5760 | * Cons: |
||
| 5761 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 5762 | * should not cause any issues with themes. |
||
| 5763 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 5764 | * jetpack_implode_frontend_css filter for a workaround |
||
| 5765 | * |
||
| 5766 | * For some situations developers may wish to disable css imploding and |
||
| 5767 | * instead operate in legacy mode where each file loads seperately and |
||
| 5768 | * can be edited individually or dequeued. This can be accomplished with |
||
| 5769 | * the following line: |
||
| 5770 | * |
||
| 5771 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 5772 | * |
||
| 5773 | * @since 3.2 |
||
| 5774 | **/ |
||
| 5775 | public function implode_frontend_css( $travis_test = false ) { |
||
| 5827 | |||
| 5828 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 5838 | |||
| 5839 | /* |
||
| 5840 | * Check the heartbeat data |
||
| 5841 | * |
||
| 5842 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 5843 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 5844 | * |
||
| 5845 | * Data will be added to "caution" array, if it either: |
||
| 5846 | * - Out of date Jetpack version |
||
| 5847 | * - Out of date WP version |
||
| 5848 | * - Out of date PHP version |
||
| 5849 | * |
||
| 5850 | * $return array $filtered_data |
||
| 5851 | */ |
||
| 5852 | public static function jetpack_check_heartbeat_data() { |
||
| 5905 | |||
| 5906 | |||
| 5907 | /* |
||
| 5908 | * This method is used to organize all options that can be reset |
||
| 5909 | * without disconnecting Jetpack. |
||
| 5910 | * |
||
| 5911 | * It is used in class.jetpack-cli.php to reset options |
||
| 5912 | * |
||
| 5913 | * @return array of options to delete. |
||
| 5914 | */ |
||
| 5915 | public static function get_jetpack_options_for_reset() { |
||
| 5982 | |||
| 5983 | /** |
||
| 5984 | * Check if an option of a Jetpack module has been updated. |
||
| 5985 | * |
||
| 5986 | * If any module option has been updated before Jump Start has been dismissed, |
||
| 5987 | * update the 'jumpstart' option so we can hide Jump Start. |
||
| 5988 | * |
||
| 5989 | * @param string $option_name |
||
| 5990 | * |
||
| 5991 | * @return bool |
||
| 5992 | */ |
||
| 5993 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
| 6014 | |||
| 6015 | /* |
||
| 6016 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 6017 | * so we can bring them directly to their site in calypso. |
||
| 6018 | * |
||
| 6019 | * @param string | url |
||
| 6020 | * @return string | url without the guff |
||
| 6021 | */ |
||
| 6022 | public static function build_raw_urls( $url ) { |
||
| 6028 | |||
| 6029 | /** |
||
| 6030 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 6031 | * |
||
| 6032 | * @param mixed $new_urls |
||
| 6033 | */ |
||
| 6034 | public static function dns_prefetch( $new_urls = null ) { |
||
| 6051 | |||
| 6052 | public function wp_dashboard_setup() { |
||
| 6080 | |||
| 6081 | /** |
||
| 6082 | * @param mixed $result Value for the user's option |
||
| 6083 | * @return mixed |
||
| 6084 | */ |
||
| 6085 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 6110 | |||
| 6111 | public static function dashboard_widget() { |
||
| 6119 | |||
| 6120 | public static function dashboard_widget_footer() { |
||
| 6153 | |||
| 6154 | public function dashboard_widget_connect_to_wpcom() { |
||
| 6176 | |||
| 6177 | /* |
||
| 6178 | * A graceful transition to using Core's site icon. |
||
| 6179 | * |
||
| 6180 | * All of the hard work has already been done with the image |
||
| 6181 | * in all_done_page(). All that needs to be done now is update |
||
| 6182 | * the option and display proper messaging. |
||
| 6183 | * |
||
| 6184 | * @todo remove when WP 4.3 is minimum |
||
| 6185 | * |
||
| 6186 | * @since 3.6.1 |
||
| 6187 | * |
||
| 6188 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
| 6189 | */ |
||
| 6190 | public static function jetpack_site_icon_available_in_core() { |
||
| 6225 | |||
| 6226 | /** |
||
| 6227 | * Return string containing the Jetpack logo. |
||
| 6228 | * |
||
| 6229 | * @since 3.9.0 |
||
| 6230 | * |
||
| 6231 | * @return string |
||
| 6232 | */ |
||
| 6233 | public static function get_jp_emblem() { |
||
| 6236 | |||
| 6237 | /* |
||
| 6238 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 6239 | */ |
||
| 6240 | function jetpack_icon_user_connected( $columns ) { |
||
| 6244 | |||
| 6245 | /* |
||
| 6246 | * Show Jetpack icon if the user is linked. |
||
| 6247 | */ |
||
| 6248 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 6260 | |||
| 6261 | /* |
||
| 6262 | * Style the Jetpack user column |
||
| 6263 | */ |
||
| 6264 | function jetpack_user_col_style() { |
||
| 6277 | |||
| 6278 | } |
||
| 6279 |
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.