diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php index 35ebb06371..23af2fff87 100644 --- a/src/wp-includes/class-wp.php +++ b/src/wp-includes/class-wp.php @@ -125,6 +125,7 @@ class WP { * filters and actions that can be used to further manipulate the result. * * @since 2.0.0 + * @since 6.0.0 A return value was added. * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * @@ -758,13 +759,17 @@ class WP { */ public function main( $query_args = '' ) { $this->init(); + $parsed = $this->parse_request( $query_args ); + $this->send_headers(); + if ( $parsed ) { $this->query_posts(); $this->handle_404(); $this->register_globals(); } + /** * Fires once the WordPress environment has been set up. * diff --git a/tests/phpunit/tests/wp/parseRequest.php b/tests/phpunit/tests/wp/parseRequest.php index 3e9d3114fd..edf65cb660 100644 --- a/tests/phpunit/tests/wp/parseRequest.php +++ b/tests/phpunit/tests/wp/parseRequest.php @@ -16,7 +16,22 @@ class Tests_WP_ParseRequest extends WP_UnitTestCase { } /** - * Test that PHP 8.1 "passing null to non-nullable" deprecation notice + * Tests the return value of the parse_request() method. + * + * @ticket 10886 + */ + public function test_parse_request_returns_bool() { + // Check that parse_request() returns true by default. + $this->assertTrue( $this->wp->parse_request() ); + + add_filter( 'do_parse_request', '__return_false' ); + + // Check that parse_request() returns false if the request was not parsed. + $this->assertFalse( $this->wp->parse_request() ); + } + + /** + * Tests that PHP 8.1 "passing null to non-nullable" deprecation notice * is not thrown when the home URL has no path/trailing slash (default setup). * * Note: This does not test the actual functioning of the parse_request() method. @@ -39,20 +54,4 @@ class Tests_WP_ParseRequest extends WP_UnitTestCase { $this->wp->parse_request(); $this->assertSame( '', $this->wp->request ); } - /** - * Test that the parse_request() returns bool - * - * @ticket 10886 - */ - public function test_parse_request_returns_bool() { - - // check if parse_request() returns true for default setup. - $this->assertTrue( $this->wp->parse_request(), 'returns true' ); - - // add filter to shortcut the parse_request function. - add_filter( 'do_parse_request', '__return_false' ); - $this->assertFalse( $this->wp->parse_request(), 'returns false' ); - remove_filter( 'do_parse_request', '__return_false' ); - - } }