Make WordPress Core


Ignore:
Timestamp:
09/03/2024 06:17:19 PM (6 weeks 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.
Note: See TracChangeset for help on using the changeset viewer.