• Skip to main content
  • Skip to primary sidebar

Edwin Velez

Just another WordPress site

Get WordPress User Role

October 9, 2019 by Edwin Velez Leave a Comment

According to WordPress current_user_can() documentation, use of this method is discouraged.

While checking against particular roles in place of a capability is supported in part, this practice is discouraged as it may produce unreliable results.

WordPress Developer Code Reference

So, how should you check a user’s role the right way? For that we need to a WP_User object. To help make things easy we can use the wp_get_current_user() function to return an instance of that object. See the below snippet for an example.

[gist id=”b3d94add6637f9e86636fb7e0ef7b67d”]

Filed Under: Code Snippets, Theme Development, WordPress

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Add a Bootstrap 4 Navigation Menu to a Genesis Child Theme
  • Get WordPress User Role
  • Get Root URL and Directory of a Plugin Dynamically
  • Genesis Responsive Menus
  • Build Table of Contents in Sidebar of a Genesis Theme

Recent Comments

    Archives

    • December 2019
    • October 2019
    • September 2019
    • August 2019
    • June 2019
    • March 2019
    • January 2019

    Categories

    • Bootstrap
    • Code Snippets
    • Genesis Framework
    • JavaScript
    • Theme Development
    • WordPress

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2019 · Genesis Sample on Genesis Framework · WordPress · Log in