Home Community WordPress How do you check whether the user is admin or not?

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • shane_x
    Participant
    Post count: 3

    How to actually check whether the current user is admin or not in WordPress?

    webroom
    Keymaster
    Post count: 14

    WordPress has a build in function to check if the current logged-in user is whether administrator, editor or any other capability you have. I am talking about the current_user_can() function and WordPress capabilities. This function returns whether the current user has the specified capability.

    PHP Snippet: How To Check For All WordPress Capabilities:

    <?php
    if( current_user_can( 'administrator' ) ){} // only if administrator
    if( current_user_can( 'editor' ) ){} // only if editor
    if( current_user_can( 'author' ) ){} // only if author
    if( current_user_can( 'contributor' ) ){} // only if contributor
    if( current_user_can( 'subscriber' ) ){} // only if subscriber
    ?>

    Learn more in the article How To Check If User Is Administrator Or Editor In WordPress

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.