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
This commit is contained in:
Felix Arntz 2024-09-03 18:19:14 +00:00
parent 77af97466f
commit 4e167c593d
24 changed files with 67 additions and 35 deletions

View File

@ -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.

View File

@ -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' );

View File

@ -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;

View File

@ -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;
}

View File

@ -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 );

View File

@ -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;

View File

@ -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() );

View File

@ -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 );

View File

@ -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() );
}

View File

@ -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 );
}

View File

@ -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.
*

View File

@ -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 ) );

View File

@ -143,7 +143,7 @@ if ( $action ) {
}
}
update_option( 'allowedthemes', $allowed_themes );
update_option( 'allowedthemes', $allowed_themes, false );
restore_current_blog();
wp_safe_redirect(

View File

@ -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() );
}

View File

@ -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 );
}
/**

View File

@ -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 );
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 );
}
/**

View File

@ -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 );
}
/**

View File

@ -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 );

View File

@ -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.