Code Modernization: Rename parameters that use reserved keywords in `wp-includes/option.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit renames the `$default` parameter to `$default_value` in: * `get_option()` * `get_user_setting()` * `get_site_option()` * `get_network_option()` * `filter_default_option()` Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947]. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #56788. Built from https://develop.svn.wordpress.org/trunk@54948 git-svn-id: http://core.svn.wordpress.org/trunk@54500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
53e90faeeb
commit
131c378f6a
|
@ -29,7 +29,7 @@
|
|||
*
|
||||
* Exceptions:
|
||||
*
|
||||
* 1. When the option has not been saved in the database, the `$default` value
|
||||
* 1. When the option has not been saved in the database, the `$default_value` value
|
||||
* is returned if provided. If not, boolean `false` is returned.
|
||||
* 2. When one of the Options API filters is used: {@see 'pre_option_$option'},
|
||||
* {@see 'default_option_$option'}, or {@see 'option_$option'}, the returned
|
||||
|
@ -67,15 +67,15 @@
|
|||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
|
||||
* @param mixed $default Optional. Default value to return if the option does not exist.
|
||||
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
|
||||
* @param mixed $default_value Optional. Default value to return if the option does not exist.
|
||||
* @return mixed Value of the option. A value of any type may be returned, including
|
||||
* scalar (string, boolean, float, integer), null, array, object.
|
||||
* Scalar and null values will be returned as strings as long as they originate
|
||||
* from a database stored option value. If there is no option in the database,
|
||||
* boolean `false` is returned.
|
||||
*/
|
||||
function get_option( $option, $default = false ) {
|
||||
function get_option( $option, $default_value = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( is_scalar( $option ) ) {
|
||||
|
@ -106,7 +106,7 @@ function get_option( $option, $default = false ) {
|
|||
$deprecated_keys[ $option ]
|
||||
)
|
||||
);
|
||||
return get_option( $deprecated_keys[ $option ], $default );
|
||||
return get_option( $deprecated_keys[ $option ], $default_value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,17 +119,17 @@ function get_option( $option, $default = false ) {
|
|||
*
|
||||
* @since 1.5.0
|
||||
* @since 4.4.0 The `$option` parameter was added.
|
||||
* @since 4.9.0 The `$default` parameter was added.
|
||||
* @since 4.9.0 The `$default_value` parameter was added.
|
||||
*
|
||||
* @param mixed $pre_option The value to return instead of the option value. This differs
|
||||
* from `$default`, which is used as the fallback value in the event
|
||||
* the option doesn't exist elsewhere in get_option().
|
||||
* Default false (to skip past the short-circuit).
|
||||
* @param string $option Option name.
|
||||
* @param mixed $default The fallback value to return if the option does not exist.
|
||||
* Default false.
|
||||
* @param mixed $pre_option The value to return instead of the option value. This differs from
|
||||
* `$default_value`, which is used as the fallback value in the event
|
||||
* the option doesn't exist elsewhere in get_option().
|
||||
* Default false (to skip past the short-circuit).
|
||||
* @param string $option Option name.
|
||||
* @param mixed $default_value The fallback value to return if the option does not exist.
|
||||
* Default false.
|
||||
*/
|
||||
$pre = apply_filters( "pre_option_{$option}", false, $option, $default );
|
||||
$pre = apply_filters( "pre_option_{$option}", false, $option, $default_value );
|
||||
|
||||
/**
|
||||
* Filters the value of all existing options before it is retrieved.
|
||||
|
@ -139,15 +139,15 @@ function get_option( $option, $default = false ) {
|
|||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param mixed $pre_option The value to return instead of the option value. This differs
|
||||
* from `$default`, which is used as the fallback value in the event
|
||||
* the option doesn't exist elsewhere in get_option().
|
||||
* Default false (to skip past the short-circuit).
|
||||
* @param string $option Name of the option.
|
||||
* @param mixed $default The fallback value to return if the option does not exist.
|
||||
* Default false.
|
||||
* @param mixed $pre_option The value to return instead of the option value. This differs from
|
||||
* `$default_value`, which is used as the fallback value in the event
|
||||
* the option doesn't exist elsewhere in get_option().
|
||||
* Default false (to skip past the short-circuit).
|
||||
* @param string $option Name of the option.
|
||||
* @param mixed $default_value The fallback value to return if the option does not exist.
|
||||
* Default false.
|
||||
*/
|
||||
$pre = apply_filters( 'pre_option', $pre, $option, $default );
|
||||
$pre = apply_filters( 'pre_option', $pre, $option, $default_value );
|
||||
|
||||
if ( false !== $pre ) {
|
||||
return $pre;
|
||||
|
@ -180,12 +180,12 @@ function get_option( $option, $default = false ) {
|
|||
* @since 4.4.0 The `$option` parameter was added.
|
||||
* @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value.
|
||||
*
|
||||
* @param mixed $default The default value to return if the option does not exist
|
||||
* in the database.
|
||||
* @param string $option Option name.
|
||||
* @param mixed $default_value The default value to return if the option does not exist
|
||||
* in the database.
|
||||
* @param string $option Option name.
|
||||
* @param bool $passed_default Was `get_option()` passed a default value?
|
||||
*/
|
||||
return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
|
||||
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
|
||||
}
|
||||
|
||||
$alloptions = wp_load_alloptions();
|
||||
|
@ -211,7 +211,7 @@ function get_option( $option, $default = false ) {
|
|||
wp_cache_set( 'notoptions', $notoptions, 'options' );
|
||||
|
||||
/** This filter is documented in wp-includes/option.php */
|
||||
return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
|
||||
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ function get_option( $option, $default = false ) {
|
|||
$value = $row->option_value;
|
||||
} else {
|
||||
/** This filter is documented in wp-includes/option.php */
|
||||
return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
|
||||
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1145,14 +1145,14 @@ function wp_user_settings() {
|
|||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @param string $name The name of the setting.
|
||||
* @param string|false $default Optional. Default value to return when $name is not set. Default false.
|
||||
* @param string $name The name of the setting.
|
||||
* @param string|false $default_value Optional. Default value to return when $name is not set. Default false.
|
||||
* @return mixed The last saved user setting or the default value/false if it doesn't exist.
|
||||
*/
|
||||
function get_user_setting( $name, $default = false ) {
|
||||
function get_user_setting( $name, $default_value = false ) {
|
||||
$all_user_settings = get_all_user_settings();
|
||||
|
||||
return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default;
|
||||
return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1324,13 +1324,13 @@ function delete_all_user_settings() {
|
|||
*
|
||||
* @see get_network_option()
|
||||
*
|
||||
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
|
||||
* @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
|
||||
* @param bool $deprecated Whether to use cache. Multisite only. Always set to true.
|
||||
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
|
||||
* @param mixed $default_value Optional. Value to return if the option doesn't exist. Default false.
|
||||
* @param bool $deprecated Whether to use cache. Multisite only. Always set to true.
|
||||
* @return mixed Value set for the option.
|
||||
*/
|
||||
function get_site_option( $option, $default = false, $deprecated = true ) {
|
||||
return get_network_option( null, $option, $default );
|
||||
function get_site_option( $option, $default_value = false, $deprecated = true ) {
|
||||
return get_network_option( null, $option, $default_value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1391,12 +1391,12 @@ function update_site_option( $option, $value ) {
|
|||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @param int $network_id ID of the network. Can be null to default to the current network ID.
|
||||
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
|
||||
* @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
|
||||
* @param int $network_id ID of the network. Can be null to default to the current network ID.
|
||||
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
|
||||
* @param mixed $default_value Optional. Value to return if the option doesn't exist. Default false.
|
||||
* @return mixed Value set for the option.
|
||||
*/
|
||||
function get_network_option( $network_id, $option, $default = false ) {
|
||||
function get_network_option( $network_id, $option, $default_value = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( $network_id && ! is_numeric( $network_id ) ) {
|
||||
|
@ -1422,18 +1422,18 @@ function get_network_option( $network_id, $option, $default = false ) {
|
|||
* @since 3.0.0
|
||||
* @since 4.4.0 The `$option` parameter was added.
|
||||
* @since 4.7.0 The `$network_id` parameter was added.
|
||||
* @since 4.9.0 The `$default` parameter was added.
|
||||
* @since 4.9.0 The `$default_value` parameter was added.
|
||||
*
|
||||
* @param mixed $pre_option The value to return instead of the option value. This differs
|
||||
* from `$default`, which is used as the fallback value in the event
|
||||
* the option doesn't exist elsewhere in get_network_option().
|
||||
* Default false (to skip past the short-circuit).
|
||||
* @param string $option Option name.
|
||||
* @param int $network_id ID of the network.
|
||||
* @param mixed $default The fallback value to return if the option does not exist.
|
||||
* Default false.
|
||||
* @param mixed $pre_option The value to return instead of the option value. This differs from
|
||||
* `$default_value`, which is used as the fallback value in the event
|
||||
* the option doesn't exist elsewhere in get_network_option().
|
||||
* Default false (to skip past the short-circuit).
|
||||
* @param string $option Option name.
|
||||
* @param int $network_id ID of the network.
|
||||
* @param mixed $default_value The fallback value to return if the option does not exist.
|
||||
* Default false.
|
||||
*/
|
||||
$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default );
|
||||
$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default_value );
|
||||
|
||||
if ( false !== $pre ) {
|
||||
return $pre;
|
||||
|
@ -1454,18 +1454,18 @@ function get_network_option( $network_id, $option, $default = false ) {
|
|||
* @since 4.4.0 The `$option` parameter was added.
|
||||
* @since 4.7.0 The `$network_id` parameter was added.
|
||||
*
|
||||
* @param mixed $default The value to return if the site option does not exist
|
||||
* in the database.
|
||||
* @param string $option Option name.
|
||||
* @param int $network_id ID of the network.
|
||||
* @param mixed $default_value The value to return if the site option does not exist
|
||||
* in the database.
|
||||
* @param string $option Option name.
|
||||
* @param int $network_id ID of the network.
|
||||
*/
|
||||
return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );
|
||||
return apply_filters( "default_site_option_{$option}", $default_value, $option, $network_id );
|
||||
}
|
||||
|
||||
if ( ! is_multisite() ) {
|
||||
/** This filter is documented in wp-includes/option.php */
|
||||
$default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
|
||||
$value = get_option( $option, $default );
|
||||
$default_value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $network_id );
|
||||
$value = get_option( $option, $default_value );
|
||||
} else {
|
||||
$cache_key = "$network_id:$option";
|
||||
$value = wp_cache_get( $cache_key, 'site-options' );
|
||||
|
@ -1487,7 +1487,7 @@ function get_network_option( $network_id, $option, $default = false ) {
|
|||
wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
|
||||
|
||||
/** This filter is documented in wp-includes/option.php */
|
||||
$value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
|
||||
$value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $network_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2554,19 +2554,19 @@ function get_registered_settings() {
|
|||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param mixed $default Existing default value to return.
|
||||
* @param mixed $default_value Existing default value to return.
|
||||
* @param string $option Option name.
|
||||
* @param bool $passed_default Was `get_option()` passed a default value?
|
||||
* @return mixed Filtered default value.
|
||||
*/
|
||||
function filter_default_option( $default, $option, $passed_default ) {
|
||||
function filter_default_option( $default_value, $option, $passed_default ) {
|
||||
if ( $passed_default ) {
|
||||
return $default;
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
$registered = get_registered_settings();
|
||||
if ( empty( $registered[ $option ] ) ) {
|
||||
return $default;
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
return $registered[ $option ]['default'];
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.2-alpha-54947';
|
||||
$wp_version = '6.2-alpha-54948';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue