From 4e167c593dd34119ccb4f290586669faa2b5807f Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 3 Sep 2024 18:19:14 +0000 Subject: [PATCH] Options, Meta APIs: Explicitly pass `$autoload` parameter to when potentially adding new options. It is recommended that for every option it is explicitly set whether to autoload it or not. This changeset updates relevant `update_option()` and `add_option()` calls. Note that the `$autoload` parameter is only needed for `update_option()` if the option is potentially not present yet, i.e. the call will pass through to `add_option()`. Since WordPress core adds the majority of its options to the database during installation, only `update_option()` calls for dynamically added options need to be modified, which is what this changeset does. As part of revisiting the autoload values for dynamically added WordPress core options, this changeset modifies some options to no longer be autoloaded, since they are only accessed in a few specific places that are not relevant for a regular request. These options are: * `recently_activated` * `_wp_suggested_policy_text_has_changed` * `{upgradeLock}.lock` * `dashboard_widget_options` * `ftp_credentials` * `adminhash` * `nav_menu_options` * `wp_force_deactivated_plugins` * `delete_blog_hash` * `allowedthemes` * `{sessionId}_paused_extensions` * `recovery_keys` * `https_detection_errors` * `fresh_site` An upgrade routine is present as well that sets those options to no longer autoload for existing sites. Props pbearne, flixos90, mukesh27, swissspidy, SergeyBiryukov, joemcgill, adamsilverstein. Fixes #61103. Built from https://develop.svn.wordpress.org/trunk@58975 git-svn-id: http://core.svn.wordpress.org/trunk@58371 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin.php | 2 +- .../includes/class-wp-plugins-list-table.php | 2 +- .../class-wp-privacy-policy-content.php | 2 +- wp-admin/includes/class-wp-upgrader.php | 2 +- wp-admin/includes/dashboard.php | 2 +- wp-admin/includes/file.php | 2 +- wp-admin/includes/misc.php | 2 +- wp-admin/includes/nav-menu.php | 2 +- wp-admin/includes/plugin.php | 4 +-- wp-admin/includes/update-core.php | 2 +- wp-admin/includes/upgrade.php | 36 +++++++++++++++++-- wp-admin/ms-delete-site.php | 2 +- wp-admin/network/site-themes.php | 2 +- wp-admin/plugins.php | 10 +++--- .../class-wp-paused-extensions-storage.php | 6 ++-- .../class-wp-recovery-mode-key-service.php | 2 +- wp-includes/class-wp-roles.php | 2 +- wp-includes/class-wp-theme.php | 4 +-- wp-includes/cron.php | 4 +-- wp-includes/deprecated.php | 2 +- wp-includes/functions.php | 2 +- wp-includes/ms-functions.php | 2 +- wp-includes/theme.php | 2 +- wp-includes/version.php | 4 +-- 24 files changed, 67 insertions(+), 35 deletions(-) diff --git a/wp-admin/admin.php b/wp-admin/admin.php index 455620f1c7..630765f77d 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -38,7 +38,7 @@ nocache_headers(); if ( get_option( 'db_upgraded' ) ) { flush_rewrite_rules(); - update_option( 'db_upgraded', false ); + update_option( 'db_upgraded', false, true ); /** * Fires on the next page load after a successful DB upgrade. diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 77ae9b57d0..e96445b771 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -194,7 +194,7 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( $screen->in_admin( 'network' ) ) { update_site_option( 'recently_activated', $recently_activated ); } else { - update_option( 'recently_activated', $recently_activated ); + update_option( 'recently_activated', $recently_activated, false ); } $plugin_info = get_site_transient( 'update_plugins' ); diff --git a/wp-admin/includes/class-wp-privacy-policy-content.php b/wp-admin/includes/class-wp-privacy-policy-content.php index e0775f7bea..04aee97aac 100644 --- a/wp-admin/includes/class-wp-privacy-policy-content.php +++ b/wp-admin/includes/class-wp-privacy-policy-content.php @@ -120,7 +120,7 @@ final class WP_Privacy_Policy_Content { // Cache the result for use before `admin_init` (see above). if ( $cached !== $state ) { - update_option( '_wp_suggested_policy_text_has_changed', $state ); + update_option( '_wp_suggested_policy_text_has_changed', $state, false ); } return 'changed' === $state; diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 9474ce0b9b..d3ca761c37 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -1053,7 +1053,7 @@ class WP_Upgrader { } // Update the lock, as by this point we've definitely got a lock, just need to fire the actions. - update_option( $lock_option, time() ); + update_option( $lock_option, time(), false ); return true; } diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index be1ac4224c..427006c03c 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -1279,7 +1279,7 @@ function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { } } - update_option( 'dashboard_widget_options', $widget_options ); + update_option( 'dashboard_widget_options', $widget_options, false ); $locale = get_user_locale(); $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index d7258e0949..b1ea3fba1b 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -2472,7 +2472,7 @@ function request_filesystem_credentials( $form_post, $type = '', $error = false, ); if ( ! wp_installing() ) { - update_option( 'ftp_credentials', $stored_credentials ); + update_option( 'ftp_credentials', $stored_credentials, false ); } return $credentials; diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 06fc294445..5ce34cf18d 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -1477,7 +1477,7 @@ function update_option_new_admin_email( $old_value, $value ) { 'hash' => $hash, 'newemail' => $value, ); - update_option( 'adminhash', $new_admin_email ); + update_option( 'adminhash', $new_admin_email, false ); $switched_locale = switch_to_user_locale( get_current_user_id() ); diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index aa72117e68..5ba3276b3a 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -1484,7 +1484,7 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); - update_option( 'nav_menu_options', $nav_menu_option ); + update_option( 'nav_menu_options', $nav_menu_option, false ); wp_defer_term_counting( false ); diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 5b63855446..de1468352b 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -2610,7 +2610,7 @@ function deactivated_plugins_notice() { if ( false === $blog_deactivated_plugins ) { // Option not in database, add an empty array to avoid extra DB queries on subsequent loads. - update_option( 'wp_force_deactivated_plugins', array() ); + update_option( 'wp_force_deactivated_plugins', array(), false ); } if ( is_multisite() ) { @@ -2664,7 +2664,7 @@ function deactivated_plugins_notice() { } // Empty the options. - update_option( 'wp_force_deactivated_plugins', array() ); + update_option( 'wp_force_deactivated_plugins', array(), false ); if ( is_multisite() ) { update_site_option( 'wp_force_deactivated_plugins', array() ); } diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index 9b6ece8d21..edda202cc5 100644 --- a/wp-admin/includes/update-core.php +++ b/wp-admin/includes/update-core.php @@ -1763,7 +1763,7 @@ function _upgrade_core_deactivate_incompatible_plugins() { } else { $deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() ); $deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg ); - update_option( 'wp_force_deactivated_plugins', $deactivated_plugins ); + update_option( 'wp_force_deactivated_plugins', $deactivated_plugins, false ); } deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true ); } diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 1b212a1950..ddab022782 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -75,7 +75,7 @@ if ( ! function_exists( 'wp_install' ) ) : update_option( 'blog_public', $is_public ); // Freshness of site - in the future, this could get more specific about actions taken, perhaps. - update_option( 'fresh_site', 1 ); + update_option( 'fresh_site', 1, false ); if ( $language ) { update_option( 'WPLANG', $language ); @@ -863,6 +863,9 @@ function upgrade_all() { upgrade_650(); } + if ( $wp_current_db_version < 58975 ) { + upgrade_670(); + } maybe_disable_link_manager(); maybe_disable_automattic_widgets(); @@ -989,7 +992,7 @@ function upgrade_110() { $time_difference = $all_options->time_difference; - $server_time = time() + gmdate( 'Z' ); + $server_time = time() + gmdate( 'Z' ); $weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS; $gmt_time = time(); @@ -2397,7 +2400,36 @@ function upgrade_650() { wp_set_option_autoload_values( $autoload ); } } +/** + * Executes changes made in WordPress 6.7.0. + * + * @ignore + * @since 6.7.0 + * + * @global int $wp_current_db_version The old (current) database version. + */ +function upgrade_670() { + global $wp_current_db_version; + if ( $wp_current_db_version < 58975 ) { + $options = array( + 'recently_activated', + '_wp_suggested_policy_text_has_changed', + 'dashboard_widget_options', + 'ftp_credentials', + 'adminhash', + 'nav_menu_options', + 'wp_force_deactivated_plugins', + 'delete_blog_hash', + 'allowedthemes', + 'recovery_keys', + 'https_detection_errors', + 'fresh_site', + ); + + wp_set_options_autoload( $options, false ); + } +} /** * Executes network-level upgrade routines. * diff --git a/wp-admin/ms-delete-site.php b/wp-admin/ms-delete-site.php index be66975f56..d98c3411fe 100644 --- a/wp-admin/ms-delete-site.php +++ b/wp-admin/ms-delete-site.php @@ -48,7 +48,7 @@ if ( isset( $_POST['action'] ) && 'deleteblog' === $_POST['action'] && isset( $_ check_admin_referer( 'delete-blog' ); $hash = wp_generate_password( 20, false ); - update_option( 'delete_blog_hash', $hash ); + update_option( 'delete_blog_hash', $hash, false ); $url_delete = esc_url( admin_url( 'ms-delete-site.php?h=' . $hash ) ); diff --git a/wp-admin/network/site-themes.php b/wp-admin/network/site-themes.php index 8d76efc259..0f2ddd5da9 100644 --- a/wp-admin/network/site-themes.php +++ b/wp-admin/network/site-themes.php @@ -143,7 +143,7 @@ if ( $action ) { } } - update_option( 'allowedthemes', $allowed_themes ); + update_option( 'allowedthemes', $allowed_themes, false ); restore_current_blog(); wp_safe_redirect( diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 783bbe9324..199fbedaa3 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -71,7 +71,7 @@ if ( $action ) { if ( ! is_network_admin() ) { $recent = (array) get_option( 'recently_activated' ); unset( $recent[ $plugin ] ); - update_option( 'recently_activated', $recent ); + update_option( 'recently_activated', $recent, false ); } else { $recent = (array) get_site_option( 'recently_activated' ); unset( $recent[ $plugin ] ); @@ -136,7 +136,7 @@ if ( $action ) { } if ( ! is_network_admin() ) { - update_option( 'recently_activated', $recent ); + update_option( 'recently_activated', $recent, false ); } else { update_site_option( 'recently_activated', $recent ); } @@ -211,7 +211,7 @@ if ( $action ) { deactivate_plugins( $plugin, false, is_network_admin() ); if ( ! is_network_admin() ) { - update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); + update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ), false ); } else { update_site_option( 'recently_activated', array( $plugin => time() ) + (array) get_site_option( 'recently_activated' ) ); } @@ -258,7 +258,7 @@ if ( $action ) { } if ( ! is_network_admin() ) { - update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) ); + update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ), false ); } else { update_site_option( 'recently_activated', $deactivated + (array) get_site_option( 'recently_activated' ) ); } @@ -436,7 +436,7 @@ if ( $action ) { exit; case 'clear-recent-list': if ( ! is_network_admin() ) { - update_option( 'recently_activated', array() ); + update_option( 'recently_activated', array(), false ); } else { update_site_option( 'recently_activated', array() ); } diff --git a/wp-includes/class-wp-paused-extensions-storage.php b/wp-includes/class-wp-paused-extensions-storage.php index a1b2b6d5ae..91f562c52c 100644 --- a/wp-includes/class-wp-paused-extensions-storage.php +++ b/wp-includes/class-wp-paused-extensions-storage.php @@ -72,7 +72,7 @@ class WP_Paused_Extensions_Storage { $paused_extensions[ $this->type ][ $extension ] = $error; - return update_option( $option_name, $paused_extensions ); + return update_option( $option_name, $paused_extensions, false ); } /** @@ -112,7 +112,7 @@ class WP_Paused_Extensions_Storage { return delete_option( $option_name ); } - return update_option( $option_name, $paused_extensions ); + return update_option( $option_name, $paused_extensions, false ); } /** @@ -190,7 +190,7 @@ class WP_Paused_Extensions_Storage { return delete_option( $option_name ); } - return update_option( $option_name, $paused_extensions ); + return update_option( $option_name, $paused_extensions, false ); } /** diff --git a/wp-includes/class-wp-recovery-mode-key-service.php b/wp-includes/class-wp-recovery-mode-key-service.php index c9a6a24368..38d5730f85 100644 --- a/wp-includes/class-wp-recovery-mode-key-service.php +++ b/wp-includes/class-wp-recovery-mode-key-service.php @@ -187,6 +187,6 @@ final class WP_Recovery_Mode_Key_Service { * @return bool True on success, false on failure. */ private function update_keys( array $keys ) { - return update_option( $this->option_name, $keys ); + return update_option( $this->option_name, $keys, false ); } } diff --git a/wp-includes/class-wp-roles.php b/wp-includes/class-wp-roles.php index 245aa2b05a..95e08e6dc7 100644 --- a/wp-includes/class-wp-roles.php +++ b/wp-includes/class-wp-roles.php @@ -165,7 +165,7 @@ class WP_Roles { 'capabilities' => $capabilities, ); if ( $this->use_db ) { - update_option( $this->role_key, $this->roles ); + update_option( $this->role_key, $this->roles, true ); } $this->role_objects[ $role ] = new WP_Role( $role, $capabilities ); $this->role_names[ $role ] = $display_name; diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index 6db75e4058..32b6bc27e3 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -1757,11 +1757,11 @@ final class WP_Theme implements ArrayAccess { // Set the option so we never have to go through this pain again. if ( is_admin() && $allowed_themes[ $blog_id ] ) { if ( $current ) { - update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); + update_option( 'allowedthemes', $allowed_themes[ $blog_id ], false ); delete_option( 'allowed_themes' ); } else { switch_to_blog( $blog_id ); - update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); + update_option( 'allowedthemes', $allowed_themes[ $blog_id ], false ); delete_option( 'allowed_themes' ); restore_current_blog(); } diff --git a/wp-includes/cron.php b/wp-includes/cron.php index 9371515aba..62bca29570 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -1240,7 +1240,7 @@ function _set_cron_array( $cron, $wp_error = false ) { $cron['version'] = 2; - $result = update_option( 'cron', $cron ); + $result = update_option( 'cron', $cron, true ); if ( $wp_error && ! $result ) { return new WP_Error( @@ -1280,7 +1280,7 @@ function _upgrade_cron_array( $cron ) { $new_cron['version'] = 2; - update_option( 'cron', $new_cron ); + update_option( 'cron', $new_cron, true ); return $new_cron; } diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index be92ba6796..8b7d84b63e 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -6002,7 +6002,7 @@ function wp_update_https_detection_errors() { */ $support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null ); if ( is_wp_error( $support_errors ) ) { - update_option( 'https_detection_errors', $support_errors->errors ); + update_option( 'https_detection_errors', $support_errors->errors, false ); return; } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 6ddd11f071..0619f44f30 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4705,7 +4705,7 @@ function _config_wp_siteurl( $url = '' ) { * @access private */ function _delete_option_fresh_site() { - update_option( 'fresh_site', '0' ); + update_option( 'fresh_site', '0', false ); } /** diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index 913f22543f..16cda4ff5c 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -2021,7 +2021,7 @@ function check_upload_mimes( $mimes ) { */ function update_posts_count( $deprecated = '' ) { global $wpdb; - update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); + update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ), true ); } /** diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 6dbb4cfbef..1a9b2479ad 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -786,7 +786,7 @@ function switch_theme( $stylesheet ) { } $nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); - update_option( 'theme_switch_menu_locations', $nav_menu_locations ); + update_option( 'theme_switch_menu_locations', $nav_menu_locations, true ); if ( func_num_args() > 1 ) { $stylesheet = func_get_arg( 1 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 8c5c0b7e4f..cc2d0719b1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,14 +16,14 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-58974'; +$wp_version = '6.7-alpha-58975'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * * @global int $wp_db_version */ -$wp_db_version = 57155; +$wp_db_version = 58975; /** * Holds the TinyMCE version.