diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 3fcb942aa7..e79f460fc5 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -2020,8 +2020,7 @@ class WP_Query { } if ( isset( $q['page'] ) ) { - $q['page'] = trim( $q['page'], '/' ); - $q['page'] = absint( $q['page'] ); + $q['page'] = is_scalar( $q['page'] ) ? absint( trim( $q['page'], '/' ) ) : 0; } // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. diff --git a/tests/phpunit/tests/query/invalidQueries.php b/tests/phpunit/tests/query/invalidQueries.php index 4c0b631f80..0cec942245 100644 --- a/tests/phpunit/tests/query/invalidQueries.php +++ b/tests/phpunit/tests/query/invalidQueries.php @@ -159,4 +159,20 @@ class Tests_Query_InvalidQueries extends WP_UnitTestCase { // Only the published post should be returned. $this->assertCount( 1, $query->posts ); } + + /** + * Ensure a non-scalar page parameter does not throw a fatal error for trim(). + * + * @ticket 56558 + * @covers WP_Query::get_posts + */ + public function test_non_scalar_page_value() { + $query = new WP_Query( + array( + 'page' => array( 1, 2, 3 ), + ) + ); + + $this->assertSame( 0, $query->query_vars['page'] ); + } }