admin管理员组文章数量:1430064
I am developing a WordPress plugin which requires certain rules to be added to the .htaccess file of the WordPress installation upon activation of the plugin.
Initially, before I switched my code to OOP (with classes and functions) the hooks and this functionality was working. But after I switched it, it doesn't work.
register_activation_hook( __FILE__, array( 'Optimizo', 'activation' ) );
The above code is how I am trying to call the function 'activation' from the class 'Optimizo' which resides in the same file as where I am writing the above activation hook. The 'activation' function has the necessary classes in it which should be called upon activation. Below is the content of the function.
protected function activation() {
$this->activate();
}
I am just wondering if I wrote the code wrong of is it because that the function is having the protected access specifier or if I am doing something entirely wrong.
PS the function 'activate' resides in another class which is being extended to the 'Optimizo' class.
I am developing a WordPress plugin which requires certain rules to be added to the .htaccess file of the WordPress installation upon activation of the plugin.
Initially, before I switched my code to OOP (with classes and functions) the hooks and this functionality was working. But after I switched it, it doesn't work.
register_activation_hook( __FILE__, array( 'Optimizo', 'activation' ) );
The above code is how I am trying to call the function 'activation' from the class 'Optimizo' which resides in the same file as where I am writing the above activation hook. The 'activation' function has the necessary classes in it which should be called upon activation. Below is the content of the function.
protected function activation() {
$this->activate();
}
I am just wondering if I wrote the code wrong of is it because that the function is having the protected access specifier or if I am doing something entirely wrong.
PS the function 'activate' resides in another class which is being extended to the 'Optimizo' class.
Share Improve this question asked May 14, 2019 at 13:43 MinhazMinhaz 11 bronze badge1 Answer
Reset to default 1The function needs to be public, but it can also be static.
For example, from the Akismet plugin:
In the plugin file:
register_activation_hook( __FILE__, array( 'Akismet', 'plugin_activation' ) );
In the Akismet class file:
public static function plugin_activation() {
...
}
本文标签: oopWordPress plugin activationdeactivation and uninstall hook not being triggered
版权声明:本文标题:oop - WordPress plugin activation, deactivation and uninstall hook not being triggered 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745495716a2660796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论