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”]
Leave a Reply