diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php index f1664747d4042..6f05a5fdd7e69 100644 --- a/src/wp-includes/class-wp.php +++ b/src/wp-includes/class-wp.php @@ -382,7 +382,10 @@ public function parse_request( $extra_query_vars = '' ) { unset( $this->query_vars['post_type'] ); } } else { - $this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types ); + $this->query_vars['post_type'] = array_intersect( + array_filter( $this->query_vars['post_type'], 'is_scalar' ), + $queryable_post_types + ); } } diff --git a/tests/phpunit/tests/wp/parseRequest.php b/tests/phpunit/tests/wp/parseRequest.php index a34a873e892fb..68b2e6c42c222 100644 --- a/tests/phpunit/tests/wp/parseRequest.php +++ b/tests/phpunit/tests/wp/parseRequest.php @@ -56,4 +56,52 @@ static function ( $url ) { $this->wp->parse_request(); $this->assertSame( '', $this->wp->request ); } + + /** + * @ticket 65123 + * @dataProvider data_parse_request_ignores_non_scalar_post_type_values + */ + public function test_parse_request_ignores_non_scalar_post_type_values( $request_method, $request_uri ) { + $original_get = $_GET; + $original_post = $_POST; + $original_request = $_SERVER['REQUEST_URI'] ?? null; + $original_self = $_SERVER['PHP_SELF'] ?? null; + + if ( 'GET' === $request_method ) { + $_GET['post_type'] = array( array( 'page' ), 'post' ); + } else { + $_POST['post_type'] = array( array( 'page' ), 'post' ); + } + + $_SERVER['REQUEST_URI'] = $request_uri; + $_SERVER['PHP_SELF'] = '/index.php'; + + try { + $this->wp->parse_request(); + + $this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) ); + } finally { + $_GET = $original_get; + $_POST = $original_post; + + if ( null === $original_request ) { + unset( $_SERVER['REQUEST_URI'] ); + } else { + $_SERVER['REQUEST_URI'] = $original_request; + } + + if ( null === $original_self ) { + unset( $_SERVER['PHP_SELF'] ); + } else { + $_SERVER['PHP_SELF'] = $original_self; + } + } + } + + public function data_parse_request_ignores_non_scalar_post_type_values() { + return array( + 'get' => array( 'GET', '/?post_type[][]=page&post_type[]=post' ), + 'post' => array( 'POST', '/' ), + ); + } }