admin管理员组文章数量:1316832
My plugin is running on every single WordPress page, and I can't find a WordPress hook so that the script will only run when the plugin is activated. I only want part of the script to run when the plugin is activated, but not when I navigate to other WordPress pages. Apologies if it's a simple or basic solution I'm quite new to this.
I've tried register_activation_hook(__FILE__, 'do_my_function' )
but that gives me an error:
the plugin generated 1500 characters of unexpected output during activation. If you notice headers already sent messages...
If I try to debug this, all I get is Fatal Errors and a whole lotta blank space even though I'm not even outputting anything.
Here's the code:
class plugin
{
public static function activate()
{
flush_rewrite_rules();
//(new self) -> do_my_function(); //if I use this line instead of add_action it causes the "plugin generated 1500 characters of unexpected output" error
}
function do_my_function(){}
function deactivate()
{
flush_rewrite_rules();
}
}
if( class_exists( 'plugin' ) )
{
$plugin = new plugin();
}
register_activation_hook( __FILE__, array($plugin, 'activate'));
register_deactivation_hook( __FILE__, array($plugin, 'deactivate'));
add_action('admin_init', array($plugin, 'plugin_activated'), 10, 0); //causes plugin to run on every wordpress page load
本文标签: hooksMy plugin runs on every single WordPress pagebut I want it to run only on activation
版权声明:本文标题:hooks - My plugin runs on every single WordPress page, but I want it to run only on activation 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742011646a2412992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论