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 | public $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 | * Allows us to build a temporary security report |
||
| 283 | * |
||
| 284 | * @var array |
||
| 285 | */ |
||
| 286 | static $security_report = array(); |
||
|
|
|||
| 287 | |||
| 288 | /** |
||
| 289 | * Jetpack_Sync object |
||
| 290 | */ |
||
| 291 | public $sync; |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Verified data for JSON authorization request |
||
| 295 | */ |
||
| 296 | public $json_api_authorization_request = array(); |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Holds the singleton instance of this class |
||
| 300 | * @since 2.3.3 |
||
| 301 | * @var Jetpack |
||
| 302 | */ |
||
| 303 | static $instance = false; |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Singleton |
||
| 307 | * @static |
||
| 308 | */ |
||
| 309 | public static function init() { |
||
| 310 | if ( ! self::$instance ) { |
||
| 311 | if ( did_action( 'plugins_loaded' ) ) |
||
| 312 | self::plugin_textdomain(); |
||
| 313 | else |
||
| 314 | add_action( 'plugins_loaded', array( __CLASS__, 'plugin_textdomain' ), 99 ); |
||
| 315 | |||
| 316 | self::$instance = new Jetpack; |
||
| 317 | |||
| 318 | self::$instance->plugin_upgrade(); |
||
| 319 | |||
| 320 | add_action( 'init', array( __CLASS__, 'perform_security_reporting' ) ); |
||
| 321 | |||
| 322 | } |
||
| 323 | |||
| 324 | return self::$instance; |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Must never be called statically |
||
| 329 | */ |
||
| 330 | function plugin_upgrade() { |
||
| 331 | if ( Jetpack::is_active() ) { |
||
| 332 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 333 | if ( JETPACK__VERSION != $version ) { |
||
| 334 | |||
| 335 | // Check which active modules actually exist and remove others from active_modules list |
||
| 336 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
| 337 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
| 338 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
| 339 | Jetpack_Options::update_option( 'active_modules', $modules ); |
||
| 340 | } |
||
| 341 | |||
| 342 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
| 343 | /** |
||
| 344 | * Fires when synchronizing all registered options and constants. |
||
| 345 | * |
||
| 346 | * @since 3.3.0 |
||
| 347 | */ |
||
| 348 | do_action( 'jetpack_sync_all_registered_options' ); |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } |
||
| 352 | |||
| 353 | static function activate_manage( ) { |
||
| 354 | |||
| 355 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
| 356 | self::activate_module( 'manage', false, false ); |
||
| 357 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
| 358 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
| 359 | } |
||
| 360 | |||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Constructor. Initializes WordPress hooks |
||
| 365 | */ |
||
| 366 | private function __construct() { |
||
| 367 | /* |
||
| 368 | * Check for and alert any deprecated hooks |
||
| 369 | */ |
||
| 370 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 371 | |||
| 372 | /* |
||
| 373 | * Do things that should run even in the network admin |
||
| 374 | * here, before we potentially fail out. |
||
| 375 | */ |
||
| 376 | add_filter( 'jetpack_require_lib_dir', array( $this, 'require_lib_dir' ) ); |
||
| 377 | |||
| 378 | /** |
||
| 379 | * We need sync object even in Multisite mode |
||
| 380 | */ |
||
| 381 | $this->sync = new Jetpack_Sync; |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Trigger a wp_version sync when updating WP versions |
||
| 385 | **/ |
||
| 386 | add_action( 'upgrader_process_complete', array( 'Jetpack', 'update_get_wp_version' ), 10, 2 ); |
||
| 387 | $this->sync->mock_option( 'wp_version', array( 'Jetpack', 'get_wp_version' ) ); |
||
| 388 | |||
| 389 | add_action( 'init', array( $this, 'sync_update_data') ); |
||
| 390 | add_action( 'init', array( $this, 'sync_theme_data' ) ); |
||
| 391 | |||
| 392 | /* |
||
| 393 | * Load things that should only be in Network Admin. |
||
| 394 | * |
||
| 395 | * For now blow away everything else until a more full |
||
| 396 | * understanding of what is needed at the network level is |
||
| 397 | * available |
||
| 398 | */ |
||
| 399 | if( is_multisite() ) { |
||
| 400 | Jetpack_Network::init(); |
||
| 401 | |||
| 402 | // Only sync this info if we are on a multi site |
||
| 403 | // @since 3.7 |
||
| 404 | $this->sync->mock_option( 'network_name', array( 'Jetpack', 'network_name' ) ); |
||
| 405 | $this->sync->mock_option( 'network_allow_new_registrations', array( 'Jetpack', 'network_allow_new_registrations' ) ); |
||
| 406 | $this->sync->mock_option( 'network_add_new_users', array( 'Jetpack', 'network_add_new_users' ) ); |
||
| 407 | $this->sync->mock_option( 'network_site_upload_space', array( 'Jetpack', 'network_site_upload_space' ) ); |
||
| 408 | $this->sync->mock_option( 'network_upload_file_types', array( 'Jetpack', 'network_upload_file_types' ) ); |
||
| 409 | $this->sync->mock_option( 'network_enable_administration_menus', array( 'Jetpack', 'network_enable_administration_menus' ) ); |
||
| 410 | |||
| 411 | if( is_network_admin() ) { |
||
| 412 | // Sync network site data if it is updated or not. |
||
| 413 | add_action( 'update_wpmu_options', array( $this, 'update_jetpack_network_settings' ) ); |
||
| 414 | return; // End here to prevent single site actions from firing |
||
| 415 | } |
||
| 416 | } |
||
| 417 | |||
| 418 | |||
| 419 | $theme_slug = get_option( 'stylesheet' ); |
||
| 420 | |||
| 421 | |||
| 422 | // Modules should do Jetpack_Sync::sync_options( __FILE__, $option, ... ); instead |
||
| 423 | // We access the "internal" method here only because the Jetpack object isn't instantiated yet |
||
| 424 | $this->sync->options( |
||
| 425 | JETPACK__PLUGIN_DIR . 'jetpack.php', |
||
| 426 | 'home', |
||
| 427 | 'siteurl', |
||
| 428 | 'blogname', |
||
| 429 | 'gmt_offset', |
||
| 430 | 'timezone_string', |
||
| 431 | 'security_report', |
||
| 432 | 'stylesheet', |
||
| 433 | "theme_mods_{$theme_slug}", |
||
| 434 | 'jetpack_sync_non_public_post_stati', |
||
| 435 | 'jetpack_options', |
||
| 436 | 'site_icon', // (int) - ID of core's Site Icon attachment ID |
||
| 437 | 'default_post_format', |
||
| 438 | 'default_category', |
||
| 439 | 'large_size_w', |
||
| 440 | 'large_size_h', |
||
| 441 | 'thumbnail_size_w', |
||
| 442 | 'thumbnail_size_h', |
||
| 443 | 'medium_size_w', |
||
| 444 | 'medium_size_h', |
||
| 445 | 'thumbnail_crop', |
||
| 446 | 'image_default_link_type' |
||
| 447 | ); |
||
| 448 | |||
| 449 | foreach( Jetpack_Options::get_option_names( 'non-compact' ) as $option ) { |
||
| 450 | $this->sync->options( __FILE__, 'jetpack_' . $option ); |
||
| 451 | } |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Sometimes you want to sync data to .com without adding options to .org sites. |
||
| 455 | * The mock option allows you to do just that. |
||
| 456 | */ |
||
| 457 | $this->sync->mock_option( 'is_main_network', array( $this, 'is_main_network_option' ) ); |
||
| 458 | $this->sync->mock_option( 'is_multi_site', array( $this, 'is_multisite' ) ); |
||
| 459 | $this->sync->mock_option( 'main_network_site', array( $this, 'jetpack_main_network_site_option' ) ); |
||
| 460 | $this->sync->mock_option( 'single_user_site', array( 'Jetpack', 'is_single_user_site' ) ); |
||
| 461 | $this->sync->mock_option( 'stat_data', array( $this, 'get_stat_data' ) ); |
||
| 462 | |||
| 463 | $this->sync->mock_option( 'has_file_system_write_access', array( 'Jetpack', 'file_system_write_access' ) ); |
||
| 464 | $this->sync->mock_option( 'is_version_controlled', array( 'Jetpack', 'is_version_controlled' ) ); |
||
| 465 | $this->sync->mock_option( 'max_upload_size', 'wp_max_upload_size' ); |
||
| 466 | $this->sync->mock_option( 'content_width', array( 'Jetpack', 'get_content_width' ) ); |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Trigger an update to the main_network_site when we update the blogname of a site. |
||
| 470 | * |
||
| 471 | */ |
||
| 472 | add_action( 'update_option_siteurl', array( $this, 'update_jetpack_main_network_site_option' ) ); |
||
| 473 | |||
| 474 | add_action( 'update_option', array( $this, 'log_settings_change' ), 10, 3 ); |
||
| 475 | |||
| 476 | // Update the settings everytime the we register a new user to the site or we delete a user. |
||
| 477 | add_action( 'user_register', array( $this, 'is_single_user_site_invalidate' ) ); |
||
| 478 | add_action( 'deleted_user', array( $this, 'is_single_user_site_invalidate' ) ); |
||
| 479 | |||
| 480 | // Unlink user before deleting the user from .com |
||
| 481 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 482 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 483 | |||
| 484 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
| 485 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
| 486 | |||
| 487 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
| 488 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
| 489 | |||
| 490 | $this->require_jetpack_authentication(); |
||
| 491 | |||
| 492 | if ( Jetpack::is_active() ) { |
||
| 493 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
| 494 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
| 495 | |||
| 496 | $signed = $this->verify_xml_rpc_signature(); |
||
| 497 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
| 498 | // The actual API methods. |
||
| 499 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
| 500 | } else { |
||
| 501 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
| 502 | // active Jetpack connection, so that additional users can link their account. |
||
| 503 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
| 504 | } |
||
| 505 | } else { |
||
| 506 | // The bootstrap API methods. |
||
| 507 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
| 508 | } |
||
| 509 | |||
| 510 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
| 511 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
| 512 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
| 513 | $this->require_jetpack_authentication(); |
||
| 514 | $this->add_remote_request_handlers(); |
||
| 515 | } else { |
||
| 516 | if ( Jetpack::is_active() ) { |
||
| 517 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
| 518 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
| 519 | } |
||
| 520 | } |
||
| 521 | |||
| 522 | if ( Jetpack::is_active() ) { |
||
| 523 | Jetpack_Heartbeat::init(); |
||
| 524 | } |
||
| 525 | |||
| 526 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
| 527 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
| 528 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
| 529 | } |
||
| 530 | |||
| 531 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
| 532 | |||
| 533 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 534 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 535 | |||
| 536 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
| 537 | |||
| 538 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 539 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 540 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 541 | |||
| 542 | add_action( 'wp_ajax_jetpack-sync-reindex-trigger', array( $this, 'sync_reindex_trigger' ) ); |
||
| 543 | add_action( 'wp_ajax_jetpack-sync-reindex-status', array( $this, 'sync_reindex_status' ) ); |
||
| 544 | |||
| 545 | // Jump Start AJAX callback function |
||
| 546 | add_action( 'wp_ajax_jetpack_jumpstart_ajax', array( $this, 'jetpack_jumpstart_ajax_callback' ) ); |
||
| 547 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
| 548 | |||
| 549 | // Identity Crisis AJAX callback function |
||
| 550 | add_action( 'wp_ajax_jetpack_resolve_identity_crisis', array( $this, 'resolve_identity_crisis_ajax_callback' ) ); |
||
| 551 | |||
| 552 | // JITM AJAX callback function |
||
| 553 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
| 554 | |||
| 555 | add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) ); |
||
| 556 | add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) ); |
||
| 557 | |||
| 558 | // Universal ajax callback for all tracking events triggered via js |
||
| 559 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
| 560 | |||
| 561 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 562 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 563 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 564 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 565 | |||
| 566 | add_action( 'jetpack_activate_module', array( $this, 'activate_module_actions' ) ); |
||
| 567 | |||
| 568 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
| 569 | |||
| 570 | add_action( 'jetpack_notices', array( $this, 'show_development_mode_notice' ) ); |
||
| 571 | |||
| 572 | /** |
||
| 573 | * These actions run checks to load additional files. |
||
| 574 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 575 | */ |
||
| 576 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 577 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 578 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 579 | |||
| 580 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 581 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 582 | |||
| 583 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
| 584 | |||
| 585 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 586 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 587 | |||
| 588 | // A filter to control all just in time messages |
||
| 589 | add_filter( 'jetpack_just_in_time_msgs', '__return_true' ); |
||
| 590 | |||
| 591 | /** |
||
| 592 | * This is the hack to concatinate all css files into one. |
||
| 593 | * For description and reasoning see the implode_frontend_css method |
||
| 594 | * |
||
| 595 | * Super late priority so we catch all the registered styles |
||
| 596 | */ |
||
| 597 | if( !is_admin() ) { |
||
| 598 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 599 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 600 | } |
||
| 601 | |||
| 602 | // Sync Core Icon: Detect changes in Core's Site Icon and make it syncable. |
||
| 603 | add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 604 | add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 605 | add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 606 | add_action( 'jetpack_heartbeat', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 607 | |||
| 608 | } |
||
| 609 | |||
| 610 | /* |
||
| 611 | * Make sure any site icon added to core can get |
||
| 612 | * synced back to dotcom, so we can display it there. |
||
| 613 | */ |
||
| 614 | function jetpack_sync_core_icon() { |
||
| 615 | if ( function_exists( 'get_site_icon_url' ) ) { |
||
| 616 | $url = get_site_icon_url(); |
||
| 617 | } else { |
||
| 618 | return; |
||
| 619 | } |
||
| 620 | |||
| 621 | require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' ); |
||
| 622 | // If there's a core icon, maybe update the option. If not, fall back to Jetpack's. |
||
| 623 | if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) { |
||
| 624 | // This is the option that is synced with dotcom |
||
| 625 | Jetpack_Options::update_option( 'site_icon_url', $url ); |
||
| 626 | } else if ( empty( $url ) && did_action( 'delete_option_site_icon' ) ) { |
||
| 627 | Jetpack_Options::delete_option( 'site_icon_url' ); |
||
| 628 | } |
||
| 629 | } |
||
| 630 | |||
| 631 | function jetpack_admin_ajax_tracks_callback() { |
||
| 632 | // Check for nonce |
||
| 633 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
| 634 | wp_die( 'Permissions check failed.' ); |
||
| 635 | } |
||
| 636 | |||
| 637 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
| 638 | wp_die( 'No valid event name or type.' ); |
||
| 639 | } |
||
| 640 | |||
| 641 | $tracks_data = array(); |
||
| 642 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
| 643 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
| 644 | } |
||
| 645 | |||
| 646 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
| 647 | wp_send_json_success(); |
||
| 648 | wp_die(); |
||
| 649 | } |
||
| 650 | |||
| 651 | function jetpack_admin_ajax_callback() { |
||
| 652 | // Check for nonce |
||
| 653 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) || ! current_user_can( 'jetpack_manage_modules' ) ) { |
|
| 654 | wp_die( 'permissions check failed' ); |
||
| 655 | } |
||
| 656 | |||
| 657 | if ( isset( $_REQUEST['toggleModule'] ) && 'nux-toggle-module' == $_REQUEST['toggleModule'] ) { |
||
| 658 | $slug = $_REQUEST['thisModuleSlug']; |
||
| 659 | |||
| 660 | if ( ! in_array( $slug, Jetpack::get_available_modules() ) ) { |
||
| 661 | wp_die( 'That is not a Jetpack module slug' ); |
||
| 662 | } |
||
| 663 | |||
| 664 | if ( Jetpack::is_module_active( $slug ) ) { |
||
| 665 | Jetpack::deactivate_module( $slug ); |
||
| 666 | } else { |
||
| 667 | Jetpack::activate_module( $slug, false, false ); |
||
| 668 | } |
||
| 669 | |||
| 670 | $modules = Jetpack_Admin::init()->get_modules(); |
||
| 671 | echo json_encode( $modules[ $slug ] ); |
||
| 672 | |||
| 673 | exit; |
||
| 674 | } |
||
| 675 | |||
| 676 | wp_die(); |
||
| 677 | } |
||
| 678 | |||
| 679 | /* |
||
| 680 | * Sometimes we need to refresh the data, |
||
| 681 | * especially if the page is visited via a 'history' |
||
| 682 | * event like back/forward |
||
| 683 | */ |
||
| 684 | function jetpack_admin_ajax_refresh_data() { |
||
| 685 | // Check for nonce |
||
| 686 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) ) { |
|
| 687 | wp_die( 'permissions check failed' ); |
||
| 688 | } |
||
| 689 | |||
| 690 | if ( isset( $_REQUEST['refreshData'] ) && 'refresh' == $_REQUEST['refreshData'] ) { |
||
| 691 | $modules = Jetpack_Admin::init()->get_modules(); |
||
| 692 | echo json_encode( $modules ); |
||
| 693 | exit; |
||
| 694 | } |
||
| 695 | |||
| 696 | wp_die(); |
||
| 697 | } |
||
| 698 | |||
| 699 | /** |
||
| 700 | * The callback for the Jump Start ajax requests. |
||
| 701 | */ |
||
| 702 | function jetpack_jumpstart_ajax_callback() { |
||
| 703 | // Check for nonce |
||
| 704 | if ( ! isset( $_REQUEST['jumpstartNonce'] ) || ! wp_verify_nonce( $_REQUEST['jumpstartNonce'], 'jetpack-jumpstart-nonce' ) ) |
||
| 705 | wp_die( 'permissions check failed' ); |
||
| 706 | |||
| 707 | if ( isset( $_REQUEST['jumpStartActivate'] ) && 'jump-start-activate' == $_REQUEST['jumpStartActivate'] ) { |
||
| 708 | // Update the jumpstart option |
||
| 709 | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
||
| 710 | Jetpack_Options::update_option( 'jumpstart', 'jumpstart_activated' ); |
||
| 711 | } |
||
| 712 | |||
| 713 | // Loops through the requested "Jump Start" modules, and activates them. |
||
| 714 | // Custom 'no_message' state, so that no message will be shown on reload. |
||
| 715 | $modules = $_REQUEST['jumpstartModSlug']; |
||
| 716 | $module_slugs = array(); |
||
| 717 | foreach( $modules as $module => $value ) { |
||
| 718 | $module_slugs[] = $value['module_slug']; |
||
| 719 | } |
||
| 720 | |||
| 721 | // Check for possible conflicting plugins |
||
| 722 | $module_slugs_filtered = $this->filter_default_modules( $module_slugs ); |
||
| 723 | |||
| 724 | foreach ( $module_slugs_filtered as $module_slug ) { |
||
| 725 | Jetpack::log( 'activate', $module_slug ); |
||
| 726 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 727 | Jetpack::state( 'message', 'no_message' ); |
||
| 728 | } |
||
| 729 | |||
| 730 | // Set the default sharing buttons and set to display on posts if none have been set. |
||
| 731 | $sharing_services = get_option( 'sharing-services' ); |
||
| 732 | $sharing_options = get_option( 'sharing-options' ); |
||
| 733 | if ( empty( $sharing_services['visible'] ) ) { |
||
| 734 | // Default buttons to set |
||
| 735 | $visible = array( |
||
| 736 | 'twitter', |
||
| 737 | 'facebook', |
||
| 738 | 'google-plus-1', |
||
| 739 | ); |
||
| 740 | $hidden = array(); |
||
| 741 | |||
| 742 | // Set some sharing settings |
||
| 743 | $sharing = new Sharing_Service(); |
||
| 744 | $sharing_options['global'] = array( |
||
| 745 | 'button_style' => 'icon', |
||
| 746 | 'sharing_label' => $sharing->default_sharing_label, |
||
| 747 | 'open_links' => 'same', |
||
| 748 | 'show' => array( 'post' ), |
||
| 749 | 'custom' => isset( $sharing_options['global']['custom'] ) ? $sharing_options['global']['custom'] : array() |
||
| 750 | ); |
||
| 751 | |||
| 752 | update_option( 'sharing-options', $sharing_options ); |
||
| 753 | |||
| 754 | // Send a success response so that we can display an error message. |
||
| 755 | $success = update_option( 'sharing-services', array( 'visible' => $visible, 'hidden' => $hidden ) ); |
||
| 756 | echo json_encode( $success ); |
||
| 757 | exit; |
||
| 758 | } |
||
| 759 | |||
| 760 | } elseif ( isset( $_REQUEST['disableJumpStart'] ) && true == $_REQUEST['disableJumpStart'] ) { |
||
| 761 | // If dismissed, flag the jumpstart option as such. |
||
| 762 | // Send a success response so that we can display an error message. |
||
| 763 | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
||
| 764 | $success = Jetpack_Options::update_option( 'jumpstart', 'jumpstart_dismissed' ); |
||
| 765 | echo json_encode( $success ); |
||
| 766 | exit; |
||
| 767 | } |
||
| 768 | |||
| 769 | } elseif ( isset( $_REQUEST['jumpStartDeactivate'] ) && 'jump-start-deactivate' == $_REQUEST['jumpStartDeactivate'] ) { |
||
| 770 | |||
| 771 | // FOR TESTING ONLY |
||
| 772 | // @todo remove |
||
| 773 | $modules = (array) $_REQUEST['jumpstartModSlug']; |
||
| 774 | foreach( $modules as $module => $value ) { |
||
| 775 | if ( !in_array( $value['module_slug'], Jetpack::get_default_modules() ) ) { |
||
| 776 | Jetpack::log( 'deactivate', $value['module_slug'] ); |
||
| 777 | Jetpack::deactivate_module( $value['module_slug'] ); |
||
| 778 | Jetpack::state( 'message', 'no_message' ); |
||
| 779 | } else { |
||
| 780 | Jetpack::log( 'activate', $value['module_slug'] ); |
||
| 781 | Jetpack::activate_module( $value['module_slug'], false, false ); |
||
| 782 | Jetpack::state( 'message', 'no_message' ); |
||
| 783 | } |
||
| 784 | } |
||
| 785 | |||
| 786 | Jetpack_Options::update_option( 'jumpstart', 'new_connection' ); |
||
| 787 | echo "reload the page"; |
||
| 788 | } |
||
| 789 | |||
| 790 | wp_die(); |
||
| 791 | } |
||
| 792 | |||
| 793 | /** |
||
| 794 | * The callback for the JITM ajax requests. |
||
| 795 | */ |
||
| 796 | function jetpack_jitm_ajax_callback() { |
||
| 797 | // Check for nonce |
||
| 798 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
| 799 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
| 800 | } |
||
| 801 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
| 802 | $module_slug = $_REQUEST['jitmModule']; |
||
| 803 | Jetpack::log( 'activate', $module_slug ); |
||
| 804 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 805 | Jetpack::state( 'message', 'no_message' ); |
||
| 806 | |||
| 807 | //A Jetpack module is being activated through a JITM, track it |
||
| 808 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
| 809 | $this->do_stats( 'server_side' ); |
||
| 810 | |||
| 811 | wp_send_json_success(); |
||
| 812 | } |
||
| 813 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
| 814 | // get the hide_jitm options array |
||
| 815 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
| 816 | $module_slug = $_REQUEST['jitmModule']; |
||
| 817 | |||
| 818 | if( ! $jetpack_hide_jitm ) { |
||
| 819 | $jetpack_hide_jitm = array( |
||
| 820 | $module_slug => 'hide' |
||
| 821 | ); |
||
| 822 | } else { |
||
| 823 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
| 824 | } |
||
| 825 | |||
| 826 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
| 827 | |||
| 828 | //jitm is being dismissed forever, track it |
||
| 829 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
| 830 | $this->do_stats( 'server_side' ); |
||
| 831 | |||
| 832 | wp_send_json_success(); |
||
| 833 | } |
||
| 834 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
| 835 | $module_slug = $_REQUEST['jitmModule']; |
||
| 836 | |||
| 837 | // User went to WordPress.com, track this |
||
| 838 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
| 839 | $this->do_stats( 'server_side' ); |
||
| 840 | |||
| 841 | wp_send_json_success(); |
||
| 842 | } |
||
| 843 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
| 844 | $track = $_REQUEST['jitmModule']; |
||
| 845 | |||
| 846 | // User is viewing JITM, track it. |
||
| 847 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
| 848 | $this->do_stats( 'server_side' ); |
||
| 849 | |||
| 850 | wp_send_json_success(); |
||
| 851 | } |
||
| 852 | } |
||
| 853 | |||
| 854 | /** |
||
| 855 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 856 | */ |
||
| 857 | function __destruct() { |
||
| 858 | if ( ! empty( $this->stats ) ) { |
||
| 859 | $this->do_stats( 'server_side' ); |
||
| 860 | } |
||
| 861 | } |
||
| 862 | |||
| 863 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 864 | switch( $cap ) { |
||
| 865 | case 'jetpack_connect' : |
||
| 866 | case 'jetpack_reconnect' : |
||
| 867 | if ( Jetpack::is_development_mode() ) { |
||
| 868 | $caps = array( 'do_not_allow' ); |
||
| 869 | break; |
||
| 870 | } |
||
| 871 | /** |
||
| 872 | * Pass through. If it's not development mode, these should match disconnect. |
||
| 873 | * Let users disconnect if it's development mode, just in case things glitch. |
||
| 874 | */ |
||
| 875 | case 'jetpack_disconnect' : |
||
| 876 | /** |
||
| 877 | * In multisite, can individual site admins manage their own connection? |
||
| 878 | * |
||
| 879 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
| 880 | */ |
||
| 881 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
| 882 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
| 883 | /** |
||
| 884 | * We need to update the option name -- it's terribly unclear which |
||
| 885 | * direction the override goes. |
||
| 886 | * |
||
| 887 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
| 888 | */ |
||
| 889 | $caps = array( 'do_not_allow' ); |
||
| 890 | break; |
||
| 891 | } |
||
| 892 | } |
||
| 893 | |||
| 894 | $caps = array( 'manage_options' ); |
||
| 895 | break; |
||
| 896 | case 'jetpack_manage_modules' : |
||
| 897 | case 'jetpack_activate_modules' : |
||
| 898 | case 'jetpack_deactivate_modules' : |
||
| 899 | $caps = array( 'manage_options' ); |
||
| 900 | break; |
||
| 901 | case 'jetpack_configure_modules' : |
||
| 902 | $caps = array( 'manage_options' ); |
||
| 903 | break; |
||
| 904 | case 'jetpack_network_admin_page': |
||
| 905 | case 'jetpack_network_settings_page': |
||
| 906 | $caps = array( 'manage_network_plugins' ); |
||
| 907 | break; |
||
| 908 | case 'jetpack_network_sites_page': |
||
| 909 | $caps = array( 'manage_sites' ); |
||
| 910 | break; |
||
| 911 | case 'jetpack_admin_page' : |
||
| 912 | if ( Jetpack::is_development_mode() ) { |
||
| 913 | $caps = array( 'manage_options' ); |
||
| 914 | break; |
||
| 915 | } |
||
| 916 | |||
| 917 | // Don't ever show to subscribers, but allow access to the page if they're trying to unlink. |
||
| 918 | if ( ! current_user_can( 'edit_posts' ) ) { |
||
| 919 | if ( isset( $_GET['redirect'] ) && 'sub-unlink' == $_GET['redirect'] ) { |
||
| 920 | // We need this in order to unlink the user. |
||
| 921 | $this->admin_page_load(); |
||
| 922 | } |
||
| 923 | if ( ! wp_verify_nonce( 'jetpack-unlink' ) ) { |
||
| 924 | $caps = array( 'do_not_allow' ); |
||
| 925 | break; |
||
| 926 | } |
||
| 927 | } |
||
| 928 | |||
| 929 | if ( ! self::is_active() && ! current_user_can( 'jetpack_connect' ) ) { |
||
| 930 | $caps = array( 'do_not_allow' ); |
||
| 931 | break; |
||
| 932 | } |
||
| 933 | /** |
||
| 934 | * Pass through. If it's not development mode, these should match the admin page. |
||
| 935 | * Let users disconnect if it's development mode, just in case things glitch. |
||
| 936 | */ |
||
| 937 | case 'jetpack_connect_user' : |
||
| 938 | if ( Jetpack::is_development_mode() ) { |
||
| 939 | $caps = array( 'do_not_allow' ); |
||
| 940 | break; |
||
| 941 | } |
||
| 942 | $caps = array( 'read' ); |
||
| 943 | break; |
||
| 944 | } |
||
| 945 | return $caps; |
||
| 946 | } |
||
| 947 | |||
| 948 | function require_jetpack_authentication() { |
||
| 949 | // Don't let anyone authenticate |
||
| 950 | $_COOKIE = array(); |
||
| 951 | remove_all_filters( 'authenticate' ); |
||
| 952 | |||
| 953 | /** |
||
| 954 | * For the moment, remove Limit Login Attempts if its xmlrpc for Jetpack. |
||
| 955 | * If Limit Login Attempts is installed as a mu-plugin, it can occasionally |
||
| 956 | * generate false-positives. |
||
| 957 | */ |
||
| 958 | remove_filter( 'wp_login_failed', 'limit_login_failed' ); |
||
| 959 | |||
| 960 | if ( Jetpack::is_active() ) { |
||
| 961 | // Allow Jetpack authentication |
||
| 962 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
| 963 | } |
||
| 964 | } |
||
| 965 | |||
| 966 | /** |
||
| 967 | * Load language files |
||
| 968 | */ |
||
| 969 | public static function plugin_textdomain() { |
||
| 970 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
| 971 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
| 972 | } |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 976 | * |
||
| 977 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 978 | * @action wp_loaded |
||
| 979 | * @return null |
||
| 980 | */ |
||
| 981 | public function register_assets() { |
||
| 982 | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
||
| 983 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
| 984 | } |
||
| 985 | |||
| 986 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
| 987 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
| 988 | } |
||
| 989 | |||
| 990 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 991 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
| 992 | } |
||
| 993 | |||
| 994 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
| 995 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
| 996 | } |
||
| 997 | |||
| 998 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 999 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
| 1000 | |||
| 1001 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 1002 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 1003 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 1004 | $fb_app_id = ''; |
||
| 1005 | } |
||
| 1006 | wp_localize_script( |
||
| 1007 | 'jetpack-facebook-embed', |
||
| 1008 | 'jpfbembed', |
||
| 1009 | array( |
||
| 1010 | 'appid' => $fb_app_id, |
||
| 1011 | 'locale' => $this->get_locale(), |
||
| 1012 | ) |
||
| 1013 | ); |
||
| 1014 | } |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 1018 | * the hook may have already fired by this point. |
||
| 1019 | * So, let's just trigger it manually. |
||
| 1020 | */ |
||
| 1021 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
| 1022 | jetpack_register_genericons(); |
||
| 1023 | |||
| 1024 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
| 1025 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 1026 | } |
||
| 1027 | |||
| 1028 | /** |
||
| 1029 | * Guess locale from language code. |
||
| 1030 | * |
||
| 1031 | * @param string $lang Language code. |
||
| 1032 | * @return string|bool |
||
| 1033 | */ |
||
| 1034 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 1035 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
| 1036 | return 'en_US'; |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
| 1040 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
| 1041 | return false; |
||
| 1042 | } |
||
| 1043 | |||
| 1044 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
| 1045 | } |
||
| 1046 | |||
| 1047 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 1048 | // WP.com: get_locale() returns 'it' |
||
| 1049 | $locale = GP_Locales::by_slug( $lang ); |
||
| 1050 | } else { |
||
| 1051 | // Jetpack: get_locale() returns 'it_IT'; |
||
| 1052 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
| 1053 | } |
||
| 1054 | |||
| 1055 | if ( ! $locale ) { |
||
| 1056 | return false; |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | if ( empty( $locale->facebook_locale ) ) { |
||
| 1060 | if ( empty( $locale->wp_locale ) ) { |
||
| 1061 | return false; |
||
| 1062 | } else { |
||
| 1063 | // Facebook SDK is smart enough to fall back to en_US if a |
||
| 1064 | // locale isn't supported. Since supported Facebook locales |
||
| 1065 | // can fall out of sync, we'll attempt to use the known |
||
| 1066 | // wp_locale value and rely on said fallback. |
||
| 1067 | return $locale->wp_locale; |
||
| 1068 | } |
||
| 1069 | } |
||
| 1070 | |||
| 1071 | return $locale->facebook_locale; |
||
| 1072 | } |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Get the locale. |
||
| 1076 | * |
||
| 1077 | * @return string|bool |
||
| 1078 | */ |
||
| 1079 | function get_locale() { |
||
| 1080 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
| 1081 | |||
| 1082 | if ( ! $locale ) { |
||
| 1083 | $locale = 'en_US'; |
||
| 1084 | } |
||
| 1085 | |||
| 1086 | return $locale; |
||
| 1087 | } |
||
| 1088 | |||
| 1089 | /** |
||
| 1090 | * Device Pixels support |
||
| 1091 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
| 1092 | */ |
||
| 1093 | function devicepx() { |
||
| 1098 | |||
| 1099 | /* |
||
| 1100 | * Returns the location of Jetpack's lib directory. This filter is applied |
||
| 1101 | * in require_lib(). |
||
| 1102 | * |
||
| 1103 | * @filter require_lib_dir |
||
| 1104 | */ |
||
| 1105 | function require_lib_dir() { |
||
| 1108 | |||
| 1109 | /** |
||
| 1110 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 1111 | * @param bool $option |
||
| 1112 | * @return string |
||
| 1113 | */ |
||
| 1114 | public function jetpack_main_network_site_option( $option ) { |
||
| 1117 | /** |
||
| 1118 | * Network Name. |
||
| 1119 | */ |
||
| 1120 | static function network_name( $option = null ) { |
||
| 1124 | /** |
||
| 1125 | * Does the network allow new user and site registrations. |
||
| 1126 | * @return string |
||
| 1127 | */ |
||
| 1128 | static function network_allow_new_registrations( $option = null ) { |
||
| 1131 | /** |
||
| 1132 | * Does the network allow admins to add new users. |
||
| 1133 | * @return boolian |
||
| 1134 | */ |
||
| 1135 | static function network_add_new_users( $option = null ) { |
||
| 1138 | /** |
||
| 1139 | * File upload psace left per site in MB. |
||
| 1140 | * -1 means NO LIMIT. |
||
| 1141 | * @return number |
||
| 1142 | */ |
||
| 1143 | static function network_site_upload_space( $option = null ) { |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * Network allowed file types. |
||
| 1150 | * @return string |
||
| 1151 | */ |
||
| 1152 | static function network_upload_file_types( $option = null ) { |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Maximum file upload size set by the network. |
||
| 1158 | * @return number |
||
| 1159 | */ |
||
| 1160 | static function network_max_upload_file_size( $option = null ) { |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Lets us know if a site allows admins to manage the network. |
||
| 1167 | * @return array |
||
| 1168 | */ |
||
| 1169 | static function network_enable_administration_menus( $option = null ) { |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Return whether we are dealing with a multi network setup or not. |
||
| 1175 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 1176 | * the result is false since when is_main_network_option return false it cases |
||
| 1177 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 1178 | * database which could be set to anything as opposed to what this function returns. |
||
| 1179 | * @param bool $option |
||
| 1180 | * |
||
| 1181 | * @return boolean |
||
| 1182 | */ |
||
| 1183 | public function is_main_network_option( $option ) { |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 1190 | * |
||
| 1191 | * @param string $option |
||
| 1192 | * @return boolean |
||
| 1193 | */ |
||
| 1194 | public function is_multisite( $option ) { |
||
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Implemented since there is no core is multi network function |
||
| 1200 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 1201 | * |
||
| 1202 | * @since 3.3 |
||
| 1203 | * @return boolean |
||
| 1204 | */ |
||
| 1205 | public static function is_multi_network() { |
||
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1223 | * @return null |
||
| 1224 | */ |
||
| 1225 | function update_jetpack_main_network_site_option() { |
||
| 1258 | /** |
||
| 1259 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1260 | * |
||
| 1261 | */ |
||
| 1262 | function update_jetpack_network_settings() { |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Get back if the current site is single user site. |
||
| 1275 | * |
||
| 1276 | * @return bool |
||
| 1277 | */ |
||
| 1278 | public static function is_single_user_site() { |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Returns true if the site has file write access false otherwise. |
||
| 1290 | * @return string ( '1' | '0' ) |
||
| 1291 | **/ |
||
| 1292 | public static function file_system_write_access() { |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Finds out if a site is using a version control system. |
||
| 1315 | * @return string ( '1' | '0' ) |
||
| 1316 | **/ |
||
| 1317 | public static function is_version_controlled() { |
||
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Determines whether the current theme supports featured images or not. |
||
| 1333 | * @return string ( '1' | '0' ) |
||
| 1334 | */ |
||
| 1335 | public static function featured_images_enabled() { |
||
| 1338 | |||
| 1339 | /* |
||
| 1340 | * Sync back wp_version |
||
| 1341 | */ |
||
| 1342 | public static function get_wp_version() { |
||
| 1346 | |||
| 1347 | /** |
||
| 1348 | * Keeps wp_version in sync with .com when WordPress core updates |
||
| 1349 | **/ |
||
| 1350 | public static function update_get_wp_version( $update, $meta_data ) { |
||
| 1360 | |||
| 1361 | /** |
||
| 1362 | * Triggers a sync of update counts and update details |
||
| 1363 | */ |
||
| 1364 | function sync_update_data() { |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * Triggers a sync of information specific to the current theme. |
||
| 1383 | */ |
||
| 1384 | function sync_theme_data() { |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * jetpack_updates is saved in the following schema: |
||
| 1391 | * |
||
| 1392 | * array ( |
||
| 1393 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1394 | * 'themes' => (int) Number of theme updates available. |
||
| 1395 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1396 | * 'translations' => (int) Number of translation updates available. |
||
| 1397 | * 'total' => (int) Total of all available updates. |
||
| 1398 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1399 | * ) |
||
| 1400 | * @return array |
||
| 1401 | */ |
||
| 1402 | public static function get_updates() { |
||
| 1419 | |||
| 1420 | public static function get_update_details() { |
||
| 1428 | |||
| 1429 | public static function refresh_update_data() { |
||
| 1453 | |||
| 1454 | public static function refresh_theme_data() { |
||
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Invalides the transient as well as triggers the update of the mock option. |
||
| 1468 | * |
||
| 1469 | * @return null |
||
| 1470 | */ |
||
| 1471 | function is_single_user_site_invalidate() { |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Is Jetpack active? |
||
| 1486 | */ |
||
| 1487 | public static function is_active() { |
||
| 1490 | |||
| 1491 | /** |
||
| 1492 | * Is Jetpack in development (offline) mode? |
||
| 1493 | */ |
||
| 1494 | public static function is_development_mode() { |
||
| 1515 | |||
| 1516 | /** |
||
| 1517 | * Get Jetpack development mode notice text and notice class. |
||
| 1518 | * |
||
| 1519 | * Mirrors the checks made in Jetpack::is_development_mode |
||
| 1520 | * |
||
| 1521 | */ |
||
| 1522 | public static function show_development_mode_notice() { |
||
| 1562 | |||
| 1563 | /** |
||
| 1564 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1565 | */ |
||
| 1566 | public static function is_development_version() { |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1572 | */ |
||
| 1573 | public static function is_user_connected( $user_id = false ) { |
||
| 1580 | |||
| 1581 | /** |
||
| 1582 | * Get the wpcom user data of the current|specified connected user. |
||
| 1583 | */ |
||
| 1584 | View Code Duplication | public static function get_connected_user_data( $user_id = null ) { |
|
| 1598 | |||
| 1599 | /** |
||
| 1600 | * Get the wpcom email of the current|specified connected user. |
||
| 1601 | */ |
||
| 1602 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Get the wpcom email of the master user. |
||
| 1619 | */ |
||
| 1620 | public static function get_master_user_email() { |
||
| 1627 | |||
| 1628 | function current_user_is_connection_owner() { |
||
| 1632 | |||
| 1633 | /** |
||
| 1634 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
| 1635 | */ |
||
| 1636 | function extra_oembed_providers() { |
||
| 1644 | |||
| 1645 | /** |
||
| 1646 | * Synchronize connected user role changes |
||
| 1647 | */ |
||
| 1648 | function user_role_change( $user_id ) { |
||
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Loads the currently active modules. |
||
| 1694 | */ |
||
| 1695 | public static function load_modules() { |
||
| 1779 | |||
| 1780 | /** |
||
| 1781 | * Check if Jetpack's REST API compat file should be included |
||
| 1782 | * @action plugins_loaded |
||
| 1783 | * @return null |
||
| 1784 | */ |
||
| 1785 | public function check_rest_api_compat() { |
||
| 1801 | |||
| 1802 | /** |
||
| 1803 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 1804 | * traditionally activated or network activated. |
||
| 1805 | * |
||
| 1806 | * @todo Store the result in core's object cache maybe? |
||
| 1807 | */ |
||
| 1808 | public static function get_active_plugins() { |
||
| 1824 | |||
| 1825 | /** |
||
| 1826 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 1827 | * |
||
| 1828 | * @since 3.8.1 |
||
| 1829 | * |
||
| 1830 | * @return array Array of plugin data |
||
| 1831 | */ |
||
| 1832 | public static function get_parsed_plugin_data() { |
||
| 1852 | |||
| 1853 | /** |
||
| 1854 | * Gets and parses theme data to send with the heartbeat data |
||
| 1855 | * |
||
| 1856 | * @since 3.8.1 |
||
| 1857 | * |
||
| 1858 | * @return array Array of theme data |
||
| 1859 | */ |
||
| 1860 | public static function get_parsed_theme_data() { |
||
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Checks whether a specific plugin is active. |
||
| 1885 | * |
||
| 1886 | * We don't want to store these in a static variable, in case |
||
| 1887 | * there are switch_to_blog() calls involved. |
||
| 1888 | */ |
||
| 1889 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 1892 | |||
| 1893 | /** |
||
| 1894 | * Check if Jetpack's Open Graph tags should be used. |
||
| 1895 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 1896 | * |
||
| 1897 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1898 | * @action plugins_loaded |
||
| 1899 | * @return null |
||
| 1900 | */ |
||
| 1901 | public function check_open_graph() { |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Check if Jetpack's Twitter tags should be used. |
||
| 1931 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 1932 | * |
||
| 1933 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1934 | * @action plugins_loaded |
||
| 1935 | * @return null |
||
| 1936 | */ |
||
| 1937 | public function check_twitter_tags() { |
||
| 1961 | |||
| 1962 | |||
| 1963 | |||
| 1964 | |||
| 1965 | /* |
||
| 1966 | * |
||
| 1967 | * Jetpack Security Reports |
||
| 1968 | * |
||
| 1969 | * Allowed types: login_form, backup, file_scanning, spam |
||
| 1970 | * |
||
| 1971 | * Args for login_form and spam: 'blocked'=>(int)(optional), 'status'=>(string)(ok, warning, error), 'message'=>(optional, disregarded if status is ok, allowed tags: a, em, strong) |
||
| 1972 | * |
||
| 1973 | * Args for backup and file_scanning: 'last'=>(timestamp)(optional), 'next'=>(timestamp)(optional), 'status'=>(string)(ok, warning, error), 'message'=>(optional, disregarded if status is ok, allowed tags: a, em, strong) |
||
| 1974 | * |
||
| 1975 | * |
||
| 1976 | * Example code to submit a security report: |
||
| 1977 | * |
||
| 1978 | * function akismet_submit_jetpack_security_report() { |
||
| 1979 | * Jetpack::submit_security_report( 'spam', __FILE__, $args = array( 'blocked' => 138284, status => 'ok' ) ); |
||
| 1980 | * } |
||
| 1981 | * add_action( 'jetpack_security_report', 'akismet_submit_jetpack_security_report' ); |
||
| 1982 | * |
||
| 1983 | */ |
||
| 1984 | |||
| 1985 | |||
| 1986 | /** |
||
| 1987 | * Calls for security report submissions. |
||
| 1988 | * |
||
| 1989 | * @return null |
||
| 1990 | */ |
||
| 1991 | public static function perform_security_reporting() { |
||
| 2008 | |||
| 2009 | /** |
||
| 2010 | * Allows plugins to submit security reports. |
||
| 2011 | * |
||
| 2012 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 2013 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 2014 | * @param array $args See definitions above |
||
| 2015 | */ |
||
| 2016 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Collects a new report if needed, then returns it. |
||
| 2083 | */ |
||
| 2084 | public function get_security_report() { |
||
| 2088 | |||
| 2089 | |||
| 2090 | /* Jetpack Options API */ |
||
| 2091 | |||
| 2092 | public static function get_option_names( $type = 'compact' ) { |
||
| 2095 | |||
| 2096 | /** |
||
| 2097 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 2098 | * |
||
| 2099 | * @param string $name Option name |
||
| 2100 | * @param mixed $default (optional) |
||
| 2101 | */ |
||
| 2102 | public static function get_option( $name, $default = false ) { |
||
| 2105 | |||
| 2106 | /** |
||
| 2107 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
| 2108 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
| 2109 | * $name must be a registered option name. |
||
| 2110 | */ |
||
| 2111 | public static function create_nonce( $name ) { |
||
| 2125 | |||
| 2126 | /** |
||
| 2127 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 2128 | * |
||
| 2129 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 2130 | * @param string $name Option name |
||
| 2131 | * @param mixed $value Option value |
||
| 2132 | */ |
||
| 2133 | public static function update_option( $name, $value ) { |
||
| 2137 | |||
| 2138 | /** |
||
| 2139 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 2140 | * |
||
| 2141 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 2142 | * @param array $array array( option name => option value, ... ) |
||
| 2143 | */ |
||
| 2144 | public static function update_options( $array ) { |
||
| 2148 | |||
| 2149 | /** |
||
| 2150 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 2151 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 2152 | * |
||
| 2153 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 2154 | * @param string|array $names |
||
| 2155 | */ |
||
| 2156 | public static function delete_option( $names ) { |
||
| 2160 | |||
| 2161 | /** |
||
| 2162 | * Enters a user token into the user_tokens option |
||
| 2163 | * |
||
| 2164 | * @param int $user_id |
||
| 2165 | * @param string $token |
||
| 2166 | * return bool |
||
| 2167 | */ |
||
| 2168 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 2182 | |||
| 2183 | /** |
||
| 2184 | * Returns an array of all PHP files in the specified absolute path. |
||
| 2185 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 2186 | * |
||
| 2187 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 2188 | * @return array Array of absolute paths to the PHP files. |
||
| 2189 | */ |
||
| 2190 | public static function glob_php( $absolute_path ) { |
||
| 2219 | |||
| 2220 | public static function activate_new_modules( $redirect = false ) { |
||
| 2278 | |||
| 2279 | /** |
||
| 2280 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 2281 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 2282 | */ |
||
| 2283 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 2340 | |||
| 2341 | /** |
||
| 2342 | * Default modules loaded on activation. |
||
| 2343 | */ |
||
| 2344 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 2375 | |||
| 2376 | /** |
||
| 2377 | * Checks activated modules during auto-activation to determine |
||
| 2378 | * if any of those modules are being deprecated. If so, close |
||
| 2379 | * them out, and add any replacement modules. |
||
| 2380 | * |
||
| 2381 | * Runs at priority 99 by default. |
||
| 2382 | * |
||
| 2383 | * This is run late, so that it can still activate a module if |
||
| 2384 | * the new module is a replacement for another that the user |
||
| 2385 | * currently has active, even if something at the normal priority |
||
| 2386 | * would kibosh everything. |
||
| 2387 | * |
||
| 2388 | * @since 2.6 |
||
| 2389 | * @uses jetpack_get_default_modules filter |
||
| 2390 | * @param array $modules |
||
| 2391 | * @return array |
||
| 2392 | */ |
||
| 2393 | function handle_deprecated_modules( $modules ) { |
||
| 2419 | |||
| 2420 | /** |
||
| 2421 | * Checks activated plugins during auto-activation to determine |
||
| 2422 | * if any of those plugins are in the list with a corresponding module |
||
| 2423 | * that is not compatible with the plugin. The module will not be allowed |
||
| 2424 | * to auto-activate. |
||
| 2425 | * |
||
| 2426 | * @since 2.6 |
||
| 2427 | * @uses jetpack_get_default_modules filter |
||
| 2428 | * @param array $modules |
||
| 2429 | * @return array |
||
| 2430 | */ |
||
| 2431 | function filter_default_modules( $modules ) { |
||
| 2455 | |||
| 2456 | /** |
||
| 2457 | * Extract a module's slug from its full path. |
||
| 2458 | */ |
||
| 2459 | public static function get_module_slug( $file ) { |
||
| 2462 | |||
| 2463 | /** |
||
| 2464 | * Generate a module's path from its slug. |
||
| 2465 | */ |
||
| 2466 | public static function get_module_path( $slug ) { |
||
| 2469 | |||
| 2470 | /** |
||
| 2471 | * Load module data from module file. Headers differ from WordPress |
||
| 2472 | * plugin headers to avoid them being identified as standalone |
||
| 2473 | * plugins on the WordPress plugins page. |
||
| 2474 | */ |
||
| 2475 | public static function get_module( $module ) { |
||
| 2558 | |||
| 2559 | /** |
||
| 2560 | * Like core's get_file_data implementation, but caches the result. |
||
| 2561 | */ |
||
| 2562 | public static function get_file_data( $file, $headers ) { |
||
| 2583 | |||
| 2584 | /** |
||
| 2585 | * Return translated module tag. |
||
| 2586 | * |
||
| 2587 | * @param string $tag Tag as it appears in each module heading. |
||
| 2588 | * |
||
| 2589 | * @return mixed |
||
| 2590 | */ |
||
| 2591 | public static function translate_module_tag( $tag ) { |
||
| 2594 | |||
| 2595 | /** |
||
| 2596 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2597 | * |
||
| 2598 | * @since 3.9.2 |
||
| 2599 | * |
||
| 2600 | * @param array $modules |
||
| 2601 | * |
||
| 2602 | * @return string|void |
||
| 2603 | */ |
||
| 2604 | public static function get_translated_modules( $modules ) { |
||
| 2617 | |||
| 2618 | /** |
||
| 2619 | * Get a list of activated modules as an array of module slugs. |
||
| 2620 | */ |
||
| 2621 | public static function get_active_modules() { |
||
| 2638 | |||
| 2639 | /** |
||
| 2640 | * Check whether or not a Jetpack module is active. |
||
| 2641 | * |
||
| 2642 | * @param string $module The slug of a Jetpack module. |
||
| 2643 | * @return bool |
||
| 2644 | * |
||
| 2645 | * @static |
||
| 2646 | */ |
||
| 2647 | public static function is_module_active( $module ) { |
||
| 2650 | |||
| 2651 | public static function is_module( $module ) { |
||
| 2654 | |||
| 2655 | /** |
||
| 2656 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2657 | * |
||
| 2658 | * @param bool $catch True to start catching, False to stop. |
||
| 2659 | * |
||
| 2660 | * @static |
||
| 2661 | */ |
||
| 2662 | public static function catch_errors( $catch ) { |
||
| 2675 | |||
| 2676 | /** |
||
| 2677 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2678 | */ |
||
| 2679 | public static function catch_errors_on_shutdown() { |
||
| 2682 | |||
| 2683 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
| 2806 | |||
| 2807 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 2808 | /** |
||
| 2809 | * Fires before a module is activated. |
||
| 2810 | * |
||
| 2811 | * @since 2.6.0 |
||
| 2812 | * |
||
| 2813 | * @param string $module Module slug. |
||
| 2814 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
| 2815 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
| 2816 | */ |
||
| 2817 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
| 2818 | |||
| 2819 | $jetpack = Jetpack::init(); |
||
| 2820 | |||
| 2821 | if ( ! strlen( $module ) ) |
||
| 2822 | return false; |
||
| 2823 | |||
| 2824 | if ( ! Jetpack::is_module( $module ) ) |
||
| 2825 | return false; |
||
| 2826 | |||
| 2827 | // If it's already active, then don't do it again |
||
| 2828 | $active = Jetpack::get_active_modules(); |
||
| 2829 | foreach ( $active as $act ) { |
||
| 2830 | if ( $act == $module ) |
||
| 2831 | return true; |
||
| 2832 | } |
||
| 2833 | |||
| 2834 | $module_data = Jetpack::get_module( $module ); |
||
| 2835 | |||
| 2836 | if ( ! Jetpack::is_active() ) { |
||
| 2837 | if ( !Jetpack::is_development_mode() ) |
||
| 2838 | return false; |
||
| 2839 | |||
| 2840 | // If we're not connected but in development mode, make sure the module doesn't require a connection |
||
| 2841 | if ( Jetpack::is_development_mode() && $module_data['requires_connection'] ) |
||
| 2842 | return false; |
||
| 2843 | } |
||
| 2844 | |||
| 2845 | // Check and see if the old plugin is active |
||
| 2846 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
| 2847 | // Deactivate the old plugin |
||
| 2848 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
| 2849 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
| 2850 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
| 2851 | Jetpack::state( 'deactivated_plugins', $module ); |
||
| 2852 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
| 2853 | exit; |
||
| 2854 | } |
||
| 2855 | } |
||
| 2856 | |||
| 2857 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
| 2858 | Jetpack::state( 'module', $module ); |
||
| 2859 | Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
| 2860 | |||
| 2861 | Jetpack::catch_errors( true ); |
||
| 2862 | ob_start(); |
||
| 2863 | require Jetpack::get_module_path( $module ); |
||
| 2864 | /** This action is documented in class.jetpack.php */ |
||
| 2865 | do_action( 'jetpack_activate_module', $module ); |
||
| 2866 | $active[] = $module; |
||
| 2867 | Jetpack_Options::update_option( 'active_modules', array_unique( $active ) ); |
||
| 2868 | Jetpack::state( 'error', false ); // the override |
||
| 2869 | Jetpack::state( 'message', 'module_activated' ); |
||
| 2870 | Jetpack::state( 'module', $module ); |
||
| 2871 | ob_end_clean(); |
||
| 2872 | Jetpack::catch_errors( false ); |
||
| 2873 | |||
| 2874 | // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. |
||
| 2875 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
| 2876 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
| 2877 | |||
| 2878 | //Jump start is being dismissed send data to MC Stats |
||
| 2879 | $jetpack->stat( 'jumpstart', 'manual,'.$module ); |
||
| 2880 | |||
| 2881 | $jetpack->do_stats( 'server_side' ); |
||
| 2882 | } |
||
| 2883 | |||
| 2884 | if ( $redirect ) { |
||
| 2885 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 2886 | } |
||
| 2887 | if ( $exit ) { |
||
| 2888 | exit; |
||
| 2889 | } |
||
| 2890 | return true; |
||
| 2891 | } |
||
| 2892 | |||
| 2893 | function activate_module_actions( $module ) { |
||
| 2906 | |||
| 2907 | public static function deactivate_module( $module ) { |
||
| 2944 | |||
| 2945 | public static function enable_module_configurable( $module ) { |
||
| 2949 | |||
| 2950 | public static function module_configuration_url( $module ) { |
||
| 2954 | |||
| 2955 | public static function module_configuration_load( $module, $method ) { |
||
| 2959 | |||
| 2960 | public static function module_configuration_head( $module, $method ) { |
||
| 2964 | |||
| 2965 | public static function module_configuration_screen( $module, $method ) { |
||
| 2969 | |||
| 2970 | public static function module_configuration_activation_screen( $module, $method ) { |
||
| 2974 | |||
| 2975 | /* Installation */ |
||
| 2976 | |||
| 2977 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 3017 | |||
| 3018 | /** |
||
| 3019 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 3020 | * @static |
||
| 3021 | */ |
||
| 3022 | public static function plugin_activation( $network_wide ) { |
||
| 3034 | /** |
||
| 3035 | * Runs before bumping version numbers up to a new version |
||
| 3036 | * @param (string) $version Version:timestamp |
||
| 3037 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
| 3038 | * @return null [description] |
||
| 3039 | */ |
||
| 3040 | public static function do_version_bump( $version, $old_version ) { |
||
| 3047 | |||
| 3048 | /** |
||
| 3049 | * Sets the internal version number and activation state. |
||
| 3050 | * @static |
||
| 3051 | */ |
||
| 3052 | public static function plugin_initialize() { |
||
| 3068 | |||
| 3069 | /** |
||
| 3070 | * Removes all connection options |
||
| 3071 | * @static |
||
| 3072 | */ |
||
| 3073 | public static function plugin_deactivation( ) { |
||
| 3082 | |||
| 3083 | /** |
||
| 3084 | * Disconnects from the Jetpack servers. |
||
| 3085 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 3086 | * @static |
||
| 3087 | */ |
||
| 3088 | public static function disconnect( $update_activated_state = true ) { |
||
| 3134 | |||
| 3135 | /** |
||
| 3136 | * Unlinks the current user from the linked WordPress.com user |
||
| 3137 | */ |
||
| 3138 | public static function unlink_user( $user_id = null ) { |
||
| 3160 | |||
| 3161 | /** |
||
| 3162 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 3163 | */ |
||
| 3164 | public static function try_registration() { |
||
| 3189 | |||
| 3190 | /** |
||
| 3191 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 3192 | * |
||
| 3193 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 3194 | */ |
||
| 3195 | public static function log( $code, $data = null ) { |
||
| 3235 | |||
| 3236 | /** |
||
| 3237 | * Get the internal event log. |
||
| 3238 | * |
||
| 3239 | * @param $event (string) - only return the specific log events |
||
| 3240 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 3241 | * |
||
| 3242 | * @return array of log events || WP_Error for invalid params |
||
| 3243 | */ |
||
| 3244 | public static function get_log( $event = false, $num = false ) { |
||
| 3280 | |||
| 3281 | /** |
||
| 3282 | * Log modification of important settings. |
||
| 3283 | */ |
||
| 3284 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 3291 | |||
| 3292 | /** |
||
| 3293 | * Return stat data for WPCOM sync |
||
| 3294 | */ |
||
| 3295 | function get_stat_data() { |
||
| 3301 | |||
| 3302 | /** |
||
| 3303 | * Get additional stat data to sync to WPCOM |
||
| 3304 | */ |
||
| 3305 | function get_additional_stat_data( $prefix = '' ) { |
||
| 3315 | |||
| 3316 | /* Admin Pages */ |
||
| 3317 | |||
| 3318 | function admin_init() { |
||
| 3378 | |||
| 3379 | function admin_body_class( $admin_body_class = '' ) { |
||
| 3387 | |||
| 3388 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 3391 | |||
| 3392 | function prepare_connect_notice() { |
||
| 3400 | /** |
||
| 3401 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
| 3402 | * |
||
| 3403 | * @return null |
||
| 3404 | */ |
||
| 3405 | function prepare_manage_jetpack_notice() { |
||
| 3410 | |||
| 3411 | function manage_activate_screen() { |
||
| 3414 | /** |
||
| 3415 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 3416 | * This function artificially throws errors for such cases (whitelisted). |
||
| 3417 | * |
||
| 3418 | * @param string $plugin The activated plugin. |
||
| 3419 | */ |
||
| 3420 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 3444 | |||
| 3445 | function intercept_plugin_error_scrape_init() { |
||
| 3448 | |||
| 3449 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 3460 | |||
| 3461 | function add_remote_request_handlers() { |
||
| 3464 | |||
| 3465 | function remote_request_handlers() { |
||
| 3499 | |||
| 3500 | function upload_handler() { |
||
| 3585 | |||
| 3586 | /** |
||
| 3587 | * Add help to the Jetpack page |
||
| 3588 | * |
||
| 3589 | * @since Jetpack (1.2.3) |
||
| 3590 | * @return false if not the Jetpack page |
||
| 3591 | */ |
||
| 3592 | function admin_help() { |
||
| 3633 | |||
| 3634 | function admin_menu_css() { |
||
| 3637 | |||
| 3638 | function admin_menu_order() { |
||
| 3641 | |||
| 3642 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
| 3657 | |||
| 3658 | function admin_head() { |
||
| 3663 | |||
| 3664 | function admin_banner_styles() { |
||
| 3671 | |||
| 3672 | function admin_scripts() { |
||
| 3685 | |||
| 3686 | function plugin_action_links( $actions ) { |
||
| 3701 | |||
| 3702 | function admin_connect_notice() { |
||
| 3736 | |||
| 3737 | /** |
||
| 3738 | * This is the first banner |
||
| 3739 | * It should be visible only to user that can update the option |
||
| 3740 | * Are not connected |
||
| 3741 | * |
||
| 3742 | * @return null |
||
| 3743 | */ |
||
| 3744 | function admin_jetpack_manage_notice() { |
||
| 3778 | |||
| 3779 | /** |
||
| 3780 | * Returns the url that the user clicks to remove the notice for the big banner |
||
| 3781 | * @return (string) |
||
| 3782 | */ |
||
| 3783 | function opt_out_jetpack_manage_url() { |
||
| 3787 | /** |
||
| 3788 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
| 3789 | * @return (string) |
||
| 3790 | */ |
||
| 3791 | function opt_in_jetpack_manage_url() { |
||
| 3794 | |||
| 3795 | function opt_in_jetpack_manage_notice() { |
||
| 3805 | /** |
||
| 3806 | * Determines whether to show the notice of not true = display notice |
||
| 3807 | * @return (bool) |
||
| 3808 | */ |
||
| 3809 | function can_display_jetpack_manage_notice() { |
||
| 3831 | |||
| 3832 | function network_connect_notice() { |
||
| 3841 | |||
| 3842 | public static function jetpack_comment_notice() { |
||
| 3877 | |||
| 3878 | /** |
||
| 3879 | * Show the survey link when the user has just disconnected Jetpack. |
||
| 3880 | */ |
||
| 3881 | function disconnect_survey_notice() { |
||
| 3900 | |||
| 3901 | /* |
||
| 3902 | * Registration flow: |
||
| 3903 | * 1 - ::admin_page_load() action=register |
||
| 3904 | * 2 - ::try_registration() |
||
| 3905 | * 3 - ::register() |
||
| 3906 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 3907 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 3908 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 3909 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 3910 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 3911 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 3912 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 3913 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 3914 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 3915 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 3916 | * 5 - user logs in with WP.com account |
||
| 3917 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 3918 | * - Jetpack_Client_Server::authorize() |
||
| 3919 | * - Jetpack_Client_Server::get_token() |
||
| 3920 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 3921 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 3922 | * - which responds with access_token, token_type, scope |
||
| 3923 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 3924 | * - Jetpack::activate_default_modules() |
||
| 3925 | * - Deactivates deprecated plugins |
||
| 3926 | * - Activates all default modules |
||
| 3927 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 3928 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 3929 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 3930 | * Done! |
||
| 3931 | */ |
||
| 3932 | |||
| 3933 | /** |
||
| 3934 | * Handles the page load events for the Jetpack admin page |
||
| 3935 | */ |
||
| 3936 | function admin_page_load() { |
||
| 3937 | $error = false; |
||
| 3938 | |||
| 3939 | // Make sure we have the right body class to hook stylings for subpages off of. |
||
| 3940 | add_filter( 'admin_body_class', array( __CLASS__, 'add_jetpack_pagestyles' ) ); |
||
| 3941 | |||
| 3942 | if ( ! empty( $_GET['jetpack_restate'] ) ) { |
||
| 3943 | // Should only be used in intermediate redirects to preserve state across redirects |
||
| 3944 | Jetpack::restate(); |
||
| 3945 | } |
||
| 3946 | |||
| 3947 | if ( isset( $_GET['connect_url_redirect'] ) ) { |
||
| 3948 | // User clicked in the iframe to link their accounts |
||
| 3949 | if ( ! Jetpack::is_user_connected() ) { |
||
| 3950 | $connect_url = $this->build_connect_url( true, false, 'iframe' ); |
||
| 3951 | if ( isset( $_GET['notes_iframe'] ) ) |
||
| 3952 | $connect_url .= '¬es_iframe'; |
||
| 3953 | wp_redirect( $connect_url ); |
||
| 3954 | exit; |
||
| 3955 | } else { |
||
| 3956 | Jetpack::state( 'message', 'already_authorized' ); |
||
| 3957 | wp_safe_redirect( Jetpack::admin_url() ); |
||
| 3958 | exit; |
||
| 3959 | } |
||
| 3960 | } |
||
| 3961 | |||
| 3962 | |||
| 3963 | if ( isset( $_GET['action'] ) ) { |
||
| 3964 | switch ( $_GET['action'] ) { |
||
| 3965 | case 'authorize': |
||
| 3966 | if ( Jetpack::is_active() && Jetpack::is_user_connected() ) { |
||
| 3967 | Jetpack::state( 'message', 'already_authorized' ); |
||
| 3968 | wp_safe_redirect( Jetpack::admin_url() ); |
||
| 3969 | exit; |
||
| 3970 | } |
||
| 3971 | Jetpack::log( 'authorize' ); |
||
| 3972 | $client_server = new Jetpack_Client_Server; |
||
| 3973 | $client_server->client_authorize(); |
||
| 3974 | exit; |
||
| 3975 | case 'register' : |
||
| 3976 | if ( ! current_user_can( 'jetpack_connect' ) ) { |
||
| 3977 | $error = 'cheatin'; |
||
| 3978 | break; |
||
| 3979 | } |
||
| 3980 | check_admin_referer( 'jetpack-register' ); |
||
| 3981 | Jetpack::log( 'register' ); |
||
| 3982 | Jetpack::maybe_set_version_option(); |
||
| 3983 | $registered = Jetpack::try_registration(); |
||
| 3984 | if ( is_wp_error( $registered ) ) { |
||
| 3985 | $error = $registered->get_error_code(); |
||
| 3986 | Jetpack::state( 'error_description', $registered->get_error_message() ); |
||
| 3987 | break; |
||
| 3988 | } |
||
| 3989 | |||
| 3990 | $from = isset( $_GET['from'] ) ? $_GET['from'] : false; |
||
| 3991 | |||
| 3992 | wp_redirect( $this->build_connect_url( true, false, $from ) ); |
||
| 3993 | exit; |
||
| 3994 | case 'activate' : |
||
| 3995 | if ( ! current_user_can( 'jetpack_activate_modules' ) ) { |
||
| 3996 | $error = 'cheatin'; |
||
| 3997 | break; |
||
| 3998 | } |
||
| 3999 | |||
| 4000 | $module = stripslashes( $_GET['module'] ); |
||
| 4001 | check_admin_referer( "jetpack_activate-$module" ); |
||
| 4002 | Jetpack::log( 'activate', $module ); |
||
| 4003 | Jetpack::activate_module( $module ); |
||
| 4004 | // The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end. |
||
| 4005 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 4006 | exit; |
||
| 4007 | case 'activate_default_modules' : |
||
| 4008 | check_admin_referer( 'activate_default_modules' ); |
||
| 4009 | Jetpack::log( 'activate_default_modules' ); |
||
| 4010 | Jetpack::restate(); |
||
| 4011 | $min_version = isset( $_GET['min_version'] ) ? $_GET['min_version'] : false; |
||
| 4012 | $max_version = isset( $_GET['max_version'] ) ? $_GET['max_version'] : false; |
||
| 4013 | $other_modules = isset( $_GET['other_modules'] ) && is_array( $_GET['other_modules'] ) ? $_GET['other_modules'] : array(); |
||
| 4014 | Jetpack::activate_default_modules( $min_version, $max_version, $other_modules ); |
||
| 4015 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 4016 | exit; |
||
| 4017 | case 'disconnect' : |
||
| 4018 | if ( ! current_user_can( 'jetpack_disconnect' ) ) { |
||
| 4019 | $error = 'cheatin'; |
||
| 4020 | break; |
||
| 4021 | } |
||
| 4022 | |||
| 4023 | check_admin_referer( 'jetpack-disconnect' ); |
||
| 4024 | Jetpack::log( 'disconnect' ); |
||
| 4025 | Jetpack::disconnect(); |
||
| 4026 | wp_safe_redirect( Jetpack::admin_url( 'disconnected=true' ) ); |
||
| 4027 | exit; |
||
| 4028 | case 'reconnect' : |
||
| 4029 | if ( ! current_user_can( 'jetpack_reconnect' ) ) { |
||
| 4030 | $error = 'cheatin'; |
||
| 4031 | break; |
||
| 4032 | } |
||
| 4033 | |||
| 4034 | check_admin_referer( 'jetpack-reconnect' ); |
||
| 4035 | Jetpack::log( 'reconnect' ); |
||
| 4036 | $this->disconnect(); |
||
| 4037 | wp_redirect( $this->build_connect_url( true, false, 'reconnect' ) ); |
||
| 4038 | exit; |
||
| 4039 | View Code Duplication | case 'deactivate' : |
|
| 4040 | if ( ! current_user_can( 'jetpack_deactivate_modules' ) ) { |
||
| 4041 | $error = 'cheatin'; |
||
| 4042 | break; |
||
| 4043 | } |
||
| 4044 | |||
| 4045 | $modules = stripslashes( $_GET['module'] ); |
||
| 4046 | check_admin_referer( "jetpack_deactivate-$modules" ); |
||
| 4047 | foreach ( explode( ',', $modules ) as $module ) { |
||
| 4048 | Jetpack::log( 'deactivate', $module ); |
||
| 4049 | Jetpack::deactivate_module( $module ); |
||
| 4050 | Jetpack::state( 'message', 'module_deactivated' ); |
||
| 4051 | } |
||
| 4052 | Jetpack::state( 'module', $modules ); |
||
| 4053 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 4054 | exit; |
||
| 4055 | case 'unlink' : |
||
| 4056 | $redirect = isset( $_GET['redirect'] ) ? $_GET['redirect'] : ''; |
||
| 4057 | check_admin_referer( 'jetpack-unlink' ); |
||
| 4058 | Jetpack::log( 'unlink' ); |
||
| 4059 | $this->unlink_user(); |
||
| 4060 | Jetpack::state( 'message', 'unlinked' ); |
||
| 4061 | if ( 'sub-unlink' == $redirect ) { |
||
| 4062 | wp_safe_redirect( admin_url() ); |
||
| 4063 | } else { |
||
| 4064 | wp_safe_redirect( Jetpack::admin_url( array( 'page' => $redirect ) ) ); |
||
| 4065 | } |
||
| 4066 | exit; |
||
| 4067 | default: |
||
| 4068 | /** |
||
| 4069 | * Fires when a Jetpack admin page is loaded with an unrecognized parameter. |
||
| 4070 | * |
||
| 4071 | * @since 2.6.0 |
||
| 4072 | * |
||
| 4073 | * @param string sanitize_key( $_GET['action'] ) Unrecognized URL parameter. |
||
| 4074 | */ |
||
| 4075 | do_action( 'jetpack_unrecognized_action', sanitize_key( $_GET['action'] ) ); |
||
| 4076 | } |
||
| 4077 | } |
||
| 4078 | |||
| 4079 | if ( ! $error = $error ? $error : Jetpack::state( 'error' ) ) { |
||
| 4080 | self::activate_new_modules( true ); |
||
| 4081 | } |
||
| 4082 | |||
| 4083 | switch ( $error ) { |
||
| 4084 | case 'cheatin' : |
||
| 4085 | $this->error = __( 'Cheatin’ uh?', 'jetpack' ); |
||
| 4086 | break; |
||
| 4087 | case 'access_denied' : |
||
| 4088 | $this->error = sprintf( __( 'Would you mind telling us why you did not complete the Jetpack connection in this <a href="%s">1 question survey</a>?', 'jetpack' ), 'http://jetpack.com/cancelled-connection/' ) . '<br /><small>' . __( 'A Jetpack connection is required for our free security and traffic features to work.', 'jetpack' ) . '</small>'; |
||
| 4089 | break; |
||
| 4090 | case 'wrong_state' : |
||
| 4091 | $this->error = __( 'You need to stay logged in to your WordPress blog while you authorize Jetpack.', 'jetpack' ); |
||
| 4092 | break; |
||
| 4093 | case 'invalid_client' : |
||
| 4094 | // @todo re-register instead of deactivate/reactivate |
||
| 4095 | $this->error = __( 'We had an issue connecting Jetpack; deactivate then reactivate the Jetpack plugin, then connect again.', 'jetpack' ); |
||
| 4096 | break; |
||
| 4097 | case 'invalid_grant' : |
||
| 4098 | $this->error = __( 'There was an issue connecting your Jetpack. Please click “Connect to WordPress.com” again.', 'jetpack' ); |
||
| 4099 | break; |
||
| 4100 | case 'site_inaccessible' : |
||
| 4101 | case 'site_requires_authorization' : |
||
| 4102 | $this->error = sprintf( __( 'Your website needs to be publicly accessible to use Jetpack: %s', 'jetpack' ), "<code>$error</code>" ); |
||
| 4103 | break; |
||
| 4104 | case 'module_activation_failed' : |
||
| 4105 | $module = Jetpack::state( 'module' ); |
||
| 4106 | if ( ! empty( $module ) && $mod = Jetpack::get_module( $module ) ) { |
||
| 4107 | $this->error = sprintf( __( '%s could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack' ), $mod['name'] ); |
||
| 4108 | if ( isset( $this->plugins_to_deactivate[$module] ) ) { |
||
| 4109 | $this->error .= ' ' . sprintf( __( 'Do you still have the %s plugin installed?', 'jetpack' ), $this->plugins_to_deactivate[$module][1] ); |
||
| 4110 | } |
||
| 4111 | } else { |
||
| 4112 | $this->error = __( 'Module could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack' ); |
||
| 4113 | } |
||
| 4114 | if ( $php_errors = Jetpack::state( 'php_errors' ) ) { |
||
| 4115 | $this->error .= "<br />\n"; |
||
| 4116 | $this->error .= $php_errors; |
||
| 4117 | } |
||
| 4118 | break; |
||
| 4119 | case 'master_user_required' : |
||
| 4120 | $module = Jetpack::state( 'module' ); |
||
| 4121 | $module_name = ''; |
||
| 4122 | if ( ! empty( $module ) && $mod = Jetpack::get_module( $module ) ) { |
||
| 4123 | $module_name = $mod['name']; |
||
| 4124 | } |
||
| 4125 | |||
| 4126 | $master_user = Jetpack_Options::get_option( 'master_user' ); |
||
| 4127 | $master_userdata = get_userdata( $master_user ) ; |
||
| 4128 | if ( $master_userdata ) { |
||
| 4129 | if ( ! in_array( $module, Jetpack::get_active_modules() ) ) { |
||
| 4130 | $this->error = sprintf( __( '%s was not activated.' , 'jetpack' ), $module_name ); |
||
| 4131 | } else { |
||
| 4132 | $this->error = sprintf( __( '%s was not deactivated.' , 'jetpack' ), $module_name ); |
||
| 4133 | } |
||
| 4134 | $this->error .= ' ' . sprintf( __( 'This module can only be altered by %s, the user who initiated the Jetpack connection on this site.' , 'jetpack' ), esc_html( $master_userdata->display_name ) ); |
||
| 4135 | |||
| 4136 | } else { |
||
| 4137 | $this->error = sprintf( __( 'Only the user who initiated the Jetpack connection on this site can toggle %s, but that user no longer exists. This should not happen.', 'jetpack' ), $module_name ); |
||
| 4138 | } |
||
| 4139 | break; |
||
| 4140 | case 'not_public' : |
||
| 4141 | $this->error = __( '<strong>Your Jetpack has a glitch.</strong> Connecting this site with WordPress.com is not possible. This usually means your site is not publicly accessible (localhost).', 'jetpack' ); |
||
| 4142 | break; |
||
| 4143 | case 'wpcom_408' : |
||
| 4144 | case 'wpcom_5??' : |
||
| 4145 | case 'wpcom_bad_response' : |
||
| 4146 | case 'wpcom_outage' : |
||
| 4147 | $this->error = __( 'WordPress.com is currently having problems and is unable to fuel up your Jetpack. Please try again later.', 'jetpack' ); |
||
| 4148 | break; |
||
| 4149 | case 'register_http_request_failed' : |
||
| 4150 | case 'token_http_request_failed' : |
||
| 4151 | $this->error = sprintf( __( 'Jetpack could not contact WordPress.com: %s. This usually means something is incorrectly configured on your web host.', 'jetpack' ), "<code>$error</code>" ); |
||
| 4152 | break; |
||
| 4153 | default : |
||
| 4154 | if ( empty( $error ) ) { |
||
| 4155 | break; |
||
| 4156 | } |
||
| 4157 | $error = trim( substr( strip_tags( $error ), 0, 20 ) ); |
||
| 4158 | // no break: fall through |
||
| 4159 | case 'no_role' : |
||
| 4160 | case 'no_cap' : |
||
| 4161 | case 'no_code' : |
||
| 4162 | case 'no_state' : |
||
| 4163 | case 'invalid_state' : |
||
| 4164 | case 'invalid_request' : |
||
| 4165 | case 'invalid_scope' : |
||
| 4166 | case 'unsupported_response_type' : |
||
| 4167 | case 'invalid_token' : |
||
| 4168 | case 'no_token' : |
||
| 4169 | case 'missing_secrets' : |
||
| 4170 | case 'home_missing' : |
||
| 4171 | case 'siteurl_missing' : |
||
| 4172 | case 'gmt_offset_missing' : |
||
| 4173 | case 'site_name_missing' : |
||
| 4174 | case 'secret_1_missing' : |
||
| 4175 | case 'secret_2_missing' : |
||
| 4176 | case 'site_lang_missing' : |
||
| 4177 | case 'home_malformed' : |
||
| 4178 | case 'siteurl_malformed' : |
||
| 4179 | case 'gmt_offset_malformed' : |
||
| 4180 | case 'timezone_string_malformed' : |
||
| 4181 | case 'site_name_malformed' : |
||
| 4182 | case 'secret_1_malformed' : |
||
| 4183 | case 'secret_2_malformed' : |
||
| 4184 | case 'site_lang_malformed' : |
||
| 4185 | case 'secrets_mismatch' : |
||
| 4186 | case 'verify_secret_1_missing' : |
||
| 4187 | case 'verify_secret_1_malformed' : |
||
| 4188 | case 'verify_secrets_missing' : |
||
| 4189 | case 'verify_secrets_mismatch' : |
||
| 4190 | $error = esc_html( $error ); |
||
| 4191 | $this->error = sprintf( __( '<strong>Your Jetpack has a glitch.</strong> We’re sorry for the inconvenience. Please try again later, if the issue continues please contact support with this message: %s', 'jetpack' ), "<code>$error</code>" ); |
||
| 4192 | if ( ! Jetpack::is_active() ) { |
||
| 4193 | $this->error .= '<br />'; |
||
| 4194 | $this->error .= sprintf( __( 'Try connecting again.', 'jetpack' ) ); |
||
| 4195 | } |
||
| 4196 | break; |
||
| 4197 | } |
||
| 4198 | |||
| 4199 | $message_code = Jetpack::state( 'message' ); |
||
| 4200 | |||
| 4201 | $active_state = Jetpack::state( 'activated_modules' ); |
||
| 4202 | if ( ! empty( $active_state ) ) { |
||
| 4203 | $available = Jetpack::get_available_modules(); |
||
| 4204 | $active_state = explode( ',', $active_state ); |
||
| 4205 | $active_state = array_intersect( $active_state, $available ); |
||
| 4206 | if ( count( $active_state ) ) { |
||
| 4207 | foreach ( $active_state as $mod ) { |
||
| 4208 | $this->stat( 'module-activated', $mod ); |
||
| 4209 | } |
||
| 4210 | } else { |
||
| 4211 | $active_state = false; |
||
| 4212 | } |
||
| 4213 | } |
||
| 4214 | if( Jetpack::state( 'optin-manage' ) ) { |
||
| 4215 | $activated_manage = $message_code; |
||
| 4216 | $message_code = 'jetpack-manage'; |
||
| 4217 | |||
| 4218 | } |
||
| 4219 | switch ( $message_code ) { |
||
| 4220 | case 'modules_activated' : |
||
| 4221 | $this->message = sprintf( |
||
| 4222 | __( 'Welcome to <strong>Jetpack %s</strong>!', 'jetpack' ), |
||
| 4223 | JETPACK__VERSION |
||
| 4224 | ); |
||
| 4225 | |||
| 4226 | if ( $active_state ) { |
||
| 4227 | $titles = array(); |
||
| 4228 | View Code Duplication | foreach ( $active_state as $mod ) { |
|
| 4229 | if ( $mod_headers = Jetpack::get_module( $mod ) ) { |
||
| 4230 | $titles[] = '<strong>' . preg_replace( '/\s+(?![^<>]++>)/', ' ', $mod_headers['name'] ) . '</strong>'; |
||
| 4231 | } |
||
| 4232 | } |
||
| 4233 | if ( $titles ) { |
||
| 4234 | $this->message .= '<br /><br />' . wp_sprintf( __( 'The following new modules have been activated: %l.', 'jetpack' ), $titles ); |
||
| 4235 | } |
||
| 4236 | } |
||
| 4237 | |||
| 4238 | if ( $reactive_state = Jetpack::state( 'reactivated_modules' ) ) { |
||
| 4239 | $titles = array(); |
||
| 4240 | View Code Duplication | foreach ( explode( ',', $reactive_state ) as $mod ) { |
|
| 4241 | if ( $mod_headers = Jetpack::get_module( $mod ) ) { |
||
| 4242 | $titles[] = '<strong>' . preg_replace( '/\s+(?![^<>]++>)/', ' ', $mod_headers['name'] ) . '</strong>'; |
||
| 4243 | } |
||
| 4244 | } |
||
| 4245 | if ( $titles ) { |
||
| 4246 | $this->message .= '<br /><br />' . wp_sprintf( __( 'The following modules have been updated: %l.', 'jetpack' ), $titles ); |
||
| 4247 | } |
||
| 4248 | } |
||
| 4249 | |||
| 4250 | $this->message .= Jetpack::jetpack_comment_notice(); |
||
| 4251 | break; |
||
| 4252 | case 'jetpack-manage': |
||
| 4253 | $this->message = '<strong>' . sprintf( __( 'You are all set! Your site can now be managed from <a href="%s" target="_blank">wordpress.com/sites</a>.', 'jetpack' ), 'https://wordpress.com/sites' ) . '</strong>'; |
||
| 4254 | if ( $activated_manage ) { |
||
| 4255 | $this->message .= '<br /><strong>' . __( 'Manage has been activated for you!', 'jetpack' ) . '</strong>'; |
||
| 4256 | } |
||
| 4257 | break; |
||
| 4258 | case 'module_activated' : |
||
| 4259 | if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) { |
||
| 4260 | $this->message = sprintf( __( '<strong>%s Activated!</strong> You can deactivate at any time by clicking the Deactivate link next to each module.', 'jetpack' ), $module['name'] ); |
||
| 4261 | $this->stat( 'module-activated', Jetpack::state( 'module' ) ); |
||
| 4262 | } |
||
| 4263 | break; |
||
| 4264 | |||
| 4265 | case 'module_deactivated' : |
||
| 4266 | $modules = Jetpack::state( 'module' ); |
||
| 4267 | if ( ! $modules ) { |
||
| 4268 | break; |
||
| 4269 | } |
||
| 4270 | |||
| 4271 | $module_names = array(); |
||
| 4272 | foreach ( explode( ',', $modules ) as $module_slug ) { |
||
| 4273 | $module = Jetpack::get_module( $module_slug ); |
||
| 4274 | if ( $module ) { |
||
| 4275 | $module_names[] = $module['name']; |
||
| 4276 | } |
||
| 4277 | |||
| 4278 | $this->stat( 'module-deactivated', $module_slug ); |
||
| 4279 | } |
||
| 4280 | |||
| 4281 | if ( ! $module_names ) { |
||
| 4282 | break; |
||
| 4283 | } |
||
| 4284 | |||
| 4285 | $this->message = wp_sprintf( |
||
| 4286 | _nx( |
||
| 4287 | '<strong>%l Deactivated!</strong> You can activate it again at any time using the activate link next to each module.', |
||
| 4288 | '<strong>%l Deactivated!</strong> You can activate them again at any time using the activate links next to each module.', |
||
| 4289 | count( $module_names ), |
||
| 4290 | '%l = list of Jetpack module/feature names', |
||
| 4291 | 'jetpack' |
||
| 4292 | ), |
||
| 4293 | $module_names |
||
| 4294 | ); |
||
| 4295 | break; |
||
| 4296 | |||
| 4297 | case 'module_configured' : |
||
| 4298 | $this->message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' ); |
||
| 4299 | break; |
||
| 4300 | |||
| 4301 | case 'already_authorized' : |
||
| 4302 | $this->message = __( '<strong>Your Jetpack is already connected.</strong> ', 'jetpack' ); |
||
| 4303 | break; |
||
| 4304 | |||
| 4305 | case 'authorized' : |
||
| 4306 | $this->message = __( '<strong>You’re fueled up and ready to go, Jetpack is now active.</strong> ', 'jetpack' ); |
||
| 4307 | $this->message .= Jetpack::jetpack_comment_notice(); |
||
| 4308 | break; |
||
| 4309 | |||
| 4310 | case 'linked' : |
||
| 4311 | $this->message = __( '<strong>You’re fueled up and ready to go.</strong> ', 'jetpack' ); |
||
| 4312 | $this->message .= Jetpack::jetpack_comment_notice(); |
||
| 4313 | break; |
||
| 4314 | |||
| 4315 | case 'unlinked' : |
||
| 4316 | $user = wp_get_current_user(); |
||
| 4317 | $this->message = sprintf( __( '<strong>You have unlinked your account (%s) from WordPress.com.</strong>', 'jetpack' ), $user->user_login ); |
||
| 4318 | break; |
||
| 4319 | |||
| 4320 | case 'switch_master' : |
||
| 4321 | global $current_user; |
||
| 4322 | $is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' ); |
||
| 4323 | $master_userdata = get_userdata( Jetpack_Options::get_option( 'master_user' ) ); |
||
| 4324 | if ( $is_master_user ) { |
||
| 4325 | $this->message = __( 'You have successfully set yourself as Jetpack’s primary user.', 'jetpack' ); |
||
| 4326 | } else { |
||
| 4327 | $this->message = sprintf( _x( 'You have successfully set %s as Jetpack’s primary user.', '%s is a username', 'jetpack' ), $master_userdata->user_login ); |
||
| 4328 | } |
||
| 4329 | break; |
||
| 4330 | } |
||
| 4331 | |||
| 4332 | $deactivated_plugins = Jetpack::state( 'deactivated_plugins' ); |
||
| 4333 | |||
| 4334 | if ( ! empty( $deactivated_plugins ) ) { |
||
| 4335 | $deactivated_plugins = explode( ',', $deactivated_plugins ); |
||
| 4336 | $deactivated_titles = array(); |
||
| 4337 | foreach ( $deactivated_plugins as $deactivated_plugin ) { |
||
| 4338 | if ( ! isset( $this->plugins_to_deactivate[$deactivated_plugin] ) ) { |
||
| 4339 | continue; |
||
| 4340 | } |
||
| 4341 | |||
| 4342 | $deactivated_titles[] = '<strong>' . str_replace( ' ', ' ', $this->plugins_to_deactivate[$deactivated_plugin][1] ) . '</strong>'; |
||
| 4343 | } |
||
| 4344 | |||
| 4345 | if ( $deactivated_titles ) { |
||
| 4346 | if ( $this->message ) { |
||
| 4347 | $this->message .= "<br /><br />\n"; |
||
| 4348 | } |
||
| 4349 | |||
| 4350 | $this->message .= wp_sprintf( |
||
| 4351 | _n( |
||
| 4352 | 'Jetpack contains the most recent version of the old %l plugin.', |
||
| 4353 | 'Jetpack contains the most recent versions of the old %l plugins.', |
||
| 4354 | count( $deactivated_titles ), |
||
| 4355 | 'jetpack' |
||
| 4356 | ), |
||
| 4357 | $deactivated_titles |
||
| 4358 | ); |
||
| 4359 | |||
| 4360 | $this->message .= "<br />\n"; |
||
| 4361 | |||
| 4362 | $this->message .= _n( |
||
| 4363 | 'The old version has been deactivated and can be removed from your site.', |
||
| 4364 | 'The old versions have been deactivated and can be removed from your site.', |
||
| 4365 | count( $deactivated_titles ), |
||
| 4366 | 'jetpack' |
||
| 4367 | ); |
||
| 4368 | } |
||
| 4369 | } |
||
| 4370 | |||
| 4371 | $this->privacy_checks = Jetpack::state( 'privacy_checks' ); |
||
| 4372 | |||
| 4373 | if ( $this->message || $this->error || $this->privacy_checks || $this->can_display_jetpack_manage_notice() ) { |
||
| 4374 | add_action( 'jetpack_notices', array( $this, 'admin_notices' ) ); |
||
| 4375 | } |
||
| 4376 | |||
| 4377 | View Code Duplication | if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) { |
|
| 4378 | /** |
||
| 4379 | * Fires when a module configuration page is loaded. |
||
| 4380 | * The dynamic part of the hook is the configure parameter from the URL. |
||
| 4381 | * |
||
| 4382 | * @since 1.1.0 |
||
| 4383 | */ |
||
| 4384 | do_action( 'jetpack_module_configuration_load_' . $_GET['configure'] ); |
||
| 4385 | } |
||
| 4386 | |||
| 4387 | add_filter( 'jetpack_short_module_description', 'wptexturize' ); |
||
| 4388 | } |
||
| 4389 | |||
| 4390 | function admin_notices() { |
||
| 4487 | |||
| 4488 | /** |
||
| 4489 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 4490 | */ |
||
| 4491 | function stat( $group, $detail ) { |
||
| 4496 | |||
| 4497 | /** |
||
| 4498 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 4499 | */ |
||
| 4500 | function do_stats( $method = '' ) { |
||
| 4515 | |||
| 4516 | /** |
||
| 4517 | * Runs stats code for a one-off, server-side. |
||
| 4518 | * |
||
| 4519 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 4520 | * |
||
| 4521 | * @return bool If it worked. |
||
| 4522 | */ |
||
| 4523 | static function do_server_side_stat( $args ) { |
||
| 4533 | |||
| 4534 | /** |
||
| 4535 | * Builds the stats url. |
||
| 4536 | * |
||
| 4537 | * @param $args array|string The arguments to append to the URL. |
||
| 4538 | * |
||
| 4539 | * @return string The URL to be pinged. |
||
| 4540 | */ |
||
| 4541 | static function build_stats_url( $args ) { |
||
| 4561 | |||
| 4562 | function translate_current_user_to_role() { |
||
| 4571 | |||
| 4572 | function translate_role_to_cap( $role ) { |
||
| 4579 | |||
| 4580 | function sign_role( $role ) { |
||
| 4592 | |||
| 4593 | |||
| 4594 | /** |
||
| 4595 | * Builds a URL to the Jetpack connection auth page |
||
| 4596 | * |
||
| 4597 | * @since 3.9.5 |
||
| 4598 | * |
||
| 4599 | * @param bool $raw If true, URL will not be escaped. |
||
| 4600 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 4601 | * If string, will be a custom redirect. |
||
| 4602 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 4603 | * |
||
| 4604 | * @return string Connect URL |
||
| 4605 | */ |
||
| 4606 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
| 4607 | if ( ! Jetpack_Options::get_option( 'blog_token' ) || ! Jetpack_Options::get_option( 'id' ) ) { |
||
| 4608 | $url = Jetpack::nonce_url_no_esc( Jetpack::admin_url( 'action=register' ), 'jetpack-register' ); |
||
| 4609 | if( is_network_admin() ) { |
||
| 4610 | $url = add_query_arg( 'is_multisite', network_admin_url( |
||
| 4611 | 'admin.php?page=jetpack-settings' ), $url ); |
||
| 4661 | |||
| 4662 | function build_reconnect_url( $raw = false ) { |
||
| 4666 | |||
| 4667 | public static function admin_url( $args = null ) { |
||
| 4672 | |||
| 4673 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 4677 | |||
| 4678 | function dismiss_jetpack_notice() { |
||
| 4752 | |||
| 4753 | function debugger_page() { |
||
| 4761 | |||
| 4762 | public static function admin_screen_configure_module( $module_id ) { |
||
| 4814 | |||
| 4815 | /** |
||
| 4816 | * Display link to activate the module to see the settings screen. |
||
| 4817 | * @param string $module_id |
||
| 4818 | * @return null |
||
| 4819 | */ |
||
| 4820 | public static function display_activate_module_link( $module_id ) { |
||
| 4872 | |||
| 4873 | public static function sort_modules( $a, $b ) { |
||
| 4879 | |||
| 4880 | View Code Duplication | function sync_reindex_trigger() { |
|
| 4888 | |||
| 4889 | View Code Duplication | function sync_reindex_status(){ |
|
| 4897 | |||
| 4898 | /* Client API */ |
||
| 4899 | |||
| 4900 | /** |
||
| 4901 | * Returns the requested Jetpack API URL |
||
| 4902 | * |
||
| 4903 | * @return string |
||
| 4904 | */ |
||
| 4905 | public static function api_url( $relative_url ) { |
||
| 4908 | |||
| 4909 | /** |
||
| 4910 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
| 4911 | */ |
||
| 4912 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 4933 | |||
| 4934 | /** |
||
| 4935 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 4936 | * |
||
| 4937 | * @since 2.3.3 |
||
| 4938 | * @return boolean |
||
| 4939 | */ |
||
| 4940 | public static function permit_ssl( $force_recheck = false ) { |
||
| 4970 | |||
| 4971 | /* |
||
| 4972 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'ALWAYS' but SSL isn't working. |
||
| 4973 | */ |
||
| 4974 | public function alert_required_ssl_fail() { |
||
| 4988 | |||
| 4989 | /** |
||
| 4990 | * Returns the Jetpack XML-RPC API |
||
| 4991 | * |
||
| 4992 | * @return string |
||
| 4993 | */ |
||
| 4994 | public static function xmlrpc_api_url() { |
||
| 4998 | |||
| 4999 | /** |
||
| 5000 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 5001 | * |
||
| 5002 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 5003 | * |
||
| 5004 | * @since 2.6 |
||
| 5005 | * @return array |
||
| 5006 | */ |
||
| 5007 | public function generate_secrets() { |
||
| 5017 | |||
| 5018 | /** |
||
| 5019 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 5020 | * |
||
| 5021 | * Based on local php max_execution_time in php.ini |
||
| 5022 | * |
||
| 5023 | * @since 2.6 |
||
| 5024 | * @return int |
||
| 5025 | **/ |
||
| 5026 | public function get_remote_query_timeout_limit() { |
||
| 5032 | |||
| 5033 | |||
| 5034 | /** |
||
| 5035 | * Takes the response from the Jetpack register new site endpoint and |
||
| 5036 | * verifies it worked properly. |
||
| 5037 | * |
||
| 5038 | * @since 2.6 |
||
| 5039 | * @return true or Jetpack_Error |
||
| 5040 | **/ |
||
| 5041 | public function validate_remote_register_response( $response ) { |
||
| 5076 | /** |
||
| 5077 | * @return bool|WP_Error |
||
| 5078 | */ |
||
| 5079 | public static function register() { |
||
| 5178 | |||
| 5179 | /** |
||
| 5180 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 5181 | * |
||
| 5182 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 5183 | */ |
||
| 5184 | public static function maybe_set_version_option() { |
||
| 5192 | |||
| 5193 | /* Client Server API */ |
||
| 5194 | |||
| 5195 | /** |
||
| 5196 | * Loads the Jetpack XML-RPC client |
||
| 5197 | */ |
||
| 5198 | public static function load_xml_rpc_client() { |
||
| 5202 | |||
| 5203 | function verify_xml_rpc_signature() { |
||
| 5301 | |||
| 5302 | /** |
||
| 5303 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 5304 | */ |
||
| 5305 | function authenticate_jetpack( $user, $username, $password ) { |
||
| 5328 | |||
| 5329 | function add_nonce( $timestamp, $nonce ) { |
||
| 5367 | |||
| 5368 | /** |
||
| 5369 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 5370 | * Capture it here so we can verify the signature later. |
||
| 5371 | */ |
||
| 5372 | function xmlrpc_methods( $methods ) { |
||
| 5376 | |||
| 5377 | function public_xmlrpc_methods( $methods ) { |
||
| 5383 | |||
| 5384 | function jetpack_getOptions( $args ) { |
||
| 5424 | |||
| 5425 | function xmlrpc_options( $options ) { |
||
| 5443 | |||
| 5444 | public static function clean_nonces( $all = false ) { |
||
| 5469 | |||
| 5470 | /** |
||
| 5471 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 5472 | * SET: state( $key, $value ); |
||
| 5473 | * GET: $value = state( $key ); |
||
| 5474 | * |
||
| 5475 | * @param string $key |
||
| 5476 | * @param string $value |
||
| 5477 | * @param bool $restate private |
||
| 5478 | */ |
||
| 5479 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 5529 | |||
| 5530 | public static function restate() { |
||
| 5533 | |||
| 5534 | public static function check_privacy( $file ) { |
||
| 5569 | |||
| 5570 | /** |
||
| 5571 | * Helper method for multicall XMLRPC. |
||
| 5572 | */ |
||
| 5573 | public static function xmlrpc_async_call() { |
||
| 5615 | |||
| 5616 | public static function staticize_subdomain( $url ) { |
||
| 5651 | |||
| 5652 | /* JSON API Authorization */ |
||
| 5653 | |||
| 5654 | /** |
||
| 5655 | * Handles the login action for Authorizing the JSON API |
||
| 5656 | */ |
||
| 5657 | function login_form_json_api_authorization() { |
||
| 5666 | |||
| 5667 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 5668 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 5681 | |||
| 5682 | // Make sure the POSTed request is handled by the same action |
||
| 5683 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 5687 | |||
| 5688 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 5689 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 5695 | |||
| 5696 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
| 5697 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 5701 | |||
| 5702 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 5703 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 5715 | |||
| 5716 | // Verifies the request by checking the signature |
||
| 5717 | function verify_json_api_authorization_request() { |
||
| 5796 | |||
| 5797 | function login_message_json_api_authorization( $message ) { |
||
| 5803 | |||
| 5804 | /** |
||
| 5805 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 5806 | */ |
||
| 5807 | public static function get_content_width() { |
||
| 5818 | |||
| 5819 | /** |
||
| 5820 | * Centralize the function here until it gets added to core. |
||
| 5821 | * |
||
| 5822 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 5823 | * @param int $size Size of the avatar image |
||
| 5824 | * @param string $default URL to a default image to use if no avatar is available |
||
| 5825 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 5826 | * |
||
| 5827 | * @return array First element is the URL, second is the class. |
||
| 5828 | */ |
||
| 5829 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 5857 | |||
| 5858 | /** |
||
| 5859 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 5860 | * |
||
| 5861 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 5862 | * |
||
| 5863 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 5864 | */ |
||
| 5865 | public function get_cloud_site_options( $option_names ) { |
||
| 5881 | |||
| 5882 | /** |
||
| 5883 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
| 5884 | * |
||
| 5885 | * @return array An array of options to check. |
||
| 5886 | */ |
||
| 5887 | public static function identity_crisis_options_to_check() { |
||
| 5893 | |||
| 5894 | /** |
||
| 5895 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
| 5896 | * |
||
| 5897 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
| 5898 | * |
||
| 5899 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
| 5900 | */ |
||
| 5901 | public static function check_identity_crisis( $force_recheck = false ) { |
||
| 5967 | |||
| 5968 | /* |
||
| 5969 | * Resolve ID crisis |
||
| 5970 | * |
||
| 5971 | * If the URL has changed, but the rest of the options are the same (i.e. blog/user tokens) |
||
| 5972 | * The user has the option to update the shadow site with the new URL before a new |
||
| 5973 | * token is created. |
||
| 5974 | * |
||
| 5975 | * @param $key : Which option to sync. null defautlts to home and siteurl |
||
| 5976 | */ |
||
| 5977 | public static function resolve_identity_crisis( $key = null ) { |
||
| 5999 | |||
| 6000 | /* |
||
| 6001 | * Whitelist URL |
||
| 6002 | * |
||
| 6003 | * Ignore the URL differences between the blog and the shadow site. |
||
| 6004 | */ |
||
| 6005 | public static function whitelist_current_url() { |
||
| 6013 | |||
| 6014 | /* |
||
| 6015 | * Ajax callbacks for ID crisis resolutions |
||
| 6016 | * |
||
| 6017 | * Things that could happen here: |
||
| 6018 | * - site_migrated : Update the URL on the shadow blog to match new domain |
||
| 6019 | * - whitelist : Ignore the URL difference |
||
| 6020 | * - default : Error message |
||
| 6021 | */ |
||
| 6022 | public static function resolve_identity_crisis_ajax_callback() { |
||
| 6062 | |||
| 6063 | /** |
||
| 6064 | * Adds a value to the whitelist for the specified key. |
||
| 6065 | * |
||
| 6066 | * @param string $key The option name that we're whitelisting the value for. |
||
| 6067 | * @param string $value The value that we're intending to add to the whitelist. |
||
| 6068 | * |
||
| 6069 | * @return bool Whether the value was added to the whitelist, or false if it was already there. |
||
| 6070 | */ |
||
| 6071 | public static function whitelist_identity_crisis_value( $key, $value ) { |
||
| 6085 | |||
| 6086 | /** |
||
| 6087 | * Checks whether a value is already whitelisted. |
||
| 6088 | * |
||
| 6089 | * @param string $key The option name that we're checking the value for. |
||
| 6090 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
| 6091 | * |
||
| 6092 | * @return bool Whether the value is whitelisted. |
||
| 6093 | */ |
||
| 6094 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
| 6101 | |||
| 6102 | /** |
||
| 6103 | * Checks whether the home and siteurl specifically are whitelisted |
||
| 6104 | * Written so that we don't have re-check $key and $value params every time |
||
| 6105 | * we want to check if this site is whitelisted, for example in footer.php |
||
| 6106 | * |
||
| 6107 | * @return bool True = already whitelsisted False = not whitelisted |
||
| 6108 | */ |
||
| 6109 | public static function is_staging_site() { |
||
| 6172 | |||
| 6173 | public function identity_crisis_js( $nonce ) { |
||
| 6243 | |||
| 6244 | /** |
||
| 6245 | * Displays an admin_notice, alerting the user to an identity crisis. |
||
| 6246 | */ |
||
| 6247 | public function alert_identity_crisis() { |
||
| 6372 | |||
| 6373 | /** |
||
| 6374 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 6375 | * |
||
| 6376 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 6377 | */ |
||
| 6378 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 6413 | |||
| 6414 | /** |
||
| 6415 | * Maybe inlines a stylesheet. |
||
| 6416 | * |
||
| 6417 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 6418 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 6419 | * |
||
| 6420 | * Attached to `style_loader_tag` filter. |
||
| 6421 | * |
||
| 6422 | * @param string $tag The tag that would link to the external asset. |
||
| 6423 | * @param string $handle The registered handle of the script in question. |
||
| 6424 | * |
||
| 6425 | * @return string |
||
| 6426 | */ |
||
| 6427 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 6477 | |||
| 6478 | /** |
||
| 6479 | * Loads a view file from the views |
||
| 6480 | * |
||
| 6481 | * Data passed in with the $data parameter will be available in the |
||
| 6482 | * template file as $data['value'] |
||
| 6483 | * |
||
| 6484 | * @param string $template - Template file to load |
||
| 6485 | * @param array $data - Any data to pass along to the template |
||
| 6486 | * @return boolean - If template file was found |
||
| 6487 | **/ |
||
| 6488 | public function load_view( $template, $data = array() ) { |
||
| 6499 | |||
| 6500 | /** |
||
| 6501 | * Sends a ping to the Jetpack servers to toggle on/off remote portions |
||
| 6502 | * required by some modules. |
||
| 6503 | * |
||
| 6504 | * @param string $module_slug |
||
| 6505 | */ |
||
| 6506 | public function toggle_module_on_wpcom( $module_slug ) { |
||
| 6514 | |||
| 6515 | /** |
||
| 6516 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
| 6517 | */ |
||
| 6518 | public function deprecated_hooks() { |
||
| 6545 | |||
| 6546 | /** |
||
| 6547 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 6548 | * |
||
| 6549 | * Considerations: |
||
| 6550 | * - Normal, relative URLs `feh.png` |
||
| 6551 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 6552 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 6553 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 6554 | * - Domain root relative URLs `/feh.png` |
||
| 6555 | * |
||
| 6556 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 6557 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 6558 | * |
||
| 6559 | * @return mixed|string |
||
| 6560 | */ |
||
| 6561 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 6605 | |||
| 6606 | /** |
||
| 6607 | * This method checks to see if SSL is required by the site in |
||
| 6608 | * order to visit it in some way other than only setting the |
||
| 6609 | * https value in the home or siteurl values. |
||
| 6610 | * |
||
| 6611 | * @since 3.2 |
||
| 6612 | * @return boolean |
||
| 6613 | **/ |
||
| 6614 | private function is_ssl_required_to_visit_site() { |
||
| 6623 | |||
| 6624 | /** |
||
| 6625 | * This methods removes all of the registered css files on the frontend |
||
| 6626 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 6627 | * all the files into one file. |
||
| 6628 | * |
||
| 6629 | * Pros: |
||
| 6630 | * - Uses only ONE css asset connection instead of 15 |
||
| 6631 | * - Saves a minimum of 56k |
||
| 6632 | * - Reduces server load |
||
| 6633 | * - Reduces time to first painted byte |
||
| 6634 | * |
||
| 6635 | * Cons: |
||
| 6636 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 6637 | * should not cause any issues with themes. |
||
| 6638 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 6639 | * jetpack_implode_frontend_css filter for a workaround |
||
| 6640 | * |
||
| 6641 | * For some situations developers may wish to disable css imploding and |
||
| 6642 | * instead operate in legacy mode where each file loads seperately and |
||
| 6643 | * can be edited individually or dequeued. This can be accomplished with |
||
| 6644 | * the following line: |
||
| 6645 | * |
||
| 6646 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 6647 | * |
||
| 6648 | * @since 3.2 |
||
| 6649 | **/ |
||
| 6650 | public function implode_frontend_css( $travis_test = false ) { |
||
| 6702 | |||
| 6703 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 6713 | |||
| 6714 | /* |
||
| 6715 | * Check the heartbeat data |
||
| 6716 | * |
||
| 6717 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 6718 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 6719 | * |
||
| 6720 | * Data will be added to "caution" array, if it either: |
||
| 6721 | * - Out of date Jetpack version |
||
| 6722 | * - Out of date WP version |
||
| 6723 | * - Out of date PHP version |
||
| 6724 | * |
||
| 6725 | * $return array $filtered_data |
||
| 6726 | */ |
||
| 6727 | public static function jetpack_check_heartbeat_data() { |
||
| 6780 | |||
| 6781 | |||
| 6782 | /* |
||
| 6783 | * This method is used to organize all options that can be reset |
||
| 6784 | * without disconnecting Jetpack. |
||
| 6785 | * |
||
| 6786 | * It is used in class.jetpack-cli.php to reset options |
||
| 6787 | * |
||
| 6788 | * @return array of options to delete. |
||
| 6789 | */ |
||
| 6790 | public static function get_jetpack_options_for_reset() { |
||
| 6856 | |||
| 6857 | /* |
||
| 6858 | * Check if an option of a Jetpack module has been updated. |
||
| 6859 | * |
||
| 6860 | * If any module option has been updated before Jump Start has been dismissed, |
||
| 6861 | * update the 'jumpstart' option so we can hide Jump Start. |
||
| 6862 | */ |
||
| 6863 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
| 6885 | |||
| 6886 | /* |
||
| 6887 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 6888 | * so we can bring them directly to their site in calypso. |
||
| 6889 | * |
||
| 6890 | * @param string | url |
||
| 6891 | * @return string | url without the guff |
||
| 6892 | */ |
||
| 6893 | public static function build_raw_urls( $url ) { |
||
| 6899 | |||
| 6900 | /** |
||
| 6901 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 6902 | * |
||
| 6903 | * @param mixed $new_urls |
||
| 6904 | */ |
||
| 6905 | public static function dns_prefetch( $new_urls = null ) { |
||
| 6922 | |||
| 6923 | public function wp_dashboard_setup() { |
||
| 6951 | |||
| 6952 | /** |
||
| 6953 | * @param mixed $result Value for the user's option |
||
| 6954 | * @return mixed |
||
| 6955 | */ |
||
| 6956 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 6981 | |||
| 6982 | public static function dashboard_widget() { |
||
| 6990 | |||
| 6991 | public static function dashboard_widget_footer() { |
||
| 7029 | |||
| 7030 | public function dashboard_widget_connect_to_wpcom() { |
||
| 7052 | |||
| 7053 | /* |
||
| 7054 | * A graceful transition to using Core's site icon. |
||
| 7055 | * |
||
| 7056 | * All of the hard work has already been done with the image |
||
| 7057 | * in all_done_page(). All that needs to be done now is update |
||
| 7058 | * the option and display proper messaging. |
||
| 7059 | * |
||
| 7060 | * @todo remove when WP 4.3 is minimum |
||
| 7061 | * |
||
| 7062 | * @since 3.6.1 |
||
| 7063 | * |
||
| 7064 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
| 7065 | */ |
||
| 7066 | public static function jetpack_site_icon_available_in_core() { |
||
| 7101 | |||
| 7102 | } |
||
| 7103 |
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.