Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#57746 closed enhancement (fixed)

bad variable name in get_previous_posts_page_link()

Reported by: dalirajab's profile dalirajab Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.2 Priority: normal
Severity: normal Version: 6.1.1
Component: Posts, Post Types Keywords: has-patch
Focuses: coding-standards Cc:

Description

Hello !

While i was reading get_previous_posts_page_link() function code:

<?php
function get_previous_posts_page_link() {
        global $paged;

        if ( ! is_single() ) {
                $nextpage = (int) $paged - 1;
                if ( $nextpage < 1 ) {
                        $nextpage = 1;
                }
                return get_pagenum_link( $nextpage );
        }
}

my brain crashed for a while because of this line :

$nextpage = (int) $paged - 1;

I'm pretty sure that the right variable name is $previouspage (instead of $nextpage)

Change History (4)

This ticket was mentioned in PR #4093 on WordPress/wordpress-develop by @dalirajab.


2 years ago
#1

  • Keywords has-patch added

Hello !
While i was reading get_previous_posts_page_link() function code:

{{{php
<?php
function get_previous_posts_page_link() {

global $paged;

if ( ! is_single() ) {

$nextpage = (int) $paged - 1;
if ( $nextpage < 1 ) {

$nextpage = 1;

}
return get_pagenum_link( $nextpage );

}

}
}}}
my brain crashed for a while because of this line :
$nextpage = (int) $paged - 1;

I'm pretty sure that the right variable name is $previouspage (instead of $nextpage)

Trac ticket: https://core.trac.wordpress.org/ticket/57746#ticket

#2 @SergeyBiryukov
2 years ago

  • Component changed from General to Posts, Post Types
  • Milestone changed from Awaiting Review to 6.2

Hi there, welcome to WordPress Trac! Thanks for the ticket.

get_previous_posts_page_link() was introduced in [5045], but the variable appears to be even older than that, it was brought over along with previous_posts()from b2/cafelog in [8].

Indeed, the suggested name makes more sense.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

#3 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 55364:

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.

@SergeyBiryukov commented on PR #4093:


2 years ago
#4

Thanks for the PR! Merged in r55364 as part of a few other similar edits.

Note: See TracTickets for help on using tickets.