WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 14 months ago

#41934 new enhancement

Update load.php with wp_is_bad_request function

Reported by: rpayne7264 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: Bootstrap/Load Keywords:
Focuses: Cc:
PR Number:

Description (last modified by SergeyBiryukov)

I propose adding a wp_is_bad_request function to load.php, as a way to allow plugin developers to short circuit code execution if the HTTP request that started the WordPress load process is considered a junk request. See: #17246

The existing wp_favicon_request (renamed to wp_favicon_request_x in test file) is re-written to use the proposed wp_is_bad_request function.

Attachments (3)

is_bad_request_test.php (2.0 KB) - added by rpayne7264 2 years ago.
test file for proposed wp_is_bad_request enhancement
is_bad_request_test_revision1.php (2.7 KB) - added by rpayne7264 2 years ago.
revised wp_is_bad_request() & added test cases
is_bad_request_test_revision2.php (2.7 KB) - added by rpayne7264 2 years ago.
Removed 'ico' param in wp_favicon_request_x() code

Download all attachments as: .zip

Change History (6)

@rpayne7264
2 years ago

test file for proposed wp_is_bad_request enhancement

#1 @SergeyBiryukov
2 years ago

  • Description modified (diff)

#2 in reply to: ↑ description @rpayne7264
2 years ago

For clarification:

When I say short circuit code execution, I mean: short circuit plugin code execution, not short circuit WordPress code execution.

Example:

<?php 

class RDP_PLUGIN {
        private static $_instance = NULL;

        private function __construct() {
            // prevent running code unnecessarily
            if(wp_is_bad_request())return;
            
            // run the plugin
            add_action('wp_loaded',array( $this, 'run'),1);             
        }//__construct
            

        public static function get_instance(){
            if (NULL === self::$_instance) self::$_instance = new self();
            return self::$_instance;
        } //get_instance 
                
                ...  other plugin code ...

}

$RDP_PLUGIN = RDP_PLUGIN::get_instance();
Last edited 2 years ago by rpayne7264 (previous) (diff)

@rpayne7264
2 years ago

revised wp_is_bad_request() & added test cases

@rpayne7264
2 years ago

Removed 'ico' param in wp_favicon_request_x() code

#3 @rpayne7264
14 months ago

After nearly one year, and still no movement on this. Bummer!

Note: See TracTickets for help on using tickets.