Make WordPress Core

Changeset 54943


Ignore:
Timestamp:
12/06/2022 09:16:09 PM (18 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/link-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 $string parameter to $url in user_trailingslashit().
  • Renames the $echo parameter to $display in:
    • edit_term_link()
    • next_posts()
    • previous_posts()
  • Renames the $class parameter to $css_class in:
    • edit_post_link()
    • _navigation_markup()

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

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

File:
1 edited

Legend:

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

    r54842 r54943  
    4040 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    4141 *
    42  * @param string $string      URL with or without a trailing slash.
     42 * @param string $url         URL with or without a trailing slash.
    4343 * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc)
    4444 *                            for use in the filter. Default empty string.
    4545 * @return string The URL with the trailing slash appended or stripped.
    4646 */
    47 function user_trailingslashit( $string, $type_of_url = '' ) {
     47function user_trailingslashit( $url, $type_of_url = '' ) {
    4848    global $wp_rewrite;
    4949    if ( $wp_rewrite->use_trailing_slashes ) {
    50         $string = trailingslashit( $string );
    51     } else {
    52         $string = untrailingslashit( $string );
     50        $url = trailingslashit( $url );
     51    } else {
     52        $url = untrailingslashit( $url );
    5353    }
    5454
     
    5858     * @since 2.2.0
    5959     *
    60      * @param string $string      URL with or without a trailing slash.
     60     * @param string $url         URL with or without a trailing slash.
    6161     * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
    6262     *                            'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed',
    6363     *                            'category', 'page', 'year', 'month', 'day', 'post_type_archive'.
    6464     */
    65     return apply_filters( 'user_trailingslashit', $string, $type_of_url );
     65    return apply_filters( 'user_trailingslashit', $url, $type_of_url );
    6666}
    6767
     
    11231123 * @since 3.1.0
    11241124 *
    1125  * @param string           $link   Optional. Anchor text. If empty, default is 'Edit This'. Default empty.
    1126  * @param string           $before Optional. Display before edit link. Default empty.
    1127  * @param string           $after  Optional. Display after edit link. Default empty.
    1128  * @param int|WP_Term|null $term   Optional. Term ID or object. If null, the queried object will be inspected. Default null.
    1129  * @param bool             $echo  Optional. Whether or not to echo the return. Default true.
     1125 * @param string           $link    Optional. Anchor text. If empty, default is 'Edit This'. Default empty.
     1126 * @param string           $before  Optional. Display before edit link. Default empty.
     1127 * @param string           $after   Optional. Display after edit link. Default empty.
     1128 * @param int|WP_Term|null $term    Optional. Term ID or object. If null, the queried object will be inspected. Default null.
     1129 * @param bool             $display Optional. Whether or not to echo the return. Default true.
    11301130 * @return string|void HTML content.
    11311131 */
    1132 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
     1132function edit_term_link( $link = '', $before = '', $after = '', $term = null, $display = true ) {
    11331133    if ( is_null( $term ) ) {
    11341134        $term = get_queried_object();
     
    11621162    $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
    11631163
    1164     if ( $echo ) {
     1164    if ( $display ) {
    11651165        echo $link;
    11661166    } else {
     
    14931493 *
    14941494 * @since 1.0.0
    1495  * @since 4.4.0 The `$class` argument was added.
    1496  *
    1497  * @param string      $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
    1498  * @param string      $before Optional. Display before edit link. Default empty.
    1499  * @param string      $after  Optional. Display after edit link. Default empty.
    1500  * @param int|WP_Post $post   Optional. Post ID or post object. Default is the global `$post`.
    1501  * @param string      $class Optional. Add custom class to link. Default 'post-edit-link'.
    1502  */
    1503 function edit_post_link( $text = null, $before = '', $after = '', $post = 0, $class = 'post-edit-link' ) {
     1495 * @since 4.4.0 The `$css_class` argument was added.
     1496 *
     1497 * @param string      $text      Optional. Anchor text. If null, default is 'Edit This'. Default null.
     1498 * @param string      $before    Optional. Display before edit link. Default empty.
     1499 * @param string      $after     Optional. Display after edit link. Default empty.
     1500 * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
     1501 * @param string      $css_class Optional. Add custom class to link. Default 'post-edit-link'.
     1502 */
     1503function edit_post_link( $text = null, $before = '', $after = '', $post = 0, $css_class = 'post-edit-link' ) {
    15041504    $post = get_post( $post );
    15051505
     
    15181518    }
    15191519
    1520     $link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>';
     1520    $link = '<a class="' . esc_attr( $css_class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>';
    15211521
    15221522    /**
     
    24892489 *
    24902490 * @param int  $max_page Optional. Max pages. Default 0.
    2491  * @param bool $echo     Optional. Whether to echo the link. Default true.
    2492  * @return string|void The link URL for next posts page if `$echo = false`.
    2493  */
    2494 function next_posts( $max_page = 0, $echo = true ) {
     2491 * @param bool $display  Optional. Whether to echo the link. Default true.
     2492 * @return string|void The link URL for next posts page if `$display = false`.
     2493 */
     2494function next_posts( $max_page = 0, $display = true ) {
    24952495    $output = esc_url( get_next_posts_page_link( $max_page ) );
    24962496
    2497     if ( $echo ) {
     2497    if ( $display ) {
    24982498        echo $output;
    24992499    } else {
     
    25872587 * @since 0.71
    25882588 *
    2589  * @param bool $echo Optional. Whether to echo the link. Default true.
    2590  * @return string|void The previous posts page link if `$echo = false`.
    2591  */
    2592 function previous_posts( $echo = true ) {
     2589 * @param bool $display Optional. Whether to echo the link. Default true.
     2590 * @return string|void The previous posts page link if `$display = false`.
     2591 */
     2592function previous_posts( $display = true ) {
    25932593    $output = esc_url( get_previous_posts_page_link() );
    25942594
    2595     if ( $echo ) {
     2595    if ( $display ) {
    25962596        echo $output;
    25972597    } else {
     
    29592959 *
    29602960 * @param string $links              Navigational links.
    2961  * @param string $class              Optional. Custom class for the nav element.
     2961 * @param string $css_class          Optional. Custom class for the nav element.
    29622962 *                                   Default 'posts-navigation'.
    29632963 * @param string $screen_reader_text Optional. Screen reader text for the nav element.
     
    29672967 * @return string Navigation template tag.
    29682968 */
    2969 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) {
     2969function _navigation_markup( $links, $css_class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) {
    29702970    if ( empty( $screen_reader_text ) ) {
    29712971        $screen_reader_text = __( 'Posts navigation' );
     
    29952995     * @since 4.4.0
    29962996     *
    2997      * @param string $template The default template.
    2998      * @param string $class    The class passed by the calling function.
     2997     * @param string $template  The default template.
     2998     * @param string $css_class The class passed by the calling function.
    29992999     * @return string Navigation template.
    30003000     */
    3001     $template = apply_filters( 'navigation_markup_template', $template, $class );
    3002 
    3003     return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) );
     3001    $template = apply_filters( 'navigation_markup_template', $template, $css_class );
     3002
     3003    return sprintf( $template, sanitize_html_class( $css_class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) );
    30043004}
    30053005
Note: See TracChangeset for help on using the changeset viewer.