Make WordPress Core


Ignore:
Timestamp:
12/09/2022 12:22:14 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/pluggable.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 $die parameter to $stop in check_ajax_referer().
  • Renames the $default parameter to $fallback_url in wp_validate_redirect().
  • Renames the $default parameter to $default_value in get_avatar().

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], [54948], [54950], [54951].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.

File:
1 edited

Legend:

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

    r54920 r54952  
    12901290         *                                `$_REQUEST` values will be evaluated for '_ajax_nonce', and '_wpnonce'
    12911291         *                                (in that order). Default false.
    1292          * @param bool         $die       Optional. Whether to die early when the nonce cannot be verified.
     1292         * @param bool         $stop      Optional. Whether to stop early when the nonce cannot be verified.
    12931293         *                                Default true.
    12941294         * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
    … …  
    12961296         *                   False if the nonce is invalid.
    12971297         */
    1298         function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
     1298        function check_ajax_referer( $action = -1, $query_arg = false, $stop = true ) {
    12991299                if ( -1 == $action ) {
    13001300                        _doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '4.7.0' );
    … …  
    13241324                do_action( 'check_ajax_referer', $action, $result );
    13251325
    1326                 if ( $die && false === $result ) {
     1326                if ( $stop && false === $result ) {
    13271327                        if ( wp_doing_ajax() ) {
    13281328                                wp_die( -1, 403 );
    … …  
    15201520                 * @param int    $status       The HTTP response status code to use.
    15211521                 */
    1522                 $location = wp_validate_redirect( $location, apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ) );
     1522                $fallback_url = apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status );
     1523
     1524                $location = wp_validate_redirect( $location, $fallback_url );
    15231525
    15241526                return wp_redirect( $location, $status, $x_redirect_by );
    … …  
    15341536         * list.
    15351537         *
    1536          * If the host is not allowed, then the redirect is to $default supplied.
     1538         * If the host is not allowed, then the redirect is to $fallback_url supplied.
    15371539         *
    15381540         * @since 2.8.1
    15391541         *
    1540          * @param string $location The redirect to validate.
    1541          * @param string $default The value to return if $location is not allowed.
    1542          * @return string redirect-sanitized URL.
    1543          */
    1544         function wp_validate_redirect( $location, $default = '' ) {
     1542         * @param string $location     The redirect to validate.
     1543         * @param string $fallback_url The value to return if $location is not allowed.
     1544         * @return string Redirect-sanitized URL.
     1545         */
     1546        function wp_validate_redirect( $location, $fallback_url = '' ) {
    15451547                $location = wp_sanitize_redirect( trim( $location, " \t\n\r\0\x08\x0B" ) );
    15461548                // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    … …  
    15581560                // Give up if malformed URL.
    15591561                if ( false === $lp ) {
    1560                         return $default;
     1562                        return $fallback_url;
    15611563                }
    15621564
    15631565                // Allow only 'http' and 'https' schemes. No 'data:', etc.
    15641566                if ( isset( $lp['scheme'] ) && ! ( 'http' === $lp['scheme'] || 'https' === $lp['scheme'] ) ) {
    1565                         return $default;
     1567                        return $fallback_url;
    15661568                }
    15671569
    … …  
    15781580                // This catches URLs like https:host.com for which parse_url() does not set the host field.
    15791581                if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
    1580                         return $default;
     1582                        return $fallback_url;
    15811583                }
    15821584
    … …  
    15841586                foreach ( array( 'user', 'pass', 'host' ) as $component ) {
    15851587                        if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
    1586                                 return $default;
     1588                                return $fallback_url;
    15871589                        }
    15881590                }
    … …  
    16011603
    16021604                if ( isset( $lp['host'] ) && ( ! in_array( $lp['host'], $allowed_hosts, true ) && strtolower( $wpp['host'] ) !== $lp['host'] ) ) {
    1603                         $location = $default;
     1605                        $location = $fallback_url;
    16041606                }
    16051607
    … …  
    27472749         * @since 4.2.0 Optional `$args` parameter added.
    27482750         *
    2749          * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
    2750          *                            user email, WP_User object, WP_Post object, or WP_Comment object.
    2751          * @param int    $size        Optional. Height and width of the avatar image file in pixels. Default 96.
    2752          * @param string $default    Optional. URL for the default image or a default type. Accepts '404'
    2753          *                            (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
    2754          *                            (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
    2755          *                            'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
    2756          *                            or 'gravatar_default' (the Gravatar logo). Default is the value of the
    2757          *                            'avatar_default' option, with a fallback of 'mystery'.
    2758          * @param string $alt         Optional. Alternative text to use in img tag. Default empty.
     2751         * @param mixed  $id_or_email   The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
     2752         *                              user email, WP_User object, WP_Post object, or WP_Comment object.
     2753         * @param int    $size          Optional. Height and width of the avatar image file in pixels. Default 96.
     2754         * @param string $default_value Optional. URL for the default image or a default type. Accepts '404'
     2755         *                              (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
     2756         *                              (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
     2757         *                              'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
     2758         *                              or 'gravatar_default' (the Gravatar logo). Default is the value of the
     2759         *                              'avatar_default' option, with a fallback of 'mystery'.
     2760         * @param string $alt           Optional. Alternative text to use in img tag. Default empty.
    27592761         * @param array  $args {
    27602762         *     Optional. Extra arguments to retrieve the avatar.
    … …  
    27772779         * @return string|false `<img>` tag for the user's avatar. False on failure.
    27782780         */
    2779         function get_avatar( $id_or_email, $size = 96, $default = '', $alt = '', $args = null ) {
     2781        function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $args = null ) {
    27802782                $defaults = array(
    27812783                        // get_avatar_data() args.
    … …  
    28042806
    28052807                $args['size']    = (int) $size;
    2806                 $args['default'] = $default;
     2808                $args['default'] = $default_value;
    28072809                $args['alt']     = $alt;
    28082810
    … …  
    29082910                 * @since 4.2.0 The `$args` parameter was added.
    29092911                 *
    2910                  * @param string $avatar      HTML for the user's avatar.
    2911                  * @param mixed  $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash,
    2912                  *                            user email, WP_User object, WP_Post object, or WP_Comment object.
    2913                  * @param int    $size        Square avatar width and height in pixels to retrieve.
    2914                  * @param string $default    URL for the default image or a default type. Accepts '404', 'retro', 'monsterid',
    2915                  *                            'wavatar', 'indenticon', 'mystery', 'mm', 'mysteryman', 'blank', or 'gravatar_default'.
    2916                  * @param string $alt         Alternative text to use in the avatar image tag.
    2917                  * @param array  $args        Arguments passed to get_avatar_data(), after processing.
     2912                 * @param string $avatar        HTML for the user's avatar.
     2913                 * @param mixed  $id_or_email   The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash,
     2914                 *                              user email, WP_User object, WP_Post object, or WP_Comment object.
     2915                 * @param int    $size          Square avatar width and height in pixels to retrieve.
     2916                 * @param string $default_value URL for the default image or a default type. Accepts '404', 'retro', 'monsterid',
     2917                 *                              'wavatar', 'indenticon', 'mystery', 'mm', 'mysteryman', 'blank', or 'gravatar_default'.
     2918                 * @param string $alt           Alternative text to use in the avatar image tag.
     2919                 * @param array  $args          Arguments passed to get_avatar_data(), after processing.
    29182920                 */
    29192921                return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args );
Note: See TracChangeset for help on using the changeset viewer.