Make WordPress Core


Ignore:
Timestamp:
11/05/2026 05:27:20 PM (4 days ago)
Author:
westonruter
Message:

Code Quality: Fix the nullCoalesce.property PHPStan error.

Since WP_Query::$max_num_pages is never null, the ?? 1 fallback in paginate_links() never applied, so the property is now read directly.

The property is also documented as a non-negative integer. This exposed that WP_Query::set_found_posts() could compute a negative page count when a found_posts filter returns a negative number, or when a filter injects a LIMIT into a query with a posts_per_page of -1, so that result is now clamped to zero. For the same reason the unreachable isset() fallback in WP_Sitemaps_Posts::get_max_num_pages() is removed, retiring its baseline entry.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/15475.
Follow-up to r48476, r57648, r61454, r65192.

Props bgturner, westonruter.
See #65817.

File:
1 edited

Legend:

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

    r65219 r65281  
    49844984
    49854985        // Get max pages and current page out of the current query, if available.
    4986         $total   = $wp_query->max_num_pages ?? 1;
     4986        $total   = $wp_query->max_num_pages;
    49874987        $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
    49884988
Note: See TracChangeset for help on using the changeset viewer.