WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I have written a custom plugin that use a specific 3rd party plugin code, so I want to declare my plugin depends on this 3rd party plugin, is it possible? What would be normal approach to this issue?

share|improve this question

marked as duplicate by s_ha_dum, toscho Oct 28 '13 at 15:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What has been your research so far? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and above all, it helps you get a more specific and relevant answer. More info about how to ask a good question can be found on the How to Ask page. – kaiser Oct 28 '13 at 14:12

It's not possible in the core. There are a few ways to approach this.

1. Hook into plugins_loaded check to see if X from your dependency plugin exists.

add_action('plugins_loaded', 'wpse120377_load');
function wpse120377_load()
    if (!class_exists('Some_Class_From_Another_Plugin')) {
         // dependency not installed, bail

    // load the rest of your plugin stuff here

Hooking into plugins_loaded is important: every plugin that's installed will be loaded by that point. It's only at (or after) plugins loaded fires that you can do an accurate check for a dependency.

2. See if the Plugins Provides Hooks

Take Posts 2 Posts. It provides a hook called p2p_init that it fires when it's loaded. If your dependency plugin does something like that, you don't need to hook into plugins_loaded and do a check. Simply hook into the plugins init action (or whatever) and load your functionality from there.

add_action('p2p_init', 'wpse120377_load2');
function wpse120377_load2()
    // load your plugin

3. The "Nice-to-the-User" Way

If your dependency doesn't exist, your plugin can't function. So be nice to the user and show an error message. admin_notices is a good hook with which to do that.

add_action('plugins_loaded', 'wpse120377_load3');
function wpse120377_load3()
    if (!class_exists('Some_Class_From_Another_Plugin')) {
         // dependency not installed, show an error and bail
         add_action('admin_notices', 'wpse120377_error');

    // load the rest of your plugin stuff here

function wpse120377_error()
    <div class="error">
            <?php _e('{PLUGIN NAME} requires {ANOTHER PLUGIN}. Please install it.', 'wpse'); ?>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.