Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Last active January 7, 2020 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfsarmento/900086d0e9a1e04a37f51565e6cb6729 to your computer and use it in GitHub Desktop.
Save nfsarmento/900086d0e9a1e04a37f51565e6cb6729 to your computer and use it in GitHub Desktop.
Show content based on multiple user roles in WordPress
<?php
global $user_login, $current_user;
wp_get_current_user();
$user_info = get_userdata($current_user->ID);
$roles = array (
'administrator',
'subscriber',
);
if (is_user_logged_in() && array_intersect( $roles, $user_info->roles)) {
echo 'success';
} else {
echo 'failure';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment