[wp-hackers] Addition to template-loader.php

Mike Schinkel mikeschinkel at newclarity.net
Thu Apr 2 17:23:18 GMT 2009


One of the things I keep running into as a problem is the inability in template-loader.php to gain control before code runs. I'd really like to see  (something like) the following added to template-loader.php just ahead of "if ( is_robots() )":

   $continue = true;
   if (is_custom() && $function = get_custom_function()) {
     $continue = call_user_func($function);
   }
   if (is_null($continue) or $continue) {
      // Existing template-loader.php code goes here
   }

Here is_custom() and get_custom_function() would inspect a global object (maybe $wp? $wp_query?) and, by default, return false and "" respectively however it could be set in the "init" action.

Another option might be to use a filter:

   if (apply_filters('custom_function',true) {
      // Existing template-loader.php code goes here
   }

Either would give a plugin and theme developer the control needed to launch any custom functionality and "hook" the template loader.  Without this one really has to hack in less-than-optimal ways (I'm no even sure specifically how) by using actions and filters not intended for launching custom functionality.  

Thoughts?


-Mike Schinkel
Custom Wordpress Plugins
http://mikeschinkel.com/custom-wordpress-plugins


More information about the wp-hackers mailing list