Make WordPress Core


Ignore:
Timestamp:
03/02/2022 03:10:48 PM (3 years ago)
Author:
spacedmonkey
Message:

Bootstrap/Load: Stop unnecessary queries when using the do_parse_request filter.

Developers of plugins and themes can use the do_parse_request filter to hot-wire requests and hook in early to render custom pages. However, even through these request may not need post queries and 404 lookups to be run, they run anyway. This can results in unnecessary SQL queries running on these requests. By adding a return value to the parse_request method of the WP class, these queries can now be skipped.

Props junsuijin, ryan, westi, sivel, dd32, wonderboymusic, arnee, tyxla, DrewAPicture, lukecavanagh, SergeyBiryukov, davidbaumwald, Spacedmonkey, pbearne.
Fixes #10886.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/wp/parseRequest.php

    r51622 r52814  
    4040        $this->assertSame( '', $this->wp->request );
    4141    }
     42    /**
     43     * Test that the parse_request() returns bool
     44     *
     45     * @ticket 10886
     46     */
     47    public function test_parse_request_returns_bool() {
     48
     49        // check if parse_request() returns true for default setup.
     50        $this->assertTrue( $this->wp->parse_request(), 'returns true' );
     51
     52        // add filter to shortcut the parse_request function.
     53        add_filter( 'do_parse_request', '__return_false' );
     54        $this->assertFalse( $this->wp->parse_request(), 'returns false' );
     55        remove_filter( 'do_parse_request', '__return_false' );
     56
     57    }
    4258}
Note: See TracChangeset for help on using the changeset viewer.