While a user is creating a new post, how do I determine his current role?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m assuming you know what hooks of WordPress you want to use. So skipping that part, it’s pretty easy to get the current role of the user
Now, you can iterate over that array to see if the user has a particular role.
Or, you can use
current_user_canto look for specific capabilities, if you just want to check whether or not a user has a specific permission versus whether or not they’re in the role. For example: