• Resolved ruthvant2022

    (@ruthvant2022)


    <?php 
    if ( UM()->user()->get_role() == 'um_royal-crescent-apartments-jersey' || 'um_03-cobalt-quarter-jersey' || 'um_05-mistral-jersey' || 'um_28-cobalt-quarter-jersey' || 'um_113-sirocco-jersey' || 'um_220-blake-building-jersey' || 'um_237-blake-building-jersey' || 'um_a601-royal-crescent-apartments-jersey' || 'um_b304-royal-crescent-apartments-jersery' || 'um_c301-royal-crescent-apartments-jersey' ) {
    echo 'Jersey '; 
    } else {
    echo '';
    } ?>

    I’m using this code to exclude certain content in a template, but it is showing these parts to anyone. If I just have one user role it works perfectly. I thought || is OR, I’ve try xor too. What have I missed?

    I have multiple logins to test this.

    <?php 
    if ( UM()->user()->get_role() == 'um_royal-crescent-apartments-jersey' ) {
    echo 'Jersey '; 
    } else {
    echo '';
    } ?>

    This works on it’s own with one role

Viewing 4 replies - 1 through 4 (of 4 total)
  • @ruthvant2022

    You can try this code snippet:

    <?php 
    if ( in_array( UM()->user()->get_role(),
                array(  'um_royal-crescent-apartments-jersey',
                        'um_03-cobalt-quarter-jersey',
                        'um_05-mistral-jersey',
                        'um_28-cobalt-quarter-jersey',
                        'um_113-sirocco-jersey',
                        'um_220-blake-building-jersey',
                        'um_237-blake-building-jersey',
                        'um_a601-royal-crescent-apartments-jersey',
                        'um_b304-royal-crescent-apartments-jersery',
                        'um_c301-royal-crescent-apartments-jersey' ))) {
        echo 'Jersey '; 
    } else {
        echo '';
    } ?>
    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hello @ruthvant2022,

    Use the PHP function in_array as @missveronicatv suggested.

    Regards

    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hi ruthvant2022,

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help.

    Merry Christmas and Happy New Year!

    Thread Starter ruthvant2022

    (@ruthvant2022)

    Works perfectly thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Allow only selected user roles with PHP’ is closed to new replies.