current_user_can on WordPress 3.1.1

I just upgraded to WordPress 3.1.1 and suddenly I’m getting the following error:

Fatal error: Call to undefined function wp_get_current_user() in /home/arisehub/arisehub.org/wp-includes/capabilities.php on line 1028

I’ve narrowed it down to my usage of “current_user_can”

Example:

if ( !current_user_can('manage_options') ) { add_action('admin_init','customize_page_meta_boxes'); }

Removing that reference to current_user_can removes the errors. Any ideas?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You are calling the function too early. The functions.php is included before current_user_can() is defined. Never do anything before the hook 'after_setup_theme':

Example for the functions.php

add_action( 'after_setup_theme', array( 'WPSE_14041_Base', 'setup' ) );

class WPSE_14041_Base
{
    public static function setup()
    {
        ! isset ( $GLOBALS['content_width'] ) and $GLOBALS['content_width'] = 480;

        add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
        add_theme_support( 'automatic-feed-links' );

        add_theme_support( 'menus' );

        add_editor_style();

        add_custom_background();

        // You may use current_user_can() here. And more. :)
    }
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x