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

i'm writing this plugin and i need to deactivate it when NextGen is deactivated:

Plugin Name: Plugin Name
Description: Description
Version: 1.0
Author: Author
Author URI: Author URI

// ini_set( "display_errors", 0);

global $nextgenUrl;
$nextgenUrl = str_replace('/','\\',WP_PLUGIN_DIR.'nextgen-gallery\nggallery.php');

register_deactivation_hook( $nextgenUrl , 'disattiva' );

[... other code ...]

function disattiva(){

but it doesn't work. Any idea? :(

I've also used these urls:

$nextgenUrl = 'nextgen-gallery\nggallery.php';
$nextgenUrl = '/nextgen-gallery/nggallery.php';

and still it doesn't work.

share|improve this question

You've got to actually check is_plugin_active. I would use something more like this, shamelessly stolen and modified from here:

register_activation_hook( __FILE__, 'dependentplugin_activate' );

function dependentplugin_activate()
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );

  if ( is_plugin_active( 'nextgen-gallery/nggallery.php' ) )
    require_once ( WP_PLUGIN_DIR . '/nextgen-gallery/nggallery.php' );
     // deactivate dependent plugin
    deactivate_plugins( __FILE__);
    //   throw new Exception('Requires another plugin!');
   //  exit();
    exit ('Requires another plugin!');

Edit: just realize you're looking for deactivate, not activate. Still, maybe this will get your brain working in the right direction.

share|improve this answer
I did it this way register_deactivation_hook( $nextgenUrl , 'disattiva' ); function disattiva(){ require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); deactivate_plugins( __FILE__); } still nothing :( – Ivano IsayBlog Mercuri Mar 14 '12 at 16:31

I resolve this with $_GET['action']

if($_GET['action'] == 'deactivate')
    //Do something
share|improve this answer
Out of curiosity: how do you know that it is the NextGen Gallery Plugin being deactivated, and not some other Plugin? – Chip Bennett Jun 7 '12 at 12:41
@ChipBennett $_GET['plugin'] holds the name. – toscho Jun 7 '12 at 12:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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