Tips and Tricks HQ Support

Support site for Tips and Tricks HQ premium products

  • Home
  • Contact Us
  • Documentation
  • Forum Home
    • Forum
    • Forum Search
    • Forum Login
    • Forum Registration

eMember not properly assigning WordPress user roles

by

Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember Troubleshooting › eMember not properly assigning WordPress user roles

  • This topic has 32 replies, 4 voices, and was last updated 13 years, 9 months ago by SeizedPropaganda.
Viewing 15 posts - 1 through 15 (of 33 total)
1 2 3 →
  • Author
    Posts
  • June 15, 2011 at 10:22 pm #3602
    SeizedPropaganda
    Member

    Hi, I’m having a bit of an issue with eMember not properly assigning user roles. I am using the SimplePress forum plugin, and have assigned various WordPress user roles that I have created to have certain forum permissions. When I manually assign a WordPress user with one of these roles, they have the appropriate forum permission based on the settings I have used.

    However, when they register via eMember and eMember assigns the user role, they are not given the proper permissions. It is very strange, because when I browse through my WordPress user list I see that users are being assigned the roles I have created, however they seem to not be assigned correctly because if they were, they would have access to those protected forums as is the case when I manually assign a user the necessary role.

    Any thoughts?

    Also, please reference this simlpe-press forum thread, there are other eMember users reporting the same issue so hopefully we can work together to figure this one out, it’s the last piece of the puzzle for me regarding my eCommerce/Membership system.

    http://simple-press.com/support-forum/simple-press-version-440/user-group-memberships-based-on-wp-role-not-working-1/

    June 16, 2011 at 1:44 am #33431
    amin007
    Participant

    Should not be hard to track. I have replied to this thread on this same issue:

    https://support.tipsandtricks-hq.com/forums/topic/member-role-not-updating-correctly-w-expired-and-on-forums

    Please let me know if simplepress can work fine when we use the following WordPress function to create the user or it needs something else:

    wp_create_user

    http://codex.wordpress.org/Function_Reference/wp_create_user

    June 16, 2011 at 3:26 am #33432
    SeizedPropaganda
    Member

    I’ll post that in the thread, the developer over there also said something about a set_user_role hook.

    June 16, 2011 at 5:18 am #33433
    SeizedPropaganda
    Member

    do_action( ‘set_user_role’, $this->ID, $role ); is what he recommends.

    June 17, 2011 at 12:02 am #33434
    amin007
    Participant

    I can definitely add that hook in eMember but that doesn’t look like an WordPress API to create user (as suggested originally). That looks like a custom hook that that the developer is using. Can you ask them for a link to the WordPress documentation for that hook if that is an official WordPress API/Hook?

    For example, we use the following two API/Function because they are the official method of creating WordPress users (this is documented on WordPress’s site):

    http://codex.wordpress.org/Function_Reference/wp_create_user

    http://codex.wordpress.org/Function_Reference/wp_update_user

    June 17, 2011 at 5:11 am #33435
    SeizedPropaganda
    Member

    Here is his (very lengthy) response:

    I dont understand their question… you posted the codex page for the wp create user function… and it does exactly what I said it does… takes username, pw and email as input… so any user created with that function will get the default wp role…

    I said, if you wanted to create a user with a non default wp role, I would use wp_insert_user function where you can set any value of the wp user class object… this is the codex page:

    http://codex.wordpress.org/Fun…..nsert_user

    all very standard…

    and to be clear, the wp function wp_create_user() function will call the wp_insert_user() function anyways, just passing the user object with the username, pw and email as the only filled in elements…

    both files are located in wp-includes/user.php

    Now if you want to create a user with the default wp role, then calling wp_create_user() is just fine and dandy… But I think we are actually more concerned here with what happens when the membership plugin wants to change the role of a user. That’s when plugins, in this case, simple press, need to know you changed a user role…

    I think perhaps where confusion lies is when I referenced the wp hook for setting the user role, so I will try to clarify…

    If you take a look at the wp-includes/user.php and look at the wp_insert_user() function (remember, it gets called even for wp_create_juser), down towards the bottom, you will see this code

    if ( isset($role) )

    $user->set_role($role);

    elseif ( !$update )

    $user->set_role(get_option(‘default_role’));

    That is where wp sets the desired role for the new user… for wp_create_user() calls, it will be the default wp role… for direct calls to wp_insert_user(), it will be whatever you set for the role in the user class object… if empty, it will also yield the default wp role…

    that user class and the class function are defined in wp-includes/capabilities.php. if you look in that set_role function, when wp sets the role for the given user, WP fires the hook

    ‘set_user_role’

    via the code

    do_action( ‘set_user_role’, $this->ID, $role );

    All I was suggesting was that if when changing the role for a given user, you didnt want to use the wp api and the user class and the set_role() function, you could simply fire the hook yourself via

    do_action( ‘set_user_role’, $userid, $role );

    again, ALL very standard… any plugin or theme can fire any wp action or filters, not just core… so if the membership plugin is changing the user role by direct db manipulation instead of the api, then just fire the wp hook via the code:

    do_action( ‘set_user_role’, $userid, $role );

    to let other plugins know that a user role was modified… pass in the user id and the new role for the user as part of the hook action…

    hope that clears it up…

    June 17, 2011 at 6:29 am #33436
    amin007
    Participant

    okay thanks. just to double check before I add this hook… were you having this role issue just after the member sings up/registers or when they pay for a membership upgrade?

    June 17, 2011 at 6:36 am #33437
    SeizedPropaganda
    Member

    When they register for the first time.

    June 17, 2011 at 6:50 am #33438
    amin007
    Participant

    Thanks.. we will have something ready within a day or two. If I forget to get back to you please post on this thread.

    June 17, 2011 at 8:03 pm #33439
    SeizedPropaganda
    Member

    Sounds good, thank you very much for looking into this.

    June 19, 2011 at 2:05 am #33440
    amin007
    Participant

    Please get a new build from here and check it out:

    https://support.tipsandtricks-hq.com/update-request

    June 20, 2011 at 3:11 am #33441
    SeizedPropaganda
    Member

    Thank you I will, can you tell me which file(s) in particular you changed? I’ve done some customizations that I don’t want to have to go back and redo.

    June 21, 2011 at 12:18 am #33442
    amin007
    Participant

    That will be tough as we always keep modifying the plugin to add features and make it more robust. So there is always multiple files changing (sometimes multiple changes in one file). I recommend you take the fresh build from us and apply your changes on top of it.

    June 21, 2011 at 3:03 am #33443
    SeizedPropaganda
    Member

    Fair enough. So I’m assuming that this only works with people who register through eMember correct? I can’t take an existing user, add them to one of my membership levels, and expect them to be added to the custom WP role I’ve assigned that level, right?

    I’ll have to wait and see what happens the next time a user registers after making a purchase, I’ll let you know how it goes.

    June 21, 2011 at 10:40 pm #33444
    amin007
    Participant

    Yes you are right but at this stage we are just going to see how the new member registration work with the forum. If everything works correctly then we will add this to all the other places (for example: the admin area).

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 33 total)
1 2 3 →
  • You must be logged in to reply to this topic.
Log In

Forum Related

  • Forum Home
  • Forum Search
  • Forum Registration
  • Forum Login

Support Related Forms

  • Contact Us
  • Customer Support
  • Request a Plugin Update
  • Request Fresh Download Links

Useful Links

  • Plugin Upgrade Instructions
  • WP eStore Documentation
  • WP eMember Documentation
  • WP Affiliate Platform Documentation
  • Tips and Tricks HQ Home Page
  • Our Projects

Quick Setup Video Tutorials

  • WP eStore Video Tutorial
  • WP eMember Video Tutorial
  • WP Affiliate Platform Video Tutorial
  • Lightbox Ultimate Video Tutorial

Our Other Plugins

  • WP Express Checkout
  • Stripe Payments Plugin
  • Simple Shopping Cart Plugin
  • Simple Download Monitor

Copyright © 2025 | Tips and Tricks HQ