检查action hooks API reference, “activated\\u plugin”是一个高级挂钩。它在正常循环之外运行,允许您做您想做的事情。
更好的方法是add_action(\'admin_footer_text\')
, 如图所示WPBeginner article.
但是,如果您只想在某个特定插件被激活时显示,可以添加以下“if”语句来检查您的plugin is active:
if (is_plugin_active($plugin_path)){
add_filter(\'admin_footer_text\', \'[your function here]\');
}
如果只想在插件激活后立即运行一次,可以使用“activated\\u plugin”设置选项变量。然后,使用“admin\\u footer\\u text”操作检查并清除该选项变量:
// Set the option indicating the plugin was just activated
function wpse_set_activated(){
add_option("wpse_my_plugin_activated",\'true\');
}
add_action("activated_plugin","wpse_set_activated");
// Setup conditional admin_footer text mod
function wpse_setup_admin_footer_text(){
if (is_plugin_active("plugin_folder/my_plugin.php")){
$just_activated = get_option("wpse_my_plugin_activated",\'false\');
if ($just_activated !== \'true\') {
echo "";
} else {
echo "My plugin is active";
delete_option("wpse_my_plugin_activated");
} // end if is_active
} else {
echo "";
}// end if is_plugin_active
}
add_filter(\'admin_footer_text\', \'wpse_set_admin_footer_text\');
希望这有帮助!