• Hi,

    When I use a snippet that has the $user->roles line, the array returned only contains the main role of the user.

    How can I get all roles that the user has?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Hi,

    In general, WP_User::roles property contains all roles granted to user.
    So $user->roles property of WP_User record is a right place to check roles granter to a user.

    Some plugins do not store their roles at the database and may create and possibly grant them to user dynamically. You will not see such role at the $user->roles in the case you check it too early, before some plugin, for example.

    Plugin Author Vladimir Garagulya

    (@shinephp)

    You may check directly at the database if all roles granted to your user saved at the database or they don’t. Example of checking user roles for admin user is here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP snippet getting all roles issue’ is closed to new replies.