Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Jetpack { |
||
| 26 | public $xmlrpc_server = null; |
||
| 27 | |||
| 28 | private $xmlrpc_verification = null; |
||
| 29 | |||
| 30 | public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA'] |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array The handles of styles that are concatenated into jetpack.css |
||
| 34 | */ |
||
| 35 | public $concatenated_style_handles = array( |
||
| 36 | 'jetpack-carousel', |
||
| 37 | 'grunion.css', |
||
| 38 | 'the-neverending-homepage', |
||
| 39 | 'jetpack_likes', |
||
| 40 | 'jetpack_related-posts', |
||
| 41 | 'sharedaddy', |
||
| 42 | 'jetpack-slideshow', |
||
| 43 | 'presentations', |
||
| 44 | 'jetpack-subscriptions', |
||
| 45 | 'tiled-gallery', |
||
| 46 | 'widget-conditions', |
||
| 47 | 'jetpack_display_posts_widget', |
||
| 48 | 'gravatar-profile-widget', |
||
| 49 | 'widget-grid-and-list', |
||
| 50 | 'jetpack-widgets', |
||
| 51 | 'goodreads-widget', |
||
| 52 | 'jetpack_social_media_icons_widget', |
||
| 53 | ); |
||
| 54 | |||
| 55 | public $plugins_to_deactivate = array( |
||
| 56 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 57 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 58 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 59 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 60 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
| 61 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 62 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 63 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 64 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 65 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 66 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 67 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 68 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 69 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
| 70 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 71 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
| 72 | ); |
||
| 73 | |||
| 74 | public $capability_translations = array( |
||
| 75 | 'administrator' => 'manage_options', |
||
| 76 | 'editor' => 'edit_others_posts', |
||
| 77 | 'author' => 'publish_posts', |
||
| 78 | 'contributor' => 'edit_posts', |
||
| 79 | 'subscriber' => 'read', |
||
| 80 | ); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 84 | * if the plugins are active. Used by filter_default_modules |
||
| 85 | * |
||
| 86 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 87 | * change `module-slug` and add this to your plugin: |
||
| 88 | * |
||
| 89 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 90 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 91 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 92 | * } |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | private $conflicting_plugins = array( |
||
| 97 | 'comments' => array( |
||
| 98 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 99 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 100 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 101 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 102 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 103 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 104 | ), |
||
| 105 | 'contact-form' => array( |
||
| 106 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 107 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 108 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 109 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 110 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 111 | ), |
||
| 112 | 'minileven' => array( |
||
| 113 | 'WPtouch' => 'wptouch/wptouch.php', |
||
| 114 | ), |
||
| 115 | 'latex' => array( |
||
| 116 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 117 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 118 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 119 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 120 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 121 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 122 | ), |
||
| 123 | 'protect' => array( |
||
| 124 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 125 | 'Captcha' => 'captcha/captcha.php', |
||
| 126 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 127 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 128 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 129 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 130 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 131 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 132 | 'Login Security' => 'login-security/login-security.php', |
||
| 133 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 134 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 135 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 136 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 137 | ), |
||
| 138 | 'random-redirect' => array( |
||
| 139 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 140 | ), |
||
| 141 | 'related-posts' => array( |
||
| 142 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 143 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 144 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 145 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 146 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 147 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 148 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 149 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 150 | ), |
||
| 151 | 'sharedaddy' => array( |
||
| 152 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 153 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 154 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 155 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 156 | ), |
||
| 157 | 'verification-tools' => array( |
||
| 158 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 159 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 160 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 161 | ), |
||
| 162 | 'widget-visibility' => array( |
||
| 163 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 164 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 165 | ), |
||
| 166 | 'sitemaps' => array( |
||
| 167 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 168 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 169 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 170 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 171 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 172 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 173 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 174 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 175 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 176 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 177 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 178 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 179 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 180 | ), |
||
| 181 | ); |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 185 | * |
||
| 186 | * Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate |
||
| 187 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 188 | * |
||
| 189 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 190 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 191 | */ |
||
| 192 | private $open_graph_conflicting_plugins = array( |
||
| 193 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 194 | // 2 Click Social Media Buttons |
||
| 195 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 196 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 197 | 'autodescription/autodescription.php', // The SEO Framework |
||
| 198 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 199 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 200 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 201 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 202 | // Facebook Featured Image & OG Meta Tags |
||
| 203 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 204 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 205 | // Facebook Open Graph Meta Tags for WordPress |
||
| 206 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 207 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 208 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 209 | // Fedmich's Facebook Open Graph Meta |
||
| 210 | 'header-footer/plugin.php', // Header and Footer |
||
| 211 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 212 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 213 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 214 | // NextScripts SNAP |
||
| 215 | 'opengraph/opengraph.php', // Open Graph |
||
| 216 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 217 | // Open Graph Protocol Framework |
||
| 218 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 219 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 220 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 221 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 222 | 'sharepress/sharepress.php', // SharePress |
||
| 223 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 224 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 225 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 226 | 'socialize/socialize.php', // Socialize |
||
| 227 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 228 | // Tweet, Like, Google +1 and Share |
||
| 229 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 230 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 231 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 232 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 233 | // WP Facebook Like Send & Open Graph Meta |
||
| 234 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 235 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 236 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 237 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
| 238 | ); |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 242 | */ |
||
| 243 | private $twitter_cards_conflicting_plugins = array( |
||
| 244 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 245 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 246 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 247 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 248 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 249 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 250 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 251 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 252 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 253 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 254 | ); |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Message to display in admin_notice |
||
| 258 | * @var string |
||
| 259 | */ |
||
| 260 | public $message = ''; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Error to display in admin_notice |
||
| 264 | * @var string |
||
| 265 | */ |
||
| 266 | public $error = ''; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Modules that need more privacy description. |
||
| 270 | * @var string |
||
| 271 | */ |
||
| 272 | public $privacy_checks = ''; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Stats to record once the page loads |
||
| 276 | * |
||
| 277 | * @var array |
||
| 278 | */ |
||
| 279 | public $stats = array(); |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Jetpack_Sync object |
||
| 283 | */ |
||
| 284 | public $sync; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Verified data for JSON authorization request |
||
| 288 | */ |
||
| 289 | public $json_api_authorization_request = array(); |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Holds the singleton instance of this class |
||
| 293 | * @since 2.3.3 |
||
| 294 | * @var Jetpack |
||
| 295 | */ |
||
| 296 | static $instance = false; |
||
|
|
|||
| 297 | |||
| 298 | /** |
||
| 299 | * Singleton |
||
| 300 | * @static |
||
| 301 | */ |
||
| 302 | public static function init() { |
||
| 303 | if ( ! self::$instance ) { |
||
| 304 | if ( did_action( 'plugins_loaded' ) ) |
||
| 305 | self::plugin_textdomain(); |
||
| 306 | else |
||
| 307 | add_action( 'plugins_loaded', array( __CLASS__, 'plugin_textdomain' ), 99 ); |
||
| 308 | |||
| 309 | self::$instance = new Jetpack; |
||
| 310 | |||
| 311 | self::$instance->plugin_upgrade(); |
||
| 312 | } |
||
| 313 | |||
| 314 | return self::$instance; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Must never be called statically |
||
| 319 | */ |
||
| 320 | function plugin_upgrade() { |
||
| 321 | if ( Jetpack::is_active() ) { |
||
| 322 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 323 | if ( JETPACK__VERSION != $version ) { |
||
| 324 | |||
| 325 | // Check which active modules actually exist and remove others from active_modules list |
||
| 326 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
| 327 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
| 328 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
| 329 | Jetpack_Options::update_option( 'active_modules', $modules ); |
||
| 330 | } |
||
| 331 | |||
| 332 | // Reset cached module data |
||
| 333 | Jetpack_Options::delete_option( 'file_data' ); |
||
| 334 | |||
| 335 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
| 336 | Jetpack::maybe_set_version_option(); |
||
| 337 | } |
||
| 338 | } |
||
| 339 | } |
||
| 340 | |||
| 341 | static function activate_manage( ) { |
||
| 342 | |||
| 343 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
| 344 | self::activate_module( 'manage', false, false ); |
||
| 345 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
| 346 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
| 347 | } |
||
| 348 | |||
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Constructor. Initializes WordPress hooks |
||
| 353 | */ |
||
| 354 | private function __construct() { |
||
| 355 | /* |
||
| 356 | * Check for and alert any deprecated hooks |
||
| 357 | */ |
||
| 358 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
| 359 | |||
| 360 | |||
| 361 | /* |
||
| 362 | * Load things that should only be in Network Admin. |
||
| 363 | * |
||
| 364 | * For now blow away everything else until a more full |
||
| 365 | * understanding of what is needed at the network level is |
||
| 366 | * available |
||
| 367 | */ |
||
| 368 | if( is_multisite() ) { |
||
| 369 | Jetpack_Network::init(); |
||
| 370 | } |
||
| 371 | |||
| 372 | // Unlink user before deleting the user from .com |
||
| 373 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 374 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
| 375 | |||
| 376 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
| 377 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
| 378 | |||
| 379 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
| 380 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
| 381 | |||
| 382 | $this->require_jetpack_authentication(); |
||
| 383 | |||
| 384 | if ( Jetpack::is_active() ) { |
||
| 385 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
| 386 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
| 387 | |||
| 388 | $signed = $this->verify_xml_rpc_signature(); |
||
| 389 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
| 390 | // The actual API methods. |
||
| 391 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
| 392 | } else { |
||
| 393 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
| 394 | // active Jetpack connection, so that additional users can link their account. |
||
| 395 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
| 396 | } |
||
| 397 | } else { |
||
| 398 | // The bootstrap API methods. |
||
| 399 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
| 400 | } |
||
| 401 | |||
| 402 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
| 403 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
| 404 | } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) { |
||
| 405 | $this->require_jetpack_authentication(); |
||
| 406 | $this->add_remote_request_handlers(); |
||
| 407 | } else { |
||
| 408 | if ( Jetpack::is_active() ) { |
||
| 409 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
| 410 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
| 411 | } |
||
| 412 | } |
||
| 413 | |||
| 414 | if ( Jetpack::is_active() ) { |
||
| 415 | Jetpack_Heartbeat::init(); |
||
| 416 | } |
||
| 417 | |||
| 418 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
| 419 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
| 420 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
| 421 | } |
||
| 422 | |||
| 423 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
| 424 | |||
| 425 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
| 426 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
| 427 | |||
| 428 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
| 429 | |||
| 430 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
| 431 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
| 432 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
| 433 | |||
| 434 | // returns HTTPS support status |
||
| 435 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
| 436 | |||
| 437 | // Jump Start AJAX callback function |
||
| 438 | add_action( 'wp_ajax_jetpack_jumpstart_ajax', array( $this, 'jetpack_jumpstart_ajax_callback' ) ); |
||
| 439 | |||
| 440 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
| 441 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
| 442 | |||
| 443 | // Identity Crisis AJAX callback function |
||
| 444 | add_action( 'wp_ajax_jetpack_resolve_identity_crisis', array( $this, 'resolve_identity_crisis_ajax_callback' ) ); |
||
| 445 | |||
| 446 | // JITM AJAX callback function |
||
| 447 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
| 448 | |||
| 449 | add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) ); |
||
| 450 | add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) ); |
||
| 451 | |||
| 452 | // Universal ajax callback for all tracking events triggered via js |
||
| 453 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
| 454 | |||
| 455 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
| 456 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 457 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 458 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
| 459 | |||
| 460 | add_action( 'jetpack_activate_module', array( $this, 'activate_module_actions' ) ); |
||
| 461 | |||
| 462 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
| 463 | |||
| 464 | add_action( 'jetpack_notices', array( $this, 'show_development_mode_notice' ) ); |
||
| 465 | |||
| 466 | /** |
||
| 467 | * These actions run checks to load additional files. |
||
| 468 | * They check for external files or plugins, so they need to run as late as possible. |
||
| 469 | */ |
||
| 470 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
| 471 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
| 472 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
| 473 | |||
| 474 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
| 475 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
| 476 | |||
| 477 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
| 478 | |||
| 479 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
| 480 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
| 481 | |||
| 482 | // A filter to control all just in time messages |
||
| 483 | add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); |
||
| 484 | |||
| 485 | /** |
||
| 486 | * This is the hack to concatinate all css files into one. |
||
| 487 | * For description and reasoning see the implode_frontend_css method |
||
| 488 | * |
||
| 489 | * Super late priority so we catch all the registered styles |
||
| 490 | */ |
||
| 491 | if( !is_admin() ) { |
||
| 492 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
| 493 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
| 494 | } |
||
| 495 | |||
| 496 | } |
||
| 497 | |||
| 498 | function jetpack_admin_ajax_tracks_callback() { |
||
| 499 | // Check for nonce |
||
| 500 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
| 501 | wp_die( 'Permissions check failed.' ); |
||
| 502 | } |
||
| 503 | |||
| 504 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
| 505 | wp_die( 'No valid event name or type.' ); |
||
| 506 | } |
||
| 507 | |||
| 508 | $tracks_data = array(); |
||
| 509 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
| 510 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
| 511 | } |
||
| 512 | |||
| 513 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
| 514 | wp_send_json_success(); |
||
| 515 | wp_die(); |
||
| 516 | } |
||
| 517 | |||
| 518 | function jetpack_admin_ajax_callback() { |
||
| 519 | // Check for nonce |
||
| 520 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) || ! current_user_can( 'jetpack_manage_modules' ) ) { |
|
| 521 | wp_die( 'permissions check failed' ); |
||
| 522 | } |
||
| 523 | |||
| 524 | if ( isset( $_REQUEST['toggleModule'] ) && 'nux-toggle-module' == $_REQUEST['toggleModule'] ) { |
||
| 525 | $slug = $_REQUEST['thisModuleSlug']; |
||
| 526 | |||
| 527 | if ( ! in_array( $slug, Jetpack::get_available_modules() ) ) { |
||
| 528 | wp_die( 'That is not a Jetpack module slug' ); |
||
| 529 | } |
||
| 530 | |||
| 531 | if ( Jetpack::is_module_active( $slug ) ) { |
||
| 532 | Jetpack::deactivate_module( $slug ); |
||
| 533 | } else { |
||
| 534 | Jetpack::activate_module( $slug, false, false ); |
||
| 535 | } |
||
| 536 | |||
| 537 | $modules = Jetpack_Admin::init()->get_modules(); |
||
| 538 | echo json_encode( $modules[ $slug ] ); |
||
| 539 | |||
| 540 | exit; |
||
| 541 | } |
||
| 542 | |||
| 543 | wp_die(); |
||
| 544 | } |
||
| 545 | |||
| 546 | /* |
||
| 547 | * Sometimes we need to refresh the data, |
||
| 548 | * especially if the page is visited via a 'history' |
||
| 549 | * event like back/forward |
||
| 550 | */ |
||
| 551 | function jetpack_admin_ajax_refresh_data() { |
||
| 552 | // Check for nonce |
||
| 553 | View Code Duplication | if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) ) { |
|
| 554 | wp_die( 'permissions check failed' ); |
||
| 555 | } |
||
| 556 | |||
| 557 | if ( isset( $_REQUEST['refreshData'] ) && 'refresh' == $_REQUEST['refreshData'] ) { |
||
| 558 | $modules = Jetpack_Admin::init()->get_modules(); |
||
| 559 | echo json_encode( $modules ); |
||
| 560 | exit; |
||
| 561 | } |
||
| 562 | |||
| 563 | wp_die(); |
||
| 564 | } |
||
| 565 | |||
| 566 | /** |
||
| 567 | * The callback for the Jump Start ajax requests. |
||
| 568 | */ |
||
| 569 | function jetpack_jumpstart_ajax_callback() { |
||
| 570 | // Check for nonce |
||
| 571 | if ( ! isset( $_REQUEST['jumpstartNonce'] ) || ! wp_verify_nonce( $_REQUEST['jumpstartNonce'], 'jetpack-jumpstart-nonce' ) ) |
||
| 572 | wp_die( 'permissions check failed' ); |
||
| 573 | |||
| 574 | if ( isset( $_REQUEST['jumpStartActivate'] ) && 'jump-start-activate' == $_REQUEST['jumpStartActivate'] ) { |
||
| 575 | // Update the jumpstart option |
||
| 576 | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
||
| 577 | Jetpack_Options::update_option( 'jumpstart', 'jumpstart_activated' ); |
||
| 578 | } |
||
| 579 | |||
| 580 | // Loops through the requested "Jump Start" modules, and activates them. |
||
| 581 | // Custom 'no_message' state, so that no message will be shown on reload. |
||
| 582 | $modules = $_REQUEST['jumpstartModSlug']; |
||
| 583 | $module_slugs = array(); |
||
| 584 | foreach( $modules as $module => $value ) { |
||
| 585 | $module_slugs[] = $value['module_slug']; |
||
| 586 | } |
||
| 587 | |||
| 588 | // Check for possible conflicting plugins |
||
| 589 | $module_slugs_filtered = $this->filter_default_modules( $module_slugs ); |
||
| 590 | |||
| 591 | foreach ( $module_slugs_filtered as $module_slug ) { |
||
| 592 | Jetpack::log( 'activate', $module_slug ); |
||
| 593 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 594 | Jetpack::state( 'message', 'no_message' ); |
||
| 595 | } |
||
| 596 | |||
| 597 | // Set the default sharing buttons and set to display on posts if none have been set. |
||
| 598 | $sharing_services = get_option( 'sharing-services' ); |
||
| 599 | $sharing_options = get_option( 'sharing-options' ); |
||
| 600 | if ( empty( $sharing_services['visible'] ) ) { |
||
| 601 | // Default buttons to set |
||
| 602 | $visible = array( |
||
| 603 | 'twitter', |
||
| 604 | 'facebook', |
||
| 605 | 'google-plus-1', |
||
| 606 | ); |
||
| 607 | $hidden = array(); |
||
| 608 | |||
| 609 | // Set some sharing settings |
||
| 610 | $sharing = new Sharing_Service(); |
||
| 611 | $sharing_options['global'] = array( |
||
| 612 | 'button_style' => 'icon', |
||
| 613 | 'sharing_label' => $sharing->default_sharing_label, |
||
| 614 | 'open_links' => 'same', |
||
| 615 | 'show' => array( 'post' ), |
||
| 616 | 'custom' => isset( $sharing_options['global']['custom'] ) ? $sharing_options['global']['custom'] : array() |
||
| 617 | ); |
||
| 618 | |||
| 619 | update_option( 'sharing-options', $sharing_options ); |
||
| 620 | |||
| 621 | // Send a success response so that we can display an error message. |
||
| 622 | $success = update_option( 'sharing-services', array( 'visible' => $visible, 'hidden' => $hidden ) ); |
||
| 623 | echo json_encode( $success ); |
||
| 624 | exit; |
||
| 625 | } |
||
| 626 | |||
| 627 | } elseif ( isset( $_REQUEST['disableJumpStart'] ) && true == $_REQUEST['disableJumpStart'] ) { |
||
| 628 | // If dismissed, flag the jumpstart option as such. |
||
| 629 | // Send a success response so that we can display an error message. |
||
| 630 | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
||
| 631 | $success = Jetpack_Options::update_option( 'jumpstart', 'jumpstart_dismissed' ); |
||
| 632 | echo json_encode( $success ); |
||
| 633 | exit; |
||
| 634 | } |
||
| 635 | |||
| 636 | } elseif ( isset( $_REQUEST['jumpStartDeactivate'] ) && 'jump-start-deactivate' == $_REQUEST['jumpStartDeactivate'] ) { |
||
| 637 | |||
| 638 | // FOR TESTING ONLY |
||
| 639 | // @todo remove |
||
| 640 | $modules = (array) $_REQUEST['jumpstartModSlug']; |
||
| 641 | foreach( $modules as $module => $value ) { |
||
| 642 | if ( !in_array( $value['module_slug'], Jetpack::get_default_modules() ) ) { |
||
| 643 | Jetpack::log( 'deactivate', $value['module_slug'] ); |
||
| 644 | Jetpack::deactivate_module( $value['module_slug'] ); |
||
| 645 | Jetpack::state( 'message', 'no_message' ); |
||
| 646 | } else { |
||
| 647 | Jetpack::log( 'activate', $value['module_slug'] ); |
||
| 648 | Jetpack::activate_module( $value['module_slug'], false, false ); |
||
| 649 | Jetpack::state( 'message', 'no_message' ); |
||
| 650 | } |
||
| 651 | } |
||
| 652 | |||
| 653 | Jetpack_Options::update_option( 'jumpstart', 'new_connection' ); |
||
| 654 | echo "reload the page"; |
||
| 655 | } |
||
| 656 | |||
| 657 | wp_die(); |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * The callback for the JITM ajax requests. |
||
| 662 | */ |
||
| 663 | function jetpack_jitm_ajax_callback() { |
||
| 664 | // Check for nonce |
||
| 665 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
| 666 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
| 667 | } |
||
| 668 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
| 669 | $module_slug = $_REQUEST['jitmModule']; |
||
| 670 | Jetpack::log( 'activate', $module_slug ); |
||
| 671 | Jetpack::activate_module( $module_slug, false, false ); |
||
| 672 | Jetpack::state( 'message', 'no_message' ); |
||
| 673 | |||
| 674 | //A Jetpack module is being activated through a JITM, track it |
||
| 675 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
| 676 | $this->do_stats( 'server_side' ); |
||
| 677 | |||
| 678 | wp_send_json_success(); |
||
| 679 | } |
||
| 680 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
| 681 | // get the hide_jitm options array |
||
| 682 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
| 683 | $module_slug = $_REQUEST['jitmModule']; |
||
| 684 | |||
| 685 | if( ! $jetpack_hide_jitm ) { |
||
| 686 | $jetpack_hide_jitm = array( |
||
| 687 | $module_slug => 'hide' |
||
| 688 | ); |
||
| 689 | } else { |
||
| 690 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
| 691 | } |
||
| 692 | |||
| 693 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
| 694 | |||
| 695 | //jitm is being dismissed forever, track it |
||
| 696 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
| 697 | $this->do_stats( 'server_side' ); |
||
| 698 | |||
| 699 | wp_send_json_success(); |
||
| 700 | } |
||
| 701 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
| 702 | $module_slug = $_REQUEST['jitmModule']; |
||
| 703 | |||
| 704 | // User went to WordPress.com, track this |
||
| 705 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
| 706 | $this->do_stats( 'server_side' ); |
||
| 707 | |||
| 708 | wp_send_json_success(); |
||
| 709 | } |
||
| 710 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
| 711 | $track = $_REQUEST['jitmModule']; |
||
| 712 | |||
| 713 | // User is viewing JITM, track it. |
||
| 714 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
| 715 | $this->do_stats( 'server_side' ); |
||
| 716 | |||
| 717 | wp_send_json_success(); |
||
| 718 | } |
||
| 719 | } |
||
| 720 | |||
| 721 | /** |
||
| 722 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 723 | */ |
||
| 724 | function __destruct() { |
||
| 725 | if ( ! empty( $this->stats ) ) { |
||
| 726 | $this->do_stats( 'server_side' ); |
||
| 727 | } |
||
| 728 | } |
||
| 729 | |||
| 730 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 731 | switch( $cap ) { |
||
| 732 | case 'jetpack_connect' : |
||
| 733 | case 'jetpack_reconnect' : |
||
| 734 | if ( Jetpack::is_development_mode() ) { |
||
| 735 | $caps = array( 'do_not_allow' ); |
||
| 736 | break; |
||
| 737 | } |
||
| 738 | /** |
||
| 739 | * Pass through. If it's not development mode, these should match disconnect. |
||
| 740 | * Let users disconnect if it's development mode, just in case things glitch. |
||
| 741 | */ |
||
| 742 | case 'jetpack_disconnect' : |
||
| 743 | /** |
||
| 744 | * In multisite, can individual site admins manage their own connection? |
||
| 745 | * |
||
| 746 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
| 747 | */ |
||
| 748 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
| 749 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
| 750 | /** |
||
| 751 | * We need to update the option name -- it's terribly unclear which |
||
| 752 | * direction the override goes. |
||
| 753 | * |
||
| 754 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
| 755 | */ |
||
| 756 | $caps = array( 'do_not_allow' ); |
||
| 757 | break; |
||
| 758 | } |
||
| 759 | } |
||
| 760 | |||
| 761 | $caps = array( 'manage_options' ); |
||
| 762 | break; |
||
| 763 | case 'jetpack_manage_modules' : |
||
| 764 | case 'jetpack_activate_modules' : |
||
| 765 | case 'jetpack_deactivate_modules' : |
||
| 766 | $caps = array( 'manage_options' ); |
||
| 767 | break; |
||
| 768 | case 'jetpack_configure_modules' : |
||
| 769 | $caps = array( 'manage_options' ); |
||
| 770 | break; |
||
| 771 | case 'jetpack_network_admin_page': |
||
| 772 | case 'jetpack_network_settings_page': |
||
| 773 | $caps = array( 'manage_network_plugins' ); |
||
| 774 | break; |
||
| 775 | case 'jetpack_network_sites_page': |
||
| 776 | $caps = array( 'manage_sites' ); |
||
| 777 | break; |
||
| 778 | case 'jetpack_admin_page' : |
||
| 779 | if ( Jetpack::is_development_mode() ) { |
||
| 780 | $caps = array( 'manage_options' ); |
||
| 781 | break; |
||
| 782 | } else { |
||
| 783 | $caps = array( 'read' ); |
||
| 784 | } |
||
| 785 | break; |
||
| 786 | case 'jetpack_connect_user' : |
||
| 787 | if ( Jetpack::is_development_mode() ) { |
||
| 788 | $caps = array( 'do_not_allow' ); |
||
| 789 | break; |
||
| 790 | } |
||
| 791 | $caps = array( 'read' ); |
||
| 792 | break; |
||
| 793 | } |
||
| 794 | return $caps; |
||
| 795 | } |
||
| 796 | |||
| 797 | function require_jetpack_authentication() { |
||
| 798 | // Don't let anyone authenticate |
||
| 799 | $_COOKIE = array(); |
||
| 800 | remove_all_filters( 'authenticate' ); |
||
| 801 | |||
| 802 | /** |
||
| 803 | * For the moment, remove Limit Login Attempts if its xmlrpc for Jetpack. |
||
| 804 | * If Limit Login Attempts is installed as a mu-plugin, it can occasionally |
||
| 805 | * generate false-positives. |
||
| 806 | */ |
||
| 807 | remove_filter( 'wp_login_failed', 'limit_login_failed' ); |
||
| 808 | |||
| 809 | if ( Jetpack::is_active() ) { |
||
| 810 | // Allow Jetpack authentication |
||
| 811 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
| 812 | } |
||
| 813 | } |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Load language files |
||
| 817 | */ |
||
| 818 | public static function plugin_textdomain() { |
||
| 819 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
| 820 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
| 821 | } |
||
| 822 | |||
| 823 | /** |
||
| 824 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 825 | * |
||
| 826 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 827 | * @action wp_loaded |
||
| 828 | * @return null |
||
| 829 | */ |
||
| 830 | public function register_assets() { |
||
| 831 | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
||
| 832 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
| 833 | } |
||
| 834 | |||
| 835 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
| 836 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
| 837 | } |
||
| 838 | |||
| 839 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 840 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
| 841 | } |
||
| 842 | |||
| 843 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
| 844 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
| 845 | } |
||
| 846 | |||
| 847 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 848 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
| 849 | |||
| 850 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 851 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 852 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 853 | $fb_app_id = ''; |
||
| 854 | } |
||
| 855 | wp_localize_script( |
||
| 856 | 'jetpack-facebook-embed', |
||
| 857 | 'jpfbembed', |
||
| 858 | array( |
||
| 859 | 'appid' => $fb_app_id, |
||
| 860 | 'locale' => $this->get_locale(), |
||
| 861 | ) |
||
| 862 | ); |
||
| 863 | } |
||
| 864 | |||
| 865 | /** |
||
| 866 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 867 | * the hook may have already fired by this point. |
||
| 868 | * So, let's just trigger it manually. |
||
| 869 | */ |
||
| 870 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
| 871 | jetpack_register_genericons(); |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Register the social logos |
||
| 875 | */ |
||
| 876 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
| 877 | jetpack_register_social_logos(); |
||
| 878 | |||
| 879 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
| 880 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 881 | } |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Guess locale from language code. |
||
| 885 | * |
||
| 886 | * @param string $lang Language code. |
||
| 887 | * @return string|bool |
||
| 888 | */ |
||
| 889 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
| 890 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
| 891 | return 'en_US'; |
||
| 892 | } |
||
| 893 | |||
| 894 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
| 895 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
| 896 | return false; |
||
| 897 | } |
||
| 898 | |||
| 899 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
| 900 | } |
||
| 901 | |||
| 902 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 903 | // WP.com: get_locale() returns 'it' |
||
| 904 | $locale = GP_Locales::by_slug( $lang ); |
||
| 905 | } else { |
||
| 906 | // Jetpack: get_locale() returns 'it_IT'; |
||
| 907 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
| 908 | } |
||
| 909 | |||
| 910 | if ( ! $locale ) { |
||
| 911 | return false; |
||
| 912 | } |
||
| 913 | |||
| 914 | if ( empty( $locale->facebook_locale ) ) { |
||
| 915 | if ( empty( $locale->wp_locale ) ) { |
||
| 916 | return false; |
||
| 917 | } else { |
||
| 918 | // Facebook SDK is smart enough to fall back to en_US if a |
||
| 919 | // locale isn't supported. Since supported Facebook locales |
||
| 920 | // can fall out of sync, we'll attempt to use the known |
||
| 921 | // wp_locale value and rely on said fallback. |
||
| 922 | return $locale->wp_locale; |
||
| 923 | } |
||
| 924 | } |
||
| 925 | |||
| 926 | return $locale->facebook_locale; |
||
| 927 | } |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Get the locale. |
||
| 931 | * |
||
| 932 | * @return string|bool |
||
| 933 | */ |
||
| 934 | function get_locale() { |
||
| 935 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
| 936 | |||
| 937 | if ( ! $locale ) { |
||
| 938 | $locale = 'en_US'; |
||
| 939 | } |
||
| 940 | |||
| 941 | return $locale; |
||
| 942 | } |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Device Pixels support |
||
| 946 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
| 947 | */ |
||
| 948 | function devicepx() { |
||
| 949 | if ( Jetpack::is_active() ) { |
||
| 950 | wp_enqueue_script( 'devicepx', set_url_scheme( 'http://s0.wp.com/wp-content/js/devicepx-jetpack.js' ), array(), gmdate( 'oW' ), true ); |
||
| 951 | } |
||
| 952 | } |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 956 | * @param bool $option |
||
| 957 | * @return string |
||
| 958 | */ |
||
| 959 | public function jetpack_main_network_site_option( $option ) { |
||
| 960 | return network_site_url(); |
||
| 961 | } |
||
| 962 | /** |
||
| 963 | * Network Name. |
||
| 964 | */ |
||
| 965 | static function network_name( $option = null ) { |
||
| 966 | global $current_site; |
||
| 967 | return $current_site->site_name; |
||
| 968 | } |
||
| 969 | /** |
||
| 970 | * Does the network allow new user and site registrations. |
||
| 971 | * @return string |
||
| 972 | */ |
||
| 973 | static function network_allow_new_registrations( $option = null ) { |
||
| 974 | return ( in_array( get_site_option( 'registration' ), array('none', 'user', 'blog', 'all' ) ) ? get_site_option( 'registration') : 'none' ); |
||
| 975 | } |
||
| 976 | /** |
||
| 977 | * Does the network allow admins to add new users. |
||
| 978 | * @return boolian |
||
| 979 | */ |
||
| 980 | static function network_add_new_users( $option = null ) { |
||
| 981 | return (bool) get_site_option( 'add_new_users' ); |
||
| 982 | } |
||
| 983 | /** |
||
| 984 | * File upload psace left per site in MB. |
||
| 985 | * -1 means NO LIMIT. |
||
| 986 | * @return number |
||
| 987 | */ |
||
| 988 | static function network_site_upload_space( $option = null ) { |
||
| 989 | // value in MB |
||
| 990 | return ( get_site_option( 'upload_space_check_disabled' ) ? -1 : get_space_allowed() ); |
||
| 991 | } |
||
| 992 | |||
| 993 | /** |
||
| 994 | * Network allowed file types. |
||
| 995 | * @return string |
||
| 996 | */ |
||
| 997 | static function network_upload_file_types( $option = null ) { |
||
| 998 | return get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ); |
||
| 999 | } |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Maximum file upload size set by the network. |
||
| 1003 | * @return number |
||
| 1004 | */ |
||
| 1005 | static function network_max_upload_file_size( $option = null ) { |
||
| 1006 | // value in KB |
||
| 1007 | return get_site_option( 'fileupload_maxk', 300 ); |
||
| 1008 | } |
||
| 1009 | |||
| 1010 | /** |
||
| 1011 | * Lets us know if a site allows admins to manage the network. |
||
| 1012 | * @return array |
||
| 1013 | */ |
||
| 1014 | static function network_enable_administration_menus( $option = null ) { |
||
| 1015 | return get_site_option( 'menu_items' ); |
||
| 1016 | } |
||
| 1017 | |||
| 1018 | /** |
||
| 1019 | * Return whether we are dealing with a multi network setup or not. |
||
| 1020 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 1021 | * the result is false since when is_main_network_option return false it cases |
||
| 1022 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 1023 | * database which could be set to anything as opposed to what this function returns. |
||
| 1024 | * @param bool $option |
||
| 1025 | * |
||
| 1026 | * @return boolean |
||
| 1027 | */ |
||
| 1028 | public function is_main_network_option( $option ) { |
||
| 1029 | // return '1' or '' |
||
| 1030 | return (string) (bool) Jetpack::is_multi_network(); |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 1035 | * |
||
| 1036 | * @param string $option |
||
| 1037 | * @return boolean |
||
| 1038 | */ |
||
| 1039 | public function is_multisite( $option ) { |
||
| 1040 | return (string) (bool) is_multisite(); |
||
| 1041 | } |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Implemented since there is no core is multi network function |
||
| 1045 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 1046 | * |
||
| 1047 | * @since 3.3 |
||
| 1048 | * @return boolean |
||
| 1049 | */ |
||
| 1050 | public static function is_multi_network() { |
||
| 1051 | global $wpdb; |
||
| 1052 | |||
| 1053 | // if we don't have a multi site setup no need to do any more |
||
| 1054 | if ( ! is_multisite() ) { |
||
| 1055 | return false; |
||
| 1056 | } |
||
| 1057 | |||
| 1058 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
| 1059 | if ( $num_sites > 1 ) { |
||
| 1060 | return true; |
||
| 1061 | } else { |
||
| 1062 | return false; |
||
| 1063 | } |
||
| 1064 | } |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 1068 | * @return null |
||
| 1069 | */ |
||
| 1070 | function update_jetpack_main_network_site_option() { |
||
| 1071 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1072 | } |
||
| 1073 | /** |
||
| 1074 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 1075 | * |
||
| 1076 | */ |
||
| 1077 | function update_jetpack_network_settings() { |
||
| 1078 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1079 | // Only sync this info for the main network site. |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * Get back if the current site is single user site. |
||
| 1084 | * |
||
| 1085 | * @return bool |
||
| 1086 | */ |
||
| 1087 | public static function is_single_user_site() { |
||
| 1088 | $user_query = new WP_User_Query( array( |
||
| 1089 | 'blog_id' => get_current_blog_id(), |
||
| 1090 | 'fields' => 'ID', |
||
| 1091 | 'number' => 2 |
||
| 1092 | ) ); |
||
| 1093 | return 1 === (int) $user_query->get_total(); |
||
| 1094 | } |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Returns true if the site has file write access false otherwise. |
||
| 1098 | * @return string ( '1' | '0' ) |
||
| 1099 | **/ |
||
| 1100 | public static function file_system_write_access() { |
||
| 1101 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
||
| 1102 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
||
| 1106 | |||
| 1107 | $filesystem_method = get_filesystem_method(); |
||
| 1108 | if ( $filesystem_method === 'direct' ) { |
||
| 1109 | return 1; |
||
| 1110 | } |
||
| 1111 | |||
| 1112 | ob_start(); |
||
| 1113 | $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
||
| 1114 | ob_end_clean(); |
||
| 1115 | if ( $filesystem_credentials_are_stored ) { |
||
| 1116 | return 1; |
||
| 1117 | } |
||
| 1118 | return 0; |
||
| 1119 | } |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Finds out if a site is using a version control system. |
||
| 1123 | * @return string ( '1' | '0' ) |
||
| 1124 | **/ |
||
| 1125 | public static function is_version_controlled() { |
||
| 1126 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); |
||
| 1127 | return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); |
||
| 1128 | } |
||
| 1129 | |||
| 1130 | /** |
||
| 1131 | * Determines whether the current theme supports featured images or not. |
||
| 1132 | * @return string ( '1' | '0' ) |
||
| 1133 | */ |
||
| 1134 | public static function featured_images_enabled() { |
||
| 1135 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1136 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
| 1137 | } |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * jetpack_updates is saved in the following schema: |
||
| 1141 | * |
||
| 1142 | * array ( |
||
| 1143 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1144 | * 'themes' => (int) Number of theme updates available. |
||
| 1145 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1146 | * 'translations' => (int) Number of translation updates available. |
||
| 1147 | * 'total' => (int) Total of all available updates. |
||
| 1148 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1149 | * ) |
||
| 1150 | * @return array |
||
| 1151 | */ |
||
| 1152 | public static function get_updates() { |
||
| 1153 | $update_data = wp_get_update_data(); |
||
| 1154 | |||
| 1155 | // Stores the individual update counts as well as the total count. |
||
| 1156 | if ( isset( $update_data['counts'] ) ) { |
||
| 1157 | $updates = $update_data['counts']; |
||
| 1158 | } |
||
| 1159 | |||
| 1160 | // If we need to update WordPress core, let's find the latest version number. |
||
| 1161 | View Code Duplication | if ( ! empty( $updates['wordpress'] ) ) { |
|
| 1162 | $cur = get_preferred_from_update_core(); |
||
| 1163 | if ( isset( $cur->response ) && 'upgrade' === $cur->response ) { |
||
| 1164 | $updates['wp_update_version'] = $cur->current; |
||
| 1165 | } |
||
| 1166 | } |
||
| 1167 | return isset( $updates ) ? $updates : array(); |
||
| 1168 | } |
||
| 1169 | |||
| 1170 | public static function get_update_details() { |
||
| 1178 | |||
| 1179 | public static function refresh_update_data() { |
||
| 1180 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1181 | |||
| 1182 | } |
||
| 1183 | |||
| 1184 | public static function refresh_theme_data() { |
||
| 1185 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
| 1186 | } |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Is Jetpack active? |
||
| 1190 | */ |
||
| 1191 | public static function is_active() { |
||
| 1192 | return (bool) Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
| 1193 | } |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * Is Jetpack in development (offline) mode? |
||
| 1197 | */ |
||
| 1198 | public static function is_development_mode() { |
||
| 1199 | $development_mode = false; |
||
| 1200 | |||
| 1201 | if ( defined( 'JETPACK_DEV_DEBUG' ) ) { |
||
| 1202 | $development_mode = JETPACK_DEV_DEBUG; |
||
| 1203 | } |
||
| 1204 | |||
| 1205 | elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
| 1206 | $development_mode = true; |
||
| 1207 | } |
||
| 1208 | /** |
||
| 1209 | * Filters Jetpack's development mode. |
||
| 1210 | * |
||
| 1211 | * @see https://jetpack.com/support/development-mode/ |
||
| 1212 | * |
||
| 1213 | * @since 2.2.1 |
||
| 1214 | * |
||
| 1215 | * @param bool $development_mode Is Jetpack's development mode active. |
||
| 1216 | */ |
||
| 1217 | return apply_filters( 'jetpack_development_mode', $development_mode ); |
||
| 1218 | } |
||
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Get Jetpack development mode notice text and notice class. |
||
| 1222 | * |
||
| 1223 | * Mirrors the checks made in Jetpack::is_development_mode |
||
| 1224 | * |
||
| 1225 | */ |
||
| 1226 | public static function show_development_mode_notice() { |
||
| 1227 | if ( Jetpack::is_development_mode() ) { |
||
| 1228 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
| 1229 | $notice = sprintf( |
||
| 1230 | /* translators: %s is a URL */ |
||
| 1231 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), |
||
| 1232 | 'https://jetpack.com/support/development-mode/' |
||
| 1233 | ); |
||
| 1234 | } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
| 1235 | $notice = sprintf( |
||
| 1236 | /* translators: %s is a URL */ |
||
| 1237 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), |
||
| 1238 | 'https://jetpack.com/support/development-mode/' |
||
| 1239 | ); |
||
| 1240 | } else { |
||
| 1241 | $notice = sprintf( |
||
| 1242 | /* translators: %s is a URL */ |
||
| 1243 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), |
||
| 1244 | 'https://jetpack.com/support/development-mode/' |
||
| 1245 | ); |
||
| 1246 | } |
||
| 1247 | |||
| 1248 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1249 | } |
||
| 1250 | |||
| 1251 | // Throw up a notice if using a development version and as for feedback. |
||
| 1252 | if ( Jetpack::is_development_version() ) { |
||
| 1253 | /* translators: %s is a URL */ |
||
| 1254 | $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/' ); |
||
| 1255 | |||
| 1256 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1257 | } |
||
| 1258 | // Throw up a notice if using staging mode |
||
| 1259 | if ( Jetpack::is_staging_site() ) { |
||
| 1260 | /* translators: %s is a URL */ |
||
| 1261 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); |
||
| 1262 | |||
| 1263 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
| 1264 | } |
||
| 1265 | } |
||
| 1266 | |||
| 1267 | /** |
||
| 1268 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1269 | */ |
||
| 1270 | public static function is_development_version() { |
||
| 1271 | return ! preg_match( '/^\d+(\.\d+)+$/', JETPACK__VERSION ); |
||
| 1272 | } |
||
| 1273 | |||
| 1274 | /** |
||
| 1275 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1276 | */ |
||
| 1277 | public static function is_user_connected( $user_id = false ) { |
||
| 1278 | $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); |
||
| 1279 | if ( ! $user_id ) { |
||
| 1280 | return false; |
||
| 1281 | } |
||
| 1282 | return (bool) Jetpack_Data::get_access_token( $user_id ); |
||
| 1283 | } |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * Get the wpcom user data of the current|specified connected user. |
||
| 1287 | */ |
||
| 1288 | View Code Duplication | public static function get_connected_user_data( $user_id = null ) { |
|
| 1289 | if ( ! $user_id ) { |
||
| 1290 | $user_id = get_current_user_id(); |
||
| 1291 | } |
||
| 1292 | Jetpack::load_xml_rpc_client(); |
||
| 1293 | $xml = new Jetpack_IXR_Client( array( |
||
| 1294 | 'user_id' => $user_id, |
||
| 1295 | ) ); |
||
| 1296 | $xml->query( 'wpcom.getUser' ); |
||
| 1297 | if ( ! $xml->isError() ) { |
||
| 1298 | return $xml->getResponse(); |
||
| 1299 | } |
||
| 1300 | return false; |
||
| 1301 | } |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Get the wpcom email of the current|specified connected user. |
||
| 1305 | */ |
||
| 1306 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
| 1307 | if ( ! $user_id ) { |
||
| 1308 | $user_id = get_current_user_id(); |
||
| 1309 | } |
||
| 1310 | Jetpack::load_xml_rpc_client(); |
||
| 1311 | $xml = new Jetpack_IXR_Client( array( |
||
| 1312 | 'user_id' => $user_id, |
||
| 1313 | ) ); |
||
| 1314 | $xml->query( 'wpcom.getUserEmail' ); |
||
| 1315 | if ( ! $xml->isError() ) { |
||
| 1316 | return $xml->getResponse(); |
||
| 1317 | } |
||
| 1318 | return false; |
||
| 1319 | } |
||
| 1320 | |||
| 1321 | /** |
||
| 1322 | * Get the wpcom email of the master user. |
||
| 1323 | */ |
||
| 1324 | public static function get_master_user_email() { |
||
| 1325 | $master_user_id = Jetpack_Options::get_option( 'master_user' ); |
||
| 1326 | if ( $master_user_id ) { |
||
| 1327 | return self::get_connected_user_email( $master_user_id ); |
||
| 1328 | } |
||
| 1329 | return ''; |
||
| 1330 | } |
||
| 1331 | |||
| 1332 | function current_user_is_connection_owner() { |
||
| 1333 | $user_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
| 1334 | return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && get_current_user_id() === $user_token->external_user_id; |
||
| 1335 | } |
||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
| 1339 | */ |
||
| 1340 | function extra_oembed_providers() { |
||
| 1341 | // Cloudup: https://dev.cloudup.com/#oembed |
||
| 1342 | wp_oembed_add_provider( 'https://cloudup.com/*' , 'https://cloudup.com/oembed' ); |
||
| 1343 | wp_oembed_add_provider( 'https://me.sh/*', 'https://me.sh/oembed?format=json' ); |
||
| 1344 | wp_oembed_add_provider( '#https?://(www\.)?gfycat\.com/.*#i', 'https://api.gfycat.com/v1/oembed', true ); |
||
| 1345 | wp_oembed_add_provider( '#https?://[^.]+\.(wistia\.com|wi\.st)/(medias|embed)/.*#', 'https://fast.wistia.com/oembed', true ); |
||
| 1346 | wp_oembed_add_provider( '#https?://sketchfab\.com/.*#i', 'https://sketchfab.com/oembed', true ); |
||
| 1347 | } |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Synchronize connected user role changes |
||
| 1351 | */ |
||
| 1352 | function user_role_change( $user_id ) { |
||
| 1353 | if ( Jetpack::is_active() && Jetpack::is_user_connected( $user_id ) ) { |
||
| 1354 | $current_user_id = get_current_user_id(); |
||
| 1355 | wp_set_current_user( $user_id ); |
||
| 1356 | $role = $this->translate_current_user_to_role(); |
||
| 1357 | $signed_role = $this->sign_role( $role ); |
||
| 1358 | wp_set_current_user( $current_user_id ); |
||
| 1359 | |||
| 1360 | $master_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
| 1361 | $master_user_id = absint( $master_token->external_user_id ); |
||
| 1362 | |||
| 1363 | if ( ! $master_user_id ) |
||
| 1364 | return; // this shouldn't happen |
||
| 1365 | |||
| 1366 | Jetpack::xmlrpc_async_call( 'jetpack.updateRole', $user_id, $signed_role ); |
||
| 1367 | //@todo retry on failure |
||
| 1368 | |||
| 1369 | //try to choose a new master if we're demoting the current one |
||
| 1370 | View Code Duplication | if ( $user_id == $master_user_id && 'administrator' != $role ) { |
|
| 1371 | $query = new WP_User_Query( |
||
| 1372 | array( |
||
| 1373 | 'fields' => array( 'id' ), |
||
| 1374 | 'role' => 'administrator', |
||
| 1375 | 'orderby' => 'id', |
||
| 1376 | 'exclude' => array( $master_user_id ), |
||
| 1377 | ) |
||
| 1378 | ); |
||
| 1379 | $new_master = false; |
||
| 1380 | foreach ( $query->results as $result ) { |
||
| 1381 | $uid = absint( $result->id ); |
||
| 1382 | if ( $uid && Jetpack::is_user_connected( $uid ) ) { |
||
| 1383 | $new_master = $uid; |
||
| 1384 | break; |
||
| 1385 | } |
||
| 1386 | } |
||
| 1387 | |||
| 1388 | if ( $new_master ) { |
||
| 1389 | Jetpack_Options::update_option( 'master_user', $new_master ); |
||
| 1390 | } |
||
| 1391 | // else disconnect..? |
||
| 1392 | } |
||
| 1393 | } |
||
| 1394 | } |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Loads the currently active modules. |
||
| 1398 | */ |
||
| 1399 | public static function load_modules() { |
||
| 1400 | if ( ! self::is_active() && !self::is_development_mode() ) { |
||
| 1401 | if ( ! is_multisite() || ! get_site_option( 'jetpack_protect_active' ) ) { |
||
| 1402 | return; |
||
| 1403 | } |
||
| 1404 | } |
||
| 1405 | |||
| 1406 | $version = Jetpack_Options::get_option( 'version' ); |
||
| 1407 | View Code Duplication | if ( ! $version ) { |
|
| 1408 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
| 1409 | /** This action is documented in class.jetpack.php */ |
||
| 1410 | do_action( 'updating_jetpack_version', $version, false ); |
||
| 1411 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
| 1412 | } |
||
| 1413 | list( $version ) = explode( ':', $version ); |
||
| 1414 | |||
| 1415 | $modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) ); |
||
| 1416 | |||
| 1417 | $modules_data = array(); |
||
| 1418 | |||
| 1419 | // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check. |
||
| 1420 | if ( version_compare( $version, JETPACK__VERSION, '<' ) ) { |
||
| 1421 | $updated_modules = array(); |
||
| 1422 | foreach ( $modules as $module ) { |
||
| 1423 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
| 1424 | if ( ! isset( $modules_data[ $module ]['changed'] ) ) { |
||
| 1425 | continue; |
||
| 1426 | } |
||
| 1427 | |||
| 1428 | if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) { |
||
| 1429 | continue; |
||
| 1430 | } |
||
| 1431 | |||
| 1432 | $updated_modules[] = $module; |
||
| 1433 | } |
||
| 1434 | |||
| 1435 | $modules = array_diff( $modules, $updated_modules ); |
||
| 1436 | } |
||
| 1437 | |||
| 1438 | $is_development_mode = Jetpack::is_development_mode(); |
||
| 1439 | |||
| 1440 | foreach ( $modules as $index => $module ) { |
||
| 1441 | // If we're in dev mode, disable modules requiring a connection |
||
| 1442 | if ( $is_development_mode ) { |
||
| 1443 | // Prime the pump if we need to |
||
| 1444 | if ( empty( $modules_data[ $module ] ) ) { |
||
| 1445 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
| 1446 | } |
||
| 1447 | // If the module requires a connection, but we're in local mode, don't include it. |
||
| 1448 | if ( $modules_data[ $module ]['requires_connection'] ) { |
||
| 1449 | continue; |
||
| 1450 | } |
||
| 1451 | } |
||
| 1452 | |||
| 1453 | if ( did_action( 'jetpack_module_loaded_' . $module ) ) { |
||
| 1454 | continue; |
||
| 1455 | } |
||
| 1456 | |||
| 1457 | if ( ! @include( Jetpack::get_module_path( $module ) ) ) { |
||
| 1458 | unset( $modules[ $index ] ); |
||
| 1459 | Jetpack_Options::update_option( 'active_modules', array_values( $modules ) ); |
||
| 1460 | continue; |
||
| 1461 | } |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Fires when a specific module is loaded. |
||
| 1465 | * The dynamic part of the hook, $module, is the module slug. |
||
| 1466 | * |
||
| 1467 | * @since 1.1.0 |
||
| 1468 | */ |
||
| 1469 | do_action( 'jetpack_module_loaded_' . $module ); |
||
| 1470 | } |
||
| 1471 | |||
| 1472 | /** |
||
| 1473 | * Fires when all the modules are loaded. |
||
| 1474 | * |
||
| 1475 | * @since 1.1.0 |
||
| 1476 | */ |
||
| 1477 | do_action( 'jetpack_modules_loaded' ); |
||
| 1478 | |||
| 1479 | // 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. |
||
| 1480 | if ( Jetpack::is_active() || Jetpack::is_development_mode() ) |
||
| 1481 | require_once( JETPACK__PLUGIN_DIR . 'modules/module-extras.php' ); |
||
| 1482 | } |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Check if Jetpack's REST API compat file should be included |
||
| 1486 | * @action plugins_loaded |
||
| 1487 | * @return null |
||
| 1488 | */ |
||
| 1489 | public function check_rest_api_compat() { |
||
| 1490 | /** |
||
| 1491 | * Filters the list of REST API compat files to be included. |
||
| 1492 | * |
||
| 1493 | * @since 2.2.5 |
||
| 1494 | * |
||
| 1495 | * @param array $args Array of REST API compat files to include. |
||
| 1496 | */ |
||
| 1497 | $_jetpack_rest_api_compat_includes = apply_filters( 'jetpack_rest_api_compat', array() ); |
||
| 1498 | |||
| 1499 | if ( function_exists( 'bbpress' ) ) |
||
| 1500 | $_jetpack_rest_api_compat_includes[] = JETPACK__PLUGIN_DIR . 'class.jetpack-bbpress-json-api-compat.php'; |
||
| 1501 | |||
| 1502 | foreach ( $_jetpack_rest_api_compat_includes as $_jetpack_rest_api_compat_include ) |
||
| 1503 | require_once $_jetpack_rest_api_compat_include; |
||
| 1504 | } |
||
| 1505 | |||
| 1506 | /** |
||
| 1507 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 1508 | * traditionally activated or network activated. |
||
| 1509 | * |
||
| 1510 | * @todo Store the result in core's object cache maybe? |
||
| 1511 | */ |
||
| 1512 | public static function get_active_plugins() { |
||
| 1513 | $active_plugins = (array) get_option( 'active_plugins', array() ); |
||
| 1514 | |||
| 1515 | if ( is_multisite() ) { |
||
| 1516 | // Due to legacy code, active_sitewide_plugins stores them in the keys, |
||
| 1517 | // whereas active_plugins stores them in the values. |
||
| 1518 | $network_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
||
| 1519 | if ( $network_plugins ) { |
||
| 1520 | $active_plugins = array_merge( $active_plugins, $network_plugins ); |
||
| 1521 | } |
||
| 1522 | } |
||
| 1523 | |||
| 1524 | sort( $active_plugins ); |
||
| 1525 | |||
| 1526 | return array_unique( $active_plugins ); |
||
| 1527 | } |
||
| 1528 | |||
| 1529 | /** |
||
| 1530 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 1531 | * |
||
| 1532 | * @since 3.8.1 |
||
| 1533 | * |
||
| 1534 | * @return array Array of plugin data |
||
| 1535 | */ |
||
| 1536 | public static function get_parsed_plugin_data() { |
||
| 1537 | if ( ! function_exists( 'get_plugins' ) ) { |
||
| 1538 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
| 1539 | } |
||
| 1540 | /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
||
| 1541 | $all_plugins = apply_filters( 'all_plugins', get_plugins() ); |
||
| 1542 | $active_plugins = Jetpack::get_active_plugins(); |
||
| 1543 | |||
| 1544 | $plugins = array(); |
||
| 1545 | foreach ( $all_plugins as $path => $plugin_data ) { |
||
| 1546 | $plugins[ $path ] = array( |
||
| 1547 | 'is_active' => in_array( $path, $active_plugins ), |
||
| 1548 | 'file' => $path, |
||
| 1549 | 'name' => $plugin_data['Name'], |
||
| 1550 | 'version' => $plugin_data['Version'], |
||
| 1551 | 'author' => $plugin_data['Author'], |
||
| 1552 | ); |
||
| 1553 | } |
||
| 1554 | |||
| 1555 | return $plugins; |
||
| 1556 | } |
||
| 1557 | |||
| 1558 | /** |
||
| 1559 | * Gets and parses theme data to send with the heartbeat data |
||
| 1560 | * |
||
| 1561 | * @since 3.8.1 |
||
| 1562 | * |
||
| 1563 | * @return array Array of theme data |
||
| 1564 | */ |
||
| 1565 | public static function get_parsed_theme_data() { |
||
| 1587 | |||
| 1588 | /** |
||
| 1589 | * Checks whether a specific plugin is active. |
||
| 1590 | * |
||
| 1591 | * We don't want to store these in a static variable, in case |
||
| 1592 | * there are switch_to_blog() calls involved. |
||
| 1593 | */ |
||
| 1594 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Check if Jetpack's Open Graph tags should be used. |
||
| 1600 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 1601 | * |
||
| 1602 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1603 | * @action plugins_loaded |
||
| 1604 | * @return null |
||
| 1605 | */ |
||
| 1606 | public function check_open_graph() { |
||
| 1633 | |||
| 1634 | /** |
||
| 1635 | * Check if Jetpack's Twitter tags should be used. |
||
| 1636 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 1637 | * |
||
| 1638 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1639 | * @action plugins_loaded |
||
| 1640 | * @return null |
||
| 1641 | */ |
||
| 1642 | public function check_twitter_tags() { |
||
| 1666 | |||
| 1667 | /** |
||
| 1668 | * Allows plugins to submit security reports. |
||
| 1669 | * |
||
| 1670 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 1671 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 1672 | * @param array $args See definitions above |
||
| 1673 | */ |
||
| 1674 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 1675 | _deprecated_function( __FUNCTION__, 'jetpack-4.2', null ); |
||
| 1676 | } |
||
| 1677 | |||
| 1678 | /* Jetpack Options API */ |
||
| 1679 | |||
| 1680 | public static function get_option_names( $type = 'compact' ) { |
||
| 1681 | return Jetpack_Options::get_option_names( $type ); |
||
| 1682 | } |
||
| 1683 | |||
| 1684 | /** |
||
| 1685 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 1686 | * |
||
| 1687 | * @param string $name Option name |
||
| 1688 | * @param mixed $default (optional) |
||
| 1689 | */ |
||
| 1690 | public static function get_option( $name, $default = false ) { |
||
| 1691 | return Jetpack_Options::get_option( $name, $default ); |
||
| 1692 | } |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
| 1696 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
| 1697 | * $name must be a registered option name. |
||
| 1698 | */ |
||
| 1699 | public static function create_nonce( $name ) { |
||
| 1700 | $secret = wp_generate_password( 32, false ) . ':' . wp_generate_password( 32, false ) . ':' . ( time() + 600 ); |
||
| 1701 | |||
| 1702 | Jetpack_Options::update_option( $name, $secret ); |
||
| 1703 | @list( $secret_1, $secret_2, $eol ) = explode( ':', Jetpack_Options::get_option( $name ) ); |
||
| 1704 | if ( empty( $secret_1 ) || empty( $secret_2 ) || $eol < time() ) |
||
| 1705 | return new Jetpack_Error( 'missing_secrets' ); |
||
| 1706 | |||
| 1707 | return array( |
||
| 1708 | 'secret_1' => $secret_1, |
||
| 1709 | 'secret_2' => $secret_2, |
||
| 1710 | 'eol' => $eol, |
||
| 1711 | ); |
||
| 1712 | } |
||
| 1713 | |||
| 1714 | /** |
||
| 1715 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 1716 | * |
||
| 1717 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 1718 | * @param string $name Option name |
||
| 1719 | * @param mixed $value Option value |
||
| 1720 | */ |
||
| 1721 | public static function update_option( $name, $value ) { |
||
| 1722 | _deprecated_function( __METHOD__, 'jetpack-3.4', 'Jetpack_Options::update_option()' ); |
||
| 1725 | |||
| 1726 | /** |
||
| 1727 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 1728 | * |
||
| 1729 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 1730 | * @param array $array array( option name => option value, ... ) |
||
| 1731 | */ |
||
| 1732 | public static function update_options( $array ) { |
||
| 1736 | |||
| 1737 | /** |
||
| 1738 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 1739 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 1740 | * |
||
| 1741 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 1742 | * @param string|array $names |
||
| 1743 | */ |
||
| 1744 | public static function delete_option( $names ) { |
||
| 1748 | |||
| 1749 | /** |
||
| 1750 | * Enters a user token into the user_tokens option |
||
| 1751 | * |
||
| 1752 | * @param int $user_id |
||
| 1753 | * @param string $token |
||
| 1754 | * return bool |
||
| 1755 | */ |
||
| 1756 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 1770 | |||
| 1771 | /** |
||
| 1772 | * Returns an array of all PHP files in the specified absolute path. |
||
| 1773 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 1774 | * |
||
| 1775 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 1776 | * @return array Array of absolute paths to the PHP files. |
||
| 1777 | */ |
||
| 1778 | public static function glob_php( $absolute_path ) { |
||
| 1807 | |||
| 1808 | public static function activate_new_modules( $redirect = false ) { |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 1869 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 1870 | */ |
||
| 1871 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Default modules loaded on activation. |
||
| 1931 | */ |
||
| 1932 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 1963 | |||
| 1964 | /** |
||
| 1965 | * Checks activated modules during auto-activation to determine |
||
| 1966 | * if any of those modules are being deprecated. If so, close |
||
| 1967 | * them out, and add any replacement modules. |
||
| 1968 | * |
||
| 1969 | * Runs at priority 99 by default. |
||
| 1970 | * |
||
| 1971 | * This is run late, so that it can still activate a module if |
||
| 1972 | * the new module is a replacement for another that the user |
||
| 1973 | * currently has active, even if something at the normal priority |
||
| 1974 | * would kibosh everything. |
||
| 1975 | * |
||
| 1976 | * @since 2.6 |
||
| 1977 | * @uses jetpack_get_default_modules filter |
||
| 1978 | * @param array $modules |
||
| 1979 | * @return array |
||
| 1980 | */ |
||
| 1981 | function handle_deprecated_modules( $modules ) { |
||
| 2007 | |||
| 2008 | /** |
||
| 2009 | * Checks activated plugins during auto-activation to determine |
||
| 2010 | * if any of those plugins are in the list with a corresponding module |
||
| 2011 | * that is not compatible with the plugin. The module will not be allowed |
||
| 2012 | * to auto-activate. |
||
| 2013 | * |
||
| 2014 | * @since 2.6 |
||
| 2015 | * @uses jetpack_get_default_modules filter |
||
| 2016 | * @param array $modules |
||
| 2017 | * @return array |
||
| 2018 | */ |
||
| 2019 | function filter_default_modules( $modules ) { |
||
| 2043 | |||
| 2044 | /** |
||
| 2045 | * Extract a module's slug from its full path. |
||
| 2046 | */ |
||
| 2047 | public static function get_module_slug( $file ) { |
||
| 2050 | |||
| 2051 | /** |
||
| 2052 | * Generate a module's path from its slug. |
||
| 2053 | */ |
||
| 2054 | public static function get_module_path( $slug ) { |
||
| 2057 | |||
| 2058 | /** |
||
| 2059 | * Load module data from module file. Headers differ from WordPress |
||
| 2060 | * plugin headers to avoid them being identified as standalone |
||
| 2061 | * plugins on the WordPress plugins page. |
||
| 2062 | */ |
||
| 2063 | public static function get_module( $module ) { |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * Like core's get_file_data implementation, but caches the result. |
||
| 2149 | */ |
||
| 2150 | public static function get_file_data( $file, $headers ) { |
||
| 2162 | |||
| 2163 | /** |
||
| 2164 | * Return translated module tag. |
||
| 2165 | * |
||
| 2166 | * @param string $tag Tag as it appears in each module heading. |
||
| 2167 | * |
||
| 2168 | * @return mixed |
||
| 2169 | */ |
||
| 2170 | public static function translate_module_tag( $tag ) { |
||
| 2173 | |||
| 2174 | /** |
||
| 2175 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2176 | * |
||
| 2177 | * @since 3.9.2 |
||
| 2178 | * |
||
| 2179 | * @param array $modules |
||
| 2180 | * |
||
| 2181 | * @return string|void |
||
| 2182 | */ |
||
| 2183 | public static function get_translated_modules( $modules ) { |
||
| 2199 | |||
| 2200 | /** |
||
| 2201 | * Get a list of activated modules as an array of module slugs. |
||
| 2202 | */ |
||
| 2203 | public static function get_active_modules() { |
||
| 2220 | |||
| 2221 | /** |
||
| 2222 | * Check whether or not a Jetpack module is active. |
||
| 2223 | * |
||
| 2224 | * @param string $module The slug of a Jetpack module. |
||
| 2225 | * @return bool |
||
| 2226 | * |
||
| 2227 | * @static |
||
| 2228 | */ |
||
| 2229 | public static function is_module_active( $module ) { |
||
| 2232 | |||
| 2233 | public static function is_module( $module ) { |
||
| 2236 | |||
| 2237 | /** |
||
| 2238 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2239 | * |
||
| 2240 | * @param bool $catch True to start catching, False to stop. |
||
| 2241 | * |
||
| 2242 | * @static |
||
| 2243 | */ |
||
| 2244 | public static function catch_errors( $catch ) { |
||
| 2257 | |||
| 2258 | /** |
||
| 2259 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2260 | */ |
||
| 2261 | public static function catch_errors_on_shutdown() { |
||
| 2264 | |||
| 2265 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
| 2388 | |||
| 2389 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 2474 | |||
| 2475 | function activate_module_actions( $module ) { |
||
| 2486 | |||
| 2487 | public static function deactivate_module( $module ) { |
||
| 2535 | |||
| 2536 | public static function enable_module_configurable( $module ) { |
||
| 2540 | |||
| 2541 | public static function module_configuration_url( $module ) { |
||
| 2545 | |||
| 2546 | public static function module_configuration_load( $module, $method ) { |
||
| 2550 | |||
| 2551 | public static function module_configuration_head( $module, $method ) { |
||
| 2555 | |||
| 2556 | public static function module_configuration_screen( $module, $method ) { |
||
| 2560 | |||
| 2561 | public static function module_configuration_activation_screen( $module, $method ) { |
||
| 2565 | |||
| 2566 | /* Installation */ |
||
| 2567 | |||
| 2568 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 2608 | |||
| 2609 | /** |
||
| 2610 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 2611 | * @static |
||
| 2612 | */ |
||
| 2613 | public static function plugin_activation( $network_wide ) { |
||
| 2625 | /** |
||
| 2626 | * Runs before bumping version numbers up to a new version |
||
| 2627 | * @param (string) $version Version:timestamp |
||
| 2628 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
| 2629 | * @return null [description] |
||
| 2630 | */ |
||
| 2631 | public static function do_version_bump( $version, $old_version ) { |
||
| 2638 | |||
| 2639 | /** |
||
| 2640 | * Sets the internal version number and activation state. |
||
| 2641 | * @static |
||
| 2642 | */ |
||
| 2643 | public static function plugin_initialize() { |
||
| 2659 | |||
| 2660 | /** |
||
| 2661 | * Removes all connection options |
||
| 2662 | * @static |
||
| 2663 | */ |
||
| 2664 | public static function plugin_deactivation( ) { |
||
| 2673 | |||
| 2674 | /** |
||
| 2675 | * Disconnects from the Jetpack servers. |
||
| 2676 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 2677 | * @static |
||
| 2678 | */ |
||
| 2679 | public static function disconnect( $update_activated_state = true ) { |
||
| 2728 | |||
| 2729 | /** |
||
| 2730 | * Unlinks the current user from the linked WordPress.com user |
||
| 2731 | */ |
||
| 2732 | public static function unlink_user( $user_id = null ) { |
||
| 2763 | |||
| 2764 | /** |
||
| 2765 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 2766 | */ |
||
| 2767 | public static function try_registration() { |
||
| 2792 | |||
| 2793 | /** |
||
| 2794 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 2795 | * |
||
| 2796 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 2797 | */ |
||
| 2798 | public static function log( $code, $data = null ) { |
||
| 2838 | |||
| 2839 | /** |
||
| 2840 | * Get the internal event log. |
||
| 2841 | * |
||
| 2842 | * @param $event (string) - only return the specific log events |
||
| 2843 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 2844 | * |
||
| 2845 | * @return array of log events || WP_Error for invalid params |
||
| 2846 | */ |
||
| 2847 | public static function get_log( $event = false, $num = false ) { |
||
| 2883 | |||
| 2884 | /** |
||
| 2885 | * Log modification of important settings. |
||
| 2886 | */ |
||
| 2887 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 2894 | |||
| 2895 | /** |
||
| 2896 | * Return stat data for WPCOM sync |
||
| 2897 | */ |
||
| 2898 | function get_stat_data() { |
||
| 2904 | |||
| 2905 | /** |
||
| 2906 | * Get additional stat data to sync to WPCOM |
||
| 2907 | */ |
||
| 2908 | function get_additional_stat_data( $prefix = '' ) { |
||
| 2918 | |||
| 2919 | /* Admin Pages */ |
||
| 2920 | |||
| 2921 | function admin_init() { |
||
| 2983 | |||
| 2984 | function admin_body_class( $admin_body_class = '' ) { |
||
| 2992 | |||
| 2993 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 2996 | |||
| 2997 | function prepare_connect_notice() { |
||
| 3005 | /** |
||
| 3006 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
| 3007 | * |
||
| 3008 | * @return null |
||
| 3009 | */ |
||
| 3010 | function prepare_manage_jetpack_notice() { |
||
| 3015 | |||
| 3016 | function manage_activate_screen() { |
||
| 3019 | /** |
||
| 3020 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 3021 | * This function artificially throws errors for such cases (whitelisted). |
||
| 3022 | * |
||
| 3023 | * @param string $plugin The activated plugin. |
||
| 3024 | */ |
||
| 3025 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 3049 | |||
| 3050 | function intercept_plugin_error_scrape_init() { |
||
| 3053 | |||
| 3054 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 3065 | |||
| 3066 | function add_remote_request_handlers() { |
||
| 3069 | |||
| 3070 | function remote_request_handlers() { |
||
| 3104 | |||
| 3105 | function upload_handler() { |
||
| 3190 | |||
| 3191 | /** |
||
| 3192 | * Add help to the Jetpack page |
||
| 3193 | * |
||
| 3194 | * @since Jetpack (1.2.3) |
||
| 3195 | * @return false if not the Jetpack page |
||
| 3196 | */ |
||
| 3197 | function admin_help() { |
||
| 3238 | |||
| 3239 | function admin_menu_css() { |
||
| 3242 | |||
| 3243 | function admin_menu_order() { |
||
| 3246 | |||
| 3247 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
| 3262 | |||
| 3263 | function admin_head() { |
||
| 3268 | |||
| 3269 | function admin_banner_styles() { |
||
| 3276 | |||
| 3277 | function admin_scripts() { |
||
| 3290 | |||
| 3291 | function plugin_action_links( $actions ) { |
||
| 3306 | |||
| 3307 | function admin_connect_notice() { |
||
| 3342 | |||
| 3343 | /** |
||
| 3344 | * This is the first banner |
||
| 3345 | * It should be visible only to user that can update the option |
||
| 3346 | * Are not connected |
||
| 3347 | * |
||
| 3348 | * @return null |
||
| 3349 | */ |
||
| 3350 | function admin_jetpack_manage_notice() { |
||
| 3385 | |||
| 3386 | /** |
||
| 3387 | * Returns the url that the user clicks to remove the notice for the big banner |
||
| 3388 | * @return (string) |
||
| 3389 | */ |
||
| 3390 | function opt_out_jetpack_manage_url() { |
||
| 3394 | /** |
||
| 3395 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
| 3396 | * @return (string) |
||
| 3397 | */ |
||
| 3398 | function opt_in_jetpack_manage_url() { |
||
| 3401 | |||
| 3402 | function opt_in_jetpack_manage_notice() { |
||
| 3412 | /** |
||
| 3413 | * Determines whether to show the notice of not true = display notice |
||
| 3414 | * @return (bool) |
||
| 3415 | */ |
||
| 3416 | function can_display_jetpack_manage_notice() { |
||
| 3438 | |||
| 3439 | function network_connect_notice() { |
||
| 3448 | |||
| 3449 | public static function jetpack_comment_notice() { |
||
| 3484 | |||
| 3485 | /** |
||
| 3486 | * Show the survey link when the user has just disconnected Jetpack. |
||
| 3487 | */ |
||
| 3488 | function disconnect_survey_notice() { |
||
| 3507 | |||
| 3508 | /* |
||
| 3509 | * Registration flow: |
||
| 3510 | * 1 - ::admin_page_load() action=register |
||
| 3511 | * 2 - ::try_registration() |
||
| 3512 | * 3 - ::register() |
||
| 3513 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 3514 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 3515 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 3516 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 3517 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 3518 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 3519 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 3520 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 3521 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 3522 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 3523 | * 5 - user logs in with WP.com account |
||
| 3524 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 3525 | * - Jetpack_Client_Server::authorize() |
||
| 3526 | * - Jetpack_Client_Server::get_token() |
||
| 3527 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 3528 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 3529 | * - which responds with access_token, token_type, scope |
||
| 3530 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 3531 | * - Jetpack::activate_default_modules() |
||
| 3532 | * - Deactivates deprecated plugins |
||
| 3533 | * - Activates all default modules |
||
| 3534 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 3535 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 3536 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 3537 | * Done! |
||
| 3538 | */ |
||
| 3539 | |||
| 3540 | /** |
||
| 3541 | * Handles the page load events for the Jetpack admin page |
||
| 3542 | */ |
||
| 3543 | function admin_page_load() { |
||
| 4001 | |||
| 4002 | function admin_notices() { |
||
| 4099 | |||
| 4100 | /** |
||
| 4101 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 4102 | */ |
||
| 4103 | function stat( $group, $detail ) { |
||
| 4108 | |||
| 4109 | /** |
||
| 4110 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 4111 | */ |
||
| 4112 | function do_stats( $method = '' ) { |
||
| 4127 | |||
| 4128 | /** |
||
| 4129 | * Runs stats code for a one-off, server-side. |
||
| 4130 | * |
||
| 4131 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 4132 | * |
||
| 4133 | * @return bool If it worked. |
||
| 4134 | */ |
||
| 4135 | static function do_server_side_stat( $args ) { |
||
| 4145 | |||
| 4146 | /** |
||
| 4147 | * Builds the stats url. |
||
| 4148 | * |
||
| 4149 | * @param $args array|string The arguments to append to the URL. |
||
| 4150 | * |
||
| 4151 | * @return string The URL to be pinged. |
||
| 4152 | */ |
||
| 4153 | static function build_stats_url( $args ) { |
||
| 4173 | |||
| 4174 | function translate_current_user_to_role() { |
||
| 4183 | |||
| 4184 | function translate_role_to_cap( $role ) { |
||
| 4191 | |||
| 4192 | function sign_role( $role ) { |
||
| 4204 | |||
| 4205 | |||
| 4206 | /** |
||
| 4207 | * Builds a URL to the Jetpack connection auth page |
||
| 4208 | * |
||
| 4209 | * @since 3.9.5 |
||
| 4210 | * |
||
| 4211 | * @param bool $raw If true, URL will not be escaped. |
||
| 4212 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 4213 | * If string, will be a custom redirect. |
||
| 4214 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 4215 | * |
||
| 4216 | * @return string Connect URL |
||
| 4217 | */ |
||
| 4218 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
| 4289 | |||
| 4290 | function build_reconnect_url( $raw = false ) { |
||
| 4294 | |||
| 4295 | public static function admin_url( $args = null ) { |
||
| 4300 | |||
| 4301 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 4305 | |||
| 4306 | function dismiss_jetpack_notice() { |
||
| 4380 | |||
| 4381 | function debugger_page() { |
||
| 4389 | |||
| 4390 | public static function admin_screen_configure_module( $module_id ) { |
||
| 4442 | |||
| 4443 | /** |
||
| 4444 | * Display link to activate the module to see the settings screen. |
||
| 4445 | * @param string $module_id |
||
| 4446 | * @return null |
||
| 4447 | */ |
||
| 4448 | public static function display_activate_module_link( $module_id ) { |
||
| 4500 | |||
| 4501 | public static function sort_modules( $a, $b ) { |
||
| 4507 | |||
| 4508 | function ajax_recheck_ssl() { |
||
| 4516 | |||
| 4517 | /* Client API */ |
||
| 4518 | |||
| 4519 | /** |
||
| 4520 | * Returns the requested Jetpack API URL |
||
| 4521 | * |
||
| 4522 | * @return string |
||
| 4523 | */ |
||
| 4524 | public static function api_url( $relative_url ) { |
||
| 4527 | |||
| 4528 | /** |
||
| 4529 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
| 4530 | */ |
||
| 4531 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 4547 | |||
| 4548 | /** |
||
| 4549 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 4550 | * |
||
| 4551 | * @since 2.3.3 |
||
| 4552 | * @return boolean |
||
| 4553 | */ |
||
| 4554 | public static function permit_ssl( $force_recheck = false ) { |
||
| 4596 | |||
| 4597 | /* |
||
| 4598 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
| 4599 | */ |
||
| 4600 | public function alert_auto_ssl_fail() { |
||
| 4649 | |||
| 4650 | /** |
||
| 4651 | * Returns the Jetpack XML-RPC API |
||
| 4652 | * |
||
| 4653 | * @return string |
||
| 4654 | */ |
||
| 4655 | public static function xmlrpc_api_url() { |
||
| 4659 | |||
| 4660 | /** |
||
| 4661 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 4662 | * |
||
| 4663 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 4664 | * |
||
| 4665 | * @since 2.6 |
||
| 4666 | * @return array |
||
| 4667 | */ |
||
| 4668 | public function generate_secrets( $action, $exp = 600 ) { |
||
| 4676 | |||
| 4677 | /** |
||
| 4678 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 4679 | * |
||
| 4680 | * Based on local php max_execution_time in php.ini |
||
| 4681 | * |
||
| 4682 | * @since 2.6 |
||
| 4683 | * @return int |
||
| 4684 | **/ |
||
| 4685 | public function get_remote_query_timeout_limit() { |
||
| 4691 | |||
| 4692 | |||
| 4693 | /** |
||
| 4694 | * Takes the response from the Jetpack register new site endpoint and |
||
| 4695 | * verifies it worked properly. |
||
| 4696 | * |
||
| 4697 | * @since 2.6 |
||
| 4698 | * @return true or Jetpack_Error |
||
| 4699 | **/ |
||
| 4700 | public function validate_remote_register_response( $response ) { |
||
| 4735 | /** |
||
| 4736 | * @return bool|WP_Error |
||
| 4737 | */ |
||
| 4738 | public static function register() { |
||
| 4835 | |||
| 4836 | /** |
||
| 4837 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 4838 | * |
||
| 4839 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 4840 | */ |
||
| 4841 | public static function maybe_set_version_option() { |
||
| 4849 | |||
| 4850 | /* Client Server API */ |
||
| 4851 | |||
| 4852 | /** |
||
| 4853 | * Loads the Jetpack XML-RPC client |
||
| 4854 | */ |
||
| 4855 | public static function load_xml_rpc_client() { |
||
| 4859 | |||
| 4860 | function verify_xml_rpc_signature() { |
||
| 4958 | |||
| 4959 | /** |
||
| 4960 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 4961 | */ |
||
| 4962 | function authenticate_jetpack( $user, $username, $password ) { |
||
| 4985 | |||
| 4986 | function add_nonce( $timestamp, $nonce ) { |
||
| 5024 | |||
| 5025 | /** |
||
| 5026 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 5027 | * Capture it here so we can verify the signature later. |
||
| 5028 | */ |
||
| 5029 | function xmlrpc_methods( $methods ) { |
||
| 5033 | |||
| 5034 | function public_xmlrpc_methods( $methods ) { |
||
| 5040 | |||
| 5041 | function jetpack_getOptions( $args ) { |
||
| 5081 | |||
| 5082 | function xmlrpc_options( $options ) { |
||
| 5100 | |||
| 5101 | public static function clean_nonces( $all = false ) { |
||
| 5126 | |||
| 5127 | /** |
||
| 5128 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 5129 | * SET: state( $key, $value ); |
||
| 5130 | * GET: $value = state( $key ); |
||
| 5131 | * |
||
| 5132 | * @param string $key |
||
| 5133 | * @param string $value |
||
| 5134 | * @param bool $restate private |
||
| 5135 | */ |
||
| 5136 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 5186 | |||
| 5187 | public static function restate() { |
||
| 5190 | |||
| 5191 | public static function check_privacy( $file ) { |
||
| 5226 | |||
| 5227 | /** |
||
| 5228 | * Helper method for multicall XMLRPC. |
||
| 5229 | */ |
||
| 5230 | public static function xmlrpc_async_call() { |
||
| 5272 | |||
| 5273 | public static function staticize_subdomain( $url ) { |
||
| 5308 | |||
| 5309 | /* JSON API Authorization */ |
||
| 5310 | |||
| 5311 | /** |
||
| 5312 | * Handles the login action for Authorizing the JSON API |
||
| 5313 | */ |
||
| 5314 | function login_form_json_api_authorization() { |
||
| 5323 | |||
| 5324 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 5325 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 5338 | |||
| 5339 | // Make sure the POSTed request is handled by the same action |
||
| 5340 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 5344 | |||
| 5345 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 5346 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 5352 | |||
| 5353 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
| 5354 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 5358 | |||
| 5359 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 5360 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 5372 | |||
| 5373 | // Verifies the request by checking the signature |
||
| 5374 | function verify_json_api_authorization_request() { |
||
| 5453 | |||
| 5454 | function login_message_json_api_authorization( $message ) { |
||
| 5460 | |||
| 5461 | /** |
||
| 5462 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 5463 | */ |
||
| 5464 | public static function get_content_width() { |
||
| 5475 | |||
| 5476 | /** |
||
| 5477 | * Centralize the function here until it gets added to core. |
||
| 5478 | * |
||
| 5479 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 5480 | * @param int $size Size of the avatar image |
||
| 5481 | * @param string $default URL to a default image to use if no avatar is available |
||
| 5482 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 5483 | * |
||
| 5484 | * @return array First element is the URL, second is the class. |
||
| 5485 | */ |
||
| 5486 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 5514 | |||
| 5515 | /** |
||
| 5516 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 5517 | * |
||
| 5518 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 5519 | * |
||
| 5520 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 5521 | */ |
||
| 5522 | public function get_cloud_site_options( $option_names ) { |
||
| 5538 | |||
| 5539 | /** |
||
| 5540 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
| 5541 | * |
||
| 5542 | * @return array An array of options to check. |
||
| 5543 | */ |
||
| 5544 | public static function identity_crisis_options_to_check() { |
||
| 5550 | |||
| 5551 | /** |
||
| 5552 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
| 5553 | * |
||
| 5554 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
| 5555 | * |
||
| 5556 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
| 5557 | */ |
||
| 5558 | public static function check_identity_crisis( $force_recheck = false ) { |
||
| 5624 | |||
| 5625 | /* |
||
| 5626 | * Resolve ID crisis |
||
| 5627 | * |
||
| 5628 | * If the URL has changed, but the rest of the options are the same (i.e. blog/user tokens) |
||
| 5629 | * The user has the option to update the shadow site with the new URL before a new |
||
| 5630 | * token is created. |
||
| 5631 | * |
||
| 5632 | * @param $key : Which option to sync. null defautlts to home and siteurl |
||
| 5633 | */ |
||
| 5634 | public static function resolve_identity_crisis( $key = null ) { |
||
| 5654 | |||
| 5655 | /* |
||
| 5656 | * Whitelist URL |
||
| 5657 | * |
||
| 5658 | * Ignore the URL differences between the blog and the shadow site. |
||
| 5659 | */ |
||
| 5660 | public static function whitelist_current_url() { |
||
| 5668 | |||
| 5669 | /* |
||
| 5670 | * Ajax callbacks for ID crisis resolutions |
||
| 5671 | * |
||
| 5672 | * Things that could happen here: |
||
| 5673 | * - site_migrated : Update the URL on the shadow blog to match new domain |
||
| 5674 | * - whitelist : Ignore the URL difference |
||
| 5675 | * - default : Error message |
||
| 5676 | */ |
||
| 5677 | public static function resolve_identity_crisis_ajax_callback() { |
||
| 5717 | |||
| 5718 | /** |
||
| 5719 | * Adds a value to the whitelist for the specified key. |
||
| 5720 | * |
||
| 5721 | * @param string $key The option name that we're whitelisting the value for. |
||
| 5722 | * @param string $value The value that we're intending to add to the whitelist. |
||
| 5723 | * |
||
| 5724 | * @return bool Whether the value was added to the whitelist, or false if it was already there. |
||
| 5725 | */ |
||
| 5726 | public static function whitelist_identity_crisis_value( $key, $value ) { |
||
| 5740 | |||
| 5741 | /** |
||
| 5742 | * Checks whether a value is already whitelisted. |
||
| 5743 | * |
||
| 5744 | * @param string $key The option name that we're checking the value for. |
||
| 5745 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
| 5746 | * |
||
| 5747 | * @return bool Whether the value is whitelisted. |
||
| 5748 | */ |
||
| 5749 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
| 5756 | |||
| 5757 | /** |
||
| 5758 | * Checks whether the home and siteurl specifically are whitelisted |
||
| 5759 | * Written so that we don't have re-check $key and $value params every time |
||
| 5760 | * we want to check if this site is whitelisted, for example in footer.php |
||
| 5761 | * |
||
| 5762 | * @return bool True = already whitelisted False = not whitelisted |
||
| 5763 | */ |
||
| 5764 | public static function is_staging_site() { |
||
| 5830 | |||
| 5831 | public function identity_crisis_js( $nonce ) { |
||
| 5901 | |||
| 5902 | /** |
||
| 5903 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 5904 | * |
||
| 5905 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 5906 | */ |
||
| 5907 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 5942 | |||
| 5943 | /** |
||
| 5944 | * Maybe inlines a stylesheet. |
||
| 5945 | * |
||
| 5946 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 5947 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 5948 | * |
||
| 5949 | * Attached to `style_loader_tag` filter. |
||
| 5950 | * |
||
| 5951 | * @param string $tag The tag that would link to the external asset. |
||
| 5952 | * @param string $handle The registered handle of the script in question. |
||
| 5953 | * |
||
| 5954 | * @return string |
||
| 5955 | */ |
||
| 5956 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 6006 | |||
| 6007 | /** |
||
| 6008 | * Loads a view file from the views |
||
| 6009 | * |
||
| 6010 | * Data passed in with the $data parameter will be available in the |
||
| 6011 | * template file as $data['value'] |
||
| 6012 | * |
||
| 6013 | * @param string $template - Template file to load |
||
| 6014 | * @param array $data - Any data to pass along to the template |
||
| 6015 | * @return boolean - If template file was found |
||
| 6016 | **/ |
||
| 6017 | public function load_view( $template, $data = array() ) { |
||
| 6028 | |||
| 6029 | /** |
||
| 6030 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
| 6031 | */ |
||
| 6032 | public function deprecated_hooks() { |
||
| 6061 | |||
| 6062 | /** |
||
| 6063 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 6064 | * |
||
| 6065 | * Considerations: |
||
| 6066 | * - Normal, relative URLs `feh.png` |
||
| 6067 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 6068 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 6069 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 6070 | * - Domain root relative URLs `/feh.png` |
||
| 6071 | * |
||
| 6072 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 6073 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 6074 | * |
||
| 6075 | * @return mixed|string |
||
| 6076 | */ |
||
| 6077 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 6121 | |||
| 6122 | /** |
||
| 6123 | * This method checks to see if SSL is required by the site in |
||
| 6124 | * order to visit it in some way other than only setting the |
||
| 6125 | * https value in the home or siteurl values. |
||
| 6126 | * |
||
| 6127 | * @since 3.2 |
||
| 6128 | * @return boolean |
||
| 6129 | **/ |
||
| 6130 | private function is_ssl_required_to_visit_site() { |
||
| 6139 | |||
| 6140 | /** |
||
| 6141 | * This methods removes all of the registered css files on the frontend |
||
| 6142 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 6143 | * all the files into one file. |
||
| 6144 | * |
||
| 6145 | * Pros: |
||
| 6146 | * - Uses only ONE css asset connection instead of 15 |
||
| 6147 | * - Saves a minimum of 56k |
||
| 6148 | * - Reduces server load |
||
| 6149 | * - Reduces time to first painted byte |
||
| 6150 | * |
||
| 6151 | * Cons: |
||
| 6152 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 6153 | * should not cause any issues with themes. |
||
| 6154 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 6155 | * jetpack_implode_frontend_css filter for a workaround |
||
| 6156 | * |
||
| 6157 | * For some situations developers may wish to disable css imploding and |
||
| 6158 | * instead operate in legacy mode where each file loads seperately and |
||
| 6159 | * can be edited individually or dequeued. This can be accomplished with |
||
| 6160 | * the following line: |
||
| 6161 | * |
||
| 6162 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 6163 | * |
||
| 6164 | * @since 3.2 |
||
| 6165 | **/ |
||
| 6166 | public function implode_frontend_css( $travis_test = false ) { |
||
| 6218 | |||
| 6219 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 6229 | |||
| 6230 | /* |
||
| 6231 | * Check the heartbeat data |
||
| 6232 | * |
||
| 6233 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 6234 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 6235 | * |
||
| 6236 | * Data will be added to "caution" array, if it either: |
||
| 6237 | * - Out of date Jetpack version |
||
| 6238 | * - Out of date WP version |
||
| 6239 | * - Out of date PHP version |
||
| 6240 | * |
||
| 6241 | * $return array $filtered_data |
||
| 6242 | */ |
||
| 6243 | public static function jetpack_check_heartbeat_data() { |
||
| 6296 | |||
| 6297 | |||
| 6298 | /* |
||
| 6299 | * This method is used to organize all options that can be reset |
||
| 6300 | * without disconnecting Jetpack. |
||
| 6301 | * |
||
| 6302 | * It is used in class.jetpack-cli.php to reset options |
||
| 6303 | * |
||
| 6304 | * @return array of options to delete. |
||
| 6305 | */ |
||
| 6306 | public static function get_jetpack_options_for_reset() { |
||
| 6372 | |||
| 6373 | /* |
||
| 6374 | * Check if an option of a Jetpack module has been updated. |
||
| 6375 | * |
||
| 6376 | * If any module option has been updated before Jump Start has been dismissed, |
||
| 6377 | * update the 'jumpstart' option so we can hide Jump Start. |
||
| 6378 | */ |
||
| 6379 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
| 6401 | |||
| 6402 | /* |
||
| 6403 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 6404 | * so we can bring them directly to their site in calypso. |
||
| 6405 | * |
||
| 6406 | * @param string | url |
||
| 6407 | * @return string | url without the guff |
||
| 6408 | */ |
||
| 6409 | public static function build_raw_urls( $url ) { |
||
| 6415 | |||
| 6416 | /** |
||
| 6417 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 6418 | * |
||
| 6419 | * @param mixed $new_urls |
||
| 6420 | */ |
||
| 6421 | public static function dns_prefetch( $new_urls = null ) { |
||
| 6438 | |||
| 6439 | public function wp_dashboard_setup() { |
||
| 6467 | |||
| 6468 | /** |
||
| 6469 | * @param mixed $result Value for the user's option |
||
| 6470 | * @return mixed |
||
| 6471 | */ |
||
| 6472 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 6497 | |||
| 6498 | public static function dashboard_widget() { |
||
| 6506 | |||
| 6507 | public static function dashboard_widget_footer() { |
||
| 6540 | |||
| 6541 | public function dashboard_widget_connect_to_wpcom() { |
||
| 6563 | |||
| 6564 | /* |
||
| 6565 | * A graceful transition to using Core's site icon. |
||
| 6566 | * |
||
| 6567 | * All of the hard work has already been done with the image |
||
| 6568 | * in all_done_page(). All that needs to be done now is update |
||
| 6569 | * the option and display proper messaging. |
||
| 6570 | * |
||
| 6571 | * @todo remove when WP 4.3 is minimum |
||
| 6572 | * |
||
| 6573 | * @since 3.6.1 |
||
| 6574 | * |
||
| 6575 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
| 6576 | */ |
||
| 6577 | public static function jetpack_site_icon_available_in_core() { |
||
| 6612 | |||
| 6613 | /** |
||
| 6614 | * Return string containing the Jetpack logo. |
||
| 6615 | * |
||
| 6616 | * @since 3.9.0 |
||
| 6617 | * |
||
| 6618 | * @return string |
||
| 6619 | */ |
||
| 6620 | public static function get_jp_emblem() { |
||
| 6623 | |||
| 6624 | /* |
||
| 6625 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 6626 | */ |
||
| 6627 | function jetpack_icon_user_connected( $columns ) { |
||
| 6631 | |||
| 6632 | /* |
||
| 6633 | * Show Jetpack icon if the user is linked. |
||
| 6634 | */ |
||
| 6635 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 6647 | |||
| 6648 | /* |
||
| 6649 | * Style the Jetpack user column |
||
| 6650 | */ |
||
| 6651 | function jetpack_user_col_style() { |
||
| 6664 | |||
| 6665 | } |
||
| 6666 |
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.