[wp-trac] [WordPress Trac] #17246: Handling of HTTP 404 errors for non-existing files

WordPress Trac noreply at wordpress.org
Thu Jun 8 17:16:36 UTC 2017


#17246: Handling of HTTP 404 errors for non-existing files
----------------------------+--------------------------
 Reporter:  azaozz          |       Owner:
     Type:  enhancement     |      Status:  reopened
 Priority:  normal          |   Milestone:
Component:  Bootstrap/Load  |     Version:  trunk
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  performance
----------------------------+--------------------------
Changes (by rpayne7264):

 * status:  closed => reopened
 * version:   => trunk
 * resolution:  maybelater =>


Comment:

 I propose that we add a wp_abort_execution filter to the core, which would
 allow developers to tell Wordpress whether or not to load their plugin.

 Personally, I am now including a check in all of my plugins, after
 realizing the Wordpress process executes for all missing files referenced
 in client-side mark-up.

 Here are the functions I am using inside a utilities class:
 {{{
     static function abortExecution(){
         $rv = false;
         $wp_action = self::globalRequest('action');
         if($wp_action == 'heartbeat')$rv = true;
         if(!$rv):
             $url = (isset($_SERVER['REQUEST_URI']))?
 $_SERVER['REQUEST_URI'] : '';
             $rv =  self::isScriptStyleImgRequest($url);
         endif;
         return $rv;
     }//abortExecution

     static function isScriptStyleImgRequest($url){
         if(empty($url))return false;
         $arrExts = self::extensionList();
         $url_parts = parse_url($url);
         $path = (empty($url_parts["path"]))? '' : $url_parts["path"];
         $urlExt = pathinfo($path, PATHINFO_EXTENSION);
         return key_exists($urlExt, $arrExts);
     }//isScriptStyleImgRequest

     static function extensionList(){
         $ext = array();
         $mimes = wp_get_mime_types();

         foreach ($mimes as $key => $value) {
             $ak = explode('|', $key);
             $ext = array_merge($ext,$ak)  ;
         }

         return $ext;
     }//extensionList
 }}}

 Either way, a "best practice" promulgation should go out to the Wordpress
 developer community to encourage implementing a check of the incoming
 request and prevent code from running unnecessarily.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/17246#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list