• Resolved snippet24

    (@snippet24)


    Hi I’m using (in which 398 is the ID level) in the theme template:

    if(rua_get_user()->has_level(398)) { ?>
    <p>authorized</p>
    <?php } else { ?>
    <p>not authorized</p>
    <?php } ?>

    Which always results in “not authorized”. Do note the shortcode is working as expected and inserting the content accordingly, but I would rather use the API instead.

    • This topic was modified 1 year, 2 months ago by snippet24.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Joachim Jensen

    (@intoxstudio)

    Thank you for reporting this.

    Are you by any chance using automators in your levels?

    Can you see if this snippet works for you:

    if(in_array(398, rua_get_user()->get_level_ids())) { ?>
    <p>authorized</p>
    <?php } else { ?>
    <p>not authorized</p>
    <?php } ?>
    Thread Starter snippet24

    (@snippet24)

    Hi, thanks to to you as well 😉

    Are you by any chance using automators in your levels?

    yep these ones:

    • [Synchronized Role] Include user for as long as they are Administrator
    • Include user for as long as they are Logged-in

    Can you see if this snippet works for you:

    Yep it does work just fine 🙂

    Thread Starter snippet24

    (@snippet24)

    Hi,

    If I understood correctly with more than one automator there’s trouble? hence the array..

    if(in_array(398, rua_get_user()->get_level_ids())) { ?>

    Question: should I stick to the above code or should I wait till it works with

    if(rua_get_user()->has_level(398)) { ?>

    Plugin Author Joachim Jensen

    (@intoxstudio)

    The has_level() method is a misnomer when it comes to Trait automators, because it only looks at levels that have specifically been given to the user.

    So in your use case, the get_level_ids() is the way to go.

    In the future I will probably combine these 2 methods into something that’s simpler to use as I acknowledge that is a bit confusing.

    Thread Starter snippet24

    (@snippet24)

    Alright, thank you 😉

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘For some reason API example is not working’ is closed to new replies.