[wp-hackers] Plugin dependency checking

Burt Adsit burt at ourcommoninterest.org
Thu Jun 11 11:27:03 GMT 2009


I have a similar issue with one of my plugins. I have classes in my 
plugin that extend native buddypress classes. There were some issues 
early on where the user loaded the plugins out of sequence. So now we 
have a standard way of determining if bp is installed and loaded at the 
time of dependent plugin load.

function oci_load_buddypress() {
    // check to see if bp is already loaded
    if ( function_exists( 'bp_core_setup_globals' ) )
        return true;

    /* Get the list of active sitewide plugins */
    $active_sitewide_plugins = maybe_unserialize( get_site_option( 
'active_sitewide_plugins' ) );

    // not activated  
    if ( !isset( $active_sidewide_plugins['buddypress/bp-loader.php'] ) )
        return false;

    // activated but not loaded yet
    if ( isset( $active_sidewide_plugins['buddypress/bp-loader.php'] ) 
&& !function_exists( 'bp_core_setup_globals' ) ) {
        require_once( WP_PLUGIN_DIR . '/buddypress/bp-loader.php' );
        return true;
    }

    return false;
}

So the fn returns true if it's ok to continue with dependent plugin load 
and false if we need a graceful exit. It doesn't require rearranging the 
list of active plugins.

scribu wrote:
> First of all, great to see WP 2.8 finally comming out. In the official blog
> post, dependency checking was mentioned at the end. What I have in mind
> might not be the same thing but it is related, so here goes:
>
> I have a plugin toolkit called
> scbFramework<http://scribu.net/wordpress/scb-framework>,
> which I would like to package as a base plugin.
>
> The solution I found involves two steps:
>
> 1. Get the base plugin to be the first plugin that is loaded, so that the
> classes are available to all the rest of the plugins. This is done
> here<http://plugins.trac.wordpress.org/browser/scb-framework/trunk/plugin.php>
> .
> 2. In each child plugin, check if the base plugin is installed. If not,
> deactivate the child plugin and issue a notice. This is done in
> scb-check.php<http://plugins.trac.wordpress.org/browser/scb-framework/trunk/scb-check.php>
> .
>
> Step two requires ticket #9991
> <http://core.trac.wordpress.org/ticket/9991>to be fixed, so that the
> user doesn't get two notices when he tries to
> activate the child plugin.
>
> Any thoughts on this method? Are there any plans to have an equivalent
> mechanism in WP 2.9?
>
>
>   

-- 
Code Is Freedom
Burt Adsit



More information about the wp-hackers mailing list