Make WordPress Core

Changeset 54932


Ignore:
Timestamp:
12/04/2022 01:20:50 PM (17 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/general-template.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 $echo parameter to $display in:
    • wp_loginout()
    • wp_register()
    • get_calendar()
    • the_date()
    • the_modified_date()
    • checked()
    • selected()
    • disabled()
    • wp_readonly()
    • __checked_selected_helper()
  • Renames the $readonly parameter to $readonly_value in wp_readonly().

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].

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

File:
1 edited

Legend:

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

    r54868 r54932  
    371371 *
    372372 * @param string $redirect Optional path to redirect to on login/logout.
    373  * @param bool   $echo     Default to echo and not return the link.
    374  * @return void|string Void if `$echo` argument is true, log in/out link if `$echo` is false.
    375  */
    376 function wp_loginout( $redirect = '', $echo = true ) {
     373 * @param bool   $display  Default to echo and not return the link.
     374 * @return void|string Void if `$display` argument is true, log in/out link if `$display` is false.
     375 */
     376function wp_loginout( $redirect = '', $display = true ) {
    377377    if ( ! is_user_logged_in() ) {
    378378        $link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
     
    381381    }
    382382
    383     if ( $echo ) {
     383    if ( $display ) {
    384384        /**
    385385         * Filters the HTML output for the Log In/Log Out link.
     
    674674 * @since 1.5.0
    675675 *
    676  * @param string $before Text to output before the link. Default `<li>`.
    677  * @param string $after  Text to output after the link. Default `</li>`.
    678  * @param bool   $echo  Default to echo and not return the link.
    679  * @return void|string Void if `$echo` argument is true, registration or admin link
    680  *                     if `$echo` is false.
    681  */
    682 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
     676 * @param string $before  Text to output before the link. Default `<li>`.
     677 * @param string $after   Text to output after the link. Default `</li>`.
     678 * @param bool   $display Default to echo and not return the link.
     679 * @return void|string Void if `$display` argument is true, registration or admin link
     680 *                     if `$display` is false.
     681 */
     682function wp_register( $before = '<li>', $after = '</li>', $display = true ) {
    683683    if ( ! is_user_logged_in() ) {
    684684        if ( get_option( 'users_can_register' ) ) {
     
    705705    $link = apply_filters( 'register', $link );
    706706
    707     if ( $echo ) {
     707    if ( $display ) {
    708708        echo $link;
    709709    } else {
     
    22212221 *
    22222222 * @param bool $initial Optional. Whether to use initial calendar names. Default true.
    2223  * @param bool $echo    Optional. Whether to display the calendar output. Default true.
    2224  * @return void|string Void if `$echo` argument is true, calendar HTML if `$echo` is false.
    2225  */
    2226 function get_calendar( $initial = true, $echo = true ) {
     2223 * @param bool $display Optional. Whether to display the calendar output. Default true.
     2224 * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false.
     2225 */
     2226function get_calendar( $initial = true, $display = true ) {
    22272227    global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    22282228
     
    22342234        $output = apply_filters( 'get_calendar', $cache[ $key ] );
    22352235
    2236         if ( $echo ) {
     2236        if ( $display ) {
    22372237            echo $output;
    22382238            return;
     
    24312431    wp_cache_set( 'get_calendar', $cache, 'calendar' );
    24322432
    2433     if ( $echo ) {
     2433    if ( $display ) {
    24342434        /**
    24352435         * Filters the HTML calendar output.
     
    25122512 * @global string $previousday The day of the previous post in the loop.
    25132513 *
    2514  * @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
    2515  * @param string $before Optional. Output before the date. Default empty.
    2516  * @param string $after  Optional. Output after the date. Default empty.
    2517  * @param bool   $echo  Optional. Whether to echo the date or return it. Default true.
     2514 * @param string $format  Optional. PHP date format. Defaults to the 'date_format' option.
     2515 * @param string $before  Optional. Output before the date. Default empty.
     2516 * @param string $after   Optional. Output after the date. Default empty.
     2517 * @param bool   $display Optional. Whether to echo the date or return it. Default true.
    25182518 * @return string|void String if retrieving.
    25192519 */
    2520 function the_date( $format = '', $before = '', $after = '', $echo = true ) {
     2520function the_date( $format = '', $before = '', $after = '', $display = true ) {
    25212521    global $currentday, $previousday;
    25222522
     
    25402540    $the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );
    25412541
    2542     if ( $echo ) {
     2542    if ( $display ) {
    25432543        echo $the_date;
    25442544    } else {
     
    25872587 * @since 2.1.0
    25882588 *
    2589  * @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
    2590  * @param string $before Optional. Output before the date. Default empty.
    2591  * @param string $after  Optional. Output after the date. Default empty.
    2592  * @param bool   $echo  Optional. Whether to echo the date or return it. Default true.
     2589 * @param string $format  Optional. PHP date format. Defaults to the 'date_format' option.
     2590 * @param string $before  Optional. Output before the date. Default empty.
     2591 * @param string $after   Optional. Output after the date. Default empty.
     2592 * @param bool   $display Optional. Whether to echo the date or return it. Default true.
    25932593 * @return string|void String if retrieving.
    25942594 */
    2595 function the_modified_date( $format = '', $before = '', $after = '', $echo = true ) {
     2595function the_modified_date( $format = '', $before = '', $after = '', $display = true ) {
    25962596    $the_modified_date = $before . get_the_modified_date( $format ) . $after;
    25972597
     
    26082608    $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after );
    26092609
    2610     if ( $echo ) {
     2610    if ( $display ) {
    26112611        echo $the_modified_date;
    26122612    } else {
     
    50675067 * @param mixed $current Optional. The other value to compare if not just true.
    50685068 *                       Default true.
    5069  * @param bool  $echo    Optional. Whether to echo or just return the string.
     5069 * @param bool  $display Optional. Whether to echo or just return the string.
    50705070 *                       Default true.
    50715071 * @return string HTML attribute or empty string.
    50725072 */
    5073 function checked( $checked, $current = true, $echo = true ) {
    5074     return __checked_selected_helper( $checked, $current, $echo, 'checked' );
     5073function checked( $checked, $current = true, $display = true ) {
     5074    return __checked_selected_helper( $checked, $current, $display, 'checked' );
    50755075}
    50765076
     
    50855085 * @param mixed $current  Optional. The other value to compare if not just true.
    50865086 *                        Default true.
    5087  * @param bool  $echo     Optional. Whether to echo or just return the string.
     5087 * @param bool  $display  Optional. Whether to echo or just return the string.
    50885088 *                        Default true.
    50895089 * @return string HTML attribute or empty string.
    50905090 */
    5091 function selected( $selected, $current = true, $echo = true ) {
    5092     return __checked_selected_helper( $selected, $current, $echo, 'selected' );
     5091function selected( $selected, $current = true, $display = true ) {
     5092    return __checked_selected_helper( $selected, $current, $display, 'selected' );
    50935093}
    50945094
     
    51035103 * @param mixed $current  Optional. The other value to compare if not just true.
    51045104 *                        Default true.
    5105  * @param bool  $echo     Optional. Whether to echo or just return the string.
     5105 * @param bool  $display  Optional. Whether to echo or just return the string.
    51065106 *                        Default true.
    51075107 * @return string HTML attribute or empty string.
    51085108 */
    5109 function disabled( $disabled, $current = true, $echo = true ) {
    5110     return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
     5109function disabled( $disabled, $current = true, $display = true ) {
     5110    return __checked_selected_helper( $disabled, $current, $display, 'disabled' );
    51115111}
    51125112
     
    51185118 * @since 5.9.0
    51195119 *
    5120  * @param mixed $readonly One of the values to compare.
    5121  * @param mixed $current  Optional. The other value to compare if not just true.
    5122  *                        Default true.
    5123  * @param bool  $echo     Optional. Whether to echo or just return the string.
    5124  *                        Default true.
     5120 * @param mixed $readonly_value One of the values to compare.
     5121 * @param mixed $current        Optional. The other value to compare if not just true.
     5122 *                              Default true.
     5123 * @param bool  $display        Optional. Whether to echo or just return the string.
     5124 *                              Default true.
    51255125 * @return string HTML attribute or empty string.
    51265126 */
    5127 function wp_readonly( $readonly, $current = true, $echo = true ) {
    5128     return __checked_selected_helper( $readonly, $current, $echo, 'readonly' );
     5127function wp_readonly( $readonly_value, $current = true, $display = true ) {
     5128    return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' );
    51295129}
    51305130
     
    51495149 * @param mixed  $helper  One of the values to compare.
    51505150 * @param mixed  $current The other value to compare if not just true.
    5151  * @param bool   $echo    Whether to echo or just return the string.
     5151 * @param bool   $display Whether to echo or just return the string.
    51525152 * @param string $type    The type of checked|selected|disabled|readonly we are doing.
    51535153 * @return string HTML attribute or empty string.
    51545154 */
    5155 function __checked_selected_helper( $helper, $current, $echo, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
     5155function __checked_selected_helper( $helper, $current, $display, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
    51565156    if ( (string) $helper === (string) $current ) {
    51575157        $result = " $type='$type'";
     
    51605160    }
    51615161
    5162     if ( $echo ) {
     5162    if ( $display ) {
    51635163        echo $result;
    51645164    }
Note: See TracChangeset for help on using the changeset viewer.