June 15, 2011 at 10:22 pm #3602
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.
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.June 16, 2011 at 1:44 am #33431
Should not be hard to track. I have replied to this thread on this same issue:
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_userJune 16, 2011 at 3:26 am #33432
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
do_action( ‘set_user_role’, $this->ID, $role ); is what he recommends.June 17, 2011 at 12:02 am #33434
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):June 17, 2011 at 5:11 am #33435
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:
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) )
elseif ( !$update )
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
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
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
When they register for the first time.June 17, 2011 at 6:50 am #33438
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
Sounds good, thank you very much for looking into this.June 19, 2011 at 2:05 am #33440
Please get a new build from here and check it out:June 20, 2011 at 3:11 am #33441
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
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
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
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).
- You must be logged in to reply to this topic.