0

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.

2 Answers 2

1

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.

1
  • 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 :( Commented Mar 14, 2012 at 16:31
0

I resolve this with $_GET['action']

if($_GET['action'] == 'deactivate')
{
    //Do something
}
2
  • 2
    Out of curiosity: how do you know that it is the NextGen Gallery Plugin being deactivated, and not some other Plugin? Commented Jun 7, 2012 at 12:41
  • 3
    @ChipBennett $_GET['plugin'] holds the name.
    – fuxia
    Commented Jun 7, 2012 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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