Support » Plugin: Restrict User Access - Ultimate Membership & Content Protection » Developer API’s and Data Location

  • Resolved atlabs

    (@atlabs)


    Hello,

    I need assistance with the developer API’s. I am new to WordPress programming.

    I am trying to put a user into a certain group once they register, but the group they get access to is based on their domain name. I believe I have that part figured out, but I’m not sure what code to use to add a user to a specific group for this plug-in.

    The developer API I believe I would use is “add_level(int $level_id):bool”, but I’m not sure what to put for the $level_id. Also I’m not sure if I’m supposed to replace “bool” with True or False (for Boolean).

    I have five groups that a user could be put into. Platinum, Gold, Silver, Bronze and Blocked.

    Also I was having trouble finding the data that shows what group a user is in (in the database). That would also be useful information.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Okay so you need the user ID, and the group ID. You can see the group ID in the URL when you’re editing the level. Or, you can get it by calling rua_get_level_by_name($slug) where $slug is ‘my-formatted-level-name’

    You’ll want to hook into the authorization or login hook, grab the user’s ID and put them in a group.

     $user = rua_get_user(get_current_user_id());
    $level = rua_get_level_by_name('platinum');
    $user->add_level($level->ID); 

    The access level is stored in the usermeta table, meta key _ca_level

    Reference:
    https://developer.wordpress.org/reference/functions/get_current_user_id/
    https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login

    Plugin Author Joachim Jensen

    (@intoxstudio)

    Thank you for your input @uncharteddesign! Appreciate your help.

    @atlabs

    When you see a method referenced like add_level(int $level_id):bool, int means that the type of $level_id should be an integer, and :bool means that you can expect the method to return true/false. Because PHP by default is weakly typed, you will not get errors if $level_id e.g. is a numeric string (“1” instead of 1).

    I hope this helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Developer API’s and Data Location’ is closed to new replies.