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 |
||
| 27 | class Jetpack { |
||
| 28 | public $xmlrpc_server = null; |
||
| 29 | |||
| 30 | private $xmlrpc_verification = null; |
||
| 31 | private $rest_authentication_status = null; |
||
| 32 | |||
| 33 | public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA'] |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var array The handles of styles that are concatenated into jetpack.css |
||
| 37 | */ |
||
| 38 | public $concatenated_style_handles = array( |
||
| 39 | 'jetpack-carousel', |
||
| 40 | 'grunion.css', |
||
| 41 | 'the-neverending-homepage', |
||
| 42 | 'jetpack_likes', |
||
| 43 | 'jetpack_related-posts', |
||
| 44 | 'sharedaddy', |
||
| 45 | 'jetpack-slideshow', |
||
| 46 | 'presentations', |
||
| 47 | 'jetpack-subscriptions', |
||
| 48 | 'jetpack-responsive-videos-style', |
||
| 49 | 'jetpack-social-menu', |
||
| 50 | 'tiled-gallery', |
||
| 51 | 'jetpack_display_posts_widget', |
||
| 52 | 'gravatar-profile-widget', |
||
| 53 | 'goodreads-widget', |
||
| 54 | 'jetpack_social_media_icons_widget', |
||
| 55 | 'jetpack-top-posts-widget', |
||
| 56 | 'jetpack_image_widget', |
||
| 57 | 'jetpack-my-community-widget', |
||
| 58 | 'wordads', |
||
| 59 | ); |
||
| 60 | |||
| 61 | public $plugins_to_deactivate = array( |
||
| 62 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 63 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 64 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 65 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 66 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
| 67 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 68 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 69 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 70 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 71 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 72 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 73 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 74 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 75 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
| 76 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 77 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
| 78 | ); |
||
| 79 | |||
| 80 | static $capability_translations = array( |
||
|
|
|||
| 81 | 'administrator' => 'manage_options', |
||
| 82 | 'editor' => 'edit_others_posts', |
||
| 83 | 'author' => 'publish_posts', |
||
| 84 | 'contributor' => 'edit_posts', |
||
| 85 | 'subscriber' => 'read', |
||
| 86 | ); |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 90 | * if the plugins are active. Used by filter_default_modules |
||
| 91 | * |
||
| 92 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 93 | * change `module-slug` and add this to your plugin: |
||
| 94 | * |
||
| 95 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 96 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 97 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 98 | * } |
||
| 99 | * |
||
| 100 | * @var array |
||
| 101 | */ |
||
| 102 | private $conflicting_plugins = array( |
||
| 103 | 'comments' => array( |
||
| 104 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 105 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 106 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 107 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 108 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 109 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 110 | ), |
||
| 111 | 'contact-form' => array( |
||
| 112 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 113 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 114 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 115 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 116 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 117 | ), |
||
| 118 | 'minileven' => array( |
||
| 119 | 'WPtouch' => 'wptouch/wptouch.php', |
||
| 120 | ), |
||
| 121 | 'latex' => array( |
||
| 122 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 123 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 124 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 125 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 126 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 127 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 128 | ), |
||
| 129 | 'protect' => array( |
||
| 130 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 131 | 'Captcha' => 'captcha/captcha.php', |
||
| 132 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 133 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 134 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 135 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 136 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 137 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 138 | 'Login Security' => 'login-security/login-security.php', |
||
| 139 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 140 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 141 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 142 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 143 | ), |
||
| 144 | 'random-redirect' => array( |
||
| 145 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 146 | ), |
||
| 147 | 'related-posts' => array( |
||
| 148 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 149 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 150 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 151 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 152 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 153 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 154 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 155 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 156 | ), |
||
| 157 | 'sharedaddy' => array( |
||
| 158 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 159 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 160 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 161 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 162 | ), |
||
| 163 | 'seo-tools' => array( |
||
| 164 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 165 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 166 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 167 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 168 | ), |
||
| 169 | 'verification-tools' => array( |
||
| 170 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 171 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 172 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 173 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 174 | ), |
||
| 175 | 'widget-visibility' => array( |
||
| 176 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 177 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 178 | ), |
||
| 179 | 'sitemaps' => array( |
||
| 180 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 181 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 182 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 183 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 184 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 185 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 186 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 187 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 188 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
| 189 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 190 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 191 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 192 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 193 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 194 | ), |
||
| 195 | ); |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 199 | * |
||
| 200 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
| 201 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 202 | * |
||
| 203 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 204 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 205 | */ |
||
| 206 | private $open_graph_conflicting_plugins = array( |
||
| 207 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 208 | // 2 Click Social Media Buttons |
||
| 209 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 210 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 211 | 'autodescription/autodescription.php', // The SEO Framework |
||
| 212 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 213 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
| 214 | // Open Graph Meta Tags by Heateor |
||
| 215 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 216 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 217 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 218 | // Facebook Featured Image & OG Meta Tags |
||
| 219 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 220 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 221 | // Facebook Open Graph Meta Tags for WordPress |
||
| 222 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 223 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 224 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 225 | // Fedmich's Facebook Open Graph Meta |
||
| 226 | 'header-footer/plugin.php', // Header and Footer |
||
| 227 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 228 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 229 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 230 | // NextScripts SNAP |
||
| 231 | 'og-tags/og-tags.php', // OG Tags |
||
| 232 | 'opengraph/opengraph.php', // Open Graph |
||
| 233 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 234 | // Open Graph Protocol Framework |
||
| 235 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 236 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 237 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 238 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 239 | 'sharepress/sharepress.php', // SharePress |
||
| 240 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 241 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 242 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 243 | 'socialize/socialize.php', // Socialize |
||
| 244 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
| 245 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 246 | // Tweet, Like, Google +1 and Share |
||
| 247 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 248 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 249 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 250 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 251 | // WP Facebook Like Send & Open Graph Meta |
||
| 252 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 253 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 254 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 255 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
| 256 | ); |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 260 | */ |
||
| 261 | private $twitter_cards_conflicting_plugins = array( |
||
| 262 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 263 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 264 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 265 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 266 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 267 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 268 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 269 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 270 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 271 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 272 | ); |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Message to display in admin_notice |
||
| 276 | * @var string |
||
| 277 | */ |
||
| 278 | public $message = ''; |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Error to display in admin_notice |
||
| 282 | * @var string |
||
| 283 | */ |
||
| 284 | public $error = ''; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Modules that need more privacy description. |
||
| 288 | * @var string |
||
| 289 | */ |
||
| 290 | public $privacy_checks = ''; |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Stats to record once the page loads |
||
| 294 | * |
||
| 295 | * @var array |
||
| 296 | */ |
||
| 297 | public $stats = array(); |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Jetpack_Sync object |
||
| 301 | */ |
||
| 302 | public $sync; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Verified data for JSON authorization request |
||
| 306 | */ |
||
| 307 | public $json_api_authorization_request = array(); |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Holds the singleton instance of this class |
||
| 311 | * @since 2.3.3 |
||
| 312 | * @var Jetpack |
||
| 313 | */ |
||
| 314 | static $instance = false; |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Singleton |
||
| 318 | * @static |
||
| 319 | */ |
||
| 320 | public static function init() { |
||
| 321 | if ( ! self::$instance ) { |
||
| 322 | self::$instance = new Jetpack; |
||
| 323 | |||
| 324 | self::$instance->plugin_upgrade(); |
||
| 325 | } |
||
| 326 | |||
| 327 | return self::$instance; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Must never be called statically |
||
| 332 | */ |
||
| 333 | function plugin_upgrade() { |
||
| 334 | if ( Jetpack::is_active() ) { |
||
| 335 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 336 | if ( JETPACK__VERSION != $version ) { |
||
| 337 | |||
| 338 | // Check which active modules actually exist and remove others from active_modules list |
||
| 339 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
| 340 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
| 341 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
| 342 | Jetpack::update_active_modules( $modules ); |
||
| 343 | } |
||
| 344 | |||
| 345 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
| 346 | |||
| 347 | // Upgrade to 4.3.0 |
||
| 348 | if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) { |
||
| 349 | Jetpack_Options::delete_option( 'identity_crisis_whitelist' ); |
||
| 350 | } |
||
| 351 | |||
| 352 | Jetpack::maybe_set_version_option(); |
||
| 353 | } |
||
| 354 | } |
||
| 355 | } |
||
| 356 | |||
| 357 | static function activate_manage( ) { |
||
| 358 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
| 359 | self::activate_module( 'manage', false, false ); |
||
| 360 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
| 361 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
| 362 | } |
||
| 363 | } |
||
| 364 | |||
| 365 | static function update_active_modules( $modules ) { |
||
| 366 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
| 367 | |||
| 368 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $modules ) ); |
||
| 369 | |||
| 370 | if ( is_array( $modules ) && is_array( $current_modules ) ) { |
||
| 371 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
| 372 | foreach( $new_active_modules as $module ) { |
||
| 373 | /** |
||
| 374 | * Fires when a specific module is activated. |
||
| 375 | * |
||
| 376 | * @since 1.9.0 |
||
| 377 | * |
||
| 378 | * @param string $module Module slug. |
||
| 379 | * @param boolean $success whether the module was activated. @since 4.2 |
||
| 380 | */ |
||
| 381 | do_action( 'jetpack_activate_module', $module, $success ); |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Fires when a module is activated. |
||
| 385 | * The dynamic part of the filter, $module, is the module slug. |
||
| 386 | * |
||
| 387 | * @since 1.9.0 |
||
| 388 | * |
||
| 389 | * @param string $module Module slug. |
||
| 390 | */ |
||
| 391 | do_action( "jetpack_activate_module_$module", $module ); |
||
| 392 | } |
||
| 393 | |||
| 394 | $new_deactive_modules = array_diff( $current_modules, $modules ); |
||
| 395 | foreach( $new_deactive_modules as $module ) { |
||
| 396 | /** |
||
| 397 | * Fired after a module has been deactivated. |
||
| 398 | * |
||
| 399 | * @since 4.2.0 |
||
| 400 | * |
||
| 401 | * @param string $module Module slug. |
||
| 402 | * @param boolean $success whether the module was deactivated. |
||
| 403 | */ |
||
| 404 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
| 405 | /** |
||
| 406 | * Fires when a module is deactivated. |
||
| 407 | * The dynamic part of the filter, $module, is the module slug. |
||
| 408 | * |
||
| 409 | * @since 1.9.0 |
||
| 410 | * |
||
| 411 | * @param string $module Module slug. |
||
| 412 | */ |
||
| 413 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
| 414 | } |
||
| 415 | } |
||
| 416 | |||
| 417 | return $success; |
||
| 418 | } |
||
| 419 | |||
| 420 | static function delete_active_modules() { |
||
| 421 | self::update_active_modules( array() ); |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Constructor. Initializes WordPress hooks |
||
| 426 | */ |
||
| 427 | private function __construct() { |
||
| 428 | /* |
||
| 429 | * Check for and alert any deprecated hooks |
||
| 430 | */ |
||
| 431 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 432 | |||
| 433 | /* |
||
| 434 | * Load things that should only be in Network Admin. |
||
| 435 | * |
||
| 436 | * For now blow away everything else until a more full |
||
| 437 | * understanding of what is needed at the network level is |
||
| 438 | * available |
||
| 439 | */ |
||
| 440 | if( is_multisite() ) { |
||
| 441 | Jetpack_Network::init(); |
||
| 442 | } |
||
| 443 | |||
| 444 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
| 445 | |||
| 446 | // Unlink user before deleting the user from .com |
||
| 447 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 448 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 449 | |||
| 450 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
| 451 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
| 452 | |||
| 453 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
| 454 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
| 455 | |||
| 456 | $this->require_jetpack_authentication(); |
||
| 457 | |||
| 458 | if ( Jetpack::is_active() ) { |
||
| 459 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
| 460 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
| 461 | |||
| 462 | $signed = $this->verify_xml_rpc_signature(); |
||
| 463 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
| 464 | // The actual API methods. |
||
| 465 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
| 466 | } else { |
||
| 467 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
| 468 | // active Jetpack connection, so that additional users can link their account. |
||
| 469 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
| 470 | } |
||
| 471 | } else { |
||
| 472 | // The bootstrap API methods. |
||
| 473 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
| 474 | } |
||
| 475 | |||
| 476 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
| 477 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
| 478 | } elseif ( |
||
| 479 | is_admin() && |
||
| 480 | isset( $_POST['action'] ) && ( |
||
| 481 | 'jetpack_upload_file' == $_POST['action'] || |
||
| 482 | 'jetpack_update_file' == $_POST['action'] |
||
| 483 | ) |
||
| 484 | ) { |
||
| 485 | $this->require_jetpack_authentication(); |
||
| 486 | $this->add_remote_request_handlers(); |
||
| 487 | } else { |
||
| 488 | if ( Jetpack::is_active() ) { |
||
| 489 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
| 490 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
| 491 | } |
||
| 492 | } |
||
| 493 | |||
| 494 | if ( Jetpack::is_active() ) { |
||
| 495 | Jetpack_Heartbeat::init(); |
||
| 496 | } |
||
| 497 | |||
| 498 | add_filter( 'determine_current_user', array( $this, 'wp_rest_authenticate' ) ); |
||
| 499 | add_filter( 'rest_authentication_errors', array( $this, 'wp_rest_authentication_errors' ) ); |
||
| 500 | |||
| 501 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
| 502 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
| 503 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
| 504 | } |
||
| 505 | |||
| 506 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
| 507 | |||
| 508 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 509 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 510 | |||
| 511 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
| 512 | |||
| 513 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 514 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 515 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 516 | |||
| 517 | // returns HTTPS support status |
||
| 518 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
| 519 | |||
| 520 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
| 521 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
| 522 | |||
| 523 | // JITM AJAX callback function |
||
| 524 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
| 525 | |||
| 526 | // Universal ajax callback for all tracking events triggered via js |
||
| 527 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
| 528 | |||
| 529 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 530 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 531 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 532 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 533 | |||
| 534 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
| 535 | |||
| 536 | /** |
||
| 537 | * These actions run checks to load additional files. |
||
| 538 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 539 | */ |
||
| 540 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 541 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 542 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 543 | |||
| 544 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 545 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 546 | |||
| 547 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
| 548 | |||
| 549 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 550 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 551 | |||
| 552 | // A filter to control all just in time messages |
||
| 553 | add_filter( 'jetpack_just_in_time_msgs', '__return_true' ); |
||
| 554 | |||
| 555 | // Update the Jetpack plan from API on heartbeats |
||
| 556 | add_action( 'jetpack_heartbeat', array( $this, 'refresh_active_plan_from_wpcom' ) ); |
||
| 557 | |||
| 558 | /** |
||
| 559 | * This is the hack to concatinate all css files into one. |
||
| 560 | * For description and reasoning see the implode_frontend_css method |
||
| 561 | * |
||
| 562 | * Super late priority so we catch all the registered styles |
||
| 563 | */ |
||
| 564 | if( !is_admin() ) { |
||
| 565 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 566 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 567 | } |
||
| 568 | } |
||
| 569 | |||
| 570 | function jetpack_admin_ajax_tracks_callback() { |
||
| 571 | // Check for nonce |
||
| 572 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
| 573 | wp_die( 'Permissions check failed.' ); |
||
| 574 | } |
||
| 575 | |||
| 576 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
| 577 | wp_die( 'No valid event name or type.' ); |
||
| 578 | } |
||
| 579 | |||
| 580 | $tracks_data = array(); |
||
| 581 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
| 582 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
| 583 | } |
||
| 584 | |||
| 585 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
| 586 | wp_send_json_success(); |
||
| 587 | wp_die(); |
||
| 588 | } |
||
| 589 | |||
| 590 | /** |
||
| 591 | * The callback for the JITM ajax requests. |
||
| 592 | */ |
||
| 593 | function jetpack_jitm_ajax_callback() { |
||
| 594 | // Check for nonce |
||
| 595 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
| 596 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
| 597 | } |
||
| 598 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
| 599 | $module_slug = $_REQUEST['jitmModule']; |
||
| 600 | Jetpack::log( 'activate', $module_slug ); |
||
| 601 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 602 | Jetpack::state( 'message', 'no_message' ); |
||
| 603 | |||
| 604 | //A Jetpack module is being activated through a JITM, track it |
||
| 605 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
| 606 | $this->do_stats( 'server_side' ); |
||
| 607 | |||
| 608 | wp_send_json_success(); |
||
| 609 | } |
||
| 610 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
| 611 | // get the hide_jitm options array |
||
| 612 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
| 613 | $module_slug = $_REQUEST['jitmModule']; |
||
| 614 | |||
| 615 | if( ! $jetpack_hide_jitm ) { |
||
| 616 | $jetpack_hide_jitm = array( |
||
| 617 | $module_slug => 'hide' |
||
| 618 | ); |
||
| 619 | } else { |
||
| 620 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
| 621 | } |
||
| 622 | |||
| 623 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
| 624 | |||
| 625 | //jitm is being dismissed forever, track it |
||
| 626 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
| 627 | $this->do_stats( 'server_side' ); |
||
| 628 | |||
| 629 | wp_send_json_success(); |
||
| 630 | } |
||
| 631 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
| 632 | $module_slug = $_REQUEST['jitmModule']; |
||
| 633 | |||
| 634 | // User went to WordPress.com, track this |
||
| 635 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
| 636 | $this->do_stats( 'server_side' ); |
||
| 637 | |||
| 638 | wp_send_json_success(); |
||
| 639 | } |
||
| 640 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
| 641 | $track = $_REQUEST['jitmModule']; |
||
| 642 | |||
| 643 | // User is viewing JITM, track it. |
||
| 644 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
| 645 | $this->do_stats( 'server_side' ); |
||
| 646 | |||
| 647 | wp_send_json_success(); |
||
| 648 | } |
||
| 649 | } |
||
| 650 | |||
| 651 | /** |
||
| 652 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 653 | */ |
||
| 654 | function __destruct() { |
||
| 655 | if ( ! empty( $this->stats ) ) { |
||
| 656 | $this->do_stats( 'server_side' ); |
||
| 657 | } |
||
| 658 | } |
||
| 659 | |||
| 660 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 661 | switch( $cap ) { |
||
| 662 | case 'jetpack_connect' : |
||
| 663 | case 'jetpack_reconnect' : |
||
| 664 | if ( Jetpack::is_development_mode() ) { |
||
| 665 | $caps = array( 'do_not_allow' ); |
||
| 666 | break; |
||
| 667 | } |
||
| 668 | /** |
||
| 669 | * Pass through. If it's not development mode, these should match disconnect. |
||
| 670 | * Let users disconnect if it's development mode, just in case things glitch. |
||
| 671 | */ |
||
| 672 | case 'jetpack_disconnect' : |
||
| 673 | /** |
||
| 674 | * In multisite, can individual site admins manage their own connection? |
||
| 675 | * |
||
| 676 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
| 677 | */ |
||
| 678 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
| 679 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
| 680 | /** |
||
| 681 | * We need to update the option name -- it's terribly unclear which |
||
| 682 | * direction the override goes. |
||
| 683 | * |
||
| 684 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
| 685 | */ |
||
| 686 | $caps = array( 'do_not_allow' ); |
||
| 687 | break; |
||
| 688 | } |
||
| 689 | } |
||
| 690 | |||
| 691 | $caps = array( 'manage_options' ); |
||
| 692 | break; |
||
| 693 | case 'jetpack_manage_modules' : |
||
| 694 | case 'jetpack_activate_modules' : |
||
| 695 | case 'jetpack_deactivate_modules' : |
||
| 696 | $caps = array( 'manage_options' ); |
||
| 697 | break; |
||
| 698 | case 'jetpack_configure_modules' : |
||
| 699 | $caps = array( 'manage_options' ); |
||
| 700 | break; |
||
| 701 | case 'jetpack_network_admin_page': |
||
| 702 | case 'jetpack_network_settings_page': |
||
| 703 | $caps = array( 'manage_network_plugins' ); |
||
| 704 | break; |
||
| 705 | case 'jetpack_network_sites_page': |
||
| 706 | $caps = array( 'manage_sites' ); |
||
| 707 | break; |
||
| 708 | case 'jetpack_admin_page' : |
||
| 709 | if ( Jetpack::is_development_mode() ) { |
||
| 710 | $caps = array( 'manage_options' ); |
||
| 711 | break; |
||
| 712 | } else { |
||
| 713 | $caps = array( 'read' ); |
||
| 714 | } |
||
| 715 | break; |
||
| 716 | case 'jetpack_connect_user' : |
||
| 717 | if ( Jetpack::is_development_mode() ) { |
||
| 718 | $caps = array( 'do_not_allow' ); |
||
| 719 | break; |
||
| 720 | } |
||
| 721 | $caps = array( 'read' ); |
||
| 722 | break; |
||
| 723 | } |
||
| 724 | return $caps; |
||
| 725 | } |
||
| 726 | |||
| 727 | function require_jetpack_authentication() { |
||
| 728 | // Don't let anyone authenticate |
||
| 729 | $_COOKIE = array(); |
||
| 730 | remove_all_filters( 'authenticate' ); |
||
| 731 | remove_all_actions( 'wp_login_failed' ); |
||
| 732 | |||
| 733 | if ( Jetpack::is_active() ) { |
||
| 734 | // Allow Jetpack authentication |
||
| 735 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
| 736 | } |
||
| 737 | } |
||
| 738 | |||
| 739 | /** |
||
| 740 | * Load language files |
||
| 741 | * @action plugins_loaded |
||
| 742 | */ |
||
| 743 | public static function plugin_textdomain() { |
||
| 744 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
| 745 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
| 746 | } |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 750 | * |
||
| 751 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 752 | * @action wp_loaded |
||
| 753 | * @return null |
||
| 754 | */ |
||
| 755 | public function register_assets() { |
||
| 756 | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
||
| 757 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
| 758 | } |
||
| 759 | |||
| 760 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
| 761 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
| 762 | } |
||
| 763 | |||
| 764 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 765 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
| 766 | } |
||
| 767 | |||
| 768 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
| 769 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
| 770 | } |
||
| 771 | |||
| 772 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 773 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
| 774 | |||
| 775 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 776 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 777 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 778 | $fb_app_id = ''; |
||
| 779 | } |
||
| 780 | wp_localize_script( |
||
| 781 | 'jetpack-facebook-embed', |
||
| 782 | 'jpfbembed', |
||
| 783 | array( |
||
| 784 | 'appid' => $fb_app_id, |
||
| 785 | 'locale' => $this->get_locale(), |
||
| 786 | ) |
||
| 787 | ); |
||
| 788 | } |
||
| 789 | |||
| 790 | /** |
||
| 791 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 792 | * the hook may have already fired by this point. |
||
| 793 | * So, let's just trigger it manually. |
||
| 794 | */ |
||
| 795 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
| 796 | jetpack_register_genericons(); |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Register the social logos |
||
| 800 | */ |
||
| 801 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
| 802 | jetpack_register_social_logos(); |
||
| 803 | |||
| 804 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
| 805 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 806 | } |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Guess locale from language code. |
||
| 810 | * |
||
| 811 | * @param string $lang Language code. |
||
| 812 | * @return string|bool |
||
| 813 | */ |
||
| 814 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 815 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
| 816 | return 'en_US'; |
||
| 817 | } |
||
| 818 | |||
| 819 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
| 820 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
| 821 | return false; |
||
| 822 | } |
||
| 823 | |||
| 824 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
| 825 | } |
||
| 826 | |||
| 827 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 828 | // WP.com: get_locale() returns 'it' |
||
| 829 | $locale = GP_Locales::by_slug( $lang ); |
||
| 830 | } else { |
||
| 831 | // Jetpack: get_locale() returns 'it_IT'; |
||
| 832 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
| 833 | } |
||
| 834 | |||
| 835 | if ( ! $locale ) { |
||
| 836 | return false; |
||
| 837 | } |
||
| 838 | |||
| 839 | if ( empty( $locale->facebook_locale ) ) { |
||
| 840 | if ( empty( $locale->wp_locale ) ) { |
||
| 841 | return false; |
||
| 842 | } else { |
||
| 843 | // Facebook SDK is smart enough to fall back to en_US if a |
||
| 844 | // locale isn't supported. Since supported Facebook locales |
||
| 845 | // can fall out of sync, we'll attempt to use the known |
||
| 846 | // wp_locale value and rely on said fallback. |
||
| 847 | return $locale->wp_locale; |
||
| 848 | } |
||
| 849 | } |
||
| 850 | |||
| 851 | return $locale->facebook_locale; |
||
| 852 | } |
||
| 853 | |||
| 854 | /** |
||
| 855 | * Get the locale. |
||
| 856 | * |
||
| 857 | * @return string|bool |
||
| 858 | */ |
||
| 859 | function get_locale() { |
||
| 860 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
| 861 | |||
| 862 | if ( ! $locale ) { |
||
| 863 | $locale = 'en_US'; |
||
| 864 | } |
||
| 865 | |||
| 866 | return $locale; |
||
| 867 | } |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Device Pixels support |
||
| 871 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
| 872 | */ |
||
| 873 | function devicepx() { |
||
| 874 | if ( Jetpack::is_active() ) { |
||
| 875 | wp_enqueue_script( 'devicepx', 'https://s0.wp.com/wp-content/js/devicepx-jetpack.js', array(), gmdate( 'oW' ), true ); |
||
| 876 | } |
||
| 877 | } |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 881 | * @param bool $option |
||
| 882 | * @return string |
||
| 883 | */ |
||
| 884 | public function jetpack_main_network_site_option( $option ) { |
||
| 885 | return network_site_url(); |
||
| 886 | } |
||
| 887 | /** |
||
| 888 | * Network Name. |
||
| 889 | */ |
||
| 890 | static function network_name( $option = null ) { |
||
| 891 | global $current_site; |
||
| 892 | return $current_site->site_name; |
||
| 893 | } |
||
| 894 | /** |
||
| 895 | * Does the network allow new user and site registrations. |
||
| 896 | * @return string |
||
| 897 | */ |
||
| 898 | static function network_allow_new_registrations( $option = null ) { |
||
| 899 | return ( in_array( get_site_option( 'registration' ), array('none', 'user', 'blog', 'all' ) ) ? get_site_option( 'registration') : 'none' ); |
||
| 900 | } |
||
| 901 | /** |
||
| 902 | * Does the network allow admins to add new users. |
||
| 903 | * @return boolian |
||
| 904 | */ |
||
| 905 | static function network_add_new_users( $option = null ) { |
||
| 906 | return (bool) get_site_option( 'add_new_users' ); |
||
| 907 | } |
||
| 908 | /** |
||
| 909 | * File upload psace left per site in MB. |
||
| 910 | * -1 means NO LIMIT. |
||
| 911 | * @return number |
||
| 912 | */ |
||
| 913 | static function network_site_upload_space( $option = null ) { |
||
| 914 | // value in MB |
||
| 915 | return ( get_site_option( 'upload_space_check_disabled' ) ? -1 : get_space_allowed() ); |
||
| 916 | } |
||
| 917 | |||
| 918 | /** |
||
| 919 | * Network allowed file types. |
||
| 920 | * @return string |
||
| 921 | */ |
||
| 922 | static function network_upload_file_types( $option = null ) { |
||
| 923 | return get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ); |
||
| 924 | } |
||
| 925 | |||
| 926 | /** |
||
| 927 | * Maximum file upload size set by the network. |
||
| 928 | * @return number |
||
| 929 | */ |
||
| 930 | static function network_max_upload_file_size( $option = null ) { |
||
| 931 | // value in KB |
||
| 932 | return get_site_option( 'fileupload_maxk', 300 ); |
||
| 933 | } |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Lets us know if a site allows admins to manage the network. |
||
| 937 | * @return array |
||
| 938 | */ |
||
| 939 | static function network_enable_administration_menus( $option = null ) { |
||
| 940 | return get_site_option( 'menu_items' ); |
||
| 941 | } |
||
| 942 | |||
| 943 | /** |
||
| 944 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
| 945 | * jetpack_other_linked_admins transient. |
||
| 946 | * |
||
| 947 | * @since 4.3.2 |
||
| 948 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
| 949 | * |
||
| 950 | * @param int $user_id The user ID whose role changed. |
||
| 951 | * @param string $role The new role. |
||
| 952 | * @param array $old_roles An array of the user's previous roles. |
||
| 953 | */ |
||
| 954 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
| 955 | if ( 'administrator' == $role |
||
| 956 | || ( is_array( $old_roles ) && in_array( 'administrator', $old_roles ) ) |
||
| 957 | || is_null( $old_roles ) |
||
| 958 | ) { |
||
| 959 | delete_transient( 'jetpack_other_linked_admins' ); |
||
| 960 | } |
||
| 961 | } |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Checks to see if there are any other users available to become primary |
||
| 965 | * Users must both: |
||
| 966 | * - Be linked to wpcom |
||
| 967 | * - Be an admin |
||
| 968 | * |
||
| 969 | * @return mixed False if no other users are linked, Int if there are. |
||
| 970 | */ |
||
| 971 | static function get_other_linked_admins() { |
||
| 972 | $other_linked_users = get_transient( 'jetpack_other_linked_admins' ); |
||
| 973 | |||
| 974 | if ( false === $other_linked_users ) { |
||
| 975 | $admins = get_users( array( 'role' => 'administrator' ) ); |
||
| 976 | if ( count( $admins ) > 1 ) { |
||
| 977 | $available = array(); |
||
| 978 | foreach ( $admins as $admin ) { |
||
| 979 | if ( Jetpack::is_user_connected( $admin->ID ) ) { |
||
| 980 | $available[] = $admin->ID; |
||
| 981 | } |
||
| 982 | } |
||
| 983 | |||
| 984 | $count_connected_admins = count( $available ); |
||
| 985 | if ( count( $available ) > 1 ) { |
||
| 986 | $other_linked_users = $count_connected_admins; |
||
| 987 | } else { |
||
| 988 | $other_linked_users = 0; |
||
| 989 | } |
||
| 990 | } else { |
||
| 991 | $other_linked_users = 0; |
||
| 992 | } |
||
| 993 | |||
| 994 | set_transient( 'jetpack_other_linked_admins', $other_linked_users, HOUR_IN_SECONDS ); |
||
| 995 | } |
||
| 996 | |||
| 997 | return ( 0 === $other_linked_users ) ? false : $other_linked_users; |
||
| 998 | } |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Return whether we are dealing with a multi network setup or not. |
||
| 1002 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 1003 | * the result is false since when is_main_network_option return false it cases |
||
| 1004 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 1005 | * database which could be set to anything as opposed to what this function returns. |
||
| 1006 | * @param bool $option |
||
| 1007 | * |
||
| 1008 | * @return boolean |
||
| 1009 | */ |
||
| 1010 | public function is_main_network_option( $option ) { |
||
| 1011 | // return '1' or '' |
||
| 1012 | return (string) (bool) Jetpack::is_multi_network(); |
||
| 1013 | } |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 1017 | * |
||
| 1018 | * @param string $option |
||
| 1019 | * @return boolean |
||
| 1020 | */ |
||
| 1021 | public function is_multisite( $option ) { |
||
| 1022 | return (string) (bool) is_multisite(); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Implemented since there is no core is multi network function |
||
| 1027 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 1028 | * |
||
| 1029 | * @since 3.3 |
||
| 1030 | * @return boolean |
||
| 1031 | */ |
||
| 1032 | public static function is_multi_network() { |
||
| 1033 | global $wpdb; |
||
| 1034 | |||
| 1035 | // if we don't have a multi site setup no need to do any more |
||
| 1036 | if ( ! is_multisite() ) { |
||
| 1037 | return false; |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
| 1041 | if ( $num_sites > 1 ) { |
||
| 1042 | return true; |
||
| 1043 | } else { |
||
| 1044 | return false; |
||
| 1045 | } |
||
| 1046 | } |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1050 | * @return null |
||
| 1051 | */ |
||
| 1052 | function update_jetpack_main_network_site_option() { |
||
| 1053 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1054 | } |
||
| 1055 | /** |
||
| 1056 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1057 | * |
||
| 1058 | */ |
||
| 1059 | function update_jetpack_network_settings() { |
||
| 1060 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1061 | // Only sync this info for the main network site. |
||
| 1062 | } |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Get back if the current site is single user site. |
||
| 1066 | * |
||
| 1067 | * @return bool |
||
| 1068 | */ |
||
| 1069 | public static function is_single_user_site() { |
||
| 1070 | global $wpdb; |
||
| 1071 | |||
| 1072 | View Code Duplication | if ( false === ( $some_users = get_transient( 'jetpack_is_single_user' ) ) ) { |
|
| 1073 | $some_users = $wpdb->get_var( "SELECT COUNT(*) FROM (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' LIMIT 2) AS someusers" ); |
||
| 1074 | set_transient( 'jetpack_is_single_user', (int) $some_users, 12 * HOUR_IN_SECONDS ); |
||
| 1075 | } |
||
| 1076 | return 1 === (int) $some_users; |
||
| 1077 | } |
||
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Returns true if the site has file write access false otherwise. |
||
| 1081 | * @return string ( '1' | '0' ) |
||
| 1082 | **/ |
||
| 1083 | public static function file_system_write_access() { |
||
| 1084 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
||
| 1085 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
||
| 1086 | } |
||
| 1087 | |||
| 1088 | require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
||
| 1089 | |||
| 1090 | $filesystem_method = get_filesystem_method(); |
||
| 1091 | if ( $filesystem_method === 'direct' ) { |
||
| 1092 | return 1; |
||
| 1093 | } |
||
| 1094 | |||
| 1095 | ob_start(); |
||
| 1096 | $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
||
| 1097 | ob_end_clean(); |
||
| 1098 | if ( $filesystem_credentials_are_stored ) { |
||
| 1099 | return 1; |
||
| 1100 | } |
||
| 1101 | return 0; |
||
| 1102 | } |
||
| 1103 | |||
| 1104 | /** |
||
| 1105 | * Finds out if a site is using a version control system. |
||
| 1106 | * @return string ( '1' | '0' ) |
||
| 1107 | **/ |
||
| 1108 | public static function is_version_controlled() { |
||
| 1109 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); |
||
| 1110 | return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); |
||
| 1111 | } |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Determines whether the current theme supports featured images or not. |
||
| 1115 | * @return string ( '1' | '0' ) |
||
| 1116 | */ |
||
| 1117 | public static function featured_images_enabled() { |
||
| 1118 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1119 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
| 1120 | } |
||
| 1121 | |||
| 1122 | /** |
||
| 1123 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
| 1124 | * |
||
| 1125 | * @deprecated 4.7 use get_avatar_url instead. |
||
| 1126 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 1127 | * @param int $size Size of the avatar image |
||
| 1128 | * @param string $default URL to a default image to use if no avatar is available |
||
| 1129 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 1130 | * |
||
| 1131 | * @return array |
||
| 1132 | */ |
||
| 1133 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 1134 | _deprecated_function( __METHOD__, 'jetpack-4.7', 'get_avatar_url' ); |
||
| 1135 | return get_avatar_url( $id_or_email, array( |
||
| 1136 | 'size' => $size, |
||
| 1137 | 'default' => $default, |
||
| 1138 | 'force_default' => $force_display, |
||
| 1139 | ) ); |
||
| 1140 | } |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * jetpack_updates is saved in the following schema: |
||
| 1144 | * |
||
| 1145 | * array ( |
||
| 1146 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1147 | * 'themes' => (int) Number of theme updates available. |
||
| 1148 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1149 | * 'translations' => (int) Number of translation updates available. |
||
| 1150 | * 'total' => (int) Total of all available updates. |
||
| 1151 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1152 | * ) |
||
| 1153 | * @return array |
||
| 1154 | */ |
||
| 1155 | public static function get_updates() { |
||
| 1156 | $update_data = wp_get_update_data(); |
||
| 1157 | |||
| 1158 | // Stores the individual update counts as well as the total count. |
||
| 1159 | if ( isset( $update_data['counts'] ) ) { |
||
| 1160 | $updates = $update_data['counts']; |
||
| 1161 | } |
||
| 1162 | |||
| 1163 | // If we need to update WordPress core, let's find the latest version number. |
||
| 1164 | View Code Duplication | if ( ! empty( $updates['wordpress'] ) ) { |
|
| 1165 | $cur = get_preferred_from_update_core(); |
||
| 1166 | if ( isset( $cur->response ) && 'upgrade' === $cur->response ) { |
||
| 1167 | $updates['wp_update_version'] = $cur->current; |
||
| 1168 | } |
||
| 1169 | } |
||
| 1170 | return isset( $updates ) ? $updates : array(); |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | public static function get_update_details() { |
||
| 1174 | $update_details = array( |
||
| 1175 | 'update_core' => get_site_transient( 'update_core' ), |
||
| 1176 | 'update_plugins' => get_site_transient( 'update_plugins' ), |
||
| 1177 | 'update_themes' => get_site_transient( 'update_themes' ), |
||
| 1178 | ); |
||
| 1179 | return $update_details; |
||
| 1180 | } |
||
| 1181 | |||
| 1182 | public static function refresh_update_data() { |
||
| 1183 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1184 | |||
| 1185 | } |
||
| 1186 | |||
| 1187 | public static function refresh_theme_data() { |
||
| 1188 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1189 | } |
||
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Is Jetpack active? |
||
| 1193 | */ |
||
| 1194 | public static function is_active() { |
||
| 1195 | return (bool) Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
| 1196 | } |
||
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Make an API call to WordPress.com for plan status |
||
| 1200 | * |
||
| 1201 | * @uses Jetpack_Options::get_option() |
||
| 1202 | * @uses Jetpack_Client::wpcom_json_api_request_as_blog() |
||
| 1203 | * @uses update_option() |
||
| 1204 | * |
||
| 1205 | * @access public |
||
| 1206 | * @static |
||
| 1207 | * |
||
| 1208 | * @return bool True if plan is updated, false if no update |
||
| 1209 | */ |
||
| 1210 | public static function refresh_active_plan_from_wpcom() { |
||
| 1211 | // Make the API request |
||
| 1212 | $request = sprintf( '/sites/%d', Jetpack_Options::get_option( 'id' ) ); |
||
| 1213 | $response = Jetpack_Client::wpcom_json_api_request_as_blog( $request, '1.1' ); |
||
| 1214 | |||
| 1215 | // Bail if there was an error or malformed response |
||
| 1216 | if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) { |
||
| 1217 | return false; |
||
| 1218 | } |
||
| 1219 | |||
| 1220 | // Decode the results |
||
| 1221 | $results = json_decode( $response['body'], true ); |
||
| 1222 | |||
| 1223 | // Bail if there were no results or plan details returned |
||
| 1224 | if ( ! is_array( $results ) || ! isset( $results['plan'] ) ) { |
||
| 1225 | return false; |
||
| 1226 | } |
||
| 1227 | |||
| 1228 | // Store the option and return true if updated |
||
| 1229 | return update_option( 'jetpack_active_plan', $results['plan'] ); |
||
| 1230 | } |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Get the plan that this Jetpack site is currently using |
||
| 1234 | * |
||
| 1235 | * @uses get_option() |
||
| 1236 | * |
||
| 1237 | * @access public |
||
| 1238 | * @static |
||
| 1239 | * |
||
| 1240 | * @return array Active Jetpack plan details |
||
| 1241 | */ |
||
| 1242 | public static function get_active_plan() { |
||
| 1243 | $plan = get_option( 'jetpack_active_plan' ); |
||
| 1244 | |||
| 1245 | // Set the default options |
||
| 1246 | if ( ! $plan ) { |
||
| 1247 | $plan = array( |
||
| 1248 | 'product_slug' => 'jetpack_free', |
||
| 1249 | 'supports' => array(), |
||
| 1250 | 'class' => 'free', |
||
| 1251 | ); |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | // Define what paid modules are supported by personal plans |
||
| 1255 | $personal_plans = array( |
||
| 1256 | 'jetpack_personal', |
||
| 1257 | 'jetpack_personal_monthly', |
||
| 1258 | ); |
||
| 1259 | |||
| 1260 | if ( in_array( $plan['product_slug'], $personal_plans ) ) { |
||
| 1261 | $plan['supports'] = array( |
||
| 1262 | 'akismet', |
||
| 1263 | ); |
||
| 1264 | $plan['class'] = 'personal'; |
||
| 1265 | } |
||
| 1266 | |||
| 1267 | // Define what paid modules are supported by premium plans |
||
| 1268 | $premium_plans = array( |
||
| 1269 | 'jetpack_premium', |
||
| 1270 | 'jetpack_premium_monthly', |
||
| 1271 | ); |
||
| 1272 | |||
| 1273 | View Code Duplication | if ( in_array( $plan['product_slug'], $premium_plans ) ) { |
|
| 1274 | $plan['supports'] = array( |
||
| 1275 | 'videopress', |
||
| 1276 | 'akismet', |
||
| 1277 | 'vaultpress', |
||
| 1278 | 'wordads', |
||
| 1279 | ); |
||
| 1280 | $plan['class'] = 'premium'; |
||
| 1281 | } |
||
| 1282 | |||
| 1283 | // Define what paid modules are supported by professional plans |
||
| 1284 | $business_plans = array( |
||
| 1285 | 'jetpack_business', |
||
| 1286 | 'jetpack_business_monthly', |
||
| 1287 | ); |
||
| 1288 | |||
| 1289 | View Code Duplication | if ( in_array( $plan['product_slug'], $business_plans ) ) { |
|
| 1290 | $plan['supports'] = array( |
||
| 1291 | 'videopress', |
||
| 1292 | 'akismet', |
||
| 1293 | 'vaultpress', |
||
| 1294 | 'seo-tools', |
||
| 1295 | 'google-analytics', |
||
| 1296 | 'wordads', |
||
| 1297 | ); |
||
| 1298 | $plan['class'] = 'business'; |
||
| 1299 | } |
||
| 1300 | |||
| 1301 | // Make sure we have an array here in the event database data is stale |
||
| 1302 | if ( ! isset( $plan['supports'] ) ) { |
||
| 1303 | $plan['supports'] = array(); |
||
| 1304 | } |
||
| 1305 | |||
| 1306 | return $plan; |
||
| 1307 | } |
||
| 1308 | |||
| 1309 | /** |
||
| 1310 | * Determine whether the active plan supports a particular feature |
||
| 1311 | * |
||
| 1312 | * @uses Jetpack::get_active_plan() |
||
| 1313 | * |
||
| 1314 | * @access public |
||
| 1315 | * @static |
||
| 1316 | * |
||
| 1317 | * @return bool True if plan supports feature, false if not |
||
| 1318 | */ |
||
| 1319 | public static function active_plan_supports( $feature ) { |
||
| 1320 | $plan = Jetpack::get_active_plan(); |
||
| 1321 | |||
| 1322 | if ( in_array( $feature, $plan['supports'] ) ) { |
||
| 1323 | return true; |
||
| 1324 | } |
||
| 1325 | |||
| 1326 | return false; |
||
| 1327 | } |
||
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Is Jetpack in development (offline) mode? |
||
| 1331 | */ |
||
| 1332 | public static function is_development_mode() { |
||
| 1333 | $development_mode = false; |
||
| 1334 | |||
| 1335 | if ( defined( 'JETPACK_DEV_DEBUG' ) ) { |
||
| 1336 | $development_mode = JETPACK_DEV_DEBUG; |
||
| 1337 | } elseif ( $site_url = site_url() ) { |
||
| 1338 | $development_mode = false === strpos( $site_url, '.' ); |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * Filters Jetpack's development mode. |
||
| 1343 | * |
||
| 1344 | * @see https://jetpack.com/support/development-mode/ |
||
| 1345 | * |
||
| 1346 | * @since 2.2.1 |
||
| 1347 | * |
||
| 1348 | * @param bool $development_mode Is Jetpack's development mode active. |
||
| 1349 | */ |
||
| 1350 | return apply_filters( 'jetpack_development_mode', $development_mode ); |
||
| 1351 | } |
||
| 1352 | |||
| 1353 | /** |
||
| 1354 | * Get Jetpack development mode notice text and notice class. |
||
| 1355 | * |
||
| 1356 | * Mirrors the checks made in Jetpack::is_development_mode |
||
| 1357 | * |
||
| 1358 | */ |
||
| 1359 | public static function show_development_mode_notice() { |
||
| 1360 | if ( Jetpack::is_development_mode() ) { |
||
| 1361 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
| 1362 | $notice = sprintf( |
||
| 1363 | /* translators: %s is a URL */ |
||
| 1364 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), |
||
| 1365 | 'https://jetpack.com/support/development-mode/' |
||
| 1366 | ); |
||
| 1367 | } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
| 1368 | $notice = sprintf( |
||
| 1369 | /* translators: %s is a URL */ |
||
| 1370 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), |
||
| 1371 | 'https://jetpack.com/support/development-mode/' |
||
| 1372 | ); |
||
| 1373 | } else { |
||
| 1374 | $notice = sprintf( |
||
| 1375 | /* translators: %s is a URL */ |
||
| 1376 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), |
||
| 1377 | 'https://jetpack.com/support/development-mode/' |
||
| 1378 | ); |
||
| 1379 | } |
||
| 1380 | |||
| 1381 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1382 | } |
||
| 1383 | |||
| 1384 | // Throw up a notice if using a development version and as for feedback. |
||
| 1385 | if ( Jetpack::is_development_version() ) { |
||
| 1386 | /* translators: %s is a URL */ |
||
| 1387 | $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.com/contact-support/beta-group/' ); |
||
| 1388 | |||
| 1389 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1390 | } |
||
| 1391 | // Throw up a notice if using staging mode |
||
| 1392 | if ( Jetpack::is_staging_site() ) { |
||
| 1393 | /* translators: %s is a URL */ |
||
| 1394 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); |
||
| 1395 | |||
| 1396 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1397 | } |
||
| 1398 | } |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1402 | */ |
||
| 1403 | public static function is_development_version() { |
||
| 1404 | /** |
||
| 1405 | * Allows filtering whether this is a development version of Jetpack. |
||
| 1406 | * |
||
| 1407 | * This filter is especially useful for tests. |
||
| 1408 | * |
||
| 1409 | * @since 4.3.0 |
||
| 1410 | * |
||
| 1411 | * @param bool $development_version Is this a develoment version of Jetpack? |
||
| 1412 | */ |
||
| 1413 | return (bool) apply_filters( |
||
| 1414 | 'jetpack_development_version', |
||
| 1415 | ! preg_match( '/^\d+(\.\d+)+$/', Jetpack_Constants::get_constant( 'JETPACK__VERSION' ) ) |
||
| 1416 | ); |
||
| 1417 | } |
||
| 1418 | |||
| 1419 | /** |
||
| 1420 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1421 | */ |
||
| 1422 | public static function is_user_connected( $user_id = false ) { |
||
| 1423 | $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); |
||
| 1424 | if ( ! $user_id ) { |
||
| 1425 | return false; |
||
| 1426 | } |
||
| 1427 | |||
| 1428 | return (bool) Jetpack_Data::get_access_token( $user_id ); |
||
| 1429 | } |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Get the wpcom user data of the current|specified connected user. |
||
| 1433 | */ |
||
| 1434 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1435 | if ( ! $user_id ) { |
||
| 1436 | $user_id = get_current_user_id(); |
||
| 1437 | } |
||
| 1438 | |||
| 1439 | $transient_key = "jetpack_connected_user_data_$user_id"; |
||
| 1440 | |||
| 1441 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
||
| 1442 | return $cached_user_data; |
||
| 1443 | } |
||
| 1444 | |||
| 1445 | Jetpack::load_xml_rpc_client(); |
||
| 1446 | $xml = new Jetpack_IXR_Client( array( |
||
| 1447 | 'user_id' => $user_id, |
||
| 1448 | ) ); |
||
| 1449 | $xml->query( 'wpcom.getUser' ); |
||
| 1450 | if ( ! $xml->isError() ) { |
||
| 1451 | $user_data = $xml->getResponse(); |
||
| 1452 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
||
| 1453 | return $user_data; |
||
| 1454 | } |
||
| 1455 | |||
| 1456 | return false; |
||
| 1457 | } |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Get the wpcom email of the current|specified connected user. |
||
| 1461 | */ |
||
| 1462 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
| 1463 | if ( ! $user_id ) { |
||
| 1464 | $user_id = get_current_user_id(); |
||
| 1465 | } |
||
| 1466 | Jetpack::load_xml_rpc_client(); |
||
| 1467 | $xml = new Jetpack_IXR_Client( array( |
||
| 1468 | 'user_id' => $user_id, |
||
| 1469 | ) ); |
||
| 1470 | $xml->query( 'wpcom.getUserEmail' ); |
||
| 1471 | if ( ! $xml->isError() ) { |
||
| 1472 | return $xml->getResponse(); |
||
| 1473 | } |
||
| 1474 | return false; |
||
| 1475 | } |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Get the wpcom email of the master user. |
||
| 1479 | */ |
||
| 1480 | public static function get_master_user_email() { |
||
| 1481 | $master_user_id = Jetpack_Options::get_option( 'master_user' ); |
||
| 1482 | if ( $master_user_id ) { |
||
| 1483 | return self::get_connected_user_email( $master_user_id ); |
||
| 1484 | } |
||
| 1485 | return ''; |
||
| 1486 | } |
||
| 1487 | |||
| 1488 | function current_user_is_connection_owner() { |
||
| 1489 | $user_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
| 1490 | return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && get_current_user_id() === $user_token->external_user_id; |
||
| 1491 | } |
||
| 1492 | |||
| 1493 | /** |
||
| 1494 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
| 1495 | */ |
||
| 1496 | function extra_oembed_providers() { |
||
| 1497 | // Cloudup: https://dev.cloudup.com/#oembed |
||
| 1498 | wp_oembed_add_provider( 'https://cloudup.com/*' , 'https://cloudup.com/oembed' ); |
||
| 1499 | wp_oembed_add_provider( 'https://me.sh/*', 'https://me.sh/oembed?format=json' ); |
||
| 1500 | wp_oembed_add_provider( '#https?://(www\.)?gfycat\.com/.*#i', 'https://api.gfycat.com/v1/oembed', true ); |
||
| 1501 | wp_oembed_add_provider( '#https?://[^.]+\.(wistia\.com|wi\.st)/(medias|embed)/.*#', 'https://fast.wistia.com/oembed', true ); |
||
| 1502 | wp_oembed_add_provider( '#https?://sketchfab\.com/.*#i', 'https://sketchfab.com/oembed', true ); |
||
| 1503 | } |
||
| 1504 | |||
| 1505 | /** |
||
| 1506 | * Synchronize connected user role changes |
||
| 1507 | */ |
||
| 1508 | function user_role_change( $user_id ) { |
||
| 1509 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Users::user_role_change()' ); |
||
| 1510 | Jetpack_Sync_Users::user_role_change( $user_id ); |
||
| 1511 | } |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Loads the currently active modules. |
||
| 1515 | */ |
||
| 1516 | public static function load_modules() { |
||
| 1517 | if ( ! self::is_active() && !self::is_development_mode() ) { |
||
| 1518 | if ( ! is_multisite() || ! get_site_option( 'jetpack_protect_active' ) ) { |
||
| 1519 | return; |
||
| 1520 | } |
||
| 1521 | } |
||
| 1522 | |||
| 1523 | $version = Jetpack_Options::get_option( 'version' ); |
||
| 1524 | View Code Duplication | if ( ! $version ) { |
|
| 1525 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
| 1526 | /** This action is documented in class.jetpack.php */ |
||
| 1527 | do_action( 'updating_jetpack_version', $version, false ); |
||
| 1528 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
| 1529 | } |
||
| 1530 | list( $version ) = explode( ':', $version ); |
||
| 1531 | |||
| 1532 | $modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) ); |
||
| 1533 | |||
| 1534 | $modules_data = array(); |
||
| 1535 | |||
| 1536 | // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check. |
||
| 1537 | if ( version_compare( $version, JETPACK__VERSION, '<' ) ) { |
||
| 1538 | $updated_modules = array(); |
||
| 1539 | foreach ( $modules as $module ) { |
||
| 1540 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
| 1541 | if ( ! isset( $modules_data[ $module ]['changed'] ) ) { |
||
| 1542 | continue; |
||
| 1543 | } |
||
| 1544 | |||
| 1545 | if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) { |
||
| 1546 | continue; |
||
| 1547 | } |
||
| 1548 | |||
| 1549 | $updated_modules[] = $module; |
||
| 1550 | } |
||
| 1551 | |||
| 1552 | $modules = array_diff( $modules, $updated_modules ); |
||
| 1553 | } |
||
| 1554 | |||
| 1555 | $is_development_mode = Jetpack::is_development_mode(); |
||
| 1556 | |||
| 1557 | foreach ( $modules as $index => $module ) { |
||
| 1558 | // If we're in dev mode, disable modules requiring a connection |
||
| 1559 | if ( $is_development_mode ) { |
||
| 1560 | // Prime the pump if we need to |
||
| 1561 | if ( empty( $modules_data[ $module ] ) ) { |
||
| 1562 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
| 1563 | } |
||
| 1564 | // If the module requires a connection, but we're in local mode, don't include it. |
||
| 1565 | if ( $modules_data[ $module ]['requires_connection'] ) { |
||
| 1566 | continue; |
||
| 1567 | } |
||
| 1568 | } |
||
| 1569 | |||
| 1570 | if ( did_action( 'jetpack_module_loaded_' . $module ) ) { |
||
| 1571 | continue; |
||
| 1572 | } |
||
| 1573 | |||
| 1574 | if ( ! @include( Jetpack::get_module_path( $module ) ) ) { |
||
| 1575 | unset( $modules[ $index ] ); |
||
| 1576 | self::update_active_modules( array_values( $modules ) ); |
||
| 1577 | continue; |
||
| 1578 | } |
||
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Fires when a specific module is loaded. |
||
| 1582 | * The dynamic part of the hook, $module, is the module slug. |
||
| 1583 | * |
||
| 1584 | * @since 1.1.0 |
||
| 1585 | */ |
||
| 1586 | do_action( 'jetpack_module_loaded_' . $module ); |
||
| 1587 | } |
||
| 1588 | |||
| 1589 | /** |
||
| 1590 | * Fires when all the modules are loaded. |
||
| 1591 | * |
||
| 1592 | * @since 1.1.0 |
||
| 1593 | */ |
||
| 1594 | do_action( 'jetpack_modules_loaded' ); |
||
| 1595 | |||
| 1596 | // Load module-specific code that is needed even when a module isn't active. Loaded here because code contained therein may need actions such as setup_theme. |
||
| 1597 | if ( Jetpack::is_active() || Jetpack::is_development_mode() ) |
||
| 1598 | require_once( JETPACK__PLUGIN_DIR . 'modules/module-extras.php' ); |
||
| 1599 | } |
||
| 1600 | |||
| 1601 | /** |
||
| 1602 | * Check if Jetpack's REST API compat file should be included |
||
| 1603 | * @action plugins_loaded |
||
| 1604 | * @return null |
||
| 1605 | */ |
||
| 1606 | public function check_rest_api_compat() { |
||
| 1607 | /** |
||
| 1608 | * Filters the list of REST API compat files to be included. |
||
| 1609 | * |
||
| 1610 | * @since 2.2.5 |
||
| 1611 | * |
||
| 1612 | * @param array $args Array of REST API compat files to include. |
||
| 1613 | */ |
||
| 1614 | $_jetpack_rest_api_compat_includes = apply_filters( 'jetpack_rest_api_compat', array() ); |
||
| 1615 | |||
| 1616 | if ( function_exists( 'bbpress' ) ) |
||
| 1617 | $_jetpack_rest_api_compat_includes[] = JETPACK__PLUGIN_DIR . 'class.jetpack-bbpress-json-api-compat.php'; |
||
| 1618 | |||
| 1619 | foreach ( $_jetpack_rest_api_compat_includes as $_jetpack_rest_api_compat_include ) |
||
| 1620 | require_once $_jetpack_rest_api_compat_include; |
||
| 1621 | } |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 1625 | * traditionally activated or network activated. |
||
| 1626 | * |
||
| 1627 | * @todo Store the result in core's object cache maybe? |
||
| 1628 | */ |
||
| 1629 | public static function get_active_plugins() { |
||
| 1630 | $active_plugins = (array) get_option( 'active_plugins', array() ); |
||
| 1631 | |||
| 1632 | if ( is_multisite() ) { |
||
| 1633 | // Due to legacy code, active_sitewide_plugins stores them in the keys, |
||
| 1634 | // whereas active_plugins stores them in the values. |
||
| 1635 | $network_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
||
| 1636 | if ( $network_plugins ) { |
||
| 1637 | $active_plugins = array_merge( $active_plugins, $network_plugins ); |
||
| 1638 | } |
||
| 1639 | } |
||
| 1640 | |||
| 1641 | sort( $active_plugins ); |
||
| 1642 | |||
| 1643 | return array_unique( $active_plugins ); |
||
| 1644 | } |
||
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 1648 | * |
||
| 1649 | * @since 3.8.1 |
||
| 1650 | * |
||
| 1651 | * @return array Array of plugin data |
||
| 1652 | */ |
||
| 1653 | public static function get_parsed_plugin_data() { |
||
| 1654 | if ( ! function_exists( 'get_plugins' ) ) { |
||
| 1655 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
| 1656 | } |
||
| 1657 | /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
||
| 1658 | $all_plugins = apply_filters( 'all_plugins', get_plugins() ); |
||
| 1659 | $active_plugins = Jetpack::get_active_plugins(); |
||
| 1660 | |||
| 1661 | $plugins = array(); |
||
| 1662 | foreach ( $all_plugins as $path => $plugin_data ) { |
||
| 1663 | $plugins[ $path ] = array( |
||
| 1664 | 'is_active' => in_array( $path, $active_plugins ), |
||
| 1665 | 'file' => $path, |
||
| 1666 | 'name' => $plugin_data['Name'], |
||
| 1667 | 'version' => $plugin_data['Version'], |
||
| 1668 | 'author' => $plugin_data['Author'], |
||
| 1669 | ); |
||
| 1670 | } |
||
| 1671 | |||
| 1672 | return $plugins; |
||
| 1673 | } |
||
| 1674 | |||
| 1675 | /** |
||
| 1676 | * Gets and parses theme data to send with the heartbeat data |
||
| 1677 | * |
||
| 1678 | * @since 3.8.1 |
||
| 1679 | * |
||
| 1680 | * @return array Array of theme data |
||
| 1681 | */ |
||
| 1682 | public static function get_parsed_theme_data() { |
||
| 1683 | $all_themes = wp_get_themes( array( 'allowed' => true ) ); |
||
| 1684 | $header_keys = array( 'Name', 'Author', 'Version', 'ThemeURI', 'AuthorURI', 'Status', 'Tags' ); |
||
| 1685 | |||
| 1686 | $themes = array(); |
||
| 1687 | foreach ( $all_themes as $slug => $theme_data ) { |
||
| 1688 | $theme_headers = array(); |
||
| 1689 | foreach ( $header_keys as $header_key ) { |
||
| 1690 | $theme_headers[ $header_key ] = $theme_data->get( $header_key ); |
||
| 1691 | } |
||
| 1692 | |||
| 1693 | $themes[ $slug ] = array( |
||
| 1694 | 'is_active_theme' => $slug == wp_get_theme()->get_template(), |
||
| 1695 | 'slug' => $slug, |
||
| 1696 | 'theme_root' => $theme_data->get_theme_root_uri(), |
||
| 1697 | 'parent' => $theme_data->parent(), |
||
| 1698 | 'headers' => $theme_headers |
||
| 1699 | ); |
||
| 1700 | } |
||
| 1701 | |||
| 1702 | return $themes; |
||
| 1703 | } |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * Checks whether a specific plugin is active. |
||
| 1707 | * |
||
| 1708 | * We don't want to store these in a static variable, in case |
||
| 1709 | * there are switch_to_blog() calls involved. |
||
| 1710 | */ |
||
| 1711 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 1712 | return in_array( $plugin, self::get_active_plugins() ); |
||
| 1713 | } |
||
| 1714 | |||
| 1715 | /** |
||
| 1716 | * Check if Jetpack's Open Graph tags should be used. |
||
| 1717 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 1718 | * |
||
| 1719 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1720 | * @action plugins_loaded |
||
| 1721 | * @return null |
||
| 1722 | */ |
||
| 1723 | public function check_open_graph() { |
||
| 1724 | if ( in_array( 'publicize', Jetpack::get_active_modules() ) || in_array( 'sharedaddy', Jetpack::get_active_modules() ) ) { |
||
| 1725 | add_filter( 'jetpack_enable_open_graph', '__return_true', 0 ); |
||
| 1726 | } |
||
| 1727 | |||
| 1728 | $active_plugins = self::get_active_plugins(); |
||
| 1729 | |||
| 1730 | if ( ! empty( $active_plugins ) ) { |
||
| 1731 | foreach ( $this->open_graph_conflicting_plugins as $plugin ) { |
||
| 1732 | if ( in_array( $plugin, $active_plugins ) ) { |
||
| 1733 | add_filter( 'jetpack_enable_open_graph', '__return_false', 99 ); |
||
| 1734 | break; |
||
| 1735 | } |
||
| 1736 | } |
||
| 1737 | } |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Allow the addition of Open Graph Meta Tags to all pages. |
||
| 1741 | * |
||
| 1742 | * @since 2.0.3 |
||
| 1743 | * |
||
| 1744 | * @param bool false Should Open Graph Meta tags be added. Default to false. |
||
| 1745 | */ |
||
| 1746 | if ( apply_filters( 'jetpack_enable_open_graph', false ) ) { |
||
| 1747 | require_once JETPACK__PLUGIN_DIR . 'functions.opengraph.php'; |
||
| 1748 | } |
||
| 1749 | } |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | * Check if Jetpack's Twitter tags should be used. |
||
| 1753 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 1754 | * |
||
| 1755 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1756 | * @action plugins_loaded |
||
| 1757 | * @return null |
||
| 1758 | */ |
||
| 1759 | public function check_twitter_tags() { |
||
| 1760 | |||
| 1761 | $active_plugins = self::get_active_plugins(); |
||
| 1762 | |||
| 1763 | if ( ! empty( $active_plugins ) ) { |
||
| 1764 | foreach ( $this->twitter_cards_conflicting_plugins as $plugin ) { |
||
| 1765 | if ( in_array( $plugin, $active_plugins ) ) { |
||
| 1766 | add_filter( 'jetpack_disable_twitter_cards', '__return_true', 99 ); |
||
| 1767 | break; |
||
| 1768 | } |
||
| 1769 | } |
||
| 1770 | } |
||
| 1771 | |||
| 1772 | /** |
||
| 1773 | * Allow Twitter Card Meta tags to be disabled. |
||
| 1774 | * |
||
| 1775 | * @since 2.6.0 |
||
| 1776 | * |
||
| 1777 | * @param bool true Should Twitter Card Meta tags be disabled. Default to true. |
||
| 1778 | */ |
||
| 1779 | if ( ! apply_filters( 'jetpack_disable_twitter_cards', false ) ) { |
||
| 1780 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-twitter-cards.php'; |
||
| 1781 | } |
||
| 1782 | } |
||
| 1783 | |||
| 1784 | /** |
||
| 1785 | * Allows plugins to submit security reports. |
||
| 1786 | * |
||
| 1787 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 1788 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 1789 | * @param array $args See definitions above |
||
| 1790 | */ |
||
| 1791 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 1792 | _deprecated_function( __FUNCTION__, 'jetpack-4.2', null ); |
||
| 1793 | } |
||
| 1794 | |||
| 1795 | /* Jetpack Options API */ |
||
| 1796 | |||
| 1797 | public static function get_option_names( $type = 'compact' ) { |
||
| 1800 | |||
| 1801 | /** |
||
| 1802 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 1803 | * |
||
| 1804 | * @param string $name Option name |
||
| 1805 | * @param mixed $default (optional) |
||
| 1806 | */ |
||
| 1807 | public static function get_option( $name, $default = false ) { |
||
| 1810 | |||
| 1811 | /** |
||
| 1812 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
| 1813 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
| 1814 | * $name must be a registered option name. |
||
| 1815 | */ |
||
| 1816 | public static function create_nonce( $name ) { |
||
| 1830 | |||
| 1831 | /** |
||
| 1832 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 1833 | * |
||
| 1834 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 1835 | * @param string $name Option name |
||
| 1836 | * @param mixed $value Option value |
||
| 1837 | */ |
||
| 1838 | public static function update_option( $name, $value ) { |
||
| 1842 | |||
| 1843 | /** |
||
| 1844 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 1845 | * |
||
| 1846 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 1847 | * @param array $array array( option name => option value, ... ) |
||
| 1848 | */ |
||
| 1849 | public static function update_options( $array ) { |
||
| 1853 | |||
| 1854 | /** |
||
| 1855 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 1856 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 1857 | * |
||
| 1858 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 1859 | * @param string|array $names |
||
| 1860 | */ |
||
| 1861 | public static function delete_option( $names ) { |
||
| 1865 | |||
| 1866 | /** |
||
| 1867 | * Enters a user token into the user_tokens option |
||
| 1868 | * |
||
| 1869 | * @param int $user_id |
||
| 1870 | * @param string $token |
||
| 1871 | * return bool |
||
| 1872 | */ |
||
| 1873 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 1887 | |||
| 1888 | /** |
||
| 1889 | * Returns an array of all PHP files in the specified absolute path. |
||
| 1890 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 1891 | * |
||
| 1892 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 1893 | * @return array Array of absolute paths to the PHP files. |
||
| 1894 | */ |
||
| 1895 | public static function glob_php( $absolute_path ) { |
||
| 1924 | |||
| 1925 | public static function activate_new_modules( $redirect = false ) { |
||
| 1983 | |||
| 1984 | /** |
||
| 1985 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 1986 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 1987 | */ |
||
| 1988 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 2045 | |||
| 2046 | /** |
||
| 2047 | * Default modules loaded on activation. |
||
| 2048 | */ |
||
| 2049 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Checks activated modules during auto-activation to determine |
||
| 2083 | * if any of those modules are being deprecated. If so, close |
||
| 2084 | * them out, and add any replacement modules. |
||
| 2085 | * |
||
| 2086 | * Runs at priority 99 by default. |
||
| 2087 | * |
||
| 2088 | * This is run late, so that it can still activate a module if |
||
| 2089 | * the new module is a replacement for another that the user |
||
| 2090 | * currently has active, even if something at the normal priority |
||
| 2091 | * would kibosh everything. |
||
| 2092 | * |
||
| 2093 | * @since 2.6 |
||
| 2094 | * @uses jetpack_get_default_modules filter |
||
| 2095 | * @param array $modules |
||
| 2096 | * @return array |
||
| 2097 | */ |
||
| 2098 | function handle_deprecated_modules( $modules ) { |
||
| 2124 | |||
| 2125 | /** |
||
| 2126 | * Checks activated plugins during auto-activation to determine |
||
| 2127 | * if any of those plugins are in the list with a corresponding module |
||
| 2128 | * that is not compatible with the plugin. The module will not be allowed |
||
| 2129 | * to auto-activate. |
||
| 2130 | * |
||
| 2131 | * @since 2.6 |
||
| 2132 | * @uses jetpack_get_default_modules filter |
||
| 2133 | * @param array $modules |
||
| 2134 | * @return array |
||
| 2135 | */ |
||
| 2136 | function filter_default_modules( $modules ) { |
||
| 2160 | |||
| 2161 | /** |
||
| 2162 | * Extract a module's slug from its full path. |
||
| 2163 | */ |
||
| 2164 | public static function get_module_slug( $file ) { |
||
| 2167 | |||
| 2168 | /** |
||
| 2169 | * Generate a module's path from its slug. |
||
| 2170 | */ |
||
| 2171 | public static function get_module_path( $slug ) { |
||
| 2174 | |||
| 2175 | /** |
||
| 2176 | * Load module data from module file. Headers differ from WordPress |
||
| 2177 | * plugin headers to avoid them being identified as standalone |
||
| 2178 | * plugins on the WordPress plugins page. |
||
| 2179 | */ |
||
| 2180 | public static function get_module( $module ) { |
||
| 2263 | |||
| 2264 | /** |
||
| 2265 | * Like core's get_file_data implementation, but caches the result. |
||
| 2266 | */ |
||
| 2267 | public static function get_file_data( $file, $headers ) { |
||
| 2288 | |||
| 2289 | /** |
||
| 2290 | * Return translated module tag. |
||
| 2291 | * |
||
| 2292 | * @param string $tag Tag as it appears in each module heading. |
||
| 2293 | * |
||
| 2294 | * @return mixed |
||
| 2295 | */ |
||
| 2296 | public static function translate_module_tag( $tag ) { |
||
| 2299 | |||
| 2300 | /** |
||
| 2301 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2302 | * |
||
| 2303 | * @since 3.9.2 |
||
| 2304 | * |
||
| 2305 | * @param array $modules |
||
| 2306 | * |
||
| 2307 | * @return string|void |
||
| 2308 | */ |
||
| 2309 | public static function get_translated_modules( $modules ) { |
||
| 2322 | |||
| 2323 | /** |
||
| 2324 | * Get a list of activated modules as an array of module slugs. |
||
| 2325 | */ |
||
| 2326 | public static function get_active_modules() { |
||
| 2327 | $active = Jetpack_Options::get_option( 'active_modules' ); |
||
| 2328 | |||
| 2329 | if ( ! is_array( $active ) ) { |
||
| 2330 | $active = array(); |
||
| 2331 | } |
||
| 2332 | |||
| 2333 | if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) { |
||
| 2334 | $active[] = 'vaultpress'; |
||
| 2335 | } else { |
||
| 2336 | $active = array_diff( $active, array( 'vaultpress' ) ); |
||
| 2337 | } |
||
| 2338 | |||
| 2339 | //If protect is active on the main site of a multisite, it should be active on all sites. |
||
| 2340 | if ( ! in_array( 'protect', $active ) && is_multisite() && get_site_option( 'jetpack_protect_active' ) ) { |
||
| 2341 | $active[] = 'protect'; |
||
| 2342 | } |
||
| 2343 | |||
| 2344 | return array_unique( $active ); |
||
| 2345 | } |
||
| 2346 | |||
| 2347 | /** |
||
| 2348 | * Check whether or not a Jetpack module is active. |
||
| 2349 | * |
||
| 2350 | * @param string $module The slug of a Jetpack module. |
||
| 2351 | * @return bool |
||
| 2352 | * |
||
| 2353 | * @static |
||
| 2354 | */ |
||
| 2355 | public static function is_module_active( $module ) { |
||
| 2356 | return in_array( $module, self::get_active_modules() ); |
||
| 2357 | } |
||
| 2358 | |||
| 2359 | public static function is_module( $module ) { |
||
| 2360 | return ! empty( $module ) && ! validate_file( $module, Jetpack::get_available_modules() ); |
||
| 2361 | } |
||
| 2362 | |||
| 2363 | /** |
||
| 2364 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2365 | * |
||
| 2366 | * @param bool $catch True to start catching, False to stop. |
||
| 2367 | * |
||
| 2368 | * @static |
||
| 2369 | */ |
||
| 2370 | public static function catch_errors( $catch ) { |
||
| 2371 | static $display_errors, $error_reporting; |
||
| 2372 | |||
| 2373 | if ( $catch ) { |
||
| 2374 | $display_errors = @ini_set( 'display_errors', 1 ); |
||
| 2375 | $error_reporting = @error_reporting( E_ALL ); |
||
| 2376 | add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
| 2377 | } else { |
||
| 2378 | @ini_set( 'display_errors', $display_errors ); |
||
| 2379 | @error_reporting( $error_reporting ); |
||
| 2380 | remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 ); |
||
| 2381 | } |
||
| 2382 | } |
||
| 2383 | |||
| 2384 | /** |
||
| 2385 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2386 | */ |
||
| 2387 | public static function catch_errors_on_shutdown() { |
||
| 2388 | Jetpack::state( 'php_errors', self::alias_directories( ob_get_clean() ) ); |
||
| 2389 | } |
||
| 2390 | |||
| 2391 | /** |
||
| 2392 | * Rewrite any string to make paths easier to read. |
||
| 2393 | * |
||
| 2394 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
| 2395 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
| 2396 | * |
||
| 2397 | * @param $string |
||
| 2398 | * @return mixed |
||
| 2399 | */ |
||
| 2400 | public static function alias_directories( $string ) { |
||
| 2408 | |||
| 2409 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
| 2526 | |||
| 2527 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 2620 | |||
| 2621 | function activate_module_actions( $module ) { |
||
| 2624 | |||
| 2625 | public static function deactivate_module( $module ) { |
||
| 2652 | |||
| 2653 | public static function enable_module_configurable( $module ) { |
||
| 2657 | |||
| 2658 | public static function module_configuration_url( $module ) { |
||
| 2662 | |||
| 2663 | public static function module_configuration_load( $module, $method ) { |
||
| 2667 | |||
| 2668 | public static function module_configuration_head( $module, $method ) { |
||
| 2672 | |||
| 2673 | public static function module_configuration_screen( $module, $method ) { |
||
| 2677 | |||
| 2678 | public static function module_configuration_activation_screen( $module, $method ) { |
||
| 2682 | |||
| 2683 | /* Installation */ |
||
| 2684 | |||
| 2685 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 2725 | |||
| 2726 | /** |
||
| 2727 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 2728 | * @static |
||
| 2729 | */ |
||
| 2730 | public static function plugin_activation( $network_wide ) { |
||
| 2742 | /** |
||
| 2743 | * Runs before bumping version numbers up to a new version |
||
| 2744 | * @param (string) $version Version:timestamp |
||
| 2745 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
| 2746 | * @return null [description] |
||
| 2747 | */ |
||
| 2748 | public static function do_version_bump( $version, $old_version ) { |
||
| 2755 | |||
| 2756 | /** |
||
| 2757 | * Sets the internal version number and activation state. |
||
| 2758 | * @static |
||
| 2759 | */ |
||
| 2760 | public static function plugin_initialize() { |
||
| 2776 | |||
| 2777 | /** |
||
| 2778 | * Removes all connection options |
||
| 2779 | * @static |
||
| 2780 | */ |
||
| 2781 | public static function plugin_deactivation( ) { |
||
| 2790 | |||
| 2791 | /** |
||
| 2792 | * Disconnects from the Jetpack servers. |
||
| 2793 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 2794 | * @static |
||
| 2795 | */ |
||
| 2796 | public static function disconnect( $update_activated_state = true ) { |
||
| 2857 | |||
| 2858 | /** |
||
| 2859 | * Unlinks the current user from the linked WordPress.com user |
||
| 2860 | */ |
||
| 2861 | public static function unlink_user( $user_id = null ) { |
||
| 2892 | |||
| 2893 | /** |
||
| 2894 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 2895 | */ |
||
| 2896 | public static function try_registration() { |
||
| 2921 | |||
| 2922 | /** |
||
| 2923 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 2924 | * |
||
| 2925 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 2926 | */ |
||
| 2927 | public static function log( $code, $data = null ) { |
||
| 2967 | |||
| 2968 | /** |
||
| 2969 | * Get the internal event log. |
||
| 2970 | * |
||
| 2971 | * @param $event (string) - only return the specific log events |
||
| 2972 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 2973 | * |
||
| 2974 | * @return array of log events || WP_Error for invalid params |
||
| 2975 | */ |
||
| 2976 | public static function get_log( $event = false, $num = false ) { |
||
| 3012 | |||
| 3013 | /** |
||
| 3014 | * Log modification of important settings. |
||
| 3015 | */ |
||
| 3016 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 3023 | |||
| 3024 | /** |
||
| 3025 | * Return stat data for WPCOM sync |
||
| 3026 | */ |
||
| 3027 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
| 3041 | |||
| 3042 | /** |
||
| 3043 | * Get additional stat data to sync to WPCOM |
||
| 3044 | */ |
||
| 3045 | public static function get_additional_stat_data( $prefix = '' ) { |
||
| 3056 | |||
| 3057 | private static function get_site_user_count() { |
||
| 3072 | |||
| 3073 | /* Admin Pages */ |
||
| 3074 | |||
| 3075 | function admin_init() { |
||
| 3124 | |||
| 3125 | function admin_body_class( $admin_body_class = '' ) { |
||
| 3133 | |||
| 3134 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 3137 | |||
| 3138 | /** |
||
| 3139 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
| 3140 | * |
||
| 3141 | * @return null |
||
| 3142 | */ |
||
| 3143 | function prepare_manage_jetpack_notice() { |
||
| 3148 | |||
| 3149 | function manage_activate_screen() { |
||
| 3152 | /** |
||
| 3153 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 3154 | * This function artificially throws errors for such cases (whitelisted). |
||
| 3155 | * |
||
| 3156 | * @param string $plugin The activated plugin. |
||
| 3157 | */ |
||
| 3158 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 3182 | |||
| 3183 | function intercept_plugin_error_scrape_init() { |
||
| 3186 | |||
| 3187 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 3198 | |||
| 3199 | function add_remote_request_handlers() { |
||
| 3203 | |||
| 3204 | function remote_request_handlers() { |
||
| 3244 | |||
| 3245 | /** |
||
| 3246 | * Uploads a file gotten from the global $_FILES. |
||
| 3247 | * If `$update_media_item` is true and `post_id` is defined |
||
| 3248 | * the attachment file of the media item (gotten through of the post_id) |
||
| 3249 | * will be updated instead of add a new one. |
||
| 3250 | * |
||
| 3251 | * @param boolean $update_media_item - update media attachment |
||
| 3252 | * @return array - An array describing the uploadind files process |
||
| 3253 | */ |
||
| 3254 | function upload_handler( $update_media_item = false ) { |
||
| 3376 | |||
| 3377 | /** |
||
| 3378 | * Add help to the Jetpack page |
||
| 3379 | * |
||
| 3380 | * @since Jetpack (1.2.3) |
||
| 3381 | * @return false if not the Jetpack page |
||
| 3382 | */ |
||
| 3383 | function admin_help() { |
||
| 3424 | |||
| 3425 | function admin_menu_css() { |
||
| 3428 | |||
| 3429 | function admin_menu_order() { |
||
| 3432 | |||
| 3433 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
| 3448 | |||
| 3449 | function admin_head() { |
||
| 3454 | |||
| 3455 | function admin_banner_styles() { |
||
| 3476 | |||
| 3477 | function plugin_action_links( $actions ) { |
||
| 3492 | |||
| 3493 | /** |
||
| 3494 | * This is the first banner |
||
| 3495 | * It should be visible only to user that can update the option |
||
| 3496 | * Are not connected |
||
| 3497 | * |
||
| 3498 | * @return null |
||
| 3499 | */ |
||
| 3500 | function admin_jetpack_manage_notice() { |
||
| 3530 | |||
| 3531 | /** |
||
| 3532 | * Returns the url that the user clicks to remove the notice for the big banner |
||
| 3533 | * @return (string) |
||
| 3534 | */ |
||
| 3535 | function opt_out_jetpack_manage_url() { |
||
| 3539 | /** |
||
| 3540 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
| 3541 | * @return (string) |
||
| 3542 | */ |
||
| 3543 | function opt_in_jetpack_manage_url() { |
||
| 3546 | |||
| 3547 | function opt_in_jetpack_manage_notice() { |
||
| 3557 | /** |
||
| 3558 | * Determines whether to show the notice of not true = display notice |
||
| 3559 | * @return (bool) |
||
| 3560 | */ |
||
| 3561 | function can_display_jetpack_manage_notice() { |
||
| 3583 | |||
| 3584 | /* |
||
| 3585 | * Registration flow: |
||
| 3586 | * 1 - ::admin_page_load() action=register |
||
| 3587 | * 2 - ::try_registration() |
||
| 3588 | * 3 - ::register() |
||
| 3589 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 3590 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 3591 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 3592 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 3593 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 3594 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 3595 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 3596 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 3597 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 3598 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 3599 | * 5 - user logs in with WP.com account |
||
| 3600 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 3601 | * - Jetpack_Client_Server::authorize() |
||
| 3602 | * - Jetpack_Client_Server::get_token() |
||
| 3603 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 3604 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 3605 | * - which responds with access_token, token_type, scope |
||
| 3606 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 3607 | * - Jetpack::activate_default_modules() |
||
| 3608 | * - Deactivates deprecated plugins |
||
| 3609 | * - Activates all default modules |
||
| 3610 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 3611 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 3612 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 3613 | * Done! |
||
| 3614 | */ |
||
| 3615 | |||
| 3616 | /** |
||
| 3617 | * Handles the page load events for the Jetpack admin page |
||
| 3618 | */ |
||
| 3619 | function admin_page_load() { |
||
| 3845 | |||
| 3846 | function admin_notices() { |
||
| 3943 | |||
| 3944 | /** |
||
| 3945 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 3946 | */ |
||
| 3947 | function stat( $group, $detail ) { |
||
| 3952 | |||
| 3953 | /** |
||
| 3954 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 3955 | */ |
||
| 3956 | function do_stats( $method = '' ) { |
||
| 3971 | |||
| 3972 | /** |
||
| 3973 | * Runs stats code for a one-off, server-side. |
||
| 3974 | * |
||
| 3975 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 3976 | * |
||
| 3977 | * @return bool If it worked. |
||
| 3978 | */ |
||
| 3979 | static function do_server_side_stat( $args ) { |
||
| 3989 | |||
| 3990 | /** |
||
| 3991 | * Builds the stats url. |
||
| 3992 | * |
||
| 3993 | * @param $args array|string The arguments to append to the URL. |
||
| 3994 | * |
||
| 3995 | * @return string The URL to be pinged. |
||
| 3996 | */ |
||
| 3997 | static function build_stats_url( $args ) { |
||
| 4017 | |||
| 4018 | static function translate_current_user_to_role() { |
||
| 4027 | |||
| 4028 | static function translate_role_to_cap( $role ) { |
||
| 4035 | |||
| 4036 | static function sign_role( $role ) { |
||
| 4048 | |||
| 4049 | |||
| 4050 | /** |
||
| 4051 | * Builds a URL to the Jetpack connection auth page |
||
| 4052 | * |
||
| 4053 | * @since 3.9.5 |
||
| 4054 | * |
||
| 4055 | * @param bool $raw If true, URL will not be escaped. |
||
| 4056 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 4057 | * If string, will be a custom redirect. |
||
| 4058 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 4059 | * |
||
| 4060 | * @return string Connect URL |
||
| 4061 | */ |
||
| 4062 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
| 4146 | |||
| 4147 | function build_reconnect_url( $raw = false ) { |
||
| 4151 | |||
| 4152 | public static function admin_url( $args = null ) { |
||
| 4157 | |||
| 4158 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 4162 | |||
| 4163 | function dismiss_jetpack_notice() { |
||
| 4237 | |||
| 4238 | function debugger_page() { |
||
| 4246 | |||
| 4247 | public static function admin_screen_configure_module( $module_id ) { |
||
| 4299 | |||
| 4300 | /** |
||
| 4301 | * Display link to activate the module to see the settings screen. |
||
| 4302 | * @param string $module_id |
||
| 4303 | * @return null |
||
| 4304 | */ |
||
| 4305 | public static function display_activate_module_link( $module_id ) { |
||
| 4357 | |||
| 4358 | public static function sort_modules( $a, $b ) { |
||
| 4364 | |||
| 4365 | function ajax_recheck_ssl() { |
||
| 4373 | |||
| 4374 | /* Client API */ |
||
| 4375 | |||
| 4376 | /** |
||
| 4377 | * Returns the requested Jetpack API URL |
||
| 4378 | * |
||
| 4379 | * @return string |
||
| 4380 | */ |
||
| 4381 | public static function api_url( $relative_url ) { |
||
| 4384 | |||
| 4385 | /** |
||
| 4386 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
| 4387 | */ |
||
| 4388 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 4404 | |||
| 4405 | /** |
||
| 4406 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 4407 | * |
||
| 4408 | * @since 2.3.3 |
||
| 4409 | * @return boolean |
||
| 4410 | */ |
||
| 4411 | public static function permit_ssl( $force_recheck = false ) { |
||
| 4453 | |||
| 4454 | /* |
||
| 4455 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
| 4456 | */ |
||
| 4457 | public function alert_auto_ssl_fail() { |
||
| 4506 | |||
| 4507 | /** |
||
| 4508 | * Returns the Jetpack XML-RPC API |
||
| 4509 | * |
||
| 4510 | * @return string |
||
| 4511 | */ |
||
| 4512 | public static function xmlrpc_api_url() { |
||
| 4516 | |||
| 4517 | /** |
||
| 4518 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 4519 | * |
||
| 4520 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 4521 | * |
||
| 4522 | * @since 2.6 |
||
| 4523 | * @return array |
||
| 4524 | */ |
||
| 4525 | public function generate_secrets( $action, $exp = 600 ) { |
||
| 4533 | |||
| 4534 | /** |
||
| 4535 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 4536 | * |
||
| 4537 | * Based on local php max_execution_time in php.ini |
||
| 4538 | * |
||
| 4539 | * @since 2.6 |
||
| 4540 | * @return int |
||
| 4541 | **/ |
||
| 4542 | public function get_remote_query_timeout_limit() { |
||
| 4548 | |||
| 4549 | |||
| 4550 | /** |
||
| 4551 | * Takes the response from the Jetpack register new site endpoint and |
||
| 4552 | * verifies it worked properly. |
||
| 4553 | * |
||
| 4554 | * @since 2.6 |
||
| 4555 | * @return string|Jetpack_Error A JSON object on success or Jetpack_Error on failures |
||
| 4556 | **/ |
||
| 4557 | public function validate_remote_register_response( $response ) { |
||
| 4597 | /** |
||
| 4598 | * @return bool|WP_Error |
||
| 4599 | */ |
||
| 4600 | public static function register() { |
||
| 4601 | add_action( 'pre_update_jetpack_option_register', array( 'Jetpack_Options', 'delete_option' ) ); |
||
| 4602 | $secrets = Jetpack::init()->generate_secrets( 'register' ); |
||
| 4603 | |||
| 4604 | @list( $secret_1, $secret_2, $secret_eol ) = explode( ':', $secrets ); |
||
| 4605 | View Code Duplication | if ( empty( $secret_1 ) || empty( $secret_2 ) || empty( $secret_eol ) || $secret_eol < time() ) { |
|
| 4606 | return new Jetpack_Error( 'missing_secrets' ); |
||
| 4607 | } |
||
| 4608 | |||
| 4609 | $timeout = Jetpack::init()->get_remote_query_timeout_limit(); |
||
| 4610 | |||
| 4611 | $gmt_offset = get_option( 'gmt_offset' ); |
||
| 4612 | if ( ! $gmt_offset ) { |
||
| 4613 | $gmt_offset = 0; |
||
| 4614 | } |
||
| 4615 | |||
| 4616 | $stats_options = get_option( 'stats_options' ); |
||
| 4617 | $stats_id = isset($stats_options['blog_id']) ? $stats_options['blog_id'] : null; |
||
| 4618 | |||
| 4619 | $args = array( |
||
| 4620 | 'method' => 'POST', |
||
| 4621 | 'body' => array( |
||
| 4622 | 'siteurl' => site_url(), |
||
| 4623 | 'home' => home_url(), |
||
| 4624 | 'gmt_offset' => $gmt_offset, |
||
| 4625 | 'timezone_string' => (string) get_option( 'timezone_string' ), |
||
| 4626 | 'site_name' => (string) get_option( 'blogname' ), |
||
| 4627 | 'secret_1' => $secret_1, |
||
| 4628 | 'secret_2' => $secret_2, |
||
| 4629 | 'site_lang' => get_locale(), |
||
| 4630 | 'timeout' => $timeout, |
||
| 4631 | 'stats_id' => $stats_id, |
||
| 4632 | 'state' => get_current_user_id(), |
||
| 4633 | ), |
||
| 4634 | 'headers' => array( |
||
| 4635 | 'Accept' => 'application/json', |
||
| 4636 | ), |
||
| 4637 | 'timeout' => $timeout, |
||
| 4638 | ); |
||
| 4639 | $response = Jetpack_Client::_wp_remote_request( Jetpack::fix_url_for_bad_hosts( Jetpack::api_url( 'register' ) ), $args, true ); |
||
| 4640 | |||
| 4641 | // Make sure the response is valid and does not contain any Jetpack errors |
||
| 4642 | $registration_details = Jetpack::init()->validate_remote_register_response( $response ); |
||
| 4643 | if ( is_wp_error( $registration_details ) ) { |
||
| 4644 | return $registration_details; |
||
| 4645 | } elseif ( ! $registration_details ) { |
||
| 4646 | return new Jetpack_Error( 'unknown_error', __( 'Unknown error registering your Jetpack site', 'jetpack' ), wp_remote_retrieve_response_code( $response ) ); |
||
| 4647 | } |
||
| 4648 | |||
| 4649 | View Code Duplication | if ( empty( $registration_details->jetpack_secret ) || ! is_string( $registration_details->jetpack_secret ) ) { |
|
| 4650 | return new Jetpack_Error( 'jetpack_secret', '', wp_remote_retrieve_response_code( $response ) ); |
||
| 4651 | } |
||
| 4652 | |||
| 4653 | if ( isset( $registration_details->jetpack_public ) ) { |
||
| 4654 | $jetpack_public = (int) $registration_details->jetpack_public; |
||
| 4655 | } else { |
||
| 4656 | $jetpack_public = false; |
||
| 4657 | } |
||
| 4658 | |||
| 4659 | Jetpack_Options::update_options( |
||
| 4660 | array( |
||
| 4661 | 'id' => (int) $registration_details->jetpack_id, |
||
| 4662 | 'blog_token' => (string) $registration_details->jetpack_secret, |
||
| 4663 | 'public' => $jetpack_public, |
||
| 4664 | ) |
||
| 4665 | ); |
||
| 4666 | |||
| 4667 | /** |
||
| 4668 | * Fires when a site is registered on WordPress.com. |
||
| 4669 | * |
||
| 4670 | * @since 3.7.0 |
||
| 4671 | * |
||
| 4672 | * @param int $json->jetpack_id Jetpack Blog ID. |
||
| 4673 | * @param string $json->jetpack_secret Jetpack Blog Token. |
||
| 4674 | * @param int|bool $jetpack_public Is the site public. |
||
| 4675 | */ |
||
| 4676 | do_action( 'jetpack_site_registered', $registration_details->jetpack_id, $registration_details->jetpack_secret, $jetpack_public ); |
||
| 4677 | |||
| 4678 | // Initialize Jump Start for the first and only time. |
||
| 4679 | if ( ! Jetpack_Options::get_option( 'jumpstart' ) ) { |
||
| 4680 | Jetpack_Options::update_option( 'jumpstart', 'new_connection' ); |
||
| 4681 | |||
| 4682 | $jetpack = Jetpack::init(); |
||
| 4683 | |||
| 4684 | $jetpack->stat( 'jumpstart', 'unique-views' ); |
||
| 4685 | $jetpack->do_stats( 'server_side' ); |
||
| 4686 | }; |
||
| 4687 | |||
| 4688 | return true; |
||
| 4689 | } |
||
| 4690 | |||
| 4691 | /** |
||
| 4692 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 4693 | * |
||
| 4694 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 4695 | */ |
||
| 4696 | public static function maybe_set_version_option() { |
||
| 4710 | |||
| 4711 | /* Client Server API */ |
||
| 4712 | |||
| 4713 | /** |
||
| 4714 | * Loads the Jetpack XML-RPC client |
||
| 4715 | */ |
||
| 4716 | public static function load_xml_rpc_client() { |
||
| 4720 | |||
| 4721 | /** |
||
| 4722 | * Resets the saved authentication state in between testing requests. |
||
| 4723 | */ |
||
| 4724 | public function reset_saved_auth_state() { |
||
| 4728 | |||
| 4729 | function verify_xml_rpc_signature() { |
||
| 4828 | |||
| 4829 | /** |
||
| 4830 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 4831 | */ |
||
| 4832 | function authenticate_jetpack( $user, $username, $password ) { |
||
| 4855 | |||
| 4856 | // Authenticates requests from Jetpack server to WP REST API endpoints. |
||
| 4857 | // Uses the existing XMLRPC request signing implementation. |
||
| 4858 | function wp_rest_authenticate( $user ) { |
||
| 4952 | |||
| 4953 | /** |
||
| 4954 | * Report authentication status to the WP REST API. |
||
| 4955 | * |
||
| 4956 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
| 4957 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
| 4958 | */ |
||
| 4959 | public function wp_rest_authentication_errors( $value ) { |
||
| 4965 | |||
| 4966 | function add_nonce( $timestamp, $nonce ) { |
||
| 5004 | |||
| 5005 | /** |
||
| 5006 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 5007 | * Capture it here so we can verify the signature later. |
||
| 5008 | */ |
||
| 5009 | function xmlrpc_methods( $methods ) { |
||
| 5013 | |||
| 5014 | function public_xmlrpc_methods( $methods ) { |
||
| 5020 | |||
| 5021 | function jetpack_getOptions( $args ) { |
||
| 5061 | |||
| 5062 | function xmlrpc_options( $options ) { |
||
| 5080 | |||
| 5081 | public static function clean_nonces( $all = false ) { |
||
| 5102 | |||
| 5103 | /** |
||
| 5104 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 5105 | * SET: state( $key, $value ); |
||
| 5106 | * GET: $value = state( $key ); |
||
| 5107 | * |
||
| 5108 | * @param string $key |
||
| 5109 | * @param string $value |
||
| 5110 | * @param bool $restate private |
||
| 5111 | */ |
||
| 5112 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 5162 | |||
| 5163 | public static function restate() { |
||
| 5166 | |||
| 5167 | public static function check_privacy( $file ) { |
||
| 5202 | |||
| 5203 | /** |
||
| 5204 | * Helper method for multicall XMLRPC. |
||
| 5205 | */ |
||
| 5206 | public static function xmlrpc_async_call() { |
||
| 5248 | |||
| 5249 | public static function staticize_subdomain( $url ) { |
||
| 5284 | |||
| 5285 | /* JSON API Authorization */ |
||
| 5286 | |||
| 5287 | /** |
||
| 5288 | * Handles the login action for Authorizing the JSON API |
||
| 5289 | */ |
||
| 5290 | function login_form_json_api_authorization() { |
||
| 5299 | |||
| 5300 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 5301 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 5314 | |||
| 5315 | // Make sure the POSTed request is handled by the same action |
||
| 5316 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 5320 | |||
| 5321 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 5322 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 5328 | |||
| 5329 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
| 5330 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 5334 | |||
| 5335 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 5336 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 5348 | |||
| 5349 | |||
| 5350 | /** |
||
| 5351 | * Verifies the request by checking the signature |
||
| 5352 | * |
||
| 5353 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
| 5354 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
| 5355 | * |
||
| 5356 | * @param null|array $environment |
||
| 5357 | */ |
||
| 5358 | function verify_json_api_authorization_request( $environment = null ) { |
||
| 5451 | |||
| 5452 | function login_message_json_api_authorization( $message ) { |
||
| 5458 | |||
| 5459 | /** |
||
| 5460 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 5461 | */ |
||
| 5462 | public static function get_content_width() { |
||
| 5473 | |||
| 5474 | /** |
||
| 5475 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 5476 | * |
||
| 5477 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 5478 | * |
||
| 5479 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 5480 | */ |
||
| 5481 | public function get_cloud_site_options( $option_names ) { |
||
| 5497 | |||
| 5498 | /** |
||
| 5499 | * Checks if the site is currently in an identity crisis. |
||
| 5500 | * |
||
| 5501 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
| 5502 | */ |
||
| 5503 | public static function check_identity_crisis() { |
||
| 5510 | |||
| 5511 | /** |
||
| 5512 | * Checks whether the home and siteurl specifically are whitelisted |
||
| 5513 | * Written so that we don't have re-check $key and $value params every time |
||
| 5514 | * we want to check if this site is whitelisted, for example in footer.php |
||
| 5515 | * |
||
| 5516 | * @since 3.8.0 |
||
| 5517 | * @return bool True = already whitelisted False = not whitelisted |
||
| 5518 | */ |
||
| 5519 | public static function is_staging_site() { |
||
| 5578 | |||
| 5579 | /** |
||
| 5580 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
| 5581 | * |
||
| 5582 | * @return bool |
||
| 5583 | */ |
||
| 5584 | public static function validate_sync_error_idc_option() { |
||
| 5628 | |||
| 5629 | /** |
||
| 5630 | * Normalizes a url by doing three things: |
||
| 5631 | * - Strips protocol |
||
| 5632 | * - Strips www |
||
| 5633 | * - Adds a trailing slash |
||
| 5634 | * |
||
| 5635 | * @since 4.4.0 |
||
| 5636 | * @param string $url |
||
| 5637 | * @return WP_Error|string |
||
| 5638 | */ |
||
| 5639 | public static function normalize_url_protocol_agnostic( $url ) { |
||
| 5649 | |||
| 5650 | /** |
||
| 5651 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
| 5652 | * |
||
| 5653 | * @since 4.4.0 |
||
| 5654 | * |
||
| 5655 | * @param array $response |
||
| 5656 | * @return array Array of the local urls, wpcom urls, and error code |
||
| 5657 | */ |
||
| 5658 | public static function get_sync_error_idc_option( $response = array() ) { |
||
| 5682 | |||
| 5683 | /** |
||
| 5684 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
| 5685 | * If set to true, the site will be put into staging mode. |
||
| 5686 | * |
||
| 5687 | * @since 4.3.2 |
||
| 5688 | * @return bool |
||
| 5689 | */ |
||
| 5690 | public static function sync_idc_optin() { |
||
| 5708 | |||
| 5709 | /** |
||
| 5710 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 5711 | * |
||
| 5712 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 5713 | */ |
||
| 5714 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 5749 | |||
| 5750 | /** |
||
| 5751 | * Maybe inlines a stylesheet. |
||
| 5752 | * |
||
| 5753 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 5754 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 5755 | * |
||
| 5756 | * Attached to `style_loader_tag` filter. |
||
| 5757 | * |
||
| 5758 | * @param string $tag The tag that would link to the external asset. |
||
| 5759 | * @param string $handle The registered handle of the script in question. |
||
| 5760 | * |
||
| 5761 | * @return string |
||
| 5762 | */ |
||
| 5763 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 5813 | |||
| 5814 | /** |
||
| 5815 | * Loads a view file from the views |
||
| 5816 | * |
||
| 5817 | * Data passed in with the $data parameter will be available in the |
||
| 5818 | * template file as $data['value'] |
||
| 5819 | * |
||
| 5820 | * @param string $template - Template file to load |
||
| 5821 | * @param array $data - Any data to pass along to the template |
||
| 5822 | * @return boolean - If template file was found |
||
| 5823 | **/ |
||
| 5824 | public function load_view( $template, $data = array() ) { |
||
| 5835 | |||
| 5836 | /** |
||
| 5837 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
| 5838 | */ |
||
| 5839 | public function deprecated_hooks() { |
||
| 5888 | |||
| 5889 | /** |
||
| 5890 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 5891 | * |
||
| 5892 | * Considerations: |
||
| 5893 | * - Normal, relative URLs `feh.png` |
||
| 5894 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 5895 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 5896 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 5897 | * - Domain root relative URLs `/feh.png` |
||
| 5898 | * |
||
| 5899 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 5900 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 5901 | * |
||
| 5902 | * @return mixed|string |
||
| 5903 | */ |
||
| 5904 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 5948 | |||
| 5949 | /** |
||
| 5950 | * This methods removes all of the registered css files on the front end |
||
| 5951 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 5952 | * all the files into one file. |
||
| 5953 | * |
||
| 5954 | * Pros: |
||
| 5955 | * - Uses only ONE css asset connection instead of 15 |
||
| 5956 | * - Saves a minimum of 56k |
||
| 5957 | * - Reduces server load |
||
| 5958 | * - Reduces time to first painted byte |
||
| 5959 | * |
||
| 5960 | * Cons: |
||
| 5961 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 5962 | * should not cause any issues with themes. |
||
| 5963 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 5964 | * jetpack_implode_frontend_css filter for a workaround |
||
| 5965 | * |
||
| 5966 | * For some situations developers may wish to disable css imploding and |
||
| 5967 | * instead operate in legacy mode where each file loads seperately and |
||
| 5968 | * can be edited individually or dequeued. This can be accomplished with |
||
| 5969 | * the following line: |
||
| 5970 | * |
||
| 5971 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 5972 | * |
||
| 5973 | * @since 3.2 |
||
| 5974 | **/ |
||
| 5975 | public function implode_frontend_css( $travis_test = false ) { |
||
| 6027 | |||
| 6028 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 6038 | |||
| 6039 | /* |
||
| 6040 | * Check the heartbeat data |
||
| 6041 | * |
||
| 6042 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 6043 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 6044 | * |
||
| 6045 | * Data will be added to "caution" array, if it either: |
||
| 6046 | * - Out of date Jetpack version |
||
| 6047 | * - Out of date WP version |
||
| 6048 | * - Out of date PHP version |
||
| 6049 | * |
||
| 6050 | * $return array $filtered_data |
||
| 6051 | */ |
||
| 6052 | public static function jetpack_check_heartbeat_data() { |
||
| 6105 | |||
| 6106 | |||
| 6107 | /* |
||
| 6108 | * This method is used to organize all options that can be reset |
||
| 6109 | * without disconnecting Jetpack. |
||
| 6110 | * |
||
| 6111 | * It is used in class.jetpack-cli.php to reset options |
||
| 6112 | * |
||
| 6113 | * @return array of options to delete. |
||
| 6114 | */ |
||
| 6115 | public static function get_jetpack_options_for_reset() { |
||
| 6182 | |||
| 6183 | /** |
||
| 6184 | * Check if an option of a Jetpack module has been updated. |
||
| 6185 | * |
||
| 6186 | * If any module option has been updated before Jump Start has been dismissed, |
||
| 6187 | * update the 'jumpstart' option so we can hide Jump Start. |
||
| 6188 | * |
||
| 6189 | * @param string $option_name |
||
| 6190 | * |
||
| 6191 | * @return bool |
||
| 6192 | */ |
||
| 6193 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
| 6214 | |||
| 6215 | /* |
||
| 6216 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 6217 | * so we can bring them directly to their site in calypso. |
||
| 6218 | * |
||
| 6219 | * @param string | url |
||
| 6220 | * @return string | url without the guff |
||
| 6221 | */ |
||
| 6222 | public static function build_raw_urls( $url ) { |
||
| 6228 | |||
| 6229 | /** |
||
| 6230 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 6231 | * |
||
| 6232 | * @param mixed $new_urls |
||
| 6233 | */ |
||
| 6234 | public static function dns_prefetch( $new_urls = null ) { |
||
| 6251 | |||
| 6252 | public function wp_dashboard_setup() { |
||
| 6280 | |||
| 6281 | /** |
||
| 6282 | * @param mixed $result Value for the user's option |
||
| 6283 | * @return mixed |
||
| 6284 | */ |
||
| 6285 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 6310 | |||
| 6311 | public static function dashboard_widget() { |
||
| 6319 | |||
| 6320 | public static function dashboard_widget_footer() { |
||
| 6353 | |||
| 6354 | public function dashboard_widget_connect_to_wpcom() { |
||
| 6376 | |||
| 6377 | /** |
||
| 6378 | * Return string containing the Jetpack logo. |
||
| 6379 | * |
||
| 6380 | * @since 3.9.0 |
||
| 6381 | * |
||
| 6382 | * @return string |
||
| 6383 | */ |
||
| 6384 | public static function get_jp_emblem() { |
||
| 6387 | |||
| 6388 | /* |
||
| 6389 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 6390 | */ |
||
| 6391 | function jetpack_icon_user_connected( $columns ) { |
||
| 6395 | |||
| 6396 | /* |
||
| 6397 | * Show Jetpack icon if the user is linked. |
||
| 6398 | */ |
||
| 6399 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 6411 | |||
| 6412 | /* |
||
| 6413 | * Style the Jetpack user column |
||
| 6414 | */ |
||
| 6415 | function jetpack_user_col_style() { |
||
| 6432 | } |
||
| 6433 |
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.