summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/class.jetpack.php')
-rw-r--r--plugins/jetpack/class.jetpack.php155
1 files changed, 135 insertions, 20 deletions
diff --git a/plugins/jetpack/class.jetpack.php b/plugins/jetpack/class.jetpack.php
index 66923080..e716cb2f 100644
--- a/plugins/jetpack/class.jetpack.php
+++ b/plugins/jetpack/class.jetpack.php
@@ -553,6 +553,11 @@ class Jetpack {
} else {
// The bootstrap API methods.
add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) );
+ $signed = $this->verify_xml_rpc_signature();
+ if ( $signed && ! is_wp_error( $signed ) ) {
+ // the jetpack Provision method is available for blog-token-signed requests
+ add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'provision_xmlrpc_methods' ) );
+ }
}
// Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on.
@@ -575,8 +580,10 @@ class Jetpack {
if ( Jetpack::is_active() ) {
Jetpack_Heartbeat::init();
- require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php';
- Jetpack_Search_Performance_Logger::init();
+ if ( Jetpack::is_module_active( 'stats' ) && Jetpack::is_module_active( 'search' ) ) {
+ require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php';
+ Jetpack_Search_Performance_Logger::init();
+ }
}
add_filter( 'determine_current_user', array( $this, 'wp_rest_authenticate' ) );
@@ -617,6 +624,9 @@ class Jetpack {
add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) );
+ // gutenberg locale
+ add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_gutenberg_locale' ) );
+
add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 );
/**
@@ -655,7 +665,7 @@ class Jetpack {
add_action( 'jetpack_heartbeat', array( $this, 'refresh_active_plan_from_wpcom' ) );
/**
- * This is the hack to concatinate all css files into one.
+ * This is the hack to concatenate all css files into one.
* For description and reasoning see the implode_frontend_css method
*
* Super late priority so we catch all the registered styles
@@ -1083,7 +1093,7 @@ class Jetpack {
* This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers.
*/
function devicepx() {
- if ( Jetpack::is_active() ) {
+ if ( Jetpack::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 );
}
}
@@ -1455,20 +1465,20 @@ class Jetpack {
global $active_plan_cache;
// this can be expensive to compute so we cache for the duration of a request
- if ( $active_plan_cache ) {
+ if ( is_array( $active_plan_cache ) && ! empty( $active_plan_cache ) ) {
return $active_plan_cache;
}
$plan = get_option( 'jetpack_active_plan', array() );
// Set the default options
- if ( empty( $plan ) || ( isset( $plan['product_slug'] ) && 'jetpack_free' === $plan['product_slug'] ) ) {
- $plan = wp_parse_args( $plan, array(
- 'product_slug' => 'jetpack_free',
- 'supports' => array(),
- 'class' => 'free',
- ) );
- }
+ $plan = wp_parse_args( $plan, array(
+ 'product_slug' => 'jetpack_free',
+ 'class' => 'free',
+ 'features' => array(
+ 'active' => array()
+ ),
+ ) );
$supports = array();
@@ -1515,6 +1525,9 @@ class Jetpack {
// get available features
foreach ( self::get_available_modules() as $module_slug ) {
$module = self::get_module( $module_slug );
+ if ( ! isset( $module ) || ! is_array( $module ) ) {
+ continue;
+ }
if ( in_array( 'free', $module['plan_classes'] ) || in_array( $plan['class'], $module['plan_classes'] ) ) {
$supports[] = $module_slug;
}
@@ -1540,7 +1553,23 @@ class Jetpack {
public static function active_plan_supports( $feature ) {
$plan = Jetpack::get_active_plan();
- if ( in_array( $feature, $plan['supports'] ) ) {
+ // Manually mapping WordPress.com features to Jetpack module slugs
+ foreach ( $plan['features']['active'] as $wpcom_feature ) {
+ switch ( $wpcom_feature ) {
+ case 'wordads-jetpack';
+
+ // WordAds are supported for this site
+ if ( 'wordads' === $feature ) {
+ return true;
+ }
+ break;
+ }
+ }
+
+ if (
+ in_array( $feature, $plan['supports'] )
+ || in_array( $feature, $plan['features']['active'] )
+ ) {
return true;
}
@@ -1568,7 +1597,8 @@ class Jetpack {
*
* @param bool $development_mode Is Jetpack's development mode active.
*/
- return apply_filters( 'jetpack_development_mode', $development_mode );
+ $development_mode = ( bool ) apply_filters( 'jetpack_development_mode', $development_mode );
+ return $development_mode;
}
/**
@@ -2564,6 +2594,30 @@ class Jetpack {
}
/**
+ * Get i18n strings as a JSON-encoded string
+ *
+ * @return string The locale as JSON
+ */
+ public static function get_i18n_data_json() {
+ $i18n_json = JETPACK__PLUGIN_DIR . 'languages/json/jetpack-' . jetpack_get_user_locale() . '.json';
+
+ if ( is_file( $i18n_json ) && is_readable( $i18n_json ) ) {
+ $locale_data = @file_get_contents( $i18n_json );
+ if ( $locale_data ) {
+ return $locale_data;
+ }
+ }
+
+ // Return valid empty Jed locale
+ return json_encode( array(
+ '' => array(
+ 'domain' => 'jetpack',
+ 'lang' => is_admin() ? get_user_locale() : get_locale(),
+ ),
+ ) );
+ }
+
+ /**
* Return module name translation. Uses matching string created in modules/module-headings.php.
*
* @since 3.9.2
@@ -2782,7 +2836,7 @@ class Jetpack {
}
ob_start();
- require $file;
+ require_once $file;
$active[] = $module;
@@ -2880,9 +2934,7 @@ class Jetpack {
}
}
- $plan = Jetpack::get_active_plan();
-
- if ( ! in_array( $module, $plan['supports'] ) ) {
+ if ( ! Jetpack::active_plan_supports( $module ) ) {
return false;
}
@@ -3793,6 +3845,13 @@ p {
return true;
}
+ function enqueue_gutenberg_locale() {
+ wp_add_inline_script(
+ 'wp-i18n',
+ 'wp.i18n.setLocaleData( ' . self::get_i18n_data_json() . ', \'jetpack\' );'
+ );
+ }
+
function jetpack_menu_order( $menu_order ) {
$jp_menu_order = array();
@@ -6563,6 +6622,9 @@ p {
'jetpack_is_holiday_snow_season' => null,
'jetpack_holiday_snow_option_updated' => null,
'jetpack_holiday_snowing' => null,
+ 'jetpack_sso_auth_cookie_expirtation' => 'jetpack_sso_auth_cookie_expiration',
+ 'jetpack_cache_plans' => null,
+ 'jetpack_updated_theme' => 'jetpack_updated_themes',
);
// This is a silly loop depth. Better way?
@@ -7040,12 +7102,34 @@ p {
/**
* Checks if Akismet is active and working.
*
+ * We dropped support for Akismet 3.0 with Jetpack 6.1.1 while introducing a check for an Akismet valid key
+ * that implied usage of methods present since more recent version.
+ * See https://github.com/Automattic/jetpack/pull/9585
+ *
* @since 5.1.0
+ *
* @return bool True = Akismet available. False = Aksimet not available.
*/
public static function is_akismet_active() {
- if ( method_exists( 'Akismet' , 'http_post' ) || function_exists( 'akismet_http_post' ) ) {
- return true;
+ if ( method_exists( 'Akismet' , 'http_post' ) ) {
+ $akismet_key = Akismet::get_api_key();
+ if ( ! $akismet_key ) {
+ return false;
+ }
+ $cached_key_verification = get_transient( 'jetpack_akismet_key_is_valid' );
+
+ // We cache the result of the Akismet key verification for ten minutes.
+ if ( in_array( $cached_key_verification, array( 'valid', 'invalid' ) ) ) {
+ $akismet_key_state = $cached_key_verification;
+ } else {
+ $akismet_key_state = Akismet::verify_key( $akismet_key );
+ if ( 'failed' === $akismet_key_state ) {
+ return false;
+ }
+ set_transient( 'jetpack_akismet_key_is_valid', $akismet_key_state, 10 * MINUTE_IN_SECONDS );
+ }
+
+ return ( 'valid' === $akismet_key_state );
}
return false;
}
@@ -7134,4 +7218,35 @@ p {
public static function jetpack_tos_agreed() {
return Jetpack_Options::get_option( 'tos_agreed' ) || Jetpack::is_active();
}
+
+ /**
+ * Handles activating default modules as well general cleanup for the new connection.
+ *
+ * @param boolean $activate_sso Whether to activate the SSO module when activating default modules.
+ * @param boolean $redirect_on_activation_error Whether to redirect on activation error.
+ * @return void
+ */
+ public static function handle_post_authorization_actions( $activate_sso = false, $redirect_on_activation_error = false ) {
+ $other_modules = $activate_sso
+ ? array( 'sso' )
+ : array();
+
+ if ( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) {
+ Jetpack::delete_active_modules();
+
+ Jetpack::activate_default_modules( 999, 1, array_merge( $active_modules, $other_modules ), $redirect_on_activation_error, false );
+ } else {
+ Jetpack::activate_default_modules( false, false, $other_modules, $redirect_on_activation_error, false );
+ }
+
+ // Since this is a fresh connection, be sure to clear out IDC options
+ Jetpack_IDC::clear_all_idc_options();
+ Jetpack_Options::delete_raw_option( 'jetpack_last_connect_url_check' );
+
+ // Start nonce cleaner
+ wp_clear_scheduled_hook( 'jetpack_clean_nonces' );
+ wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' );
+
+ Jetpack::state( 'message', 'authorized' );
+ }
}