<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
* This contains too much, so please think twice before adding more.
* @package automattic/jetpack
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Boost_Speed_Score\Speed_Score;
use Automattic\Jetpack\Config;
use Automattic\Jetpack\Connection\Authorize_Json_Api;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Connection\Rest_Authentication as Connection_Rest_Authentication;
use Automattic\Jetpack\Connection\Secrets;
use Automattic\Jetpack\Connection\Tokens;
use Automattic\Jetpack\Connection\Webhooks\Authorize_Redirect;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\CookieState;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\Device_Detection\User_Agent_Info;
use Automattic\Jetpack\Errors;
use Automattic\Jetpack\Files;
use Automattic\Jetpack\Identity_Crisis;
use Automattic\Jetpack\Licensing;
use Automattic\Jetpack\Modules;
use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
use Automattic\Jetpack\Paths;
use Automattic\Jetpack\Plugin\Deprecate;
use Automattic\Jetpack\Plugin\Tracking as Plugin_Tracking;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
use Automattic\Jetpack\Status\Visitor;
use Automattic\Jetpack\Sync\Actions as Sync_Actions;
use Automattic\Jetpack\Sync\Health;
use Automattic\Jetpack\Sync\Sender;
use Automattic\Jetpack\Terms_Of_Service;
use Automattic\Jetpack\Tracking;
if ( ! defined( 'ABSPATH' ) ) {
@see Jetpack_Options::get_option_names()
jetpack_register (string)
Temporary verification secrets.
1: the plugin was activated normally
2: the plugin was activated on this site because of a network-wide activation
3: the plugin was auto-installed
4: the plugin was manually disconnected (but is still installed)
jetpack_active_modules (array)
Array of active module slugs.
jetpack_do_activate (bool)
Flag for "activating" the plugin on sites where the activation hook never fired (auto-installs)
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.media.php';
* XMLRPC server instance.
* @var null|Jetpack_XMLRPC_Server XMLRPC server used by Jetpack.
public $xmlrpc_server = null;
* Contains all assets that have had their URL rewritten to minified versions.
public static $min_assets = array();
* @var array Plugins to deactivate by module.
public $plugins_to_deactivate = array(
array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ),
array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ),
'gravatar-hovercards' => array(
array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ),
array( 'wp-latex/wp-latex.php', 'WP LaTeX' ),
array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ),
array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ),
array( 'stats/stats.php', 'WordPress.com Stats' ),
array( 'stats/stats.php', 'WordPress.com Stats' ),
'twitter-widget' => array(
array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ),
array( 'video/video.php', 'VideoPress' ),
'widget-visibility' => array(
array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ),
array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ),
* Map of roles we care about, and their corresponding minimum capabilities.
* @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead.
public static $capability_translations = array(
'administrator' => 'manage_options',
'editor' => 'edit_others_posts',
'author' => 'publish_posts',
'contributor' => 'edit_posts',
* Map of modules that have conflicts with plugins and should not be auto-activated
* if the plugins are active. Used by filter_default_modules
* Plugin Authors: If you'd like to prevent a single module from auto-activating,
* change `module-slug` and add this to your plugin:
* add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' );
* function my_jetpack_get_default_modules( $modules ) {
* return array_diff( $modules, array( 'module-slug' ) );
private $conflicting_plugins = array(
'Intense Debate' => 'intensedebate/intensedebate.php',
'Disqus' => 'disqus-comment-system/disqus.php',
'Livefyre' => 'livefyre-comments/livefyre.php',
'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php',
'Google+ Comments' => 'google-plus-comments/google-plus-comments.php',
'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php',
'comment-likes' => array(
'Epoch' => 'epoch/plugincore.php',
'LaTeX for WordPress' => 'latex/latex.php',
'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php',
'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php',
'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php',
'Enable Latex' => 'enable-latex/enable-latex.php',
'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php',
'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php',
'Captcha' => 'captcha/captcha.php',
'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php',
'Login Security Solution' => 'login-security-solution/login-security-solution.php',
'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php',
'BulletProof Security' => 'bulletproof-security/bulletproof-security.php',
'SiteGuard WP Plugin' => 'siteguard/siteguard.php',
'Security-protection' => 'security-protection/security-protection.php',
'Login Security' => 'login-security/login-security.php',
'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php',
'Wordfence Security' => 'wordfence/wordfence.php',
'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php',
'iThemes Security' => 'better-wp-security/better-wp-security.php',
'related-posts' => array(
'YARPP' => 'yet-another-related-posts-plugin/yarpp.php',
'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php',
'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php',
'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php',
'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php',
'outbrain' => 'outbrain/outbrain.php',
'Shareaholic' => 'shareaholic/shareaholic.php',
'Sexybookmarks' => 'sexybookmarks/shareaholic.php',
'AddThis' => 'addthis/addthis_social_widget.php',
'Add To Any' => 'add-to-any/add-to-any.php',
'ShareThis' => 'share-this/sharethis.php',
'Shareaholic' => 'shareaholic/shareaholic.php',
'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php',
'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php',
'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
'The SEO Framework' => 'autodescription/autodescription.php',
'Rank Math' => 'seo-by-rank-math/rank-math.php',
'Slim SEO' => 'slim-seo/slim-seo.php',
'SEOKEY' => 'seo-key/seo-key.php',
'SEOKEY Pro' => 'seo-key-pro/seo-key.php',
'SEOPress' => 'wp-seopress/seopress.php',
'SEOPress Pro' => 'wp-seopress-pro/seopress-pro.php',
'verification-tools' => array(
'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php',
'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php',
'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
'The SEO Framework' => 'autodescription/autodescription.php',
'Rank Math' => 'seo-by-rank-math/rank-math.php',
'Slim SEO' => 'slim-seo/slim-seo.php',
'widget-visibility' => array(
'Widget Logic' => 'widget-logic/widget_logic.php',
'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php',
'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php',
'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php',
'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php',
'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php',
'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php',
'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php',
'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php',
'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
'The SEO Framework' => 'autodescription/autodescription.php',
'Sitemap' => 'sitemap/sitemap.php',
'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php',
'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php',
'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php',
'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php',
'Rank Math' => 'seo-by-rank-math/rank-math.php',
'Slim SEO' => 'slim-seo/slim-seo.php',
* Plugins for which we turn off our Facebook OG Tags implementation.
* Note: the following plugins automatically deactivate Jetpack's Open
* Graph tags via filter when their Social Meta modules are active:
* - All in One SEO Pack, All in one SEO Pack Pro
* - WordPress SEO by Yoast, WordPress SEO Premium by Yoast
* Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter:
* add_filter( 'jetpack_enable_open_graph', '__return_false' );
* @var array Array of plugin slugs.
private $open_graph_conflicting_plugins = array(
'2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', // 2 Click Social Media Buttons.
'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook.
'add-meta-tags/add-meta-tags.php', // Add Meta Tags.
'complete-open-graph/complete-open-graph.php', // Complete Open Graph.
'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail.
'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', // Open Graph Meta Tags by Heateor.
'facebook/facebook.php', // Facebook (official plugin).
'facebook-awd/AWD_facebook.php', // Facebook AWD All in one.
'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', // Facebook Featured Image & OG Meta Tags.
'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags.
'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', // Facebook Open Graph Meta Tags for WordPress.
'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag.
'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer.
'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', // Fedmich's Facebook Open Graph Meta.
'network-publisher/networkpub.php', // Network Publisher.
'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG.
'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', // NextScripts SNAP.
'og-tags/og-tags.php', // OG Tags.
'opengraph/opengraph.php', // Open Graph.
'open-graph-protocol-framework/open-graph-protocol-framework.php', // Open Graph Protocol Framework.
'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments.
'seo-ultimate/seo-ultimate.php', // SEO Ultimate.
'sexybookmarks/sexy-bookmarks.php', // Shareaholic.
'shareaholic/sexy-bookmarks.php', // Shareaholic.
'sharepress/sharepress.php', // SharePress.
'simple-facebook-connect/sfc.php', // Simple Facebook Connect.
'social-discussions/social-discussions.php', // Social Discussions.
'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit.
'socialize/socialize.php', // Socialize.
'squirrly-seo/squirrly.php', // SEO by SQUIRRLYâ„¢.
'only-tweet-like-share-and-google-1/tweet-like-plusone.php', // Tweet, Like, Google +1 and Share.
'wordbooker/wordbooker.php', // Wordbooker.
'wpsso/wpsso.php', // WordPress Social Sharing Optimization.
'wp-caregiver/wp-caregiver.php', // WP Caregiver.
'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', // WP Facebook Like Send & Open Graph Meta.
'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol.
'wp-ogp/wp-ogp.php', // WP-OGP.
'wp-seopress/seopress.php', // SEOPress.
'wp-seopress-pro/seopress-pro.php', // SEOPress Pro.
'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin.
'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button.
'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox.
'seo-by-rank-math/rank-math.php', // Rank Math.
'slim-seo/slim-seo.php', // Slim SEO.
* Plugins for which we turn off our Twitter Cards Tags implementation.
* @var array Plugins that conflict with Twitter cards.
private $twitter_cards_conflicting_plugins = array(
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
// 'twitter/twitter.php', // The official one handles this on its own.
// https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php
'eewee-twitter-card/index.php', // Eewee Twitter Card.
'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards.
'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards.
'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', // Pure Web Brilliant's Social Graph Twitter Cards Extension.
'twitter-cards/twitter-cards.php', // Twitter Cards.
'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta.
'wp-to-twitter/wp-to-twitter.php', // WP to Twitter.
'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards.
'seo-by-rank-math/rank-math.php', // Rank Math.
'slim-seo/slim-seo.php', // Slim SEO.
* Message to display in admin_notice
* Error to display in admin_notice
* Modules that need more privacy description.
public $privacy_checks = '';
* Stats to record once the page loads
* @todo This is also seemingly unused.
* Verified data for JSON authorization request
public $json_api_authorization_request = array();
* @var Automattic\Jetpack\Connection\Manager
protected $connection_manager;
* @var string Transient key used to prevent multiple simultaneous plugin upgrades
public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock';
* Holds an instance of Automattic\Jetpack\A8c_Mc_Stats
* @var Automattic\Jetpack\A8c_Mc_Stats
public $a8c_mc_stats_instance;
* Constant for login redirect key.
public static $jetpack_redirect_login = 'jetpack_connect_login_redirect';
* Holds the singleton instance of this class
public static $instance = false;
public static function init() {
if ( ! self::$instance ) {
self::$instance = new Jetpack();
add_action( 'plugins_loaded', array( self::$instance, 'plugin_upgrade' ) );
add_action( 'jetpack_idc_disconnect', array( __CLASS__, 'on_idc_disconnect' ) );
* Must never be called statically
public function plugin_upgrade() {
if ( self::is_connection_ready() ) {
list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) );
if ( JETPACK__VERSION !== $version ) {
// Prevent multiple upgrades at once - only a single process should trigger an upgrade to avoid stampedes.
if ( wp_using_ext_object_cache() ) {
if ( true !== wp_cache_add( self::$plugin_upgrade_lock_key, 1, 'transient', 10 ) ) {
if ( false !== get_transient( self::$plugin_upgrade_lock_key ) ) {
set_transient( self::$plugin_upgrade_lock_key, 1, 10 );
// check which active modules actually exist and remove others from active_modules list.
$unfiltered_modules = self::get_active_modules();
$modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) );
if ( array_diff( $unfiltered_modules, $modules ) ) {
self::update_active_modules( $modules );
add_action( 'init', array( __CLASS__, 'activate_new_modules' ) );
if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) {
Jetpack_Options::delete_option( 'identity_crisis_whitelist' );
// Make sure Markdown for posts gets turned back on.
if ( ! get_option( 'wpcom_publish_posts_with_markdown' ) ) {
update_option( 'wpcom_publish_posts_with_markdown', true );
* Minileven deprecation. 8.3.0.
* Only delete options if not using
* the replacement standalone Minileven plugin.
! self::is_plugin_active( 'minileven-master/minileven.php' )
&& ! self::is_plugin_active( 'minileven/minileven.php' )
if ( get_option( 'wp_mobile_custom_css' ) ) {
delete_option( 'wp_mobile_custom_css' );
if ( get_option( 'wp_mobile_excerpt' ) ) {
delete_option( 'wp_mobile_excerpt' );
if ( get_option( 'wp_mobile_featured_images' ) ) {
delete_option( 'wp_mobile_featured_images' );
if ( get_option( 'wp_mobile_app_promos' ) ) {
delete_option( 'wp_mobile_app_promos' );
if ( Jetpack_Options::get_option( 'ab_connect_banner_green_bar' ) ) {