WordPress.org

Ready to get started?Download WordPress

Forums

How do I get the current user's role? (6 posts)

  1. roblgs
    Member
    Posted 8 years ago #

    Hi,

    I have need to modify the administrative interface based upon the role (WP2) of the currently logged in user.

    How can I retrieve this information?

    Is it possible to substitute, or modufy the editing interface for posts/pages via a plugin (preferable), or does this require hacking around (yuk) in the core code?

    I understand that it is possible to add elements to the admin interface via plugins, but not sure on modifying or removing parts of the core interface.

    Thanks in advance.

    Rob

  2. McShelby
    Member
    Posted 8 years ago #

    You can use the global variable $current_user. This is an instance of a WP_User. Look in capabilities.php for the interface of this class. Each instance carries a roles member variable.

    You can use the actions simple_edit_form and edit_form_advanced to add items to the edit post interface. I bet there is also one on the edit page interface, but don't know for sure.

  3. roblgs
    Member
    Posted 8 years ago #

    Cheers McShelby... will take a look

    Rob

  4. roblgs
    Member
    Posted 8 years ago #

    Well, almost, but not quite...

    $current_user includes what is being reported as an array that is

    $current_user['wp_capabilities'] that must include the info that I want, but I'm not clear on how to get it out. Although reported as an array, it's not behaving as such... a foreach loop doesn't yield anything.

    I need another nudge in the right direction...

    TIA

    Rob

  5. syndromes
    Member
    Posted 8 years ago #

  6. roblgs
    Member
    Posted 8 years ago #

    Thanks syndromes... again a good pointer... unfortunately I'm just plain dense when it comes to objects.

    For now I can simulate the level of switching based upon specific capabilities using

    if (current_user_can('do_foo'))...

    But I'm curious, and not good enough with OO coding, to understand whether or not the named 'Role' is directly accessible through the API provided by the capabilities.php file.

    Thanks again.

    Rob

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.