WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get_currentuserinfo alternative in 3.3 beta 3? (6 posts)

  1. itsalltech1
    Member
    Posted 2 years ago #

    Hello.

    Just updated to WordPress 3.3 beta 3 and noticed that the following code isn't working properly:
    <?php get_currentuserinfo() ; global $user_level; if ($user_level >= 2) {?>

    The code is supposed to check the current user that is logged in and see if that user is above a level (2), then display a specific link on the page. However, that link is not visible at all - logged in or logged out.

    Are there any alternatives to achieving the same idea? Thanks!

  2. Big Bagel
    Member
    Posted 2 years ago #

    User levels have been deprecated. You should check user roles instead:

    Roles and Capabilities

    If you need to check that the current user has the appropriate privileges, you can use current_user_can():

    Function Reference/current user can

  3. NateJacobs
    Member
    Posted 2 years ago #

    From the Codex:
    Note: User Levels were introduced in WordPress 1.5, they were replaced by Roles and Capabilities in WordPress 2.0, and were finaly deprecated in WordPress 3.0.

    You will want to use the function current_user_can( $capability or $role ).

    http://codex.wordpress.org/Function_Reference/current_user_can

  4. Jon Cave
    WordPress Dev
    Posted 2 years ago #

    Thanks for the report. I have created a ticket for this to be fixed before the final release of 3.3 at http://core.trac.wordpress.org/ticket/19265.

    However, as suggested by the two other replies you should update your code use roles and capabilities rather than user levels as that is the correct method for determining privileges.

  5. itsalltech1
    Member
    Posted 2 years ago #

    Thanks guys. I've switched the code to the following:

    <?php if (current_user_can('author') || current_user_can('editor') || current_user_can('administrator')) {?>
  6. Big Bagel
    Member
    Posted 2 years ago #

    If you wanted to simplify that slightly, you could instead check for a certain capability that all those roles would share. For example:

    <?php if ( current_user_can( 'publish_posts' ) ) { ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.