I want to know what roles a logged in user belongs to without having to check the user against all possible roles (i.e. using Page.User.IsInRole())
First off, we check that the user is actually logged in. If they're not logged in, they won't have a role assigned. If the user is logged in, we use wp_get_current_user to return the WP_User object. This provides us with a stack of information about the data and we can access their user role(s) via $user->roles .
In cPanel go to phpMyAdmin menu in Databases section: Once there, select your WordPress database. NOTE: You can check the database name of your installation in wp-config. php file, line define ('DB_NAME', 'databasename');
var user = new ApplicationUser { UserName = model. Email, Email = model. Email }; var userRoles = await _userManager. GetRolesAsync(user);
using System.Web.Security;
Roles.GetRolesForUser()
Or
Roles.GetRolesForUser(String)
if not targeting the currently logged in user.
try this if you want to check the currently logged in user for specific role:
Roles.IsUserInRole("Admin")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With