Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Plugin Devs Please Read


Jeff Sayre
Participant

@jeffsayre

Here’s how I handle it for my BuddyPress Privacy Component. I have a loader file called bp-authz-loader.php. It contains all the necessary plugin metadata at the top of the file. After the metadata, I have this as the first function:

/**
* BPAz_init()
*
* Initialize basic constants and make sure BuddyPress
* is installed and activated. If true, then allow for
* Privacy Component to finish loading.
*
* @since 0.4
*/
function BPAz_init() {

/* Define the component's parent folder name */
define( 'BP_AUTHZ_PLUGIN_NAME', 'bp-authz' );

/* Define component's directory and URL Paths */
define( 'BP_AUTHZ_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . BP_AUTHZ_PLUGIN_NAME );
define( 'BP_AUTHZ_PLUGIN_URL', WP_PLUGIN_URL . '/' . BP_AUTHZ_PLUGIN_NAME );

/* Define the directory where user settings' functions reside */
define( 'BP_AUTHZ_SETTINGS', BP_AUTHZ_PLUGIN_DIR . '/' . 'settings' );

/* BuddyPress is installed and activated, finish initialization and go! */
require_once( BP_AUTHZ_PLUGIN_DIR . '/bp-authz-core.php' );
}
add_action( 'bp_init', 'BPAz_init' );

I have two more functions in this file, one to register the plugin upon activation, the other to register it upon deactivation. But that is all. Just these three functions.

If BuddyPress is installed and activated, BPAz_init() will fire, resulting in the rest of my component being activated when bp-authz-core.php is loaded. I’ve tested it and it works as expected without causing BP to crash. In other words, if BP is not activated but my plugin is activated, nothing happens. This is what you want.

Skip to toolbar