Make WordPress Core

Changeset 58975


Ignore:
Timestamp:
09/03/2024 06:17:19 PM (2 years ago)
Author:
flixos90
Message:

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.

Location:
trunk/src
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/admin.php

    r55917 r58975  
    3939
    4040        flush_rewrite_rules();
    41         update_option( 'db_upgraded', false );
     41        update_option( 'db_upgraded', false, true );
    4242
    4343        /**
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r58745 r58975  
    195195                        update_site_option( 'recently_activated', $recently_activated );
    196196                } else {
    197                         update_option( 'recently_activated', $recently_activated );
     197                        update_option( 'recently_activated', $recently_activated, false );
    198198                }
    199199
  • trunk/src/wp-admin/includes/class-wp-privacy-policy-content.php

    r57741 r58975  
    121121                // Cache the result for use before `admin_init` (see above).
    122122                if ( $cached !== $state ) {
    123                         update_option( '_wp_suggested_policy_text_has_changed', $state );
     123                        update_option( '_wp_suggested_policy_text_has_changed', $state, false );
    124124                }
    125125
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r58319 r58975  
    10541054
    10551055                // Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
    1056                 update_option( $lock_option, time() );
     1056                update_option( $lock_option, time(), false );
    10571057
    10581058                return true;
  • trunk/src/wp-admin/includes/dashboard.php

    r58888 r58975  
    12801280                }
    12811281
    1282                 update_option( 'dashboard_widget_options', $widget_options );
     1282                update_option( 'dashboard_widget_options', $widget_options, false );
    12831283
    12841284                $locale    = get_user_locale();
  • trunk/src/wp-admin/includes/file.php

    r58678 r58975  
    24732473
    24742474                if ( ! wp_installing() ) {
    2475                         update_option( 'ftp_credentials', $stored_credentials );
     2475                        update_option( 'ftp_credentials', $stored_credentials, false );
    24762476                }
    24772477
  • trunk/src/wp-admin/includes/misc.php

    r58075 r58975  
    14781478                'newemail' => $value,
    14791479        );
    1480         update_option( 'adminhash', $new_admin_email );
     1480        update_option( 'adminhash', $new_admin_email, false );
    14811481
    14821482        $switched_locale = switch_to_user_locale( get_current_user_id() );
  • trunk/src/wp-admin/includes/nav-menu.php

    r58419 r58975  
    14851485        );
    14861486
    1487         update_option( 'nav_menu_options', $nav_menu_option );
     1487        update_option( 'nav_menu_options', $nav_menu_option, false );
    14881488
    14891489        wp_defer_term_counting( false );
  • trunk/src/wp-admin/includes/plugin.php

    r58419 r58975  
    26112611        if ( false === $blog_deactivated_plugins ) {
    26122612                // Option not in database, add an empty array to avoid extra DB queries on subsequent loads.
    2613                 update_option( 'wp_force_deactivated_plugins', array() );
     2613                update_option( 'wp_force_deactivated_plugins', array(), false );
    26142614        }
    26152615
     
    26652665
    26662666        // Empty the options.
    2667         update_option( 'wp_force_deactivated_plugins', array() );
     2667        update_option( 'wp_force_deactivated_plugins', array(), false );
    26682668        if ( is_multisite() ) {
    26692669                update_site_option( 'wp_force_deactivated_plugins', array() );
  • trunk/src/wp-admin/includes/update-core.php

    r58744 r58975  
    17641764                        $deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() );
    17651765                        $deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
    1766                         update_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
     1766                        update_option( 'wp_force_deactivated_plugins', $deactivated_plugins, false );
    17671767                }
    17681768                deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
  • trunk/src/wp-admin/includes/upgrade.php

    r58945 r58975  
    7676
    7777                // Freshness of site - in the future, this could get more specific about actions taken, perhaps.
    78                 update_option( 'fresh_site', 1 );
     78                update_option( 'fresh_site', 1, false );
    7979
    8080                if ( $language ) {
     
    864864        }
    865865
     866        if ( $wp_current_db_version < 58975 ) {
     867                upgrade_670();
     868        }
    866869        maybe_disable_link_manager();
    867870
     
    990993        $time_difference = $all_options->time_difference;
    991994
    992                 $server_time = time() + gmdate( 'Z' );
     995        $server_time    = time() + gmdate( 'Z' );
    993996        $weblogger_time  = $server_time + $time_difference * HOUR_IN_SECONDS;
    994997        $gmt_time        = time();
     
    23982401        }
    23992402}
    2400 
     2403/**
     2404 * Executes changes made in WordPress 6.7.0.
     2405 *
     2406 * @ignore
     2407 * @since 6.7.0
     2408 *
     2409 * @global int  $wp_current_db_version The old (current) database version.
     2410 */
     2411function upgrade_670() {
     2412        global $wp_current_db_version;
     2413
     2414        if ( $wp_current_db_version < 58975 ) {
     2415                $options = array(
     2416                        'recently_activated',
     2417                        '_wp_suggested_policy_text_has_changed',
     2418                        'dashboard_widget_options',
     2419                        'ftp_credentials',
     2420                        'adminhash',
     2421                        'nav_menu_options',
     2422                        'wp_force_deactivated_plugins',
     2423                        'delete_blog_hash',
     2424                        'allowedthemes',
     2425                        'recovery_keys',
     2426                        'https_detection_errors',
     2427                        'fresh_site',
     2428                );
     2429
     2430                wp_set_options_autoload( $options, false );
     2431        }
     2432}
    24012433/**
    24022434 * Executes network-level upgrade routines.
  • trunk/src/wp-admin/ms-delete-site.php

    r54840 r58975  
    4949
    5050        $hash = wp_generate_password( 20, false );
    51         update_option( 'delete_blog_hash', $hash );
     51        update_option( 'delete_blog_hash', $hash, false );
    5252
    5353        $url_delete = esc_url( admin_url( 'ms-delete-site.php?h=' . $hash ) );
  • trunk/src/wp-admin/network/site-themes.php

    r58405 r58975  
    144144        }
    145145
    146         update_option( 'allowedthemes', $allowed_themes );
     146        update_option( 'allowedthemes', $allowed_themes, false );
    147147        restore_current_blog();
    148148
  • trunk/src/wp-admin/plugins.php

    r58879 r58975  
    7272                                $recent = (array) get_option( 'recently_activated' );
    7373                                unset( $recent[ $plugin ] );
    74                                 update_option( 'recently_activated', $recent );
     74                                update_option( 'recently_activated', $recent, false );
    7575                        } else {
    7676                                $recent = (array) get_site_option( 'recently_activated' );
     
    137137
    138138                        if ( ! is_network_admin() ) {
    139                                 update_option( 'recently_activated', $recent );
     139                                update_option( 'recently_activated', $recent, false );
    140140                        } else {
    141141                                update_site_option( 'recently_activated', $recent );
     
    212212
    213213                        if ( ! is_network_admin() ) {
    214                                 update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
     214                                update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ), false );
    215215                        } else {
    216216                                update_site_option( 'recently_activated', array( $plugin => time() ) + (array) get_site_option( 'recently_activated' ) );
     
    259259
    260260                        if ( ! is_network_admin() ) {
    261                                 update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
     261                                update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ), false );
    262262                        } else {
    263263                                update_site_option( 'recently_activated', $deactivated + (array) get_site_option( 'recently_activated' ) );
     
    437437                case 'clear-recent-list':
    438438                        if ( ! is_network_admin() ) {
    439                                 update_option( 'recently_activated', array() );
     439                                update_option( 'recently_activated', array(), false );
    440440                        } else {
    441441                                update_site_option( 'recently_activated', array() );
  • trunk/src/wp-includes/class-wp-paused-extensions-storage.php

    r57644 r58975  
    7373                $paused_extensions[ $this->type ][ $extension ] = $error;
    7474
    75                 return update_option( $option_name, $paused_extensions );
     75                return update_option( $option_name, $paused_extensions, false );
    7676        }
    7777
     
    113113                }
    114114
    115                 return update_option( $option_name, $paused_extensions );
     115                return update_option( $option_name, $paused_extensions, false );
    116116        }
    117117
     
    191191                }
    192192
    193                 return update_option( $option_name, $paused_extensions );
     193                return update_option( $option_name, $paused_extensions, false );
    194194        }
    195195
  • trunk/src/wp-includes/class-wp-recovery-mode-key-service.php

    r57226 r58975  
    188188         */
    189189        private function update_keys( array $keys ) {
    190                 return update_option( $this->option_name, $keys );
     190                return update_option( $this->option_name, $keys, false );
    191191        }
    192192}
  • trunk/src/wp-includes/class-wp-roles.php

    r56321 r58975  
    166166                );
    167167                if ( $this->use_db ) {
    168                         update_option( $this->role_key, $this->roles );
     168                        update_option( $this->role_key, $this->roles, true );
    169169                }
    170170                $this->role_objects[ $role ] = new WP_Role( $role, $capabilities );
  • trunk/src/wp-includes/class-wp-theme.php

    r58025 r58975  
    17581758                        if ( is_admin() && $allowed_themes[ $blog_id ] ) {
    17591759                                if ( $current ) {
    1760                                         update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
     1760                                        update_option( 'allowedthemes', $allowed_themes[ $blog_id ], false );
    17611761                                        delete_option( 'allowed_themes' );
    17621762                                } else {
    17631763                                        switch_to_blog( $blog_id );
    1764                                         update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
     1764                                        update_option( 'allowedthemes', $allowed_themes[ $blog_id ], false );
    17651765                                        delete_option( 'allowed_themes' );
    17661766                                        restore_current_blog();
  • trunk/src/wp-includes/cron.php

    r58075 r58975  
    12411241        $cron['version'] = 2;
    12421242
    1243         $result = update_option( 'cron', $cron );
     1243        $result = update_option( 'cron', $cron, true );
    12441244
    12451245        if ( $wp_error && ! $result ) {
     
    12811281        $new_cron['version'] = 2;
    12821282
    1283         update_option( 'cron', $new_cron );
     1283        update_option( 'cron', $new_cron, true );
    12841284
    12851285        return $new_cron;
  • trunk/src/wp-includes/deprecated.php

    r58951 r58975  
    60036003        $support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null );
    60046004        if ( is_wp_error( $support_errors ) ) {
    6005                 update_option( 'https_detection_errors', $support_errors->errors );
     6005                update_option( 'https_detection_errors', $support_errors->errors, false );
    60066006                return;
    60076007        }
  • trunk/src/wp-includes/functions.php

    r58923 r58975  
    47064706 */
    47074707function _delete_option_fresh_site() {
    4708         update_option( 'fresh_site', '0' );
     4708        update_option( 'fresh_site', '0', false );
    47094709}
    47104710
  • trunk/src/wp-includes/ms-functions.php

    r57108 r58975  
    20222022function update_posts_count( $deprecated = '' ) {
    20232023        global $wpdb;
    2024         update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) );
     2024        update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ), true );
    20252025}
    20262026
  • trunk/src/wp-includes/theme.php

    r58409 r58975  
    787787
    788788        $nav_menu_locations = get_theme_mod( 'nav_menu_locations' );
    789         update_option( 'theme_switch_menu_locations', $nav_menu_locations );
     789        update_option( 'theme_switch_menu_locations', $nav_menu_locations, true );
    790790
    791791        if ( func_num_args() > 1 ) {
  • trunk/src/wp-includes/version.php

    r58576 r58975  
    2424 * @global int $wp_db_version
    2525 */
    26 $wp_db_version = 57155;
     26$wp_db_version = 58975;
    2727
    2828/**
Note: See TracChangeset for help on using the changeset viewer.