Support » Plugin: Restrict User Access - Membership & Content Protection » Shortcode getting rua_get_user_levels

  • Resolved ggarmory

    (@ggarmory)


    I was wondering if it is possible to create a shortcode to display the level access levels from the current user front-end, and if possible how.

    The shortcode would, for example, display the following: level_1, level_2, level_5

    Thanks in advance!

    • This topic was modified 5 years, 4 months ago by ggarmory.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Joachim Jensen

    (@intoxstudio)

    This is not currently possible, but thank you for your feedback and suggestion!

    Can you explain your use case in more detail? Then it will be easier for me to see how I can implement this in a flexible way 🙂

    Thread Starter ggarmory

    (@ggarmory)

    https://github.com/intoxstudio/restrict-user-access/blob/master/api/level.php

    I would like to retrieve the access levels of the current user. I have created my own plugin/addon to collect the current user ID with the intention to use it in combination with your API.

    I have been trying to use the level.php file, specificly the one function below:

    /**
    * API to get user levels
    *
    * @since 0.9
    * @param int $user_id
    * @param boolean $hierarchical
    * @param boolean $synced_roles
    * @param boolean $include_expired
    * @return array
    */
    function rua_get_user_levels(
    $user_id = null,
    $hierarchical = true,
    $synced_roles = true,
    $include_expired = false) {
    return RUA_App::instance()->level_manager->get_user_levels($user_id,$hierarchical,$synced_roles,$include_expired);
    }

    For some odd reason, it returns the text “array” not actually an array of user access levels.

    I am calling the function with the following line, am I doing something wrong?:

    $current_user_levels = rua_get_user_levels($current_user_id);

    Kind Regards,

    Thread Starter ggarmory

    (@ggarmory)

    I was being stupid, I found out how to do it! For all the newbie scripters out there like me:

    add_action(‘init’, ‘rua_get_user_levels_custom’);

    function rua_get_user_levels_custom($user_id){
    $user_id = get_current_user_id();
    $user_levels = rua_get_user_levels($user_id);
    echo implode(“,”, $user_levels );
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode getting rua_get_user_levels’ is closed to new replies.