ADMIN_NOTICES挂钩在插件激活后显示消息所有管理页面

时间:2015-07-27 作者:deemi-D-nadeem

I am working on a plugin and in plugin i use admin_notices hook for showing my custom message. When a user activate plugin the message show blew the plugin activate successfully, but my message shows all the other admin pages.

I want to show message only the plugins page after plugin activate or my plugin settings page. I don\'t know how can i fix this.

Here is my code:

add_action(\'admin_notices\', \'wpc_plugin_notices\');
function wpc_plugin_notices() {
    $plugin = plugin_basename(__FILE__);
    if (is_plugin_active($plugin)) {
        echo "<div class=\'updated\'>
                <p>
                    Please go to this page
                    <a href=\'".site_url()."/wp-admin/edit.php?post_type=wpcproduct&page=image_resize&action=wpc_resize&products=1\'>Click Here</a>
                </p>
              </div>";
    }
}

Please guide me how can i fix this.

1 个回复
SO网友:Mte90

为此,您需要在db中保存一个值,以记住警报已显示。否则你可以试试看https://codex.wordpress.org/Function_Reference/register_activation_hook. 有了它,你只能在插件的激活操作上执行一个钩子。

结束

相关推荐

排除Plugins.php HTTP安装路径与单个插件的HTTPS的故障

我正在尝试对插件中显示的安装路径进行故障排除。php作为我在自己的网站上安装的插件,我最初并没有编写该插件。当我的站点的其余部分是HTTPS时,此插件引用和安装的所有资源都会显示为混合内容HTTP。我一直在玩弄下面的代码段,但它似乎没有起到什么作用,也没有解决问题。有人能指出我遗漏了什么吗? /** * registers scripts and stylesheets */ public function register_assets() {&