Skip to content

Instantly share code, notes, and snippets.

@patrickatwsrn
Created July 18, 2023 10:05
Show Gist options
  • Save patrickatwsrn/b0eb061b383322f6a2e555b14a8a0dde to your computer and use it in GitHub Desktop.
Save patrickatwsrn/b0eb061b383322f6a2e555b14a8a0dde to your computer and use it in GitHub Desktop.
wordpress - check user role of current user
<?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