Execute Hook on the footer or header after activating a plugin

I have the following code fraction, but it does not work, I want that after activating a plugin this calls an action on

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
Add a comment  | 

1 Answer 1

Reset to default 2

Checking 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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744938661a4602184.html

相关推荐

  • Execute Hook on the footer or header after activating a plugin

    I have the following code fraction, but it does not work, I want that after activating a plugin this calls an action on

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信