[wp-hackers] Plugin dependency checking

Mike Schinkel mikeschinkel at newclarity.net
Mon Jun 15 05:44:34 GMT 2009


"Stephen Rider" <wp-hackers at striderweb.com> wrote:
> So... rather than Master/Slave, or even "dependent", what 
> we need is something in WP Core that allows for some plugins 
> to say "offers X" and others to say "uses X"; and if the two 
> match up then we get the "sub plugin" UI changes.  

Dayum! I should have read ahead. I just wrote a ton and in this last paragraph you essentially described interfaces.  So I deleted everything that came before and am just sending this. If the WP community would instead want to call it "offers" instead of "interfaces" then that's completely copasetic with me.

I think we'd probably want something like this:

// Parent Plugin
wp_defines('my_offering.php');
wp_uses('my-offering',1.0);
...

// Child Plugin
wp_defines('my_offering.php');
wp_offers('my-offering',1.5);
...

// In WP Core
function wp_defines($file) {
  if ($GLOBALS['validate_offerings'])
    require_once($file);
}
function wp_uses($name,$version) {
  if ($GLOBALS['validate_offerings'])
    ...
}
function wp_offers($name,$version) {
  if ($GLOBALS['validate_offerings'])
    ...
}

// In my_offering.php
$o = new WP_Offering('my-offering');
$o->add_hook('foo','This hooks does foo.');
$o->add_hook('bar','This hooks does bar.');
$o->add_other_stuff('other stuff','This does other stuff.');
add_offering($o);

Now I haven't tried to implement any of this so the stuff in "my_offering.php" might need to be vastly different and of course maybe the "offering" part is too paganistic for this day and age, but you get the idea. :-)

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


More information about the wp-hackers mailing list