[wp-hackers] Plugin main file name

Stephen Rider wp-hackers at striderweb.com
Tue Aug 26 04:06:09 GMT 2008

I've worked out a system for versioning common plugin code.  Each  
plugin has its own copy of the common code file.  System checks them  
all, finds the highest version, and loads that file, then loads the  
plugins that use it.  Details below...

On Aug 24, 2008, at 10:08 AM, Andrew Ozz wrote:

> Stephen Rider wrote:
>> Maybe I can figure out a way to load all the plugins, and have  
>> something hooked to call the correct core file at the end, and then  
>> create all the objects for all the plugins at once.  Potential  
>> there....
>> I could build an array of each copy of the core file containing  
>> version and path.  Then at the end look at the versions and load  
>> the highest one, then load the plugin classes.
> I can see the value in this: someone has several of your plugins  
> installed, updates one and all get to use the new "main" code. May  
> get a bit messy as it will have to support all the old versions of  
> the plugins that use it.
> Loading it at init or plugins_loaded seems late though, may want to  
> use it while loading the plugins too.
> Why not add an option with the version number and the path to the  
> latest file. The version number can even be included in the file  
> name, something like: main_20080824.php. Then when the first plugin  
> is loading, it can check where the latest file is and load it first.
> If another plugin is installed with an older version of the main  
> file, it can check the version and not overwrite the path.

Okay, I've got something working, but it needs some polish.  Here's  
how it works:

1) Plugin file is loaded.  This file is very simple:
* Plugin Headers
* adds path to secondary plugin file (containing the plugin's real  
code) to $strider_core_plugins[] array
* calls its copy of strider_core.php

2) strider_core.php loads.
* if( ! function_exists('load_strider_core') && !  
$strider_core_version && ! class_exists( 'strider_core' )  ) ... it  
creates the strider_core class.  This will be false at this point --  
no class is created.
* if( ! function_exists('load_strider_core') ) creates that function  
and adds it as a hook to plugins_loaded.  Thus this file is created  
only once and hooked only once.
* Adds current strider_core __FILE__ and version to  

3) Repeat 1 and 2 for each plugin using strider_core

4) Upon plugins_loaded, runs load_strider_core(), which...
* loops through $strider_core_version[], finds the core file with the  
highest version.
* sets $strider_core_version[] to null
* loads chosen strider_core file.  Look at the first if() in step 2  
above.  Now that $strider_core_version is null, it creates the  
strider_core class.
* Loop through $strider_core_plugins[] and include all the "real"  
plugin files....

Here's my question:

Does plugins_loaded run immediately after all the plugins are loaded?   
Is there something better I might hook to?  All plugins have to have  
been loaded so that we've seen all the strider_core.php files that  
might exist, so I think this is where to do it.

Ideas are welcome. :)

I'll do a more detailed writeup on my blog (and post the first plugins  
using it) in a day or so once I've worked out any kinks. :)


More information about the wp-hackers mailing list