Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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. :)
    }
}
share|improve this answer
    
Thank you! I will look into this further. –  Jonathan Wold Apr 12 '11 at 15:41
1  
Actually the 'plugins_loaded' action is fired almost immediately after the pluggable.php file is loaded, this would be the optimal action to hook. –  Jonathon Byrd Jan 23 '12 at 22:53
    
add_action isn't defined until after functions.php is included! Where should this code be placed? @toscho –  bozdoz Oct 11 '12 at 22:41
    
@bozdoz add_action() exists already at the very bottom of the wp-config.php. That's very early even before the mu-plugins are loaded. –  toscho Oct 12 '12 at 1:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.