admin管理员组文章数量:1410737
I have the following code fraction, but it does not work, I want that after activating a plugin this calls an action on the footer and prints something, but I can't do it, the problem seems that the admin_footer
does not run, I don't know if activated_plugin
is just before or after the html is printed so that the admin_footer
, or how could I fix it?
add_action( 'activated_plugin', 'admin_activated_plugin' );
function admin_activated_plugin(){
// up to here if you run ....
// but
// the hook below doesn't
add_action( 'admin_footer', 'after_activate_print_footer', 99 );
}
function after_activate_print_footer(){
echo "something";
}
In conclusion, I want to print a text in the header or footer just after a plugin is activated
I have the following code fraction, but it does not work, I want that after activating a plugin this calls an action on the footer and prints something, but I can't do it, the problem seems that the admin_footer
does not run, I don't know if activated_plugin
is just before or after the html is printed so that the admin_footer
, or how could I fix it?
add_action( 'activated_plugin', 'admin_activated_plugin' );
function admin_activated_plugin(){
// up to here if you run ....
// but
// the hook below doesn't
add_action( 'admin_footer', 'after_activate_print_footer', 99 );
}
function after_activate_print_footer(){
echo "something";
}
In conclusion, I want to print a text in the header or footer just after a plugin is activated
Share Improve this question edited Dec 4, 2019 at 23:45 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Dec 4, 2019 at 21:15 LΞИIИLΞИIИ 1947 bronze badges 1- 1 you can show a message with that : codex.wordpress/Plugin_API/Action_Reference/admin_notices – Kaperto Commented Dec 4, 2019 at 21:33
1 Answer
Reset to default 2Checking the action hooks API reference, "activated_plugin" is an Advanced hook. It operates outside the normal loop which would permit you to do what you want.
A better way would be to add_action('admin_footer_text')
, as illustrated in this WPBeginner article.
However, if you only want this to show when a particular plugin is activated, you can add the following "if" statement to check if your plugin is active:
if (is_plugin_active($plugin_path)){
add_filter('admin_footer_text', '[your function here]');
}
If you only want this to run once, immediately after the plugin is activated, you might use your "activated_plugin" to set an option variable. Then, use your "admin_footer_text" action to check for and clear that option variable:
// 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');
Hope this helps!
本文标签: Execute Hook on the footer or header after activating a plugin
版权声明:本文标题:Execute Hook on the footer or header after activating a plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744938661a2633346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论