summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/class.jetpack.php')
-rw-r--r--plugins/jetpack/class.jetpack.php273
1 files changed, 123 insertions, 150 deletions
diff --git a/plugins/jetpack/class.jetpack.php b/plugins/jetpack/class.jetpack.php
index 36b4b7a2..ff8aa073 100644
--- a/plugins/jetpack/class.jetpack.php
+++ b/plugins/jetpack/class.jetpack.php
@@ -1,12 +1,12 @@
<?php
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Assets\Logo as Jetpack_Logo;
+use Automattic\Jetpack\Config;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
-use Automattic\Jetpack\Connection\REST_Connector as REST_Connector;
-use Automattic\Jetpack\Connection\XMLRPC_Connector as XMLRPC_Connector;
use Automattic\Jetpack\Connection\Utils as Connection_Utils;
use Automattic\Jetpack\Constants;
+use Automattic\Jetpack\Partner;
use Automattic\Jetpack\Roles;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Sync\Functions;
@@ -47,8 +47,6 @@ class Jetpack {
public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA']
- private $tracking;
-
/**
* @var array The handles of styles that are concatenated into jetpack.css.
*
@@ -270,6 +268,7 @@ class Jetpack {
// 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
@@ -397,8 +396,7 @@ class Jetpack {
public static function init() {
if ( ! self::$instance ) {
self::$instance = new Jetpack();
-
- self::$instance->plugin_upgrade();
+ add_action( 'plugins_loaded', array( self::$instance, 'plugin_upgrade' ) );
}
return self::$instance;
@@ -560,17 +558,8 @@ class Jetpack {
*/
add_action( 'init', array( $this, 'deprecated_hooks' ) );
- /*
- * Enable enhanced handling of previewing sites in Calypso
- */
- if ( self::is_active() ) {
- require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php';
- add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 );
- require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php';
- add_action( 'init', array( 'Jetpack_Keyring_Service_Helper', 'init' ), 9, 0 );
- }
-
- add_action( 'plugins_loaded', array( $this, 'after_plugins_loaded' ) );
+ add_action( 'plugins_loaded', array( $this, 'configure' ), 1 );
+ add_action( 'plugins_loaded', array( $this, 'late_initialization' ), 90 );
add_filter(
'jetpack_connection_secret_generator',
@@ -583,21 +572,6 @@ class Jetpack {
add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) );
- $this->connection_manager = new Connection_Manager();
- $this->connection_manager->init();
-
- /*
- * Load things that should only be in Network Admin.
- *
- * For now blow away everything else until a more full
- * understanding of what is needed at the network level is
- * available
- */
- if ( is_multisite() ) {
- $network = Jetpack_Network::init();
- $network->set_connection( $this->connection_manager );
- }
-
add_filter(
'jetpack_signature_check_token',
array( __CLASS__, 'verify_onboarding_token' ),
@@ -619,19 +593,6 @@ class Jetpack {
add_action( 'deleted_user', array( 'Automattic\\Jetpack\\Connection\\Manager', 'disconnect_user' ), 10, 1 );
add_action( 'remove_user_from_blog', array( 'Automattic\\Jetpack\\Connection\\Manager', 'disconnect_user' ), 10, 1 );
- // Initialize remote file upload request handlers.
- $this->add_remote_request_handlers();
-
- if ( self::is_active() ) {
- add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) );
-
- Jetpack_Heartbeat::init();
- if ( self::is_module_active( 'stats' ) && self::is_module_active( 'search' ) ) {
- require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php';
- Jetpack_Search_Performance_Logger::init();
- }
- }
-
add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 );
add_filter( 'determine_current_user', array( $this, 'wp_rest_authenticate' ) );
@@ -652,9 +613,6 @@ class Jetpack {
add_action( 'wp_ajax_jetpack_connection_banner', array( $this, 'jetpack_connection_banner_callback' ) );
add_action( 'wp_loaded', array( $this, 'register_assets' ) );
- add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) );
- add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) );
add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 );
@@ -671,7 +629,6 @@ class Jetpack {
add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 );
add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 );
- add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 );
add_filter( 'profile_update', array( 'Jetpack', 'user_meta_cleanup' ) );
add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) );
@@ -682,17 +639,6 @@ class Jetpack {
add_filter( 'jetpack_just_in_time_msg_cache', '__return_true', 9 );
- // If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin.
- // We should make sure to only do this for front end links.
- if ( self::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) {
- add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 );
- add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 );
-
- // we'll override wp_notify_postauthor and wp_notify_moderator pluggable functions
- // so they point moderation links on emails to Calypso
- jetpack_require_lib( 'functions.wp-notify' );
- }
-
// Hide edit post link if mobile app.
if ( Jetpack_User_Agent_Info::is_mobile_app() ) {
add_filter( 'edit_post_link', '__return_empty_string' );
@@ -739,20 +685,105 @@ class Jetpack {
}
/**
- * Runs after all the plugins have loaded but before init.
+ * Before everything else starts getting initalized, we need to initialize Jetpack using the
+ * Config object.
*/
- function after_plugins_loaded() {
+ public function configure() {
+ $config = new Config();
- $terms_of_service = new Terms_Of_Service();
- $tracking = new Plugin_Tracking();
- if ( $terms_of_service->has_agreed() ) {
- add_action( 'init', array( $tracking, 'init' ) );
- } else {
- /**
- * Initialize tracking right after the user agrees to the terms of service.
+ foreach (
+ array(
+ 'connection',
+ 'sync',
+ 'tracking',
+ 'tos',
+ )
+ as $feature
+ ) {
+ $config->ensure( $feature );
+ }
+
+ if ( is_admin() ) {
+ $config->ensure( 'jitm' );
+ }
+
+ $this->connection_manager = new Connection_Manager();
+
+ /*
+ * Load things that should only be in Network Admin.
+ *
+ * For now blow away everything else until a more full
+ * understanding of what is needed at the network level is
+ * available
+ */
+ if ( is_multisite() ) {
+ $network = Jetpack_Network::init();
+ $network->set_connection( $this->connection_manager );
+ }
+
+ if ( $this->connection_manager->is_active() ) {
+ add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) );
+
+ Jetpack_Heartbeat::init();
+ if ( self::is_module_active( 'stats' ) && self::is_module_active( 'search' ) ) {
+ require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php';
+ Jetpack_Search_Performance_Logger::init();
+ }
+ }
+
+ // Initialize remote file upload request handlers.
+ $this->add_remote_request_handlers();
+
+ /*
+ * Enable enhanced handling of previewing sites in Calypso
+ */
+ if ( self::is_active() ) {
+ require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php';
+ add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 );
+ require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php';
+ add_action( 'init', array( 'Jetpack_Keyring_Service_Helper', 'init' ), 9, 0 );
+ }
+
+ /*
+ * If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin.
+ * We should make sure to only do this for front end links.
+ */
+ if ( self::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) {
+ add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 );
+ add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 );
+
+ /*
+ * We'll override wp_notify_postauthor and wp_notify_moderator pluggable functions
+ * so they point moderation links on emails to Calypso.
*/
- add_action( 'jetpack_agreed_to_terms_of_service', array( $tracking, 'init' ) );
+ jetpack_require_lib( 'functions.wp-notify' );
}
+
+ }
+
+ /**
+ * Runs on plugins_loaded. Use this to add code that needs to be executed later than other
+ * initialization code.
+ *
+ * @action plugins_loaded
+ */
+ public function late_initialization() {
+ add_action( 'plugins_loaded', array( 'Jetpack', 'plugin_textdomain' ), 99 );
+ add_action( 'plugins_loaded', array( 'Jetpack', 'load_modules' ), 100 );
+
+ Partner::init();
+
+ /**
+ * Fires when Jetpack is fully loaded and ready. This is the point where it's safe
+ * to instantiate classes from packages and namespaces that are managed by the Jetpack Autoloader.
+ *
+ * @since 8.1.0
+ *
+ * @param Jetpack $jetpack the main plugin class object.
+ */
+ do_action( 'jetpack_loaded', $this );
+
+ add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 );
}
/**
@@ -1185,16 +1216,6 @@ class Jetpack {
}
/**
- * Device Pixels support
- * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers.
- */
- function devicepx() {
- if ( self::is_active() && ! Jetpack_AMP_Support::is_amp_request() ) {
- wp_enqueue_script( 'devicepx', 'https://s0.wp.com/wp-content/js/devicepx-jetpack.js', array(), gmdate( 'oW' ), true );
- }
- }
-
- /**
* Return the network_site_url so that .com knows what network this site is a part of.
*
* @param bool $option
@@ -1636,7 +1657,7 @@ class Jetpack {
echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>';
}
// Throw up a notice if using staging mode
- if ( self::is_staging_site() ) {
+ if ( ( new Status() )->is_staging_site() ) {
/* translators: %s is a URL */
$notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' );
@@ -4615,14 +4636,16 @@ endif;
$url = add_query_arg( 'from', $from, $url );
}
- // Ensure that class to get the affiliate code is loaded
- if ( ! class_exists( 'Jetpack_Affiliate' ) ) {
- require_once JETPACK__PLUGIN_DIR . 'class.jetpack-affiliate.php';
- }
- // Get affiliate code and add it to the URL
- $url = Jetpack_Affiliate::init()->add_code_as_query_arg( $url );
-
- return $raw ? esc_url_raw( $url ) : esc_url( $url );
+ $url = $raw ? esc_url_raw( $url ) : esc_url( $url );
+ /**
+ * Filter the URL used when connecting a user to a WordPress.com account.
+ *
+ * @since 8.1.0
+ *
+ * @param string $url Connection URL.
+ * @param bool $raw If true, URL will not be escaped.
+ */
+ return apply_filters( 'jetpack_build_connection_url', $url, $raw );
}
public static function build_authorize_url( $redirect = false, $iframe = false ) {
@@ -5118,6 +5141,11 @@ endif;
return self::connection()->xmlrpc_api_url();
}
+ /**
+ * Returns the connection manager object.
+ *
+ * @return Automattic\Jetpack\Connection\Manager
+ */
public static function connection() {
return self::init()->connection_manager;
}
@@ -5307,8 +5335,7 @@ endif;
* @deprecated since 7.7.0
*/
public static function load_xml_rpc_client() {
- // Removed the php notice that shows up in order to give time to Akismet and VaultPress time to update.
- // _deprecated_function( __METHOD__, 'jetpack-7.7' );
+ _deprecated_function( __METHOD__, 'jetpack-7.7' );
}
/**
@@ -5590,7 +5617,9 @@ endif;
$value = $value[0];
}
$state[ $key ] = $value;
- setcookie( "jetpackState[$key]", $value, 0, $path, $domain );
+ if ( ! headers_sent() ) {
+ setcookie( "jetpackState[$key]", $value, 0, $path, $domain );
+ }
}
}
@@ -5988,64 +6017,8 @@ endif;
* @return bool True = already whitelisted False = not whitelisted
*/
public static function is_staging_site() {
- $is_staging = false;
-
- $known_staging = array(
- 'urls' => array(
- '#\.staging\.wpengine\.com$#i', // WP Engine
- '#\.staging\.kinsta\.com$#i', // Kinsta.com
- '#\.stage\.site$#i', // DreamPress
- ),
- 'constants' => array(
- 'IS_WPE_SNAPSHOT', // WP Engine
- 'KINSTA_DEV_ENV', // Kinsta.com
- 'WPSTAGECOACH_STAGING', // WP Stagecoach
- 'JETPACK_STAGING_MODE', // Generic
- ),
- );
- /**
- * Filters the flags of known staging sites.
- *
- * @since 3.9.0
- *
- * @param array $known_staging {
- * An array of arrays that each are used to check if the current site is staging.
- * @type array $urls URLs of staging sites in regex to check against site_url.
- * @type array $constants PHP constants of known staging/developement environments.
- * }
- */
- $known_staging = apply_filters( 'jetpack_known_staging', $known_staging );
-
- if ( isset( $known_staging['urls'] ) ) {
- foreach ( $known_staging['urls'] as $url ) {
- if ( preg_match( $url, site_url() ) ) {
- $is_staging = true;
- break;
- }
- }
- }
-
- if ( isset( $known_staging['constants'] ) ) {
- foreach ( $known_staging['constants'] as $constant ) {
- if ( defined( $constant ) && constant( $constant ) ) {
- $is_staging = true;
- }
- }
- }
-
- // Last, let's check if sync is erroring due to an IDC. If so, set the site to staging mode.
- if ( ! $is_staging && self::validate_sync_error_idc_option() ) {
- $is_staging = true;
- }
-
- /**
- * Filters is_staging_site check.
- *
- * @since 3.9.0
- *
- * @param bool $is_staging If the current site is a staging site.
- */
- return apply_filters( 'jetpack_is_staging_site', $is_staging );
+ _deprecated_function( 'Jetpack::is_staging_site', 'jetpack-8.1', '/Automattic/Jetpack/Status->is_staging_site' );
+ return ( new Status() )->is_staging_site();
}
/**