[wp-hackers] register_activation_hook only if is_admin() ?

Andrew Nacin wp at andrewnacin.com
Thu Jan 27 08:51:46 UTC 2011


On Thu, Jan 27, 2011 at 12:57 AM, Martin Widmann
<widmann.martin at gmail.com>wrote:

> The register_activation_hook action is only executed when the plugin is
> activated through the plugins page. It's not called every time the plugin is
> initialized. So there's no need basically to ask for is_admin() or if the
> current_user_can do something special.
>
> See also
> http://codex.wordpress.org/Function_Reference/register_activation_hook
>
>  On Jan 26, 2011, at 10:34 PM, Kevin Newman wrote:
>
> > Hello all,
> >
> > I'd like to know if I need to always register_activation_hook for my
> install routine (in a plugin), or is it ok to just register that if
> "is_admin()" is true (and maybe if current_user_can('manage_options')). I
> like to keep my overhead small.
> >
> > If there are cases where the activation_hook can be automatically invoked
> without admin or is_admin of the current user, I guess it'd have to be
> registered every time.
>

Adding to that, register_activation_hook() is nothing more than a
do_action() call under the hood. The is_admin() check isn't going to be much
faster. :-)

Nacin


More information about the wp-hackers mailing list