• Resolved woodypad

    (@woodypad)


    Hello,
    i am trying to customize the backend and want to apply it to some roles.
    But I can’t apply it correctly to multiple roles.
    I tried to write like this:

    add_action( 'admin_head', function () {
    	$user = wp_get_current_user();
    	if ( ! in_array( ‘user-role-1’,‘user-role-1’,‘user-role-3’, (array) $user->roles ) ) return;
    	?>
    	<style>
    
    	</style>
    	<?php
    } );
    

    I also tried like that

    add_action( 'admin_head', function () {
    	$user = wp_get_current_user();
    	if ( ! in_array( ‘user-role-1’, (array) $user->roles ) ) return;
    	if ( ! in_array( ‘user-role-2’, (array) $user->roles ) ) return;
    	if ( ! in_array( ‘user-role-3’, (array) $user->roles ) ) return;
    	?>
    	<style>
    
    	</style>
    	<?php
    } );
    

    but in both cases it is not good, how can I indicate more roles?
    Thank you

    • This topic was modified 2 years, 8 months ago by woodypad.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter woodypad

    (@woodypad)

    Sorry maybe the question is not clear.
    How do I add more than one role to this code?

    if (!in_array( 'editor', (array) $user->roles)) return;

    Thank you

    Thread Starter woodypad

    (@woodypad)

    Thanks always for your awesome plugin, I love it!

    Unfortunately I couldn’t find a solution to put multiple roles in the code.
    I always get error.

    I also tried that, but it doesn’t work. I always get error.
    if (!in_array( 'editor','author', (array) $user->roles)) return;

    Thank you

    Plugin Author Shea Bunge

    (@bungeshea)

    You can’t use in_array to check multiple things at once – you need to make two separate checks, separated by &&:

    if ( ! in_array( 'editor', (array) $user->roles ) && ! in_array( 'author', (array) $user->roles ) ) return;

    Thread Starter woodypad

    (@woodypad)

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Apply to multiple Roles’ is closed to new replies.