Make WordPress Core

Changeset 55364


Ignore:
Timestamp:
02/18/2023 03:07:12 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Improve variables names in post and comment page link functions.

This commit renames a few internal variables for better clarity and consistency:

  • $nextpage to $next_page in:
    • get_next_posts_page_link()
    • get_next_posts_link()
    • get_next_comments_link()
  • $nextpage to $previous_page in:
    • get_previous_posts_page_link()
  • $prevpage to $previous_page in:
    • get_previous_comments_link()

Includes minor code layout fixes for better readability.

Follow-up to [5045], [8502], [8961], [28111].

Props dalirajab, SergeyBiryukov.
Fixes #57746.

File:
1 edited

Legend:

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

    r55289 r55364  
    24822482                        $paged = 1;
    24832483                }
    2484                 $nextpage = (int) $paged + 1;
    2485                 if ( ! $max_page || $max_page >= $nextpage ) {
    2486                         return get_pagenum_link( $nextpage );
     2484
     2485                $next_page = (int) $paged + 1;
     2486
     2487                if ( ! $max_page || $max_page >= $next_page ) {
     2488                        return get_pagenum_link( $next_page );
    24872489                }
    24882490        }
     
    25312533        }
    25322534
    2533         $nextpage = (int) $paged + 1;
     2535        $next_page = (int) $paged + 1;
    25342536
    25352537        if ( null === $label ) {
     
    25372539        }
    25382540
    2539         if ( ! is_single() && ( $nextpage <= $max_page ) ) {
     2541        if ( ! is_single() && ( $next_page <= $max_page ) ) {
    25402542                /**
    25412543                 * Filters the anchor tag attributes for the next posts page link.
     
    25472549                $attr = apply_filters( 'next_posts_link_attributes', '' );
    25482550
    2549                 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
     2551                return sprintf(
     2552                        '<a href="%1$s" %2$s>%3$s</a>',
     2553                        next_posts( $max_page, false ),
     2554                        $attr,
     2555                        preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )
     2556                );
    25502557        }
    25512558}
     
    25802587
    25812588        if ( ! is_single() ) {
    2582                 $nextpage = (int) $paged - 1;
    2583                 if ( $nextpage < 1 ) {
    2584                         $nextpage = 1;
    2585                 }
    2586                 return get_pagenum_link( $nextpage );
     2589                $previous_page = (int) $paged - 1;
     2590
     2591                if ( $previous_page < 1 ) {
     2592                        $previous_page = 1;
     2593                }
     2594
     2595                return get_pagenum_link( $previous_page );
    25872596        }
    25882597}
     
    26322641                 */
    26332642                $attr = apply_filters( 'previous_posts_link_attributes', '' );
    2634                 return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
     2643
     2644                return sprintf(
     2645                        '<a href="%1$s" %2$s>%3$s</a>',
     2646                        previous_posts( false ),
     2647                        $attr,
     2648                        preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )
     2649                );
    26352650        }
    26362651}
     
    30803095        }
    30813096
    3082         $nextpage = (int) $page + 1;
     3097        $next_page = (int) $page + 1;
    30833098
    30843099        if ( empty( $max_page ) ) {
     
    30903105        }
    30913106
    3092         if ( $nextpage > $max_page ) {
     3107        if ( $next_page > $max_page ) {
    30933108                return;
    30943109        }
     
    31053120         * @param string $attributes Attributes for the anchor tag.
    31063121         */
    3107         return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
     3122        $attr = apply_filters( 'next_comments_link_attributes', '' );
     3123
     3124        return sprintf(
     3125                '<a href="%1$s" %2$s>%3$s</a>',
     3126                esc_url( get_comments_pagenum_link( $next_page, $max_page ) ),
     3127                $attr,
     3128                preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )
     3129        );
    31083130}
    31093131
     
    31393161        }
    31403162
    3141         $prevpage = (int) $page - 1;
     3163        $previous_page = (int) $page - 1;
    31423164
    31433165        if ( empty( $label ) ) {
     
    31523174         * @param string $attributes Attributes for the anchor tag.
    31533175         */
    3154         return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
     3176        $attr = apply_filters( 'previous_comments_link_attributes', '' );
     3177
     3178        return sprintf(
     3179                '<a href="%1$s" %2$s>%3$s</a>',
     3180                esc_url( get_comments_pagenum_link( $previous_page ) ),
     3181                $attr,
     3182                preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )
     3183        );
    31553184}
    31563185
Note: See TracChangeset for help on using the changeset viewer.