Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Jetpack { |
||
| 26 | public $xmlrpc_server = null; |
||
| 27 | |||
| 28 | private $xmlrpc_verification = null; |
||
| 29 | |||
| 30 | public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA'] |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array The handles of styles that are concatenated into jetpack.css |
||
| 34 | */ |
||
| 35 | public $concatenated_style_handles = array( |
||
| 36 | 'jetpack-carousel', |
||
| 37 | 'grunion.css', |
||
| 38 | 'the-neverending-homepage', |
||
| 39 | 'jetpack_likes', |
||
| 40 | 'jetpack_related-posts', |
||
| 41 | 'sharedaddy', |
||
| 42 | 'jetpack-slideshow', |
||
| 43 | 'presentations', |
||
| 44 | 'jetpack-subscriptions', |
||
| 45 | 'tiled-gallery', |
||
| 46 | 'widget-conditions', |
||
| 47 | 'jetpack_display_posts_widget', |
||
| 48 | 'gravatar-profile-widget', |
||
| 49 | 'widget-grid-and-list', |
||
| 50 | 'jetpack-widgets', |
||
| 51 | 'goodreads-widget', |
||
| 52 | 'jetpack_social_media_icons_widget', |
||
| 53 | ); |
||
| 54 | |||
| 55 | public $plugins_to_deactivate = array( |
||
| 56 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 57 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
| 58 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
| 59 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
| 60 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
| 61 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
| 62 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
| 63 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
| 64 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
| 65 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
| 66 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
| 67 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
| 68 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
| 69 | 'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ), |
||
| 70 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
| 71 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
| 72 | ); |
||
| 73 | |||
| 74 | static $capability_translations = array( |
||
|
|
|||
| 75 | 'administrator' => 'manage_options', |
||
| 76 | 'editor' => 'edit_others_posts', |
||
| 77 | 'author' => 'publish_posts', |
||
| 78 | 'contributor' => 'edit_posts', |
||
| 79 | 'subscriber' => 'read', |
||
| 80 | ); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
| 84 | * if the plugins are active. Used by filter_default_modules |
||
| 85 | * |
||
| 86 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
| 87 | * change `module-slug` and add this to your plugin: |
||
| 88 | * |
||
| 89 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
| 90 | * function my_jetpack_get_default_modules( $modules ) { |
||
| 91 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
| 92 | * } |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | private $conflicting_plugins = array( |
||
| 97 | 'comments' => array( |
||
| 98 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
| 99 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
| 100 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
| 101 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
| 102 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
| 103 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
| 104 | ), |
||
| 105 | 'contact-form' => array( |
||
| 106 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
| 107 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
| 108 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
| 109 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
| 110 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
| 111 | ), |
||
| 112 | 'minileven' => array( |
||
| 113 | 'WPtouch' => 'wptouch/wptouch.php', |
||
| 114 | ), |
||
| 115 | 'latex' => array( |
||
| 116 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
| 117 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
| 118 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
| 119 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
| 120 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
| 121 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
| 122 | ), |
||
| 123 | 'protect' => array( |
||
| 124 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
| 125 | 'Captcha' => 'captcha/captcha.php', |
||
| 126 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
| 127 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
| 128 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
| 129 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
| 130 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
| 131 | 'Security-protection' => 'security-protection/security-protection.php', |
||
| 132 | 'Login Security' => 'login-security/login-security.php', |
||
| 133 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
| 134 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
| 135 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
| 136 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
| 137 | ), |
||
| 138 | 'random-redirect' => array( |
||
| 139 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
| 140 | ), |
||
| 141 | 'related-posts' => array( |
||
| 142 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
| 143 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
| 144 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
| 145 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
| 146 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
| 147 | 'outbrain' => 'outbrain/outbrain.php', |
||
| 148 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 149 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
| 150 | ), |
||
| 151 | 'sharedaddy' => array( |
||
| 152 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
| 153 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
| 154 | 'ShareThis' => 'share-this/sharethis.php', |
||
| 155 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
| 156 | ), |
||
| 157 | 'verification-tools' => array( |
||
| 158 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 159 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 160 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 161 | ), |
||
| 162 | 'widget-visibility' => array( |
||
| 163 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
| 164 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
| 165 | ), |
||
| 166 | 'sitemaps' => array( |
||
| 167 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
| 168 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
| 169 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
| 170 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
| 171 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
| 172 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
| 173 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
| 174 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
| 175 | 'Sitemap' => 'sitemap/sitemap.php', |
||
| 176 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
| 177 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
| 178 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
| 179 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
| 180 | ), |
||
| 181 | ); |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
| 185 | * |
||
| 186 | * Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate |
||
| 187 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
| 188 | * |
||
| 189 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
| 190 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
| 191 | */ |
||
| 192 | private $open_graph_conflicting_plugins = array( |
||
| 193 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
| 194 | // 2 Click Social Media Buttons |
||
| 195 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
| 196 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
| 197 | 'autodescription/autodescription.php', // The SEO Framework |
||
| 198 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
| 199 | 'facebook/facebook.php', // Facebook (official plugin) |
||
| 200 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
| 201 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
| 202 | // Facebook Featured Image & OG Meta Tags |
||
| 203 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
| 204 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
| 205 | // Facebook Open Graph Meta Tags for WordPress |
||
| 206 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
| 207 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
| 208 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
| 209 | // Fedmich's Facebook Open Graph Meta |
||
| 210 | 'header-footer/plugin.php', // Header and Footer |
||
| 211 | 'network-publisher/networkpub.php', // Network Publisher |
||
| 212 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
| 213 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
| 214 | // NextScripts SNAP |
||
| 215 | 'opengraph/opengraph.php', // Open Graph |
||
| 216 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
| 217 | // Open Graph Protocol Framework |
||
| 218 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
| 219 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
| 220 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
| 221 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
| 222 | 'sharepress/sharepress.php', // SharePress |
||
| 223 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
| 224 | 'social-discussions/social-discussions.php', // Social Discussions |
||
| 225 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
| 226 | 'socialize/socialize.php', // Socialize |
||
| 227 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
| 228 | // Tweet, Like, Google +1 and Share |
||
| 229 | 'wordbooker/wordbooker.php', // Wordbooker |
||
| 230 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
| 231 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
| 232 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
| 233 | // WP Facebook Like Send & Open Graph Meta |
||
| 234 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
| 235 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
| 236 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
| 237 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php' // WP Facebook Like Button |
||
| 238 | ); |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
| 242 | */ |
||
| 243 | private $twitter_cards_conflicting_plugins = array( |
||
| 244 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
| 245 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
| 246 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
| 247 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
| 248 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
| 249 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
| 250 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
| 251 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
| 252 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
| 253 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
| 254 | ); |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Message to display in admin_notice |
||
| 258 | * @var string |
||
| 259 | */ |
||
| 260 | public $message = ''; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Error to display in admin_notice |
||
| 264 | * @var string |
||
| 265 | */ |
||
| 266 | public $error = ''; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Modules that need more privacy description. |
||
| 270 | * @var string |
||
| 271 | */ |
||
| 272 | public $privacy_checks = ''; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Stats to record once the page loads |
||
| 276 | * |
||
| 277 | * @var array |
||
| 278 | */ |
||
| 279 | public $stats = array(); |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Jetpack_Sync object |
||
| 283 | */ |
||
| 284 | public $sync; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Verified data for JSON authorization request |
||
| 288 | */ |
||
| 289 | public $json_api_authorization_request = array(); |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Holds the singleton instance of this class |
||
| 293 | * @since 2.3.3 |
||
| 294 | * @var Jetpack |
||
| 295 | */ |
||
| 296 | static $instance = false; |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Singleton |
||
| 300 | * @static |
||
| 301 | */ |
||
| 302 | public static function init() { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Must never be called statically |
||
| 314 | */ |
||
| 315 | function plugin_upgrade() { |
||
| 332 | |||
| 333 | static function activate_manage( ) { |
||
| 340 | |||
| 341 | static function update_active_modules( $modules ) { |
||
| 395 | |||
| 396 | static function delete_active_modules() { |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Constructor. Initializes WordPress hooks |
||
| 402 | */ |
||
| 403 | private function __construct() { |
||
| 533 | |||
| 534 | function jetpack_admin_ajax_tracks_callback() { |
||
| 553 | |||
| 554 | /** |
||
| 555 | * The callback for the JITM ajax requests. |
||
| 556 | */ |
||
| 557 | function jetpack_jitm_ajax_callback() { |
||
| 614 | |||
| 615 | /** |
||
| 616 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
| 617 | */ |
||
| 618 | function __destruct() { |
||
| 623 | |||
| 624 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
| 690 | |||
| 691 | function require_jetpack_authentication() { |
||
| 692 | // Don't let anyone authenticate |
||
| 693 | $_COOKIE = array(); |
||
| 694 | remove_all_filters( 'authenticate' ); |
||
| 695 | remove_all_actions( 'wp_login_failed' ); |
||
| 696 | |||
| 697 | if ( Jetpack::is_active() ) { |
||
| 698 | // Allow Jetpack authentication |
||
| 699 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
| 700 | } |
||
| 701 | } |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Load language files |
||
| 705 | * @action plugins_loaded |
||
| 706 | */ |
||
| 707 | public static function plugin_textdomain() { |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Register assets for use in various modules and the Jetpack admin page. |
||
| 714 | * |
||
| 715 | * @uses wp_script_is, wp_register_script, plugins_url |
||
| 716 | * @action wp_loaded |
||
| 717 | * @return null |
||
| 718 | */ |
||
| 719 | public function register_assets() { |
||
| 720 | View Code Duplication | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
|
| 721 | wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' ); |
||
| 722 | } |
||
| 723 | |||
| 724 | View Code Duplication | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
|
| 725 | wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' ); |
||
| 726 | } |
||
| 727 | |||
| 728 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
| 729 | wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); |
||
| 730 | } |
||
| 731 | |||
| 732 | View Code Duplication | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
|
| 733 | wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '4.0.0', true ); |
||
| 734 | } |
||
| 735 | |||
| 736 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
| 737 | wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); |
||
| 738 | |||
| 739 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
| 740 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
| 741 | if ( ! is_numeric( $fb_app_id ) ) { |
||
| 742 | $fb_app_id = ''; |
||
| 743 | } |
||
| 744 | wp_localize_script( |
||
| 745 | 'jetpack-facebook-embed', |
||
| 746 | 'jpfbembed', |
||
| 747 | array( |
||
| 748 | 'appid' => $fb_app_id, |
||
| 749 | 'locale' => $this->get_locale(), |
||
| 750 | ) |
||
| 751 | ); |
||
| 752 | } |
||
| 753 | |||
| 754 | /** |
||
| 755 | * As jetpack_register_genericons is by default fired off a hook, |
||
| 756 | * the hook may have already fired by this point. |
||
| 757 | * So, let's just trigger it manually. |
||
| 758 | */ |
||
| 759 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
| 760 | jetpack_register_genericons(); |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Register the social logos |
||
| 764 | */ |
||
| 765 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
| 766 | jetpack_register_social_logos(); |
||
| 767 | |||
| 768 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
| 769 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
| 770 | } |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Guess locale from language code. |
||
| 774 | * |
||
| 775 | * @param string $lang Language code. |
||
| 776 | * @return string|bool |
||
| 777 | */ |
||
| 778 | function guess_locale_from_lang( $lang ) { |
||
| 779 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
| 780 | return 'en_US'; |
||
| 781 | } |
||
| 782 | |||
| 783 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
| 784 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
| 785 | return false; |
||
| 786 | } |
||
| 787 | |||
| 788 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
| 789 | } |
||
| 790 | |||
| 791 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 792 | // WP.com: get_locale() returns 'it' |
||
| 793 | $locale = GP_Locales::by_slug( $lang ); |
||
| 794 | } else { |
||
| 795 | // Jetpack: get_locale() returns 'it_IT'; |
||
| 796 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
| 797 | } |
||
| 798 | |||
| 799 | if ( ! $locale ) { |
||
| 800 | return false; |
||
| 801 | } |
||
| 802 | |||
| 803 | if ( empty( $locale->facebook_locale ) ) { |
||
| 804 | if ( empty( $locale->wp_locale ) ) { |
||
| 805 | return false; |
||
| 806 | } else { |
||
| 807 | // Facebook SDK is smart enough to fall back to en_US if a |
||
| 808 | // locale isn't supported. Since supported Facebook locales |
||
| 809 | // can fall out of sync, we'll attempt to use the known |
||
| 810 | // wp_locale value and rely on said fallback. |
||
| 811 | return $locale->wp_locale; |
||
| 812 | } |
||
| 813 | } |
||
| 814 | |||
| 815 | return $locale->facebook_locale; |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Get the locale. |
||
| 820 | * |
||
| 821 | * @return string|bool |
||
| 822 | */ |
||
| 823 | function get_locale() { |
||
| 832 | |||
| 833 | /** |
||
| 834 | * Device Pixels support |
||
| 835 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
| 836 | */ |
||
| 837 | function devicepx() { |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
| 845 | * @param bool $option |
||
| 846 | * @return string |
||
| 847 | */ |
||
| 848 | public function jetpack_main_network_site_option( $option ) { |
||
| 851 | /** |
||
| 852 | * Network Name. |
||
| 853 | */ |
||
| 854 | static function network_name( $option = null ) { |
||
| 858 | /** |
||
| 859 | * Does the network allow new user and site registrations. |
||
| 860 | * @return string |
||
| 861 | */ |
||
| 862 | static function network_allow_new_registrations( $option = null ) { |
||
| 865 | /** |
||
| 866 | * Does the network allow admins to add new users. |
||
| 867 | * @return boolian |
||
| 868 | */ |
||
| 869 | static function network_add_new_users( $option = null ) { |
||
| 872 | /** |
||
| 873 | * File upload psace left per site in MB. |
||
| 874 | * -1 means NO LIMIT. |
||
| 875 | * @return number |
||
| 876 | */ |
||
| 877 | static function network_site_upload_space( $option = null ) { |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Network allowed file types. |
||
| 884 | * @return string |
||
| 885 | */ |
||
| 886 | static function network_upload_file_types( $option = null ) { |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Maximum file upload size set by the network. |
||
| 892 | * @return number |
||
| 893 | */ |
||
| 894 | static function network_max_upload_file_size( $option = null ) { |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Lets us know if a site allows admins to manage the network. |
||
| 901 | * @return array |
||
| 902 | */ |
||
| 903 | static function network_enable_administration_menus( $option = null ) { |
||
| 906 | |||
| 907 | /** |
||
| 908 | * Return whether we are dealing with a multi network setup or not. |
||
| 909 | * The reason we are type casting this is because we want to avoid the situation where |
||
| 910 | * the result is false since when is_main_network_option return false it cases |
||
| 911 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
| 912 | * database which could be set to anything as opposed to what this function returns. |
||
| 913 | * @param bool $option |
||
| 914 | * |
||
| 915 | * @return boolean |
||
| 916 | */ |
||
| 917 | public function is_main_network_option( $option ) { |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
| 924 | * |
||
| 925 | * @param string $option |
||
| 926 | * @return boolean |
||
| 927 | */ |
||
| 928 | public function is_multisite( $option ) { |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Implemented since there is no core is multi network function |
||
| 934 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
| 935 | * |
||
| 936 | * @since 3.3 |
||
| 937 | * @return boolean |
||
| 938 | */ |
||
| 939 | public static function is_multi_network() { |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
| 957 | * @return null |
||
| 958 | */ |
||
| 959 | function update_jetpack_main_network_site_option() { |
||
| 962 | /** |
||
| 963 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
| 964 | * |
||
| 965 | */ |
||
| 966 | function update_jetpack_network_settings() { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Get back if the current site is single user site. |
||
| 973 | * |
||
| 974 | * @return bool |
||
| 975 | */ |
||
| 976 | public static function is_single_user_site() { |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Returns true if the site has file write access false otherwise. |
||
| 984 | * @return string ( '1' | '0' ) |
||
| 985 | **/ |
||
| 986 | public static function file_system_write_access() { |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Finds out if a site is using a version control system. |
||
| 1009 | * @return string ( '1' | '0' ) |
||
| 1010 | **/ |
||
| 1011 | public static function is_version_controlled() { |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Determines whether the current theme supports featured images or not. |
||
| 1018 | * @return string ( '1' | '0' ) |
||
| 1019 | */ |
||
| 1020 | public static function featured_images_enabled() { |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * jetpack_updates is saved in the following schema: |
||
| 1027 | * |
||
| 1028 | * array ( |
||
| 1029 | * 'plugins' => (int) Number of plugin updates available. |
||
| 1030 | * 'themes' => (int) Number of theme updates available. |
||
| 1031 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
| 1032 | * 'translations' => (int) Number of translation updates available. |
||
| 1033 | * 'total' => (int) Total of all available updates. |
||
| 1034 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
| 1035 | * ) |
||
| 1036 | * @return array |
||
| 1037 | */ |
||
| 1038 | public static function get_updates() { |
||
| 1055 | |||
| 1056 | public static function get_update_details() { |
||
| 1064 | |||
| 1065 | public static function refresh_update_data() { |
||
| 1069 | |||
| 1070 | public static function refresh_theme_data() { |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Is Jetpack active? |
||
| 1076 | */ |
||
| 1077 | public static function is_active() { |
||
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Is Jetpack in development (offline) mode? |
||
| 1083 | */ |
||
| 1084 | public static function is_development_mode() { |
||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Get Jetpack development mode notice text and notice class. |
||
| 1108 | * |
||
| 1109 | * Mirrors the checks made in Jetpack::is_development_mode |
||
| 1110 | * |
||
| 1111 | */ |
||
| 1112 | public static function show_development_mode_notice() { |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Whether Jetpack's version maps to a public release, or a development version. |
||
| 1155 | */ |
||
| 1156 | public static function is_development_version() { |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
| 1162 | */ |
||
| 1163 | public static function is_user_connected( $user_id = false ) { |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Get the wpcom user data of the current|specified connected user. |
||
| 1174 | */ |
||
| 1175 | public static function get_connected_user_data( $user_id = null ) { |
||
| 1176 | if ( ! $user_id ) { |
||
| 1177 | $user_id = get_current_user_id(); |
||
| 1178 | } |
||
| 1179 | |||
| 1180 | $transient_key = "jetpack_connected_user_data_$user_id"; |
||
| 1181 | |||
| 1182 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
||
| 1183 | return $cached_user_data; |
||
| 1184 | } |
||
| 1185 | |||
| 1186 | Jetpack::load_xml_rpc_client(); |
||
| 1187 | $xml = new Jetpack_IXR_Client( array( |
||
| 1188 | 'user_id' => $user_id, |
||
| 1189 | ) ); |
||
| 1190 | $xml->query( 'wpcom.getUser' ); |
||
| 1191 | if ( ! $xml->isError() ) { |
||
| 1192 | $user_data = $xml->getResponse(); |
||
| 1193 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
||
| 1194 | return $user_data; |
||
| 1195 | } |
||
| 1196 | |||
| 1197 | return false; |
||
| 1198 | } |
||
| 1199 | |||
| 1200 | /** |
||
| 1201 | * Get the wpcom email of the current|specified connected user. |
||
| 1202 | */ |
||
| 1203 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Get the wpcom email of the master user. |
||
| 1220 | */ |
||
| 1221 | public static function get_master_user_email() { |
||
| 1228 | |||
| 1229 | function current_user_is_connection_owner() { |
||
| 1233 | |||
| 1234 | /** |
||
| 1235 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
| 1236 | */ |
||
| 1237 | function extra_oembed_providers() { |
||
| 1245 | |||
| 1246 | /** |
||
| 1247 | * Synchronize connected user role changes |
||
| 1248 | */ |
||
| 1249 | function user_role_change( $user_id ) { |
||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Loads the currently active modules. |
||
| 1256 | */ |
||
| 1257 | public static function load_modules() { |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * Check if Jetpack's REST API compat file should be included |
||
| 1344 | * @action plugins_loaded |
||
| 1345 | * @return null |
||
| 1346 | */ |
||
| 1347 | public function check_rest_api_compat() { |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Gets all plugins currently active in values, regardless of whether they're |
||
| 1366 | * traditionally activated or network activated. |
||
| 1367 | * |
||
| 1368 | * @todo Store the result in core's object cache maybe? |
||
| 1369 | */ |
||
| 1370 | public static function get_active_plugins() { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Gets and parses additional plugin data to send with the heartbeat data |
||
| 1389 | * |
||
| 1390 | * @since 3.8.1 |
||
| 1391 | * |
||
| 1392 | * @return array Array of plugin data |
||
| 1393 | */ |
||
| 1394 | public static function get_parsed_plugin_data() { |
||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Gets and parses theme data to send with the heartbeat data |
||
| 1418 | * |
||
| 1419 | * @since 3.8.1 |
||
| 1420 | * |
||
| 1421 | * @return array Array of theme data |
||
| 1422 | */ |
||
| 1423 | public static function get_parsed_theme_data() { |
||
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Checks whether a specific plugin is active. |
||
| 1448 | * |
||
| 1449 | * We don't want to store these in a static variable, in case |
||
| 1450 | * there are switch_to_blog() calls involved. |
||
| 1451 | */ |
||
| 1452 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Check if Jetpack's Open Graph tags should be used. |
||
| 1458 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
| 1459 | * |
||
| 1460 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1461 | * @action plugins_loaded |
||
| 1462 | * @return null |
||
| 1463 | */ |
||
| 1464 | public function check_open_graph() { |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Check if Jetpack's Twitter tags should be used. |
||
| 1494 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
| 1495 | * |
||
| 1496 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
| 1497 | * @action plugins_loaded |
||
| 1498 | * @return null |
||
| 1499 | */ |
||
| 1500 | public function check_twitter_tags() { |
||
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Allows plugins to submit security reports. |
||
| 1527 | * |
||
| 1528 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
| 1529 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
| 1530 | * @param array $args See definitions above |
||
| 1531 | */ |
||
| 1532 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
| 1535 | |||
| 1536 | /* Jetpack Options API */ |
||
| 1537 | |||
| 1538 | public static function get_option_names( $type = 'compact' ) { |
||
| 1541 | |||
| 1542 | /** |
||
| 1543 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
| 1544 | * |
||
| 1545 | * @param string $name Option name |
||
| 1546 | * @param mixed $default (optional) |
||
| 1547 | */ |
||
| 1548 | public static function get_option( $name, $default = false ) { |
||
| 1551 | |||
| 1552 | /** |
||
| 1553 | * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action |
||
| 1554 | * Does some extra verification so urls (such as those to public-api, register, etc) can't just be crafted |
||
| 1555 | * $name must be a registered option name. |
||
| 1556 | */ |
||
| 1557 | public static function create_nonce( $name ) { |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
| 1574 | * |
||
| 1575 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
| 1576 | * @param string $name Option name |
||
| 1577 | * @param mixed $value Option value |
||
| 1578 | */ |
||
| 1579 | public static function update_option( $name, $value ) { |
||
| 1583 | |||
| 1584 | /** |
||
| 1585 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
| 1586 | * |
||
| 1587 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
| 1588 | * @param array $array array( option name => option value, ... ) |
||
| 1589 | */ |
||
| 1590 | public static function update_options( $array ) { |
||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Deletes the given option. May be passed multiple option names as an array. |
||
| 1597 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
| 1598 | * |
||
| 1599 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
| 1600 | * @param string|array $names |
||
| 1601 | */ |
||
| 1602 | public static function delete_option( $names ) { |
||
| 1606 | |||
| 1607 | /** |
||
| 1608 | * Enters a user token into the user_tokens option |
||
| 1609 | * |
||
| 1610 | * @param int $user_id |
||
| 1611 | * @param string $token |
||
| 1612 | * return bool |
||
| 1613 | */ |
||
| 1614 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Returns an array of all PHP files in the specified absolute path. |
||
| 1631 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
| 1632 | * |
||
| 1633 | * @param string $absolute_path The absolute path of the directory to search. |
||
| 1634 | * @return array Array of absolute paths to the PHP files. |
||
| 1635 | */ |
||
| 1636 | public static function glob_php( $absolute_path ) { |
||
| 1665 | |||
| 1666 | public static function activate_new_modules( $redirect = false ) { |
||
| 1724 | |||
| 1725 | /** |
||
| 1726 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
| 1727 | * Make sure to tuck away module "library" files in a sub-directory. |
||
| 1728 | */ |
||
| 1729 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
| 1786 | |||
| 1787 | /** |
||
| 1788 | * Default modules loaded on activation. |
||
| 1789 | */ |
||
| 1790 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * Checks activated modules during auto-activation to determine |
||
| 1824 | * if any of those modules are being deprecated. If so, close |
||
| 1825 | * them out, and add any replacement modules. |
||
| 1826 | * |
||
| 1827 | * Runs at priority 99 by default. |
||
| 1828 | * |
||
| 1829 | * This is run late, so that it can still activate a module if |
||
| 1830 | * the new module is a replacement for another that the user |
||
| 1831 | * currently has active, even if something at the normal priority |
||
| 1832 | * would kibosh everything. |
||
| 1833 | * |
||
| 1834 | * @since 2.6 |
||
| 1835 | * @uses jetpack_get_default_modules filter |
||
| 1836 | * @param array $modules |
||
| 1837 | * @return array |
||
| 1838 | */ |
||
| 1839 | function handle_deprecated_modules( $modules ) { |
||
| 1865 | |||
| 1866 | /** |
||
| 1867 | * Checks activated plugins during auto-activation to determine |
||
| 1868 | * if any of those plugins are in the list with a corresponding module |
||
| 1869 | * that is not compatible with the plugin. The module will not be allowed |
||
| 1870 | * to auto-activate. |
||
| 1871 | * |
||
| 1872 | * @since 2.6 |
||
| 1873 | * @uses jetpack_get_default_modules filter |
||
| 1874 | * @param array $modules |
||
| 1875 | * @return array |
||
| 1876 | */ |
||
| 1877 | function filter_default_modules( $modules ) { |
||
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Extract a module's slug from its full path. |
||
| 1904 | */ |
||
| 1905 | public static function get_module_slug( $file ) { |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * Generate a module's path from its slug. |
||
| 1911 | */ |
||
| 1912 | public static function get_module_path( $slug ) { |
||
| 1915 | |||
| 1916 | /** |
||
| 1917 | * Load module data from module file. Headers differ from WordPress |
||
| 1918 | * plugin headers to avoid them being identified as standalone |
||
| 1919 | * plugins on the WordPress plugins page. |
||
| 1920 | */ |
||
| 1921 | public static function get_module( $module ) { |
||
| 2004 | |||
| 2005 | /** |
||
| 2006 | * Like core's get_file_data implementation, but caches the result. |
||
| 2007 | */ |
||
| 2008 | public static function get_file_data( $file, $headers ) { |
||
| 2029 | |||
| 2030 | /** |
||
| 2031 | * Return translated module tag. |
||
| 2032 | * |
||
| 2033 | * @param string $tag Tag as it appears in each module heading. |
||
| 2034 | * |
||
| 2035 | * @return mixed |
||
| 2036 | */ |
||
| 2037 | public static function translate_module_tag( $tag ) { |
||
| 2040 | |||
| 2041 | /** |
||
| 2042 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
| 2043 | * |
||
| 2044 | * @since 3.9.2 |
||
| 2045 | * |
||
| 2046 | * @param array $modules |
||
| 2047 | * |
||
| 2048 | * @return string|void |
||
| 2049 | */ |
||
| 2050 | public static function get_translated_modules( $modules ) { |
||
| 2063 | |||
| 2064 | /** |
||
| 2065 | * Get a list of activated modules as an array of module slugs. |
||
| 2066 | */ |
||
| 2067 | public static function get_active_modules() { |
||
| 2084 | |||
| 2085 | /** |
||
| 2086 | * Check whether or not a Jetpack module is active. |
||
| 2087 | * |
||
| 2088 | * @param string $module The slug of a Jetpack module. |
||
| 2089 | * @return bool |
||
| 2090 | * |
||
| 2091 | * @static |
||
| 2092 | */ |
||
| 2093 | public static function is_module_active( $module ) { |
||
| 2096 | |||
| 2097 | public static function is_module( $module ) { |
||
| 2100 | |||
| 2101 | /** |
||
| 2102 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
| 2103 | * |
||
| 2104 | * @param bool $catch True to start catching, False to stop. |
||
| 2105 | * |
||
| 2106 | * @static |
||
| 2107 | */ |
||
| 2108 | public static function catch_errors( $catch ) { |
||
| 2121 | |||
| 2122 | /** |
||
| 2123 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
| 2124 | */ |
||
| 2125 | public static function catch_errors_on_shutdown() { |
||
| 2128 | |||
| 2129 | public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array(), $redirect = true ) { |
||
| 2130 | $jetpack = Jetpack::init(); |
||
| 2131 | |||
| 2132 | $modules = Jetpack::get_default_modules( $min_version, $max_version ); |
||
| 2133 | $modules = array_merge( $other_modules, $modules ); |
||
| 2134 | |||
| 2135 | // Look for standalone plugins and disable if active. |
||
| 2136 | |||
| 2137 | $to_deactivate = array(); |
||
| 2138 | foreach ( $modules as $module ) { |
||
| 2139 | if ( isset( $jetpack->plugins_to_deactivate[$module] ) ) { |
||
| 2140 | $to_deactivate[$module] = $jetpack->plugins_to_deactivate[$module]; |
||
| 2141 | } |
||
| 2142 | } |
||
| 2143 | |||
| 2144 | $deactivated = array(); |
||
| 2145 | foreach ( $to_deactivate as $module => $deactivate_me ) { |
||
| 2146 | list( $probable_file, $probable_title ) = $deactivate_me; |
||
| 2147 | if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) { |
||
| 2148 | $deactivated[] = $module; |
||
| 2149 | } |
||
| 2150 | } |
||
| 2151 | |||
| 2152 | if ( $deactivated && $redirect ) { |
||
| 2153 | Jetpack::state( 'deactivated_plugins', join( ',', $deactivated ) ); |
||
| 2154 | |||
| 2155 | $url = add_query_arg( |
||
| 2156 | array( |
||
| 2157 | 'action' => 'activate_default_modules', |
||
| 2158 | '_wpnonce' => wp_create_nonce( 'activate_default_modules' ), |
||
| 2159 | ), |
||
| 2160 | add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), Jetpack::admin_url( 'page=jetpack' ) ) |
||
| 2161 | ); |
||
| 2162 | wp_safe_redirect( $url ); |
||
| 2163 | exit; |
||
| 2164 | } |
||
| 2165 | |||
| 2166 | /** |
||
| 2167 | * Fires before default modules are activated. |
||
| 2168 | * |
||
| 2169 | * @since 1.9.0 |
||
| 2170 | * |
||
| 2171 | * @param string $min_version Minimum version number required to use modules. |
||
| 2172 | * @param string $max_version Maximum version number required to use modules. |
||
| 2173 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
| 2174 | */ |
||
| 2175 | do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
| 2176 | |||
| 2177 | // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating |
||
| 2178 | Jetpack::restate(); |
||
| 2179 | Jetpack::catch_errors( true ); |
||
| 2180 | |||
| 2181 | $active = Jetpack::get_active_modules(); |
||
| 2182 | |||
| 2183 | foreach ( $modules as $module ) { |
||
| 2184 | if ( did_action( "jetpack_module_loaded_$module" ) ) { |
||
| 2185 | $active[] = $module; |
||
| 2186 | self::update_active_modules( $active ); |
||
| 2187 | continue; |
||
| 2188 | } |
||
| 2189 | |||
| 2190 | if ( in_array( $module, $active ) ) { |
||
| 2191 | $module_info = Jetpack::get_module( $module ); |
||
| 2192 | if ( ! $module_info['deactivate'] ) { |
||
| 2193 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
| 2194 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
| 2195 | $active_state = explode( ',', $active_state ); |
||
| 2196 | } else { |
||
| 2197 | $active_state = array(); |
||
| 2198 | } |
||
| 2199 | $active_state[] = $module; |
||
| 2200 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
| 2201 | } |
||
| 2202 | continue; |
||
| 2203 | } |
||
| 2204 | |||
| 2205 | $file = Jetpack::get_module_path( $module ); |
||
| 2206 | if ( ! file_exists( $file ) ) { |
||
| 2207 | continue; |
||
| 2208 | } |
||
| 2209 | |||
| 2210 | // we'll override this later if the plugin can be included without fatal error |
||
| 2211 | if ( $redirect ) { |
||
| 2212 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 2213 | } |
||
| 2214 | Jetpack::state( 'error', 'module_activation_failed' ); |
||
| 2215 | Jetpack::state( 'module', $module ); |
||
| 2216 | ob_start(); |
||
| 2217 | require $file; |
||
| 2218 | |||
| 2219 | $active[] = $module; |
||
| 2220 | $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules'; |
||
| 2221 | View Code Duplication | if ( $active_state = Jetpack::state( $state ) ) { |
|
| 2222 | $active_state = explode( ',', $active_state ); |
||
| 2223 | } else { |
||
| 2224 | $active_state = array(); |
||
| 2225 | } |
||
| 2226 | $active_state[] = $module; |
||
| 2227 | Jetpack::state( $state, implode( ',', $active_state ) ); |
||
| 2228 | Jetpack::update_active_modules( $active ); |
||
| 2229 | |||
| 2230 | ob_end_clean(); |
||
| 2231 | } |
||
| 2232 | Jetpack::state( 'error', false ); |
||
| 2233 | Jetpack::state( 'module', false ); |
||
| 2234 | Jetpack::catch_errors( false ); |
||
| 2235 | /** |
||
| 2236 | * Fires when default modules are activated. |
||
| 2237 | * |
||
| 2238 | * @since 1.9.0 |
||
| 2239 | * |
||
| 2240 | * @param string $min_version Minimum version number required to use modules. |
||
| 2241 | * @param string $max_version Maximum version number required to use modules. |
||
| 2242 | * @param array $other_modules Array of other modules to activate alongside the default modules. |
||
| 2243 | */ |
||
| 2244 | do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules ); |
||
| 2245 | } |
||
| 2246 | |||
| 2247 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
| 2248 | /** |
||
| 2249 | * Fires before a module is activated. |
||
| 2250 | * |
||
| 2251 | * @since 2.6.0 |
||
| 2252 | * |
||
| 2253 | * @param string $module Module slug. |
||
| 2254 | * @param bool $exit Should we exit after the module has been activated. Default to true. |
||
| 2255 | * @param bool $redirect Should the user be redirected after module activation? Default to true. |
||
| 2256 | */ |
||
| 2257 | do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); |
||
| 2258 | |||
| 2259 | $jetpack = Jetpack::init(); |
||
| 2260 | |||
| 2261 | if ( ! strlen( $module ) ) |
||
| 2262 | return false; |
||
| 2263 | |||
| 2264 | if ( ! Jetpack::is_module( $module ) ) |
||
| 2265 | return false; |
||
| 2266 | |||
| 2267 | // If it's already active, then don't do it again |
||
| 2268 | $active = Jetpack::get_active_modules(); |
||
| 2269 | foreach ( $active as $act ) { |
||
| 2270 | if ( $act == $module ) |
||
| 2271 | return true; |
||
| 2272 | } |
||
| 2273 | |||
| 2274 | $module_data = Jetpack::get_module( $module ); |
||
| 2275 | |||
| 2276 | if ( ! Jetpack::is_active() ) { |
||
| 2277 | if ( !Jetpack::is_development_mode() ) |
||
| 2278 | return false; |
||
| 2279 | |||
| 2280 | // If we're not connected but in development mode, make sure the module doesn't require a connection |
||
| 2281 | if ( Jetpack::is_development_mode() && $module_data['requires_connection'] ) |
||
| 2282 | return false; |
||
| 2283 | } |
||
| 2284 | |||
| 2285 | // Check and see if the old plugin is active |
||
| 2286 | if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { |
||
| 2287 | // Deactivate the old plugin |
||
| 2288 | if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[ $module ][0], $jetpack->plugins_to_deactivate[ $module ][1] ) ) { |
||
| 2289 | // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module |
||
| 2290 | // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. |
||
| 2291 | Jetpack::state( 'deactivated_plugins', $module ); |
||
| 2292 | wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); |
||
| 2293 | exit; |
||
| 2294 | } |
||
| 2295 | } |
||
| 2296 | |||
| 2297 | // Check the file for fatal errors, a la wp-admin/plugins.php::activate |
||
| 2298 | Jetpack::state( 'module', $module ); |
||
| 2299 | Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error |
||
| 2300 | |||
| 2301 | Jetpack::catch_errors( true ); |
||
| 2302 | ob_start(); |
||
| 2303 | require Jetpack::get_module_path( $module ); |
||
| 2304 | /** This action is documented in class.jetpack.php */ |
||
| 2305 | do_action( 'jetpack_activate_module', $module ); |
||
| 2306 | $active[] = $module; |
||
| 2307 | Jetpack::update_active_modules( $active ); |
||
| 2308 | |||
| 2309 | Jetpack::state( 'error', false ); // the override |
||
| 2310 | ob_end_clean(); |
||
| 2311 | Jetpack::catch_errors( false ); |
||
| 2312 | |||
| 2313 | // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. |
||
| 2314 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
| 2315 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
| 2316 | |||
| 2317 | //Jump start is being dismissed send data to MC Stats |
||
| 2318 | $jetpack->stat( 'jumpstart', 'manual,'.$module ); |
||
| 2319 | |||
| 2320 | $jetpack->do_stats( 'server_side' ); |
||
| 2321 | } |
||
| 2322 | |||
| 2323 | if ( $redirect ) { |
||
| 2324 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 2325 | } |
||
| 2326 | if ( $exit ) { |
||
| 2327 | exit; |
||
| 2328 | } |
||
| 2329 | return true; |
||
| 2330 | } |
||
| 2331 | |||
| 2332 | function activate_module_actions( $module ) { |
||
| 2333 | _deprecated_function( __METHOD__, 'jeptack-4.2' ); |
||
| 2334 | } |
||
| 2335 | |||
| 2336 | public static function deactivate_module( $module ) { |
||
| 2337 | /** |
||
| 2338 | * Fires when a module is deactivated. |
||
| 2339 | * |
||
| 2340 | * @since 1.9.0 |
||
| 2341 | * |
||
| 2342 | * @param string $module Module slug. |
||
| 2343 | */ |
||
| 2344 | do_action( 'jetpack_pre_deactivate_module', $module ); |
||
| 2345 | |||
| 2346 | $jetpack = Jetpack::init(); |
||
| 2347 | |||
| 2348 | $active = Jetpack::get_active_modules(); |
||
| 2349 | $new = array_filter( array_diff( $active, (array) $module ) ); |
||
| 2350 | |||
| 2351 | // A flag for Jump Start so it's not shown again. |
||
| 2352 | View Code Duplication | if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { |
|
| 2353 | Jetpack_Options::update_option( 'jumpstart', 'jetpack_action_taken' ); |
||
| 2354 | |||
| 2355 | //Jump start is being dismissed send data to MC Stats |
||
| 2356 | $jetpack->stat( 'jumpstart', 'manual,deactivated-'.$module ); |
||
| 2357 | |||
| 2358 | $jetpack->do_stats( 'server_side' ); |
||
| 2359 | } |
||
| 2360 | |||
| 2361 | return self::update_active_modules( $new ); |
||
| 2362 | } |
||
| 2363 | |||
| 2364 | public static function enable_module_configurable( $module ) { |
||
| 2368 | |||
| 2369 | public static function module_configuration_url( $module ) { |
||
| 2373 | |||
| 2374 | public static function module_configuration_load( $module, $method ) { |
||
| 2378 | |||
| 2379 | public static function module_configuration_head( $module, $method ) { |
||
| 2383 | |||
| 2384 | public static function module_configuration_screen( $module, $method ) { |
||
| 2388 | |||
| 2389 | public static function module_configuration_activation_screen( $module, $method ) { |
||
| 2393 | |||
| 2394 | /* Installation */ |
||
| 2395 | |||
| 2396 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
| 2436 | |||
| 2437 | /** |
||
| 2438 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
| 2439 | * @static |
||
| 2440 | */ |
||
| 2441 | public static function plugin_activation( $network_wide ) { |
||
| 2453 | /** |
||
| 2454 | * Runs before bumping version numbers up to a new version |
||
| 2455 | * @param (string) $version Version:timestamp |
||
| 2456 | * @param (string) $old_version Old Version:timestamp or false if not set yet. |
||
| 2457 | * @return null [description] |
||
| 2458 | */ |
||
| 2459 | public static function do_version_bump( $version, $old_version ) { |
||
| 2466 | |||
| 2467 | /** |
||
| 2468 | * Sets the internal version number and activation state. |
||
| 2469 | * @static |
||
| 2470 | */ |
||
| 2471 | public static function plugin_initialize() { |
||
| 2487 | |||
| 2488 | /** |
||
| 2489 | * Removes all connection options |
||
| 2490 | * @static |
||
| 2491 | */ |
||
| 2492 | public static function plugin_deactivation( ) { |
||
| 2501 | |||
| 2502 | /** |
||
| 2503 | * Disconnects from the Jetpack servers. |
||
| 2504 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
| 2505 | * @static |
||
| 2506 | */ |
||
| 2507 | public static function disconnect( $update_activated_state = true ) { |
||
| 2557 | |||
| 2558 | /** |
||
| 2559 | * Unlinks the current user from the linked WordPress.com user |
||
| 2560 | */ |
||
| 2561 | public static function unlink_user( $user_id = null ) { |
||
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
| 2595 | */ |
||
| 2596 | public static function try_registration() { |
||
| 2621 | |||
| 2622 | /** |
||
| 2623 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
| 2624 | * |
||
| 2625 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
| 2626 | */ |
||
| 2627 | public static function log( $code, $data = null ) { |
||
| 2667 | |||
| 2668 | /** |
||
| 2669 | * Get the internal event log. |
||
| 2670 | * |
||
| 2671 | * @param $event (string) - only return the specific log events |
||
| 2672 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
| 2673 | * |
||
| 2674 | * @return array of log events || WP_Error for invalid params |
||
| 2675 | */ |
||
| 2676 | public static function get_log( $event = false, $num = false ) { |
||
| 2712 | |||
| 2713 | /** |
||
| 2714 | * Log modification of important settings. |
||
| 2715 | */ |
||
| 2716 | public static function log_settings_change( $option, $old_value, $value ) { |
||
| 2723 | |||
| 2724 | /** |
||
| 2725 | * Return stat data for WPCOM sync |
||
| 2726 | */ |
||
| 2727 | public static function get_stat_data( $encode = true ) { |
||
| 2728 | $heartbeat_data = Jetpack_Heartbeat::generate_stats_array(); |
||
| 2729 | $additional_data = self::get_additional_stat_data(); |
||
| 2730 | |||
| 2731 | $merged_data = array_merge( $heartbeat_data, $additional_data ); |
||
| 2732 | |||
| 2733 | if ( $encode ) { |
||
| 2734 | return json_encode( $merged_data ); |
||
| 2735 | } |
||
| 2736 | |||
| 2737 | return $merged_data; |
||
| 2738 | } |
||
| 2739 | |||
| 2740 | /** |
||
| 2741 | * Get additional stat data to sync to WPCOM |
||
| 2742 | */ |
||
| 2743 | public static function get_additional_stat_data( $prefix = '' ) { |
||
| 2744 | $return["{$prefix}themes"] = Jetpack::get_parsed_theme_data(); |
||
| 2745 | $return["{$prefix}plugins-extra"] = Jetpack::get_parsed_plugin_data(); |
||
| 2746 | $return["{$prefix}users"] = count_users(); |
||
| 2747 | $return["{$prefix}site-count"] = 0; |
||
| 2748 | if ( function_exists( 'get_blog_count' ) ) { |
||
| 2749 | $return["{$prefix}site-count"] = get_blog_count(); |
||
| 2750 | } |
||
| 2751 | return $return; |
||
| 2752 | } |
||
| 2753 | |||
| 2754 | /* Admin Pages */ |
||
| 2755 | |||
| 2756 | function admin_init() { |
||
| 2810 | |||
| 2811 | function admin_body_class( $admin_body_class = '' ) { |
||
| 2819 | |||
| 2820 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
| 2823 | |||
| 2824 | function prepare_connect_notice() { |
||
| 2832 | /** |
||
| 2833 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
| 2834 | * |
||
| 2835 | * @return null |
||
| 2836 | */ |
||
| 2837 | function prepare_manage_jetpack_notice() { |
||
| 2842 | |||
| 2843 | function manage_activate_screen() { |
||
| 2846 | /** |
||
| 2847 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
| 2848 | * This function artificially throws errors for such cases (whitelisted). |
||
| 2849 | * |
||
| 2850 | * @param string $plugin The activated plugin. |
||
| 2851 | */ |
||
| 2852 | function throw_error_on_activate_plugin( $plugin ) { |
||
| 2876 | |||
| 2877 | function intercept_plugin_error_scrape_init() { |
||
| 2880 | |||
| 2881 | function intercept_plugin_error_scrape( $action, $result ) { |
||
| 2892 | |||
| 2893 | function add_remote_request_handlers() { |
||
| 2896 | |||
| 2897 | function remote_request_handlers() { |
||
| 2931 | |||
| 2932 | function upload_handler() { |
||
| 3017 | |||
| 3018 | /** |
||
| 3019 | * Add help to the Jetpack page |
||
| 3020 | * |
||
| 3021 | * @since Jetpack (1.2.3) |
||
| 3022 | * @return false if not the Jetpack page |
||
| 3023 | */ |
||
| 3024 | function admin_help() { |
||
| 3065 | |||
| 3066 | function admin_menu_css() { |
||
| 3069 | |||
| 3070 | function admin_menu_order() { |
||
| 3073 | |||
| 3074 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
| 3089 | |||
| 3090 | function admin_head() { |
||
| 3095 | |||
| 3096 | View Code Duplication | function admin_banner_styles() { |
|
| 3103 | |||
| 3104 | function plugin_action_links( $actions ) { |
||
| 3119 | |||
| 3120 | function admin_connect_notice() { |
||
| 3155 | |||
| 3156 | /** |
||
| 3157 | * This is the first banner |
||
| 3158 | * It should be visible only to user that can update the option |
||
| 3159 | * Are not connected |
||
| 3160 | * |
||
| 3161 | * @return null |
||
| 3162 | */ |
||
| 3163 | function admin_jetpack_manage_notice() { |
||
| 3164 | $screen = get_current_screen(); |
||
| 3165 | |||
| 3166 | // Don't show the connect notice on the jetpack settings page. |
||
| 3167 | if ( ! in_array( $screen->base, array( 'dashboard' ) ) || $screen->is_network || $screen->action ) |
||
| 3168 | return; |
||
| 3169 | |||
| 3170 | // Only show it if don't have the managment option set. |
||
| 3171 | // And not dismissed it already. |
||
| 3172 | if ( ! $this->can_display_jetpack_manage_notice() || Jetpack_Options::get_option( 'dismissed_manage_banner' ) ) { |
||
| 3173 | return; |
||
| 3174 | } |
||
| 3175 | |||
| 3176 | $opt_out_url = $this->opt_out_jetpack_manage_url(); |
||
| 3177 | $opt_in_url = $this->opt_in_jetpack_manage_url(); |
||
| 3178 | /** |
||
| 3179 | * I think it would be great to have different wordsing depending on where you are |
||
| 3180 | * for example if we show the notice on dashboard and a different one if we show it on Plugins screen |
||
| 3181 | * etc.. |
||
| 3182 | */ |
||
| 3183 | |||
| 3184 | ?> |
||
| 3185 | <div id="message" class="updated jp-banner"> |
||
| 3186 | <a href="<?php echo esc_url( $opt_out_url ); ?>" class="notice-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>"></a> |
||
| 3187 | <div class="jp-banner__description-container"> |
||
| 3188 | <h2 class="jp-banner__header"><?php esc_html_e( 'Jetpack Centralized Site Management', 'jetpack' ); ?></h2> |
||
| 3189 | <p class="jp-banner__description"><?php printf( __( 'Manage multiple Jetpack enabled sites from one single dashboard at wordpress.com. Allows all existing, connected Administrators to modify your site.', 'jetpack' ), 'https://jetpack.com/support/site-management' ); ?></p> |
||
| 3190 | <p class="jp-banner__button-container"> |
||
| 3191 | <a href="<?php echo esc_url( $opt_in_url ); ?>" class="button button-primary" id="wpcom-connect"><?php _e( 'Activate Jetpack Manage', 'jetpack' ); ?></a> |
||
| 3192 | <a href="https://jetpack.com/support/site-management" class="button" target="_blank" title="<?php esc_attr_e( 'Learn more about Jetpack Manage on Jetpack.com', 'jetpack' ); ?>"><?php _e( 'Learn more', 'jetpack' ); ?></a> |
||
| 3193 | </p> |
||
| 3194 | </div> |
||
| 3195 | </div> |
||
| 3196 | <?php |
||
| 3197 | } |
||
| 3198 | |||
| 3199 | /** |
||
| 3200 | * Returns the url that the user clicks to remove the notice for the big banner |
||
| 3201 | * @return (string) |
||
| 3202 | */ |
||
| 3203 | function opt_out_jetpack_manage_url() { |
||
| 3207 | /** |
||
| 3208 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
| 3209 | * @return (string) |
||
| 3210 | */ |
||
| 3211 | function opt_in_jetpack_manage_url() { |
||
| 3214 | |||
| 3215 | function opt_in_jetpack_manage_notice() { |
||
| 3225 | /** |
||
| 3226 | * Determines whether to show the notice of not true = display notice |
||
| 3227 | * @return (bool) |
||
| 3228 | */ |
||
| 3229 | function can_display_jetpack_manage_notice() { |
||
| 3251 | |||
| 3252 | function network_connect_notice() { |
||
| 3261 | |||
| 3262 | /* |
||
| 3263 | * Registration flow: |
||
| 3264 | * 1 - ::admin_page_load() action=register |
||
| 3265 | * 2 - ::try_registration() |
||
| 3266 | * 3 - ::register() |
||
| 3267 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
| 3268 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
| 3269 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
| 3270 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
| 3271 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
| 3272 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
| 3273 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
| 3274 | * jetpack_id, jetpack_secret, jetpack_public |
||
| 3275 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
| 3276 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
| 3277 | * 5 - user logs in with WP.com account |
||
| 3278 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
| 3279 | * - Jetpack_Client_Server::authorize() |
||
| 3280 | * - Jetpack_Client_Server::get_token() |
||
| 3281 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
| 3282 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
| 3283 | * - which responds with access_token, token_type, scope |
||
| 3284 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
| 3285 | * - Jetpack::activate_default_modules() |
||
| 3286 | * - Deactivates deprecated plugins |
||
| 3287 | * - Activates all default modules |
||
| 3288 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
| 3289 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
| 3290 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
| 3291 | * Done! |
||
| 3292 | */ |
||
| 3293 | |||
| 3294 | /** |
||
| 3295 | * Handles the page load events for the Jetpack admin page |
||
| 3296 | */ |
||
| 3297 | function admin_page_load() { |
||
| 3298 | $error = false; |
||
| 3299 | |||
| 3300 | // Make sure we have the right body class to hook stylings for subpages off of. |
||
| 3301 | add_filter( 'admin_body_class', array( __CLASS__, 'add_jetpack_pagestyles' ) ); |
||
| 3302 | |||
| 3303 | if ( ! empty( $_GET['jetpack_restate'] ) ) { |
||
| 3304 | // Should only be used in intermediate redirects to preserve state across redirects |
||
| 3305 | Jetpack::restate(); |
||
| 3306 | } |
||
| 3307 | |||
| 3308 | if ( isset( $_GET['connect_url_redirect'] ) ) { |
||
| 3309 | // User clicked in the iframe to link their accounts |
||
| 3310 | if ( ! Jetpack::is_user_connected() ) { |
||
| 3311 | $connect_url = $this->build_connect_url( true, false, 'iframe' ); |
||
| 3312 | if ( isset( $_GET['notes_iframe'] ) ) |
||
| 3313 | $connect_url .= '¬es_iframe'; |
||
| 3314 | wp_redirect( $connect_url ); |
||
| 3315 | exit; |
||
| 3316 | } else { |
||
| 3317 | if ( ! isset( $_GET['calypso_env'] ) ) { |
||
| 3318 | Jetpack::state( 'message', 'already_authorized' ); |
||
| 3319 | wp_safe_redirect( Jetpack::admin_url() ); |
||
| 3320 | } else { |
||
| 3321 | $connect_url = $this->build_connect_url( true, false, 'iframe' ); |
||
| 3322 | $connect_url .= '&already_authorized=true'; |
||
| 3323 | wp_redirect( $connect_url ); |
||
| 3324 | } |
||
| 3325 | } |
||
| 3326 | } |
||
| 3327 | |||
| 3328 | |||
| 3329 | if ( isset( $_GET['action'] ) ) { |
||
| 3330 | switch ( $_GET['action'] ) { |
||
| 3331 | case 'authorize': |
||
| 3332 | if ( Jetpack::is_active() && Jetpack::is_user_connected() ) { |
||
| 3333 | Jetpack::state( 'message', 'already_authorized' ); |
||
| 3334 | wp_safe_redirect( Jetpack::admin_url() ); |
||
| 3335 | exit; |
||
| 3336 | } |
||
| 3337 | Jetpack::log( 'authorize' ); |
||
| 3338 | $client_server = new Jetpack_Client_Server; |
||
| 3339 | $client_server->client_authorize(); |
||
| 3340 | exit; |
||
| 3341 | case 'register' : |
||
| 3342 | if ( ! current_user_can( 'jetpack_connect' ) ) { |
||
| 3343 | $error = 'cheatin'; |
||
| 3344 | break; |
||
| 3345 | } |
||
| 3346 | check_admin_referer( 'jetpack-register' ); |
||
| 3347 | Jetpack::log( 'register' ); |
||
| 3348 | Jetpack::maybe_set_version_option(); |
||
| 3349 | $registered = Jetpack::try_registration(); |
||
| 3350 | if ( is_wp_error( $registered ) ) { |
||
| 3351 | $error = $registered->get_error_code(); |
||
| 3352 | Jetpack::state( 'error', $error ); |
||
| 3353 | Jetpack::state( 'error', $registered->get_error_message() ); |
||
| 3354 | break; |
||
| 3355 | } |
||
| 3356 | |||
| 3357 | $from = isset( $_GET['from'] ) ? $_GET['from'] : false; |
||
| 3358 | |||
| 3359 | wp_redirect( $this->build_connect_url( true, false, $from ) ); |
||
| 3360 | exit; |
||
| 3361 | case 'activate' : |
||
| 3362 | if ( ! current_user_can( 'jetpack_activate_modules' ) ) { |
||
| 3363 | $error = 'cheatin'; |
||
| 3364 | break; |
||
| 3365 | } |
||
| 3366 | |||
| 3367 | $module = stripslashes( $_GET['module'] ); |
||
| 3368 | check_admin_referer( "jetpack_activate-$module" ); |
||
| 3369 | Jetpack::log( 'activate', $module ); |
||
| 3370 | Jetpack::activate_module( $module ); |
||
| 3371 | // The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end. |
||
| 3372 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 3373 | exit; |
||
| 3374 | case 'activate_default_modules' : |
||
| 3375 | check_admin_referer( 'activate_default_modules' ); |
||
| 3376 | Jetpack::log( 'activate_default_modules' ); |
||
| 3377 | Jetpack::restate(); |
||
| 3378 | $min_version = isset( $_GET['min_version'] ) ? $_GET['min_version'] : false; |
||
| 3379 | $max_version = isset( $_GET['max_version'] ) ? $_GET['max_version'] : false; |
||
| 3380 | $other_modules = isset( $_GET['other_modules'] ) && is_array( $_GET['other_modules'] ) ? $_GET['other_modules'] : array(); |
||
| 3381 | Jetpack::activate_default_modules( $min_version, $max_version, $other_modules ); |
||
| 3382 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 3383 | exit; |
||
| 3384 | case 'disconnect' : |
||
| 3385 | if ( ! current_user_can( 'jetpack_disconnect' ) ) { |
||
| 3386 | $error = 'cheatin'; |
||
| 3387 | break; |
||
| 3388 | } |
||
| 3389 | |||
| 3390 | check_admin_referer( 'jetpack-disconnect' ); |
||
| 3391 | Jetpack::log( 'disconnect' ); |
||
| 3392 | Jetpack::disconnect(); |
||
| 3393 | wp_safe_redirect( Jetpack::admin_url( 'disconnected=true' ) ); |
||
| 3394 | exit; |
||
| 3395 | case 'reconnect' : |
||
| 3396 | if ( ! current_user_can( 'jetpack_reconnect' ) ) { |
||
| 3397 | $error = 'cheatin'; |
||
| 3398 | break; |
||
| 3399 | } |
||
| 3400 | |||
| 3401 | check_admin_referer( 'jetpack-reconnect' ); |
||
| 3402 | Jetpack::log( 'reconnect' ); |
||
| 3403 | $this->disconnect(); |
||
| 3404 | wp_redirect( $this->build_connect_url( true, false, 'reconnect' ) ); |
||
| 3405 | exit; |
||
| 3406 | View Code Duplication | case 'deactivate' : |
|
| 3407 | if ( ! current_user_can( 'jetpack_deactivate_modules' ) ) { |
||
| 3408 | $error = 'cheatin'; |
||
| 3409 | break; |
||
| 3410 | } |
||
| 3411 | |||
| 3412 | $modules = stripslashes( $_GET['module'] ); |
||
| 3413 | check_admin_referer( "jetpack_deactivate-$modules" ); |
||
| 3414 | foreach ( explode( ',', $modules ) as $module ) { |
||
| 3415 | Jetpack::log( 'deactivate', $module ); |
||
| 3416 | Jetpack::deactivate_module( $module ); |
||
| 3417 | Jetpack::state( 'message', 'module_deactivated' ); |
||
| 3418 | } |
||
| 3419 | Jetpack::state( 'module', $modules ); |
||
| 3420 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); |
||
| 3421 | exit; |
||
| 3422 | case 'unlink' : |
||
| 3423 | $redirect = isset( $_GET['redirect'] ) ? $_GET['redirect'] : ''; |
||
| 3424 | check_admin_referer( 'jetpack-unlink' ); |
||
| 3425 | Jetpack::log( 'unlink' ); |
||
| 3426 | $this->unlink_user(); |
||
| 3427 | Jetpack::state( 'message', 'unlinked' ); |
||
| 3428 | if ( 'sub-unlink' == $redirect ) { |
||
| 3429 | wp_safe_redirect( admin_url() ); |
||
| 3430 | } else { |
||
| 3431 | wp_safe_redirect( Jetpack::admin_url( array( 'page' => $redirect ) ) ); |
||
| 3432 | } |
||
| 3433 | exit; |
||
| 3434 | default: |
||
| 3435 | /** |
||
| 3436 | * Fires when a Jetpack admin page is loaded with an unrecognized parameter. |
||
| 3437 | * |
||
| 3438 | * @since 2.6.0 |
||
| 3439 | * |
||
| 3440 | * @param string sanitize_key( $_GET['action'] ) Unrecognized URL parameter. |
||
| 3441 | */ |
||
| 3442 | do_action( 'jetpack_unrecognized_action', sanitize_key( $_GET['action'] ) ); |
||
| 3443 | } |
||
| 3444 | } |
||
| 3445 | |||
| 3446 | if ( ! $error = $error ? $error : Jetpack::state( 'error' ) ) { |
||
| 3447 | self::activate_new_modules( true ); |
||
| 3448 | } |
||
| 3449 | |||
| 3450 | $message_code = Jetpack::state( 'message' ); |
||
| 3451 | if ( Jetpack::state( 'optin-manage' ) ) { |
||
| 3452 | $activated_manage = $message_code; |
||
| 3453 | $message_code = 'jetpack-manage'; |
||
| 3454 | } |
||
| 3455 | |||
| 3456 | switch ( $message_code ) { |
||
| 3457 | case 'jetpack-manage': |
||
| 3458 | $this->message = '<strong>' . sprintf( __( 'You are all set! Your site can now be managed from <a href="%s" target="_blank">wordpress.com/sites</a>.', 'jetpack' ), 'https://wordpress.com/sites' ) . '</strong>'; |
||
| 3459 | if ( $activated_manage ) { |
||
| 3460 | $this->message .= '<br /><strong>' . __( 'Manage has been activated for you!', 'jetpack' ) . '</strong>'; |
||
| 3461 | } |
||
| 3462 | break; |
||
| 3463 | |||
| 3464 | } |
||
| 3465 | |||
| 3466 | $deactivated_plugins = Jetpack::state( 'deactivated_plugins' ); |
||
| 3467 | |||
| 3468 | if ( ! empty( $deactivated_plugins ) ) { |
||
| 3469 | $deactivated_plugins = explode( ',', $deactivated_plugins ); |
||
| 3470 | $deactivated_titles = array(); |
||
| 3471 | foreach ( $deactivated_plugins as $deactivated_plugin ) { |
||
| 3472 | if ( ! isset( $this->plugins_to_deactivate[$deactivated_plugin] ) ) { |
||
| 3473 | continue; |
||
| 3474 | } |
||
| 3475 | |||
| 3476 | $deactivated_titles[] = '<strong>' . str_replace( ' ', ' ', $this->plugins_to_deactivate[$deactivated_plugin][1] ) . '</strong>'; |
||
| 3477 | } |
||
| 3478 | |||
| 3479 | if ( $deactivated_titles ) { |
||
| 3480 | if ( $this->message ) { |
||
| 3481 | $this->message .= "<br /><br />\n"; |
||
| 3482 | } |
||
| 3483 | |||
| 3484 | $this->message .= wp_sprintf( |
||
| 3485 | _n( |
||
| 3486 | 'Jetpack contains the most recent version of the old %l plugin.', |
||
| 3487 | 'Jetpack contains the most recent versions of the old %l plugins.', |
||
| 3488 | count( $deactivated_titles ), |
||
| 3489 | 'jetpack' |
||
| 3490 | ), |
||
| 3491 | $deactivated_titles |
||
| 3492 | ); |
||
| 3493 | |||
| 3494 | $this->message .= "<br />\n"; |
||
| 3495 | |||
| 3496 | $this->message .= _n( |
||
| 3497 | 'The old version has been deactivated and can be removed from your site.', |
||
| 3498 | 'The old versions have been deactivated and can be removed from your site.', |
||
| 3499 | count( $deactivated_titles ), |
||
| 3500 | 'jetpack' |
||
| 3501 | ); |
||
| 3502 | } |
||
| 3503 | } |
||
| 3504 | |||
| 3505 | $this->privacy_checks = Jetpack::state( 'privacy_checks' ); |
||
| 3506 | |||
| 3507 | if ( $this->message || $this->error || $this->privacy_checks || $this->can_display_jetpack_manage_notice() ) { |
||
| 3508 | add_action( 'jetpack_notices', array( $this, 'admin_notices' ) ); |
||
| 3509 | } |
||
| 3510 | |||
| 3511 | View Code Duplication | if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) { |
|
| 3512 | /** |
||
| 3513 | * Fires when a module configuration page is loaded. |
||
| 3514 | * The dynamic part of the hook is the configure parameter from the URL. |
||
| 3515 | * |
||
| 3516 | * @since 1.1.0 |
||
| 3517 | */ |
||
| 3518 | do_action( 'jetpack_module_configuration_load_' . $_GET['configure'] ); |
||
| 3519 | } |
||
| 3520 | |||
| 3521 | add_filter( 'jetpack_short_module_description', 'wptexturize' ); |
||
| 3522 | } |
||
| 3523 | |||
| 3524 | function admin_notices() { |
||
| 3621 | |||
| 3622 | /** |
||
| 3623 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
| 3624 | */ |
||
| 3625 | function stat( $group, $detail ) { |
||
| 3630 | |||
| 3631 | /** |
||
| 3632 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
| 3633 | */ |
||
| 3634 | function do_stats( $method = '' ) { |
||
| 3649 | |||
| 3650 | /** |
||
| 3651 | * Runs stats code for a one-off, server-side. |
||
| 3652 | * |
||
| 3653 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
| 3654 | * |
||
| 3655 | * @return bool If it worked. |
||
| 3656 | */ |
||
| 3657 | static function do_server_side_stat( $args ) { |
||
| 3667 | |||
| 3668 | /** |
||
| 3669 | * Builds the stats url. |
||
| 3670 | * |
||
| 3671 | * @param $args array|string The arguments to append to the URL. |
||
| 3672 | * |
||
| 3673 | * @return string The URL to be pinged. |
||
| 3674 | */ |
||
| 3675 | static function build_stats_url( $args ) { |
||
| 3695 | |||
| 3696 | static function translate_current_user_to_role() { |
||
| 3705 | |||
| 3706 | static function translate_role_to_cap( $role ) { |
||
| 3713 | |||
| 3714 | static function sign_role( $role ) { |
||
| 3726 | |||
| 3727 | |||
| 3728 | /** |
||
| 3729 | * Builds a URL to the Jetpack connection auth page |
||
| 3730 | * |
||
| 3731 | * @since 3.9.5 |
||
| 3732 | * |
||
| 3733 | * @param bool $raw If true, URL will not be escaped. |
||
| 3734 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
| 3735 | * If string, will be a custom redirect. |
||
| 3736 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
| 3737 | * |
||
| 3738 | * @return string Connect URL |
||
| 3739 | */ |
||
| 3740 | function build_connect_url( $raw = false, $redirect = false, $from = false ) { |
||
| 3814 | |||
| 3815 | function build_reconnect_url( $raw = false ) { |
||
| 3819 | |||
| 3820 | public static function admin_url( $args = null ) { |
||
| 3825 | |||
| 3826 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
| 3830 | |||
| 3831 | function dismiss_jetpack_notice() { |
||
| 3905 | |||
| 3906 | function debugger_page() { |
||
| 3914 | |||
| 3915 | public static function admin_screen_configure_module( $module_id ) { |
||
| 3967 | |||
| 3968 | /** |
||
| 3969 | * Display link to activate the module to see the settings screen. |
||
| 3970 | * @param string $module_id |
||
| 3971 | * @return null |
||
| 3972 | */ |
||
| 3973 | public static function display_activate_module_link( $module_id ) { |
||
| 4025 | |||
| 4026 | public static function sort_modules( $a, $b ) { |
||
| 4032 | |||
| 4033 | function ajax_recheck_ssl() { |
||
| 4041 | |||
| 4042 | /* Client API */ |
||
| 4043 | |||
| 4044 | /** |
||
| 4045 | * Returns the requested Jetpack API URL |
||
| 4046 | * |
||
| 4047 | * @return string |
||
| 4048 | */ |
||
| 4049 | public static function api_url( $relative_url ) { |
||
| 4052 | |||
| 4053 | /** |
||
| 4054 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
| 4055 | */ |
||
| 4056 | public static function fix_url_for_bad_hosts( $url ) { |
||
| 4072 | |||
| 4073 | /** |
||
| 4074 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
| 4075 | * |
||
| 4076 | * @since 2.3.3 |
||
| 4077 | * @return boolean |
||
| 4078 | */ |
||
| 4079 | public static function permit_ssl( $force_recheck = false ) { |
||
| 4121 | |||
| 4122 | /* |
||
| 4123 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
| 4124 | */ |
||
| 4125 | public function alert_auto_ssl_fail() { |
||
| 4174 | |||
| 4175 | /** |
||
| 4176 | * Returns the Jetpack XML-RPC API |
||
| 4177 | * |
||
| 4178 | * @return string |
||
| 4179 | */ |
||
| 4180 | public static function xmlrpc_api_url() { |
||
| 4184 | |||
| 4185 | /** |
||
| 4186 | * Creates two secret tokens and the end of life timestamp for them. |
||
| 4187 | * |
||
| 4188 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
| 4189 | * |
||
| 4190 | * @since 2.6 |
||
| 4191 | * @return array |
||
| 4192 | */ |
||
| 4193 | public function generate_secrets( $action, $exp = 600 ) { |
||
| 4201 | |||
| 4202 | /** |
||
| 4203 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
| 4204 | * |
||
| 4205 | * Based on local php max_execution_time in php.ini |
||
| 4206 | * |
||
| 4207 | * @since 2.6 |
||
| 4208 | * @return int |
||
| 4209 | **/ |
||
| 4210 | public function get_remote_query_timeout_limit() { |
||
| 4216 | |||
| 4217 | |||
| 4218 | /** |
||
| 4219 | * Takes the response from the Jetpack register new site endpoint and |
||
| 4220 | * verifies it worked properly. |
||
| 4221 | * |
||
| 4222 | * @since 2.6 |
||
| 4223 | * @return true or Jetpack_Error |
||
| 4224 | **/ |
||
| 4225 | public function validate_remote_register_response( $response ) { |
||
| 4260 | /** |
||
| 4261 | * @return bool|WP_Error |
||
| 4262 | */ |
||
| 4263 | public static function register() { |
||
| 4360 | |||
| 4361 | /** |
||
| 4362 | * If the db version is showing something other that what we've got now, bump it to current. |
||
| 4363 | * |
||
| 4364 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
| 4365 | */ |
||
| 4366 | public static function maybe_set_version_option() { |
||
| 4367 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
| 4368 | if ( JETPACK__VERSION != $version ) { |
||
| 4369 | Jetpack_Options::update_option( 'version', JETPACK__VERSION . ':' . time() ); |
||
| 4370 | |||
| 4371 | if ( version_compare( JETPACK__VERSION, $version, '>' ) ) { |
||
| 4372 | /** This action is documented in class.jetpack.php */ |
||
| 4373 | do_action( 'updating_jetpack_version', JETPACK__VERSION, $version ); |
||
| 4374 | } |
||
| 4375 | |||
| 4376 | return true; |
||
| 4377 | } |
||
| 4378 | return false; |
||
| 4379 | } |
||
| 4380 | |||
| 4381 | /* Client Server API */ |
||
| 4382 | |||
| 4383 | /** |
||
| 4384 | * Loads the Jetpack XML-RPC client |
||
| 4385 | */ |
||
| 4386 | public static function load_xml_rpc_client() { |
||
| 4390 | |||
| 4391 | function verify_xml_rpc_signature() { |
||
| 4489 | |||
| 4490 | /** |
||
| 4491 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
| 4492 | */ |
||
| 4493 | function authenticate_jetpack( $user, $username, $password ) { |
||
| 4516 | |||
| 4517 | function add_nonce( $timestamp, $nonce ) { |
||
| 4555 | |||
| 4556 | /** |
||
| 4557 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
| 4558 | * Capture it here so we can verify the signature later. |
||
| 4559 | */ |
||
| 4560 | function xmlrpc_methods( $methods ) { |
||
| 4564 | |||
| 4565 | function public_xmlrpc_methods( $methods ) { |
||
| 4571 | |||
| 4572 | function jetpack_getOptions( $args ) { |
||
| 4612 | |||
| 4613 | function xmlrpc_options( $options ) { |
||
| 4631 | |||
| 4632 | public static function clean_nonces( $all = false ) { |
||
| 4657 | |||
| 4658 | /** |
||
| 4659 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
| 4660 | * SET: state( $key, $value ); |
||
| 4661 | * GET: $value = state( $key ); |
||
| 4662 | * |
||
| 4663 | * @param string $key |
||
| 4664 | * @param string $value |
||
| 4665 | * @param bool $restate private |
||
| 4666 | */ |
||
| 4667 | public static function state( $key = null, $value = null, $restate = false ) { |
||
| 4717 | |||
| 4718 | public static function restate() { |
||
| 4721 | |||
| 4722 | public static function check_privacy( $file ) { |
||
| 4757 | |||
| 4758 | /** |
||
| 4759 | * Helper method for multicall XMLRPC. |
||
| 4760 | */ |
||
| 4761 | public static function xmlrpc_async_call() { |
||
| 4803 | |||
| 4804 | public static function staticize_subdomain( $url ) { |
||
| 4839 | |||
| 4840 | /* JSON API Authorization */ |
||
| 4841 | |||
| 4842 | /** |
||
| 4843 | * Handles the login action for Authorizing the JSON API |
||
| 4844 | */ |
||
| 4845 | function login_form_json_api_authorization() { |
||
| 4854 | |||
| 4855 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
| 4856 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
| 4869 | |||
| 4870 | // Make sure the POSTed request is handled by the same action |
||
| 4871 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
| 4875 | |||
| 4876 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
| 4877 | function store_json_api_authorization_token( $user_login, $user ) { |
||
| 4883 | |||
| 4884 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
| 4885 | function allow_wpcom_public_api_domain( $domains ) { |
||
| 4889 | |||
| 4890 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
| 4891 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
| 4903 | |||
| 4904 | // Verifies the request by checking the signature |
||
| 4905 | function verify_json_api_authorization_request() { |
||
| 4984 | |||
| 4985 | function login_message_json_api_authorization( $message ) { |
||
| 4991 | |||
| 4992 | /** |
||
| 4993 | * Get $content_width, but with a <s>twist</s> filter. |
||
| 4994 | */ |
||
| 4995 | public static function get_content_width() { |
||
| 5006 | |||
| 5007 | /** |
||
| 5008 | * Centralize the function here until it gets added to core. |
||
| 5009 | * |
||
| 5010 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
| 5011 | * @param int $size Size of the avatar image |
||
| 5012 | * @param string $default URL to a default image to use if no avatar is available |
||
| 5013 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
| 5014 | * |
||
| 5015 | * @return array First element is the URL, second is the class. |
||
| 5016 | */ |
||
| 5017 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
| 5045 | |||
| 5046 | /** |
||
| 5047 | * Pings the WordPress.com Mirror Site for the specified options. |
||
| 5048 | * |
||
| 5049 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
| 5050 | * |
||
| 5051 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
| 5052 | */ |
||
| 5053 | public function get_cloud_site_options( $option_names ) { |
||
| 5069 | |||
| 5070 | /** |
||
| 5071 | * Fetch the filtered array of options that we should compare to determine an identity crisis. |
||
| 5072 | * |
||
| 5073 | * @return array An array of options to check. |
||
| 5074 | */ |
||
| 5075 | public static function identity_crisis_options_to_check() { |
||
| 5081 | |||
| 5082 | /** |
||
| 5083 | * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours. |
||
| 5084 | * |
||
| 5085 | * @param bool $force_recheck Whether to ignore any cached transient and manually re-check. |
||
| 5086 | * |
||
| 5087 | * @return array An array of options that do not match. If everything is good, it will evaluate to false. |
||
| 5088 | */ |
||
| 5089 | public static function check_identity_crisis( $force_recheck = false ) { |
||
| 5154 | |||
| 5155 | /** |
||
| 5156 | * Checks whether a value is already whitelisted. |
||
| 5157 | * |
||
| 5158 | * @param string $key The option name that we're checking the value for. |
||
| 5159 | * @param string $value The value that we're curious to see if it's on the whitelist. |
||
| 5160 | * |
||
| 5161 | * @return bool Whether the value is whitelisted. |
||
| 5162 | */ |
||
| 5163 | public static function is_identity_crisis_value_whitelisted( $key, $value ) { |
||
| 5170 | |||
| 5171 | /** |
||
| 5172 | * Checks whether the home and siteurl specifically are whitelisted |
||
| 5173 | * Written so that we don't have re-check $key and $value params every time |
||
| 5174 | * we want to check if this site is whitelisted, for example in footer.php |
||
| 5175 | * |
||
| 5176 | * @return bool True = already whitelisted False = not whitelisted |
||
| 5177 | */ |
||
| 5178 | public static function is_staging_site() { |
||
| 5179 | $is_staging = false; |
||
| 5180 | |||
| 5181 | $current_whitelist = Jetpack_Options::get_option( 'identity_crisis_whitelist' ); |
||
| 5182 | if ( $current_whitelist && ! get_transient( 'jetpack_checked_is_staging' ) ) { |
||
| 5183 | $options_to_check = Jetpack::identity_crisis_options_to_check(); |
||
| 5184 | $cloud_options = Jetpack::init()->get_cloud_site_options( $options_to_check ); |
||
| 5185 | |||
| 5186 | foreach ( $cloud_options as $cloud_key => $cloud_value ) { |
||
| 5187 | if ( self::is_identity_crisis_value_whitelisted( $cloud_key, $cloud_value ) ) { |
||
| 5188 | $is_staging = true; |
||
| 5189 | break; |
||
| 5190 | } |
||
| 5191 | } |
||
| 5192 | // set a flag so we don't check again for an hour |
||
| 5193 | set_transient( 'jetpack_checked_is_staging', 1, HOUR_IN_SECONDS ); |
||
| 5194 | } |
||
| 5195 | $known_staging = array( |
||
| 5196 | 'urls' => array( |
||
| 5197 | '#\.staging\.wpengine\.com$#i', // WP Engine |
||
| 5198 | ), |
||
| 5199 | 'constants' => array( |
||
| 5200 | 'IS_WPE_SNAPSHOT', // WP Engine |
||
| 5201 | 'KINSTA_DEV_ENV', // Kinsta.com |
||
| 5202 | 'WPSTAGECOACH_STAGING', // WP Stagecoach |
||
| 5203 | 'JETPACK_STAGING_MODE', // Generic |
||
| 5204 | ) |
||
| 5205 | ); |
||
| 5206 | /** |
||
| 5207 | * Filters the flags of known staging sites. |
||
| 5208 | * |
||
| 5209 | * @since 3.9.0 |
||
| 5210 | * |
||
| 5211 | * @param array $known_staging { |
||
| 5212 | * An array of arrays that each are used to check if the current site is staging. |
||
| 5213 | * @type array $urls URLs of staging sites in regex to check against site_url. |
||
| 5214 | * @type array $constants PHP constants of known staging/developement environments. |
||
| 5215 | * } |
||
| 5216 | */ |
||
| 5217 | $known_staging = apply_filters( 'jetpack_known_staging', $known_staging ); |
||
| 5218 | |||
| 5219 | if ( isset( $known_staging['urls'] ) ) { |
||
| 5220 | foreach ( $known_staging['urls'] as $url ){ |
||
| 5221 | if ( preg_match( $url, site_url() ) ) { |
||
| 5222 | $is_staging = true; |
||
| 5223 | break; |
||
| 5224 | } |
||
| 5225 | } |
||
| 5226 | } |
||
| 5227 | |||
| 5228 | if ( isset( $known_staging['constants'] ) ) { |
||
| 5229 | foreach ( $known_staging['constants'] as $constant ) { |
||
| 5230 | if ( defined( $constant ) && constant( $constant ) ) { |
||
| 5231 | $is_staging = true; |
||
| 5232 | } |
||
| 5233 | } |
||
| 5234 | } |
||
| 5235 | |||
| 5236 | /** |
||
| 5237 | * Filters is_staging_site check. |
||
| 5238 | * |
||
| 5239 | * @since 3.9.0 |
||
| 5240 | * |
||
| 5241 | * @param bool $is_staging If the current site is a staging site. |
||
| 5242 | */ |
||
| 5243 | return apply_filters( 'jetpack_is_staging_site', $is_staging ); |
||
| 5244 | } |
||
| 5245 | |||
| 5246 | /** |
||
| 5247 | * Maybe Use a .min.css stylesheet, maybe not. |
||
| 5248 | * |
||
| 5249 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
| 5250 | */ |
||
| 5251 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
| 5252 | // Short out on things trying to find actual paths. |
||
| 5253 | if ( ! $path || empty( $plugin ) ) { |
||
| 5254 | return $url; |
||
| 5255 | } |
||
| 5256 | |||
| 5257 | // Strip out the abspath. |
||
| 5258 | $base = dirname( plugin_basename( $plugin ) ); |
||
| 5259 | |||
| 5260 | // Short out on non-Jetpack assets. |
||
| 5261 | if ( 'jetpack/' !== substr( $base, 0, 8 ) ) { |
||
| 5262 | return $url; |
||
| 5263 | } |
||
| 5264 | |||
| 5265 | // File name parsing. |
||
| 5266 | $file = "{$base}/{$path}"; |
||
| 5267 | $full_path = JETPACK__PLUGIN_DIR . substr( $file, 8 ); |
||
| 5268 | $file_name = substr( $full_path, strrpos( $full_path, '/' ) + 1 ); |
||
| 5269 | $file_name_parts_r = array_reverse( explode( '.', $file_name ) ); |
||
| 5270 | $extension = array_shift( $file_name_parts_r ); |
||
| 5271 | |||
| 5272 | if ( in_array( strtolower( $extension ), array( 'css', 'js' ) ) ) { |
||
| 5273 | // Already pointing at the minified version. |
||
| 5274 | if ( 'min' === $file_name_parts_r[0] ) { |
||
| 5275 | return $url; |
||
| 5276 | } |
||
| 5277 | |||
| 5278 | $min_full_path = preg_replace( "#\.{$extension}$#", ".min.{$extension}", $full_path ); |
||
| 5279 | if ( file_exists( $min_full_path ) ) { |
||
| 5280 | $url = preg_replace( "#\.{$extension}$#", ".min.{$extension}", $url ); |
||
| 5281 | } |
||
| 5282 | } |
||
| 5283 | |||
| 5284 | return $url; |
||
| 5285 | } |
||
| 5286 | |||
| 5287 | /** |
||
| 5288 | * Maybe inlines a stylesheet. |
||
| 5289 | * |
||
| 5290 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
| 5291 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
| 5292 | * |
||
| 5293 | * Attached to `style_loader_tag` filter. |
||
| 5294 | * |
||
| 5295 | * @param string $tag The tag that would link to the external asset. |
||
| 5296 | * @param string $handle The registered handle of the script in question. |
||
| 5297 | * |
||
| 5298 | * @return string |
||
| 5299 | */ |
||
| 5300 | public static function maybe_inline_style( $tag, $handle ) { |
||
| 5301 | global $wp_styles; |
||
| 5302 | $item = $wp_styles->registered[ $handle ]; |
||
| 5303 | |||
| 5304 | if ( ! isset( $item->extra['jetpack-inline'] ) || ! $item->extra['jetpack-inline'] ) { |
||
| 5305 | return $tag; |
||
| 5306 | } |
||
| 5307 | |||
| 5308 | if ( preg_match( '# href=\'([^\']+)\' #i', $tag, $matches ) ) { |
||
| 5309 | $href = $matches[1]; |
||
| 5310 | // Strip off query string |
||
| 5311 | if ( $pos = strpos( $href, '?' ) ) { |
||
| 5312 | $href = substr( $href, 0, $pos ); |
||
| 5313 | } |
||
| 5314 | // Strip off fragment |
||
| 5315 | if ( $pos = strpos( $href, '#' ) ) { |
||
| 5316 | $href = substr( $href, 0, $pos ); |
||
| 5317 | } |
||
| 5318 | } else { |
||
| 5319 | return $tag; |
||
| 5320 | } |
||
| 5321 | |||
| 5322 | $plugins_dir = plugin_dir_url( JETPACK__PLUGIN_FILE ); |
||
| 5323 | if ( $plugins_dir !== substr( $href, 0, strlen( $plugins_dir ) ) ) { |
||
| 5324 | return $tag; |
||
| 5325 | } |
||
| 5326 | |||
| 5327 | // If this stylesheet has a RTL version, and the RTL version replaces normal... |
||
| 5328 | if ( isset( $item->extra['rtl'] ) && 'replace' === $item->extra['rtl'] && is_rtl() ) { |
||
| 5329 | // And this isn't the pass that actually deals with the RTL version... |
||
| 5330 | if ( false === strpos( $tag, " id='$handle-rtl-css' " ) ) { |
||
| 5331 | // Short out, as the RTL version will deal with it in a moment. |
||
| 5332 | return $tag; |
||
| 5333 | } |
||
| 5334 | } |
||
| 5335 | |||
| 5336 | $file = JETPACK__PLUGIN_DIR . substr( $href, strlen( $plugins_dir ) ); |
||
| 5337 | $css = Jetpack::absolutize_css_urls( file_get_contents( $file ), $href ); |
||
| 5338 | if ( $css ) { |
||
| 5339 | $tag = "<!-- Inline {$item->handle} -->\r\n"; |
||
| 5340 | if ( empty( $item->extra['after'] ) ) { |
||
| 5341 | wp_add_inline_style( $handle, $css ); |
||
| 5342 | } else { |
||
| 5343 | array_unshift( $item->extra['after'], $css ); |
||
| 5344 | wp_style_add_data( $handle, 'after', $item->extra['after'] ); |
||
| 5345 | } |
||
| 5346 | } |
||
| 5347 | |||
| 5348 | return $tag; |
||
| 5349 | } |
||
| 5350 | |||
| 5351 | /** |
||
| 5352 | * Loads a view file from the views |
||
| 5353 | * |
||
| 5354 | * Data passed in with the $data parameter will be available in the |
||
| 5355 | * template file as $data['value'] |
||
| 5356 | * |
||
| 5357 | * @param string $template - Template file to load |
||
| 5358 | * @param array $data - Any data to pass along to the template |
||
| 5359 | * @return boolean - If template file was found |
||
| 5360 | **/ |
||
| 5361 | public function load_view( $template, $data = array() ) { |
||
| 5372 | |||
| 5373 | /** |
||
| 5374 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
| 5375 | */ |
||
| 5376 | public function deprecated_hooks() { |
||
| 5418 | |||
| 5419 | /** |
||
| 5420 | * Converts any url in a stylesheet, to the correct absolute url. |
||
| 5421 | * |
||
| 5422 | * Considerations: |
||
| 5423 | * - Normal, relative URLs `feh.png` |
||
| 5424 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
| 5425 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
| 5426 | * - Absolute URLs `http://domain.com/feh.png` |
||
| 5427 | * - Domain root relative URLs `/feh.png` |
||
| 5428 | * |
||
| 5429 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
| 5430 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
| 5431 | * |
||
| 5432 | * @return mixed|string |
||
| 5433 | */ |
||
| 5434 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
| 5435 | $pattern = '#url\((?P<path>[^)]*)\)#i'; |
||
| 5436 | $css_dir = dirname( $css_file_url ); |
||
| 5437 | $p = parse_url( $css_dir ); |
||
| 5438 | $domain = sprintf( |
||
| 5439 | '%1$s//%2$s%3$s%4$s', |
||
| 5440 | isset( $p['scheme'] ) ? "{$p['scheme']}:" : '', |
||
| 5441 | isset( $p['user'], $p['pass'] ) ? "{$p['user']}:{$p['pass']}@" : '', |
||
| 5442 | $p['host'], |
||
| 5443 | isset( $p['port'] ) ? ":{$p['port']}" : '' |
||
| 5444 | ); |
||
| 5445 | |||
| 5446 | if ( preg_match_all( $pattern, $css, $matches, PREG_SET_ORDER ) ) { |
||
| 5447 | $find = $replace = array(); |
||
| 5448 | foreach ( $matches as $match ) { |
||
| 5449 | $url = trim( $match['path'], "'\" \t" ); |
||
| 5450 | |||
| 5451 | // If this is a data url, we don't want to mess with it. |
||
| 5452 | if ( 'data:' === substr( $url, 0, 5 ) ) { |
||
| 5453 | continue; |
||
| 5454 | } |
||
| 5455 | |||
| 5456 | // If this is an absolute or protocol-agnostic url, |
||
| 5457 | // we don't want to mess with it. |
||
| 5458 | if ( preg_match( '#^(https?:)?//#i', $url ) ) { |
||
| 5459 | continue; |
||
| 5460 | } |
||
| 5461 | |||
| 5462 | switch ( substr( $url, 0, 1 ) ) { |
||
| 5463 | case '/': |
||
| 5464 | $absolute = $domain . $url; |
||
| 5465 | break; |
||
| 5466 | default: |
||
| 5467 | $absolute = $css_dir . '/' . $url; |
||
| 5468 | } |
||
| 5469 | |||
| 5470 | $find[] = $match[0]; |
||
| 5471 | $replace[] = sprintf( 'url("%s")', $absolute ); |
||
| 5472 | } |
||
| 5473 | $css = str_replace( $find, $replace, $css ); |
||
| 5474 | } |
||
| 5475 | |||
| 5476 | return $css; |
||
| 5477 | } |
||
| 5478 | |||
| 5479 | /** |
||
| 5480 | * This method checks to see if SSL is required by the site in |
||
| 5481 | * order to visit it in some way other than only setting the |
||
| 5482 | * https value in the home or siteurl values. |
||
| 5483 | * |
||
| 5484 | * @since 3.2 |
||
| 5485 | * @return boolean |
||
| 5486 | **/ |
||
| 5487 | private function is_ssl_required_to_visit_site() { |
||
| 5488 | global $wp_version; |
||
| 5489 | $ssl = is_ssl(); |
||
| 5490 | |||
| 5491 | if ( force_ssl_admin() ) { |
||
| 5492 | $ssl = true; |
||
| 5493 | } |
||
| 5494 | return $ssl; |
||
| 5495 | } |
||
| 5496 | |||
| 5497 | /** |
||
| 5498 | * This methods removes all of the registered css files on the front end |
||
| 5499 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
| 5500 | * all the files into one file. |
||
| 5501 | * |
||
| 5502 | * Pros: |
||
| 5503 | * - Uses only ONE css asset connection instead of 15 |
||
| 5504 | * - Saves a minimum of 56k |
||
| 5505 | * - Reduces server load |
||
| 5506 | * - Reduces time to first painted byte |
||
| 5507 | * |
||
| 5508 | * Cons: |
||
| 5509 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
| 5510 | * should not cause any issues with themes. |
||
| 5511 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
| 5512 | * jetpack_implode_frontend_css filter for a workaround |
||
| 5513 | * |
||
| 5514 | * For some situations developers may wish to disable css imploding and |
||
| 5515 | * instead operate in legacy mode where each file loads seperately and |
||
| 5516 | * can be edited individually or dequeued. This can be accomplished with |
||
| 5517 | * the following line: |
||
| 5518 | * |
||
| 5519 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
| 5520 | * |
||
| 5521 | * @since 3.2 |
||
| 5522 | **/ |
||
| 5523 | public function implode_frontend_css( $travis_test = false ) { |
||
| 5575 | |||
| 5576 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
| 5586 | |||
| 5587 | /* |
||
| 5588 | * Check the heartbeat data |
||
| 5589 | * |
||
| 5590 | * Organizes the heartbeat data by severity. For example, if the site |
||
| 5591 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
| 5592 | * |
||
| 5593 | * Data will be added to "caution" array, if it either: |
||
| 5594 | * - Out of date Jetpack version |
||
| 5595 | * - Out of date WP version |
||
| 5596 | * - Out of date PHP version |
||
| 5597 | * |
||
| 5598 | * $return array $filtered_data |
||
| 5599 | */ |
||
| 5600 | public static function jetpack_check_heartbeat_data() { |
||
| 5653 | |||
| 5654 | |||
| 5655 | /* |
||
| 5656 | * This method is used to organize all options that can be reset |
||
| 5657 | * without disconnecting Jetpack. |
||
| 5658 | * |
||
| 5659 | * It is used in class.jetpack-cli.php to reset options |
||
| 5660 | * |
||
| 5661 | * @return array of options to delete. |
||
| 5662 | */ |
||
| 5663 | public static function get_jetpack_options_for_reset() { |
||
| 5730 | |||
| 5731 | /** |
||
| 5732 | * Check if an option of a Jetpack module has been updated. |
||
| 5733 | * |
||
| 5734 | * If any module option has been updated before Jump Start has been dismissed, |
||
| 5735 | * update the 'jumpstart' option so we can hide Jump Start. |
||
| 5736 | * |
||
| 5737 | * @param string $option_name |
||
| 5738 | * |
||
| 5739 | * @return bool |
||
| 5740 | */ |
||
| 5741 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
| 5762 | |||
| 5763 | /* |
||
| 5764 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
| 5765 | * so we can bring them directly to their site in calypso. |
||
| 5766 | * |
||
| 5767 | * @param string | url |
||
| 5768 | * @return string | url without the guff |
||
| 5769 | */ |
||
| 5770 | public static function build_raw_urls( $url ) { |
||
| 5776 | |||
| 5777 | /** |
||
| 5778 | * Stores and prints out domains to prefetch for page speed optimization. |
||
| 5779 | * |
||
| 5780 | * @param mixed $new_urls |
||
| 5781 | */ |
||
| 5782 | public static function dns_prefetch( $new_urls = null ) { |
||
| 5799 | |||
| 5800 | public function wp_dashboard_setup() { |
||
| 5828 | |||
| 5829 | /** |
||
| 5830 | * @param mixed $result Value for the user's option |
||
| 5831 | * @return mixed |
||
| 5832 | */ |
||
| 5833 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
| 5858 | |||
| 5859 | public static function dashboard_widget() { |
||
| 5867 | |||
| 5868 | public static function dashboard_widget_footer() { |
||
| 5901 | |||
| 5902 | public function dashboard_widget_connect_to_wpcom() { |
||
| 5924 | |||
| 5925 | /* |
||
| 5926 | * A graceful transition to using Core's site icon. |
||
| 5927 | * |
||
| 5928 | * All of the hard work has already been done with the image |
||
| 5929 | * in all_done_page(). All that needs to be done now is update |
||
| 5930 | * the option and display proper messaging. |
||
| 5931 | * |
||
| 5932 | * @todo remove when WP 4.3 is minimum |
||
| 5933 | * |
||
| 5934 | * @since 3.6.1 |
||
| 5935 | * |
||
| 5936 | * @return bool false = Core's icon not available || true = Core's icon is available |
||
| 5937 | */ |
||
| 5938 | public static function jetpack_site_icon_available_in_core() { |
||
| 5973 | |||
| 5974 | /** |
||
| 5975 | * Return string containing the Jetpack logo. |
||
| 5976 | * |
||
| 5977 | * @since 3.9.0 |
||
| 5978 | * |
||
| 5979 | * @return string |
||
| 5980 | */ |
||
| 5981 | public static function get_jp_emblem() { |
||
| 5984 | |||
| 5985 | /* |
||
| 5986 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
| 5987 | */ |
||
| 5988 | function jetpack_icon_user_connected( $columns ) { |
||
| 5992 | |||
| 5993 | /* |
||
| 5994 | * Show Jetpack icon if the user is linked. |
||
| 5995 | */ |
||
| 5996 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
| 6008 | |||
| 6009 | /* |
||
| 6010 | * Style the Jetpack user column |
||
| 6011 | */ |
||
| 6012 | function jetpack_user_col_style() { |
||
| 6025 | |||
| 6026 | } |
||
| 6027 |
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.