Must activation/deactivation functions in a class be static?
The description for register_uninstall_hook
's $callback
parameter states:
Must be a static method or function.1
There is no such comment for register_activation_hook
or register_deactivation_hook
. However, in the Codex entry for register_activation_hook
there is an example that reads:
Or, because the activation hook requires a static function, if you're inside of a __construct():2
In a GitHub issue, "why is activate a static method?", a user states:
You can't define them as standard functions because they require an instance of the plugin to fire, but you can't instantiate the plugin prior to firing the activation function because the constructor will fire (even if it's empty), so functions need to be marked as static so that any preliminary work required to prepare the plugin for de/activation can be set.3
When using classes to (de)activate a plugin, are the functions required to be static? If so, is the explanation as to why correct?
Topic deactivation activation Wordpress
Category Web