summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/class.jetpack-options.php')
-rw-r--r--plugins/jetpack/class.jetpack-options.php181
1 files changed, 179 insertions, 2 deletions
diff --git a/plugins/jetpack/class.jetpack-options.php b/plugins/jetpack/class.jetpack-options.php
index 7acf9e7d..cf0a4444 100644
--- a/plugins/jetpack/class.jetpack-options.php
+++ b/plugins/jetpack/class.jetpack-options.php
@@ -52,6 +52,7 @@ class Jetpack_Options {
'safe_mode_confirmed', // (bool) True if someone confirms that this site was correctly put into safe mode automatically after an identity crisis is discovered.
'migrate_for_idc', // (bool) True if someone confirms that this site should migrate stats and subscribers from its previous URL
'dismissed_connection_banner', // (bool) True if the connection banner has been dismissed
+ 'onboarding', // (string) Auth token to be used in the onboarding connection flow
);
case 'private' :
@@ -63,6 +64,7 @@ class Jetpack_Options {
case 'network' :
return array(
+ 'onboarding', // (string) Auth token to be used in the onboarding connection flow
'file_data' // (array) List of absolute paths to all Jetpack modules
);
}
@@ -86,6 +88,7 @@ class Jetpack_Options {
'hide_jitm', // (array) A list of just in time messages that we should not show because they have been dismissed by the user
'custom_css_4.7_migration', // (bool) Whether Custom CSS has scanned for and migrated any legacy CSS CPT entries to the new Core format.
'image_widget_migration', // (bool) Whether any legacy Image Widgets have been converted to the new Core widget
+ 'gallery_widget_migration', // (bool) Whether any legacy Gallery Widgets have been converted to the new Core widget
);
}
@@ -185,7 +188,7 @@ class Jetpack_Options {
$is_network_option = self::is_network_option( $jetpack_name );
$value = $is_network_option ? get_site_option( $name ) : get_option( $name );
- if ( $value === false && $default !== false ) {
+ if ( false === $value && false !== $default ) {
if ( $is_network_option ) {
update_site_option( $name, $default );
} else {
@@ -331,10 +334,13 @@ class Jetpack_Options {
* Deletes an option via $wpdb query.
*
* @param string $name Option name.
- *
+ *
* @return bool Is the option deleted?
*/
static function delete_raw_option( $name ) {
+ if ( self::bypass_raw_option( $name ) ) {
+ return delete_option( $name );
+ }
global $wpdb;
$result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $name ) );
return $result;
@@ -350,6 +356,9 @@ class Jetpack_Options {
* @return bool Is the option updated?
*/
static function update_raw_option( $name, $value, $autoload = false ) {
+ if ( self::bypass_raw_option( $name ) ) {
+ return update_option( $name, $value, $autoload );
+ }
global $wpdb;
$autoload_value = $autoload ? 'yes' : 'no';
@@ -380,12 +389,18 @@ class Jetpack_Options {
/**
* Gets an option via $wpdb query.
*
+ * @since 5.4.0
+ *
* @param string $name Option name.
* @param mixed $default Default option value if option is not found.
*
* @return mixed Option value, or null if option is not found and default is not specified.
*/
static function get_raw_option( $name, $default = null ) {
+ if ( self::bypass_raw_option( $name ) ) {
+ return get_option( $name, $default );
+ }
+
global $wpdb;
$value = $wpdb->get_var(
$wpdb->prepare(
@@ -402,4 +417,166 @@ class Jetpack_Options {
return $value;
}
+ /**
+ * This function checks for a constant that, if present, will disable direct DB queries Jetpack uses to manage certain options and force Jetpack to always use Options API instead.
+ * Options can be selectively managed via a blacklist by filtering option names via the jetpack_disabled_raw_option filter.
+ *
+ * @param $name Option name
+ *
+ * @return bool
+ */
+ static function bypass_raw_option( $name ) {
+
+ if ( Jetpack_Constants::get_constant( 'JETPACK_DISABLE_RAW_OPTIONS' ) ) {
+ return true;
+ }
+ /**
+ * Allows to disable particular raw options.
+ * @since 5.5.0
+ *
+ * @param array $disabled_raw_options An array of option names that you can selectively blacklist from being managed via direct database queries.
+ */
+ $disabled_raw_options = apply_filters( 'jetpack_disabled_raw_options', array() );
+ return isset( $disabled_raw_options[ $name ] );
+ }
+
+ /**
+ * Gets all known options that are used by Jetpack and managed by Jetpack_Options.
+ *
+ * @since 5.4.0
+ *
+ * @param boolean $strip_unsafe_options If true, and by default, will strip out options necessary for the connection to WordPress.com.
+ * @return array An array of all options managed via the Jetpack_Options class.
+ */
+ static function get_all_jetpack_options( $strip_unsafe_options = true ) {
+ $jetpack_options = self::get_option_names();
+ $jetpack_options_non_compat = self::get_option_names( 'non_compact' );
+ $jetpack_options_private = self::get_option_names( 'private' );
+
+ $all_jp_options = array_merge( $jetpack_options, $jetpack_options_non_compat, $jetpack_options_private );
+
+ if ( $strip_unsafe_options ) {
+ // Flag some Jetpack options as unsafe
+ $unsafe_options = array(
+ 'id', // (int) The Client ID/WP.com Blog ID of this site.
+ 'master_user', // (int) The local User ID of the user who connected this site to jetpack.wordpress.com.
+ 'version', // (string) Used during upgrade procedure to auto-activate new modules. version:time
+ 'jumpstart', // (string) A flag for whether or not to show the Jump Start. Accepts: new_connection, jumpstart_activated, jetpack_action_taken, jumpstart_dismissed.
+
+ // non_compact
+ 'activated',
+
+ // private
+ 'register',
+ 'blog_token', // (string) The Client Secret/Blog Token of this site.
+ 'user_token', // (string) The User Token of this site. (deprecated)
+ 'user_tokens'
+ );
+
+ // Remove the unsafe Jetpack options
+ foreach ( $unsafe_options as $unsafe_option ) {
+ if ( false !== ( $key = array_search( $unsafe_option, $all_jp_options ) ) ) {
+ unset( $all_jp_options[ $key ] );
+ }
+ }
+ }
+
+ return $all_jp_options;
+ }
+
+ /**
+ * Get all options that are not managed by the Jetpack_Options class that are used by Jetpack.
+ *
+ * @since 5.4.0
+ *
+ * @return array
+ */
+ static function get_all_wp_options() {
+ // A manual build of the wp options
+ return array(
+ 'sharing-options',
+ 'disabled_likes',
+ 'disabled_reblogs',
+ 'jetpack_comments_likes_enabled',
+ 'wp_mobile_excerpt',
+ 'wp_mobile_featured_images',
+ 'wp_mobile_app_promos',
+ 'stats_options',
+ 'stats_dashboard_widget',
+ 'safecss_preview_rev',
+ 'safecss_rev',
+ 'safecss_revision_migrated',
+ 'nova_menu_order',
+ 'jetpack_portfolio',
+ 'jetpack_portfolio_posts_per_page',
+ 'jetpack_testimonial',
+ 'jetpack_testimonial_posts_per_page',
+ 'wp_mobile_custom_css',
+ 'sharedaddy_disable_resources',
+ 'sharing-options',
+ 'sharing-services',
+ 'site_icon_temp_data',
+ 'featured-content',
+ 'site_logo',
+ 'jetpack_dismissed_notices',
+ 'jetpack-twitter-cards-site-tag',
+ 'jetpack-sitemap-state',
+ 'jetpack_sitemap_post_types',
+ 'jetpack_sitemap_location',
+ 'jetpack_protect_key',
+ 'jetpack_protect_blocked_attempts',
+ 'jetpack_protect_activating',
+ 'jetpack_connection_banner_ab',
+ 'jetpack_active_plan',
+ 'jetpack_activation_source',
+ 'jetpack_sso_match_by_email',
+ 'jetpack_sso_require_two_step',
+ 'jetpack_sso_remove_login_form',
+ 'jetpack_last_connect_url_check',
+ );
+ }
+
+ /**
+ * Gets all options that can be safely reset by CLI.
+ *
+ * @since 5.4.0
+ *
+ * @return array array Associative array containing jp_options which are managed by the Jetpack_Options class and wp_options which are not.
+ */
+ static function get_options_for_reset() {
+ $all_jp_options = self::get_all_jetpack_options();
+
+ $wp_options = self::get_all_wp_options();
+
+ $options = array(
+ 'jp_options' => $all_jp_options,
+ 'wp_options' => $wp_options
+ );
+
+ return $options;
+ }
+
+ /**
+ * Delete all known options
+ *
+ * @since 5.4.0
+ *
+ * @return void
+ */
+ static function delete_all_known_options() {
+ // Delete all compact options
+ foreach ( (array) self::$grouped_options as $option_name ) {
+ delete_option( $option_name );
+ }
+
+ // Delete all non-compact Jetpack options
+ foreach ( (array) self::get_option_names( 'non-compact' ) as $option_name ) {
+ Jetpack_Options::delete_option( $option_name );
+ }
+
+ // Delete all options that can be reset via CLI, that aren't Jetpack options
+ foreach ( (array) self::get_all_wp_options() as $option_name ) {
+ delete_option( $option_name );
+ }
+ }
}