我正在编写这个插件,当NextGen被停用时,我需要停用它:
<?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__);
}
但它不起作用。有什么想法吗?:(
我还使用了以下URL:
$nextgenUrl = \'nextgen-gallery\\nggallery.php\';
$nextgenUrl = \'/nextgen-gallery/nggallery.php\';
但还是不起作用。
SO网友:SickHippie
你必须检查一下is_plugin_active
. 我会用更像这样的东西,不知羞耻地从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!\');
}
}
编辑:只需意识到您正在寻找的是停用,而不是激活。不过,也许这会让你的大脑朝着正确的方向工作。