[wp-hackers] plugin activation help

Andrew Nacin wp at andrewnacin.com
Wed Sep 1 09:22:07 UTC 2010

On Wed, Sep 1, 2010 at 5:08 AM, Rich Pedley <elfin at elfden.co.uk> wrote:

>  ugh, could this be caused by my using this:
>> require( ABSPATH . WPINC . '/pluggable.php' );
>> shamed to say that was left over from my early coding, and I've now
>> removed it...
> apologies ignore me, have to use it so changed it to require_once
> The following if statement won't work without it, unless I'm referencing
> the wrong file?
> if(is_user_logged_in() && current_user_can('eShop_admin')){

Don't include pluggable.php before core does. That can definitely cause
problems. (You're preventing other plugins from replacing those functions.)

The reason why is_user_logged_in() and current_user_can() don't work when
you're trying to use them, is because we haven't initialized the current
user yet. We don't do that until just before the init hook.

Anything affecting the current user all need to wait until init. Same goes
for $wp_rewrite, $wp_query, the list goes on. Realistically, the plugin
should be waiting for init to do *anything* at all, beyond attaching hooks.

Invalid bug reports caused by plugins doing things before init include:

http://core.trac.wordpress.org/ticket/14728 - using is_super_admin() before
http://core.trac.wordpress.org/ticket/14729 - using conditional tags (which
rely on $wp_query) before init.
http://core.trac.wordpress.org/ticket/13957 - using register_taxonomy() or
register_post_type() before init.

Hope that helps,

More information about the wp-hackers mailing list