[wp-hackers] plugin activation help

Rich Pedley elfin at elfden.co.uk
Wed Sep 1 10:01:29 UTC 2010


On 01/09/2010 10:22, Andrew Nacin wrote:
> 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
> init.
> 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,

It sure does, I found a few more that could be potentially erm 
troublesome. I've now wrapped them in a nice add_action on init.

Thank you, sometimes to takes having some one pointing out the 
blindingly obvious to see your mistake.

Luckily I was redoing things to better split the admin based functions 
off from the public facing ones, so the change was easy to add in.

many many thanks.

Rich
(now I just need to tidy it all up...)



More information about the wp-hackers mailing list