Repository navigation
Conversation
Add a test that `paginate_links()` returns null when the global query reports zero total pages, matching its behavior for a single total page. See #65817.
…e the baseline. `WP_Query::$max_num_pages` defaults to `0` and is never `null`, so the `?? 1` fallback in `paginate_links()` never ran. Use `?:` instead, which also falls back for `0`, and retire the now-empty baseline. See #65817.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…ort ternary. WordPress Coding Standards disallows `?:` (Universal.Operators.DisallowShortTernary). Use the `$x ? $x : $y` form already used elsewhere in core for a falsy fallback. See #65817.
|
Closed accidentally by a branch rename (GitHub's branch-rename API deleted the old ref instead of retargeting this PR). Same commits now live at #15475. |
Trac ticket: https://core.trac.wordpress.org/ticket/65817
Fixes the one remaining
nullCoalesce.propertyerror and removestests/phpstan/baselines/nullCoalesce.property.neon.The error
WP_Query::$max_num_pagesdefaults to0and is nevernull, so?? 1inpaginate_links()never ran.The fix
Swap
??for?:, which falls back on any falsy value, including0. This matches what the function's own docblock already claims: "Default is the value WP_Query'smax_num_pagesor 1."Why this is safe
This is narrower than the attempt in #13982, where a reviewer asked for this exact line to be reverted because it also added a null-guard around
$wp_queryitself and brokeget_query_var( 'paged' ). This PR doesn't touch$wp_query's nullability -- only the fallback condition on one property that can never be null.A new test,
test_paginate_links_falls_back_to_global_query_with_zero_max_num_pages, pins the only caller-visible path through this line (max_num_pages = 0returnsnull, sincepaginate_links()treats totals under 2 the same way) and passes identically before and after this change.