summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/class.jetpack.php')
-rw-r--r--plugins/jetpack/class.jetpack.php191
1 files changed, 129 insertions, 62 deletions
diff --git a/plugins/jetpack/class.jetpack.php b/plugins/jetpack/class.jetpack.php
index 8566fd67..8e790dd8 100644
--- a/plugins/jetpack/class.jetpack.php
+++ b/plugins/jetpack/class.jetpack.php
@@ -33,7 +33,9 @@ class Jetpack {
public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA']
/**
- * @var array The handles of styles that are concatenated into jetpack.css
+ * @var array The handles of styles that are concatenated into jetpack.css.
+ *
+ * When making changes to that list, you must also update concat_list in tools/builder/frontend-css.js.
*/
public $concatenated_style_handles = array(
'jetpack-carousel',
@@ -44,6 +46,7 @@ class Jetpack {
'sharedaddy',
'jetpack-slideshow',
'presentations',
+ 'quiz',
'jetpack-subscriptions',
'jetpack-responsive-videos-style',
'jetpack-social-menu',
@@ -55,11 +58,13 @@ class Jetpack {
'jetpack-top-posts-widget',
'jetpack_image_widget',
'jetpack-my-community-widget',
+ 'jetpack-authors-widget',
'wordads',
'eu-cookie-law-style',
'flickr-widget-style',
'jetpack-search-widget',
'jetpack-simple-payments-widget-style',
+ 'jetpack-widget-social-icons-styles',
);
/**
@@ -179,12 +184,14 @@ class Jetpack {
'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',
),
'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',
),
'widget-visibility' => array(
'Widget Logic' => 'widget-logic/widget_logic.php',
@@ -200,6 +207,7 @@ class Jetpack {
'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',
@@ -227,7 +235,6 @@ 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
- 'autodescription/autodescription.php', // The SEO Framework
'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
@@ -415,7 +422,7 @@ class Jetpack {
Jetpack::maybe_set_version_option();
- if ( class_exists( 'Jetpack_Widget_Conditions' ) ) {
+ if ( method_exists( 'Jetpack_Widget_Conditions', 'migrate_post_type_rules' ) ) {
Jetpack_Widget_Conditions::migrate_post_type_rules();
}
@@ -511,6 +518,8 @@ class Jetpack {
if ( Jetpack::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 );
}
/*
@@ -524,6 +533,14 @@ class Jetpack {
Jetpack_Network::init();
}
+ /**
+ * Prepare Gutenberg Editor functionality
+ */
+ require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php';
+ add_action( 'init', array( 'Jetpack_Gutenberg', 'load_blocks' ) ); // Registers all the Jetpack blocks .
+ add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) );
+ add_filter( 'jetpack_set_available_blocks', array( 'Jetpack_Gutenberg', 'jetpack_set_available_blocks' ) );
+
add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 );
// Unlink user before deleting the user from .com
@@ -625,9 +642,6 @@ 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 );
/**
@@ -894,6 +908,12 @@ class Jetpack {
case 'jetpack_configure_modules' :
$caps = array( 'manage_options' );
break;
+ case 'jetpack_manage_autoupdates' :
+ $caps = array(
+ 'manage_options',
+ 'update_plugins',
+ );
+ break;
case 'jetpack_network_admin_page':
case 'jetpack_network_settings_page':
$caps = array( 'manage_network_plugins' );
@@ -1488,6 +1508,7 @@ class Jetpack {
'jetpack_personal',
'jetpack_personal_monthly',
'personal-bundle',
+ 'personal-bundle-2y',
);
if ( in_array( $plan['product_slug'], $personal_plans ) ) {
@@ -1501,12 +1522,14 @@ class Jetpack {
'jetpack_premium',
'jetpack_premium_monthly',
'value_bundle',
+ 'value_bundle-2y',
);
if ( in_array( $plan['product_slug'], $premium_plans ) ) {
$supports[] = 'akismet';
$supports[] = 'simple-payments';
$supports[] = 'vaultpress';
+ $supports[] = 'videopress';
$plan['class'] = 'premium';
}
@@ -1515,6 +1538,7 @@ class Jetpack {
'jetpack_business',
'jetpack_business_monthly',
'business-bundle',
+ 'business-bundle-2y',
'vip',
);
@@ -1522,6 +1546,7 @@ class Jetpack {
$supports[] = 'akismet';
$supports[] = 'simple-payments';
$supports[] = 'vaultpress';
+ $supports[] = 'videopress';
$plan['class'] = 'business';
}
@@ -2602,7 +2627,7 @@ class Jetpack {
* @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';
+ $i18n_json = JETPACK__PLUGIN_DIR . 'languages/json/jetpack-' . get_user_locale() . '.json';
if ( is_file( $i18n_json ) && is_readable( $i18n_json ) ) {
$locale_data = @file_get_contents( $i18n_json );
@@ -2621,6 +2646,32 @@ class Jetpack {
}
/**
+ * Add locale data setup to wp-i18n
+ *
+ * Any Jetpack script that depends on wp-i18n should use this method to set up the locale.
+ *
+ * The locale setup depends on an adding inline script. This is error-prone and could easily
+ * result in multiple additions of the same script when exactly 0 or 1 is desireable.
+ *
+ * This method provides a safe way to request the setup multiple times but add the script at
+ * most once.
+ *
+ * @since 6.7.0
+ *
+ * @return void
+ */
+ public static function setup_wp_i18n_locale_data() {
+ static $script_added = false;
+ if ( ! $script_added ) {
+ $script_added = true;
+ wp_add_inline_script(
+ 'wp-i18n',
+ 'wp.i18n.setLocaleData( ' . Jetpack::get_i18n_data_json() . ', \'jetpack\' );'
+ );
+ }
+ }
+
+ /**
* Return module name translation. Uses matching string created in modules/module-headings.php.
*
* @since 3.9.2
@@ -2796,8 +2847,10 @@ class Jetpack {
do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules );
// Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating
- Jetpack::restate();
- Jetpack::catch_errors( true );
+ if ( $send_state_messages ) {
+ Jetpack::restate();
+ Jetpack::catch_errors( true );
+ }
$active = Jetpack::get_active_modules();
@@ -3160,10 +3213,14 @@ p {
* @return null [description]
*/
public static function do_version_bump( $version, $old_version ) {
-
if ( ! $old_version ) { // For new sites
// Setting up jetpack manage
Jetpack::activate_manage();
+ } else {
+ // If a Jetpack is still active but not connected when updating verion, remind them to connect with the banner.
+ if ( ! Jetpack::is_active() ) {
+ Jetpack_Options::delete_option( 'dismissed_connection_banner' );
+ }
}
}
@@ -3848,13 +3905,6 @@ 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();
@@ -3901,7 +3951,7 @@ p {
function plugin_action_links( $actions ) {
- $jetpack_home = array( 'jetpack-home' => sprintf( '<a href="%s">%s</a>', Jetpack::admin_url( 'page=jetpack' ), __( 'Jetpack', 'jetpack' ) ) );
+ $jetpack_home = array( 'jetpack-home' => sprintf( '<a href="%s">%s</a>', Jetpack::admin_url( 'page=jetpack' ), 'Jetpack' ) );
if( current_user_can( 'jetpack_manage_modules' ) && ( Jetpack::is_active() || Jetpack::is_development_mode() ) ) {
return array_merge(
@@ -4802,7 +4852,6 @@ p {
<h3>
<?php
$module = Jetpack::get_module( $module_id );
- echo '<a href="' . Jetpack::admin_url( 'page=jetpack_modules' ) . '">' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</a> &rarr; ';
printf( __( 'Configure %s', 'jetpack' ), $module['name'] );
?>
</h3>
@@ -5599,25 +5648,6 @@ p {
return null;
}
- if ( ! empty( $_SERVER['CONTENT_TYPE'] ) ) {
- $content_type = $_SERVER['CONTENT_TYPE'];
- } elseif ( ! empty( $_SERVER['HTTP_CONTENT_TYPE'] ) ) {
- $content_type = $_SERVER['HTTP_CONTENT_TYPE'];
- }
-
- if (
- isset( $content_type ) &&
- $content_type !== 'application/x-www-form-urlencoded' &&
- $content_type !== 'application/json'
- ) {
- $this->rest_authentication_status = new WP_Error(
- 'rest_invalid_request',
- __( 'This Content-Type is not supported.', 'jetpack' ),
- array( 'status' => 400 )
- );
- return null;
- }
-
$verified = $this->verify_xml_rpc_signature();
if ( is_wp_error( $verified ) ) {
@@ -6628,6 +6658,8 @@ p {
'jetpack_sso_auth_cookie_expirtation' => 'jetpack_sso_auth_cookie_expiration',
'jetpack_cache_plans' => null,
'jetpack_updated_theme' => 'jetpack_updated_themes',
+ 'jetpack_lazy_images_skip_image_with_atttributes' => 'jetpack_lazy_images_skip_image_with_attributes',
+ 'jetpack_enable_site_verification' => null,
);
// This is a silly loop depth. Better way?
@@ -7114,27 +7146,39 @@ p {
* @return bool True = Akismet available. False = Aksimet not available.
*/
public static function is_akismet_active() {
- 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' );
+ static $status = null;
- // 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 );
- }
+ if ( ! is_null( $status ) ) {
+ return $status;
+ }
- return ( 'valid' === $akismet_key_state );
+ // Check if a modern version of Akismet is active.
+ if ( ! method_exists( 'Akismet', 'http_post' ) ) {
+ $status = false;
+ return $status;
}
- return false;
+
+ // Make sure there is a key known to Akismet at all before verifying key.
+ $akismet_key = Akismet::get_api_key();
+ if ( ! $akismet_key ) {
+ $status = false;
+ return $status;
+ }
+
+ // Possible values: valid, invalid, failure via Akismet. false if no status is cached.
+ $akismet_key_state = get_transient( 'jetpack_akismet_key_is_valid' );
+
+ // Do not used the cache result in wp-admin or REST API requests if the key isn't valid, in case someone is actively renewing, etc.
+ $recheck = ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) && 'valid' !== $akismet_key_state;
+ // We cache the result of the Akismet key verification for ten minutes.
+ if ( ! $akismet_key_state || $recheck ) {
+ $akismet_key_state = Akismet::verify_key( $akismet_key );
+ set_transient( 'jetpack_akismet_key_is_valid', $akismet_key_state, 10 * MINUTE_IN_SECONDS );
+ }
+
+ $status = 'valid' === $akismet_key_state;
+
+ return $status;
}
/**
@@ -7145,7 +7189,7 @@ p {
* @return bool
*/
public static function is_function_in_backtrace( $names ) {
- $backtrace = debug_backtrace( false );
+ $backtrace = debug_backtrace( false ); // phpcs:ignore PHPCompatibility.PHP.NewFunctionParameters.debug_backtrace_optionsFound
if ( ! is_array( $names ) ) {
$names = array( $names );
}
@@ -7153,7 +7197,7 @@ p {
//Do check in constant O(1) time for PHP5.5+
if ( function_exists( 'array_column' ) ) {
- $backtrace_functions = array_column( $backtrace, 'function' );
+ $backtrace_functions = array_column( $backtrace, 'function' ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_columnFound
$backtrace_functions_as_keys = array_flip( $backtrace_functions );
$intersection = array_intersect_key( $backtrace_functions_as_keys, $names_as_keys );
return ! empty ( $intersection );
@@ -7227,9 +7271,14 @@ p {
*
* @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.
+ * @param boolean $send_state_messages Whether to send state messages.
* @return void
*/
- public static function handle_post_authorization_actions( $activate_sso = false, $redirect_on_activation_error = false ) {
+ public static function handle_post_authorization_actions(
+ $activate_sso = false,
+ $redirect_on_activation_error = false,
+ $send_state_messages = true
+ ) {
$other_modules = $activate_sso
? array( 'sso' )
: array();
@@ -7237,9 +7286,9 @@ p {
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 );
+ Jetpack::activate_default_modules( 999, 1, array_merge( $active_modules, $other_modules ), $redirect_on_activation_error, $send_state_messages );
} else {
- Jetpack::activate_default_modules( false, false, $other_modules, $redirect_on_activation_error, false );
+ Jetpack::activate_default_modules( false, false, $other_modules, $redirect_on_activation_error, $send_state_messages );
}
// Since this is a fresh connection, be sure to clear out IDC options
@@ -7250,6 +7299,24 @@ p {
wp_clear_scheduled_hook( 'jetpack_clean_nonces' );
wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' );
- Jetpack::state( 'message', 'authorized' );
+ if ( $send_state_messages ) {
+ Jetpack::state( 'message', 'authorized' );
+ }
+ }
+
+ /**
+ * Returns a boolean for whether backups UI should be displayed or not.
+ *
+ * @return bool Should backups UI be displayed?
+ */
+ public static function show_backups_ui() {
+ /**
+ * Whether UI for backups should be displayed.
+ *
+ * @since 6.5.0
+ *
+ * @param bool $show_backups Should UI for backups be displayed? True by default.
+ */
+ return Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) || apply_filters( 'jetpack_show_backups', true );
}
}