Make WordPress Core

Changeset 54948


Ignore:
Timestamp:
12/07/2022 09:30:47 PM (23 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r54637 r54948  
    3030 * Exceptions:
    3131 *
    32  * 1. When the option has not been saved in the database, the `$default` value
     32 * 1. When the option has not been saved in the database, the `$default_value` value
    3333 *    is returned if provided. If not, boolean `false` is returned.
    3434 * 2. When one of the Options API filters is used: {@see 'pre_option_$option'},
     
    6868 * @global wpdb $wpdb WordPress database abstraction object.
    6969 *
    70  * @param string $option  Name of the option to retrieve. Expected to not be SQL-escaped.
    71  * @param mixed  $default Optional. Default value to return if the option does not exist.
     70 * @param string $option        Name of the option to retrieve. Expected to not be SQL-escaped.
     71 * @param mixed  $default_value Optional. Default value to return if the option does not exist.
    7272 * @return mixed Value of the option. A value of any type may be returned, including
    7373 *               scalar (string, boolean, float, integer), null, array, object.
     
    7676 *               boolean `false` is returned.
    7777 */
    78 function get_option( $option, $default = false ) {
     78function get_option( $option, $default_value = false ) {
    7979    global $wpdb;
    8080
     
    107107            )
    108108        );
    109         return get_option( $deprecated_keys[ $option ], $default );
     109        return get_option( $deprecated_keys[ $option ], $default_value );
    110110    }
    111111
     
    120120     * @since 1.5.0
    121121     * @since 4.4.0 The `$option` parameter was added.
    122      * @since 4.9.0 The `$default` parameter was added.
    123      *
    124      * @param mixed  $pre_option The value to return instead of the option value. This differs
    125      *                           from `$default`, which is used as the fallback value in the event
    126      *                           the option doesn't exist elsewhere in get_option().
    127      *                           Default false (to skip past the short-circuit).
    128      * @param string $option     Option name.
    129      * @param mixed  $default    The fallback value to return if the option does not exist.
    130      *                           Default false.
    131      */
    132     $pre = apply_filters( "pre_option_{$option}", false, $option, $default );
     122     * @since 4.9.0 The `$default_value` parameter was added.
     123     *
     124     * @param mixed  $pre_option    The value to return instead of the option value. This differs from
     125     *                              `$default_value`, which is used as the fallback value in the event
     126     *                              the option doesn't exist elsewhere in get_option().
     127     *                              Default false (to skip past the short-circuit).
     128     * @param string $option        Option name.
     129     * @param mixed  $default_value The fallback value to return if the option does not exist.
     130     *                              Default false.
     131     */
     132    $pre = apply_filters( "pre_option_{$option}", false, $option, $default_value );
    133133
    134134    /**
     
    140140     * @since 6.1.0
    141141     *
    142      * @param mixed  $pre_option  The value to return instead of the option value. This differs
    143      *                            from `$default`, which is used as the fallback value in the event
    144      *                            the option doesn't exist elsewhere in get_option().
    145      *                            Default false (to skip past the short-circuit).
    146      * @param string $option      Name of the option.
    147      * @param mixed  $default    The fallback value to return if the option does not exist.
    148      *                            Default false.
    149      */
    150     $pre = apply_filters( 'pre_option', $pre, $option, $default );
     142     * @param mixed  $pre_option    The value to return instead of the option value. This differs from
     143     *                              `$default_value`, which is used as the fallback value in the event
     144     *                              the option doesn't exist elsewhere in get_option().
     145     *                              Default false (to skip past the short-circuit).
     146     * @param string $option        Name of the option.
     147     * @param mixed  $default_value The fallback value to return if the option does not exist.
     148     *                              Default false.
     149     */
     150    $pre = apply_filters( 'pre_option', $pre, $option, $default_value );
    151151
    152152    if ( false !== $pre ) {
     
    181181             * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value.
    182182             *
    183              * @param mixed  $default The default value to return if the option does not exist
    184              *                        in the database.
    185              * @param string $option  Option name.
     183             * @param mixed  $default_value The default value to return if the option does not exist
     184             *                               in the database.
     185             * @param string $option         Option name.
    186186             * @param bool   $passed_default Was `get_option()` passed a default value?
    187187             */
    188             return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
     188            return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
    189189        }
    190190
     
    212212
    213213                    /** This filter is documented in wp-includes/option.php */
    214                     return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
     214                    return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
    215215                }
    216216            }
     
    225225        } else {
    226226            /** This filter is documented in wp-includes/option.php */
    227             return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
     227            return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
    228228        }
    229229    }
     
    11461146 * @since 2.7.0
    11471147 *
    1148  * @param string       $name    The name of the setting.
    1149  * @param string|false $default Optional. Default value to return when $name is not set. Default false.
     1148 * @param string       $name          The name of the setting.
     1149 * @param string|false $default_value Optional. Default value to return when $name is not set. Default false.
    11501150 * @return mixed The last saved user setting or the default value/false if it doesn't exist.
    11511151 */
    1152 function get_user_setting( $name, $default = false ) {
     1152function get_user_setting( $name, $default_value = false ) {
    11531153    $all_user_settings = get_all_user_settings();
    11541154
    1155     return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default;
     1155    return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default_value;
    11561156}
    11571157
     
    13251325 * @see get_network_option()
    13261326 *
    1327  * @param string $option     Name of the option to retrieve. Expected to not be SQL-escaped.
    1328  * @param mixed  $default    Optional. Value to return if the option doesn't exist. Default false.
    1329  * @param bool   $deprecated Whether to use cache. Multisite only. Always set to true.
     1327 * @param string $option        Name of the option to retrieve. Expected to not be SQL-escaped.
     1328 * @param mixed  $default_value Optional. Value to return if the option doesn't exist. Default false.
     1329 * @param bool   $deprecated    Whether to use cache. Multisite only. Always set to true.
    13301330 * @return mixed Value set for the option.
    13311331 */
    1332 function get_site_option( $option, $default = false, $deprecated = true ) {
    1333     return get_network_option( null, $option, $default );
     1332function get_site_option( $option, $default_value = false, $deprecated = true ) {
     1333    return get_network_option( null, $option, $default_value );
    13341334}
    13351335
     
    13921392 * @global wpdb $wpdb WordPress database abstraction object.
    13931393 *
    1394  * @param int    $network_id ID of the network. Can be null to default to the current network ID.
    1395  * @param string $option     Name of the option to retrieve. Expected to not be SQL-escaped.
    1396  * @param mixed  $default    Optional. Value to return if the option doesn't exist. Default false.
     1394 * @param int    $network_id    ID of the network. Can be null to default to the current network ID.
     1395 * @param string $option        Name of the option to retrieve. Expected to not be SQL-escaped.
     1396 * @param mixed  $default_value Optional. Value to return if the option doesn't exist. Default false.
    13971397 * @return mixed Value set for the option.
    13981398 */
    1399 function get_network_option( $network_id, $option, $default = false ) {
     1399function get_network_option( $network_id, $option, $default_value = false ) {
    14001400    global $wpdb;
    14011401
     
    14231423     * @since 4.4.0 The `$option` parameter was added.
    14241424     * @since 4.7.0 The `$network_id` parameter was added.
    1425      * @since 4.9.0 The `$default` parameter was added.
    1426      *
    1427      * @param mixed  $pre_option The value to return instead of the option value. This differs
    1428      *                           from `$default`, which is used as the fallback value in the event
    1429      *                           the option doesn't exist elsewhere in get_network_option().
    1430      *                           Default false (to skip past the short-circuit).
    1431      * @param string $option     Option name.
    1432      * @param int    $network_id ID of the network.
    1433      * @param mixed  $default    The fallback value to return if the option does not exist.
    1434      *                           Default false.
    1435      */
    1436     $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default );
     1425     * @since 4.9.0 The `$default_value` parameter was added.
     1426     *
     1427     * @param mixed  $pre_option    The value to return instead of the option value. This differs from
     1428     *                              `$default_value`, which is used as the fallback value in the event
     1429     *                              the option doesn't exist elsewhere in get_network_option().
     1430     *                              Default false (to skip past the short-circuit).
     1431     * @param string $option        Option name.
     1432     * @param int    $network_id    ID of the network.
     1433     * @param mixed  $default_value The fallback value to return if the option does not exist.
     1434     *                              Default false.
     1435     */
     1436    $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default_value );
    14371437
    14381438    if ( false !== $pre ) {
     
    14551455         * @since 4.7.0 The `$network_id` parameter was added.
    14561456         *
    1457          * @param mixed  $default    The value to return if the site option does not exist
    1458          *                           in the database.
    1459          * @param string $option     Option name.
    1460          * @param int    $network_id ID of the network.
     1457         * @param mixed  $default_value The value to return if the site option does not exist
     1458         *                              in the database.
     1459         * @param string $option        Option name.
     1460         * @param int    $network_id    ID of the network.
    14611461         */
    1462         return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );
     1462        return apply_filters( "default_site_option_{$option}", $default_value, $option, $network_id );
    14631463    }
    14641464
    14651465    if ( ! is_multisite() ) {
    14661466        /** This filter is documented in wp-includes/option.php */
    1467         $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
    1468         $value   = get_option( $option, $default );
     1467        $default_value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $network_id );
     1468        $value   = get_option( $option, $default_value );
    14691469    } else {
    14701470        $cache_key = "$network_id:$option";
     
    14881488
    14891489                /** This filter is documented in wp-includes/option.php */
    1490                 $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
     1490                $value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $network_id );
    14911491            }
    14921492        }
     
    25552555 * @since 4.7.0
    25562556 *
    2557  * @param mixed  $default        Existing default value to return.
     2557 * @param mixed  $default_value  Existing default value to return.
    25582558 * @param string $option         Option name.
    25592559 * @param bool   $passed_default Was `get_option()` passed a default value?
    25602560 * @return mixed Filtered default value.
    25612561 */
    2562 function filter_default_option( $default, $option, $passed_default ) {
     2562function filter_default_option( $default_value, $option, $passed_default ) {
    25632563    if ( $passed_default ) {
    2564         return $default;
     2564        return $default_value;
    25652565    }
    25662566
    25672567    $registered = get_registered_settings();
    25682568    if ( empty( $registered[ $option ] ) ) {
    2569         return $default;
     2569        return $default_value;
    25702570    }
    25712571
Note: See TracChangeset for help on using the changeset viewer.