0

I have this code, which works perfectly:

    if (in_array('administrator', $user->roles)) {

I need it to also check for another role, so that it would be an, 'if this or that' scenario, such as, if administrator or editor

I've tried:

if (in_array('administrator', 'editor' $user->roles)) {

But that didn't work. Any help is appreciated.

1 Answer 1

0

If I understand you correctly, you want to determine if the user has any role that is in some pre-defined list like this:

$accepted_roles = array(
    'administrator',
    'editor',
);

if ( ! empty( array_intersect( $accepted_roles, $user->roles ) ) ) {
   ...

Not the answer you're looking for? Browse other questions tagged or ask your own question.