첫 번째 플러그인을 활성화하는 동안 두 번째 플러그인을 자동으로 활성화하려고합니다.
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');
});
}
});