Declare plugin dependency [duplicate]

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
         return;
    }

    // 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');
         return;
    }

    // load the rest of your plugin stuff here
}

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