我正在尝试在激活第一个插件时自动激活第二个插件。
register_activation_hook(__FILE__, 'example_activation' );
function example_activation() {
include_once(ABSPATH .'/wp-admin/includes/plugin.php');
activate_plugin('hello.php');
}
它不能在register_activation_hook内部工作。如果我直接使用它,则它的工作方式如下:
include_once(ABSPATH .'/wp-admin/includes/plugin.php');
activate_plugin('hello.php');
我该如何解决?感谢帮助
解:
我现在为自己使用它:
// When this plugin activate, activate another plugin too.
register_activation_hook(__FILE__, function(){
$dependent = 'hello.php';
if( is_plugin_inactive($dependent) ){
add_action('update_option_active_plugins', function($dependent){
/* for some reason,
activate_plugin($dependent);
is not working */
activate_plugin('hello.php');
});
}
});
// When this plugin deactivate, deactivate another plugin too.
register_deactivation_hook(__FILE__, function(){
$dependent = 'hello.php';
if( is_plugin_active($dependent) ){
add_action('update_option_active_plugins', function($dependent){
deactivate_plugins('hello.php');
});
}
});
我原本误读了您的帖子。我必须说,它的格式正确。这个功能在您的插件主程序中吗?
—
克里斯(Chris)
等一下。需要编辑我的帖子。
—
克里斯(Chris)
是它在试图激活第二插件的第一个插件..第二插件是hello.php为例
—
Ünsal科尔克马兹