Make WordPress Core

Changeset 58949


Ignore:
Timestamp:
08/28/2024 10:46:27 PM (5 months ago)
Author:
flixos90
Message:

Options, Meta APIs: Soft-deprecate use of 'yes' and 'no' as $autoload parameter.

WordPress 6.6 option autoload enhancements included discouraging the use of 'yes' and 'no' to indicate whether to autoload an option when calling add_option() or update_option(). Instead, a boolean should be used.

This changeset brings the newer autoload related functions wp_set_option_autoload_values(), wp_set_options_autoload(), and wp_set_option_autoload() in line with those changes. Additionally, it soft-deprecates the values more formally, as they should no longer be used. No PHP warnings will be emitted though as this is not a hard deprecation. This change is purely about documentation.

Props flixos90, joemcgill, jrf, mukesh27.
Fixes #61929.
See #61103, #61939.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r58811 r58949  
    376376 *
    377377 * @since 6.4.0
     378 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated.
    378379 *
    379380 * @global wpdb $wpdb WordPress database abstraction object.
    380381 *
    381382 * @param array $options Associative array of option names and their autoload values to set. The option names are
    382  *                       expected to not be SQL-escaped. The autoload values accept 'yes'|true to enable or 'no'|false
    383  *                       to disable.
     383 *                       expected to not be SQL-escaped. The autoload values should be boolean values. For backward
     384 *                       compatibility 'yes' and 'no' are also accepted, though using these values is deprecated.
    384385 * @return array Associative array of all provided $options as keys and boolean values for whether their autoload value
    385386 *               was updated.
     
    399400    foreach ( $options as $option => $autoload ) {
    400401        wp_protect_special_option( $option ); // Ensure only valid options can be passed.
    401         if ( 'off' === $autoload || 'no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly.
     402
     403        /*
     404         * Sanitize autoload value and categorize accordingly.
     405         * The values 'yes', 'no', 'on', and 'off' are supported for backward compatibility.
     406         */
     407        if ( 'off' === $autoload || 'no' === $autoload || false === $autoload ) {
    402408            $grouped_options['off'][] = $option;
    403409        } else {
     
    497503 *
    498504 * @since 6.4.0
     505 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated.
    499506 *
    500507 * @see wp_set_option_autoload_values()
    501508 *
    502  * @param string[]    $options  List of option names. Expected to not be SQL-escaped.
    503  * @param string|bool $autoload Autoload value to control whether to load the options when WordPress starts up.
    504  *                              Accepts 'yes'|true to enable or 'no'|false to disable.
     509 * @param string[] $options  List of option names. Expected to not be SQL-escaped.
     510 * @param bool     $autoload Autoload value to control whether to load the options when WordPress starts up.
     511 *                           For backward compatibility 'yes' and 'no' are also accepted, though using these values is
     512 *                           deprecated.
    505513 * @return array Associative array of all provided $options as keys and boolean values for whether their autoload value
    506514 *               was updated.
     
    519527 *
    520528 * @since 6.4.0
     529 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated.
    521530 *
    522531 * @see wp_set_option_autoload_values()
    523532 *
    524  * @param string      $option   Name of the option. Expected to not be SQL-escaped.
    525  * @param string|bool $autoload Autoload value to control whether to load the option when WordPress starts up.
    526  *                              Accepts 'yes'|true to enable or 'no'|false to disable.
     533 * @param string $option   Name of the option. Expected to not be SQL-escaped.
     534 * @param bool   $autoload Autoload value to control whether to load the option when WordPress starts up.
     535 *                         For backward compatibility 'yes' and 'no' are also accepted, though using these values is
     536 *                         deprecated.
    527537 * @return bool True if the autoload value was modified, false otherwise.
    528538 */
     
    804814 * @since 1.0.0
    805815 * @since 4.2.0 The `$autoload` parameter was added.
     816 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated.
    806817 *
    807818 * @global wpdb $wpdb WordPress database abstraction object.
     
    810821 * @param mixed     $value    Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
    811822 * @param bool|null $autoload Optional. Whether to load the option when WordPress starts up.
    812  *                            Accepts a boolean, or `null` to stick with the initial value or, if no initial value is set,
    813  *                            to leave the decision up to default heuristics in WordPress.
    814  *                            For existing options,
    815  *                            `$autoload` can only be updated using `update_option()` if `$value` is also changed.
    816  *                            For backward compatibility 'yes' and 'no' are also accepted.
     823 *                            Accepts a boolean, or `null` to stick with the initial value or, if no initial value is
     824 *                            set, to leave the decision up to default heuristics in WordPress.
     825 *                            For existing options, `$autoload` can only be updated using `update_option()` if `$value`
     826 *                            is also changed.
     827 *                            For backward compatibility 'yes' and 'no' are also accepted, though using these values is
     828 *                            deprecated.
    817829 *                            Autoloading too many options can lead to performance problems, especially if the
    818830 *                            options are not frequently used. For options which are accessed across several places
     
    10271039 * @since 1.0.0
    10281040 * @since 6.6.0 The $autoload parameter's default value was changed to null.
     1041 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated.
    10291042 *
    10301043 * @global wpdb $wpdb WordPress database abstraction object.
     
    10351048 * @param string    $deprecated Optional. Description. Not used anymore.
    10361049 * @param bool|null $autoload   Optional. Whether to load the option when WordPress starts up.
    1037  *                              Accepts a boolean, or `null` to leave the decision up to default heuristics in WordPress.
    1038  *                              For backward compatibility 'yes' and 'no' are also accepted.
     1050 *                              Accepts a boolean, or `null` to leave the decision up to default heuristics in
     1051 *                              WordPress. For backward compatibility 'yes' and 'no' are also accepted, though using
     1052 *                              these values is deprecated.
    10391053 *                              Autoloading too many options can lead to performance problems, especially if the
    10401054 *                              options are not frequently used. For options which are accessed across several places
    1041  *                              in the frontend, it is recommended to autoload them, by using 'yes'|true.
     1055 *                              in the frontend, it is recommended to autoload them, by using true.
    10421056 *                              For options which are accessed only on few specific URLs, it is recommended
    10431057 *                              to not autoload them, by using false.
Note: See TracChangeset for help on using the changeset viewer.