[wp-hackers] Overriding Cor Functions (Was: IIS Problem)

Ryan Boren ryan at boren.nu
Sun Apr 3 18:40:01 GMT 2005

On Sun, 2005-04-03 at 03:32 -0500, Scott Reilly wrote:
> Since you mentioned it, WP doesn't currently support plugins
> overriding core functions even if those core functions are wrapped in
> function_exists(), correct?  I know the intent is for plugins to be
> able to do that, but how?  Plugins aren't sourced until after all core
> files have been sourced, which is too late.  Or am I missing
> something?

Here's an approach I've been mulling over.

Add a preload_file action to be called from plugin files.  This allows
plugin files to specify a file to be loaded before the core WP
includes.  In the plugin:

function test_plugin_preload_file() {
   preload_file(dirname(__FILE__). '/test_preload.php');

add_action('preload_file', 'test_plugin_preload_file');

preload_file() runs plugin_basename() on the supplied file and adds it
to a 'preload' array in the options DB.

In plugins.php, we call the preload_file action whenever a plugin is
activated.  This is a bit tricky.  First we'll have to unset all
existing preload actions and then include the just activated plugin.
Then we call the preload_file action.  This is the only situation where
the preload_file action is called.

In wp-settings.php, we loop through the list of preloaded files after
wp-db.php is included but before functions.php is included.  Since
functions.php is not yet included, we have to be careful not to call
get_option() to retrieve the preload array etc.  Only wpdb may be used.



More information about the wp-hackers mailing list