Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

<?php
/*
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(){
    deactivate_plugins(__FILE__);
}

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

2 Answers 2

I resolve this with $_GET['action']

if($_GET['action'] == 'deactivate')
{
    //Do something
}
share|improve this answer
2  
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
3  
@ChipBennett $_GET['plugin'] holds the name. –  toscho Jun 7 '12 at 12:53

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' );
  }
  else
  {
     // 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
1  
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

Your Answer

 
discard

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.