Make WordPress Core

Opened 7 years ago

Last modified 4 months ago

#41934 new enhancement

Update load.php with wp_is_bad_request function

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

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 7 years ago.
test file for proposed wp_is_bad_request enhancement
is_bad_request_test_revision1.php (2.7 KB) - added by rpayne7264 7 years ago.
revised wp_is_bad_request() & added test cases
is_bad_request_test_revision2.php (2.7 KB) - added by rpayne7264 7 years ago.
Removed 'ico' param in wp_favicon_request_x() code

Download all attachments as: .zip

Change History (8)

@rpayne7264
7 years ago

test file for proposed wp_is_bad_request enhancement

#1 @SergeyBiryukov
7 years ago

  • Description modified (diff)

#2 in reply to: ↑ description @rpayne7264
7 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 7 years ago by rpayne7264 (previous) (diff)

@rpayne7264
7 years ago

revised wp_is_bad_request() & added test cases

@rpayne7264
7 years ago

Removed 'ico' param in wp_favicon_request_x() code

#3 @rpayne7264
6 years ago

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

#4 @jorbin
4 months ago

  • Keywords close added

Hi @rpayne7264, Sorry it took so long for someone to review this.

It's unclear to me of the benefits of this proposed function. For much the same reasons outlined in https://core.trac.wordpress.org/ticket/17246#comment:7, plugins can already do checks of their own when needed and core can't make many assumptions do to the number different configurations.

#5 @rpayne7264
4 months ago

  • Keywords close removed

The benefits of this proposed function is so that there is a core function that everyone can use to check if the WordPress site is being loaded due to a missing script file or missing image file or missing css file. WordPress re-loads the webpage for each occurrence of a missing script file or missing image file or missing css file. That needs to be addressed. The proposed function is akin to already-existing functions like wp_doing_ajax and wp_is_json_request.

Note: See TracTickets for help on using tickets.