Changeset 65281
- Timestamp:
- 11/05/2026 05:27:20 PM (37 hours ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 6 edited
-
phpstan.neon.dist (modified) (1 diff)
-
src/wp-includes/class-wp-query.php (modified) (2 diffs)
-
src/wp-includes/general-template.php (modified) (1 diff)
-
src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php (modified) (1 diff)
-
tests/phpstan/baselines/isset.property.neon (modified) (1 diff)
-
tests/phpstan/baselines/nullCoalesce.property.neon (deleted)
-
tests/phpunit/tests/query/noFoundRows.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpstan.neon.dist
r65265 r65281 45 45 - tests/phpstan/baselines/method.unused.neon 46 46 - tests/phpstan/baselines/notIdentical.alwaysTrue.neon 47 - tests/phpstan/baselines/nullCoalesce.property.neon48 47 - tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon 49 48 - tests/phpstan/baselines/offsetAccess.notFound.neon -
trunk/src/wp-includes/class-wp-query.php
r64794 r65281 187 187 * @since 2.1.0 188 188 * @var int 189 * @phpstan-var int<0, max> 189 190 */ 190 191 public $max_num_pages = 0; … … 3733 3734 3734 3735 if ( ! empty( $limits ) ) { 3735 $this->max_num_pages = (int) ceil( $this->found_posts / $query_vars['posts_per_page']);3736 $this->max_num_pages = max( 0, (int) ceil( $this->found_posts / (int) $query_vars['posts_per_page'] ) ); 3736 3737 } 3737 3738 } -
trunk/src/wp-includes/general-template.php
r65219 r65281 4984 4984 4985 4985 // 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; 4987 4987 $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; 4988 4988 -
trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
r65043 r65281 210 210 211 211 $min_num_pages = ( 'page' === $post_type && 'posts' === get_option( 'show_on_front' ) ) ? 1 : 0; 212 return isset( $query->max_num_pages ) ? max( $min_num_pages, $query->max_num_pages ) : 1;212 return max( $min_num_pages, $query->max_num_pages ); 213 213 } 214 214 -
trunk/tests/phpstan/baselines/isset.property.neon
r64868 r65281 180 180 path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php 181 181 - 182 message: '#^Property WP_Query\:\:\$max_num_pages \(int\) in isset\(\) is not nullable\.$#'183 identifier: isset.property184 count: 1185 path: ../../../src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php186 -187 182 message: '#^Property WP_Site\:\:\$domain \(string\) in isset\(\) is not nullable\.$#' 188 183 identifier: isset.property -
trunk/tests/phpunit/tests/query/noFoundRows.php
r54090 r65281 103 103 $this->assertSame( 1, $q->found_posts ); 104 104 } 105 106 /** 107 * Ensures {@see WP_Query::$max_num_pages} is not negative when the 108 * {@see 'found_posts'} filter returns a negative count. 109 * 110 * @ticket 65817 111 */ 112 public function test_max_num_pages_is_not_negative_when_found_posts_is_filtered_negative() { 113 self::factory()->post->create_many( 3 ); 114 115 add_filter( 116 'found_posts', 117 static function (): int { 118 return -5; 119 } 120 ); 121 122 $q = new WP_Query( 123 array( 124 'post_type' => 'post', 125 'posts_per_page' => 2, 126 ) 127 ); 128 129 $this->assertSame( -5, $q->found_posts, 'Expected the filtered found_posts value to be kept.' ); 130 $this->assertSame( 0, $q->max_num_pages, 'Expected max_num_pages to be clamped to zero.' ); 131 } 132 133 /** 134 * Ensures {@see WP_Query::$max_num_pages} is not negative when a 135 * {@see 'post_limits'} filter injects a non-empty `LIMIT` clause on a 136 * `posts_per_page = -1` query, which otherwise never runs the found-rows 137 * calculation and skips the `max_num_pages` division entirely. 138 * 139 * @ticket 65817 140 */ 141 public function test_max_num_pages_is_not_negative_when_limits_are_filtered_with_postsperpage_minus1() { 142 self::factory()->post->create_many( 3 ); 143 144 add_filter( 145 'post_limits', 146 static function (): string { 147 return 'LIMIT 0, 2'; 148 } 149 ); 150 151 $q = new WP_Query( 152 array( 153 'post_type' => 'post', 154 'posts_per_page' => -1, 155 ) 156 ); 157 158 $this->assertIsString( $q->request ); 159 $this->assertStringContainsString( 'SQL_CALC_FOUND_ROWS', $q->request, 'Expected the filtered LIMIT to trigger the found-rows query.' ); 160 $this->assertSame( 3, $q->found_posts, 'Expected found_posts to reflect all matching rows.' ); 161 $this->assertSame( 0, $q->max_num_pages, 'Expected max_num_pages to be clamped to zero.' ); 162 } 105 163 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)