Created
July 18, 2023 10:05
-
-
Save patrickatwsrn/b0eb061b383322f6a2e555b14a8a0dde to your computer and use it in GitHub Desktop.
wordpress - check user role of current user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
https://developer.wordpress.org/reference/functions/current_user_can/#comment-4083 | |
Contributed by Ahir Hemant(Woo-Expert) | |
*/ | |
$user = wp_get_current_user(); | |
$allowed_roles = array( 'editor', 'administrator', 'author' ); | |
if ( array_intersect( $allowed_roles, $user->roles ) ) { | |
// Stuff here for allowed roles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment