How do I check if a user has the ‘manage_options’ capability in WordPress?

I’m trying to figure out if the current user can manage options. I’m using the following code:

if (current_user_can('manage_options')) {
    add_filter('comments_array', 'myFunctionCall');
}

But it produces this error (in WordPress 2.9.2, latest):

Read More

Fatal error: Call to undefined
function wp_get_current_user() in
/Users/******/Sites/*****.com/wp-includes/capabilities.php on line 969

Am I going about this the wrong way?

Related posts

Leave a Reply

1 comment

  1. I checked your code and works fine in my site (using WP 2.9.2 too).

    Check that the function is defined in the pluggable.php file inside /wp-includes.

    In my WP installation I’ve got the function defined from line 69 to 76:

    if ( !function_exists('wp_get_current_user') ) :
    /**
     * Retrieve the current user object.
     *
     * @since 2.0.3
     *
     * @return WP_User Current user WP_User object
     */
    function wp_get_current_user() {
        global $current_user;
    
        get_currentuserinfo();
    
        return $current_user;
    }
    endif;