ฉันพยายามเปิดใช้งานปลั๊กอินที่สองโดยอัตโนมัติในขณะที่เปิดใช้งานปลั๊กอินแรก
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');
});
}
});