Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
How to catch the add_role action
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 11, 2014 - 2:36 pm

Yes please do come back. This clearly needs to be sorted out.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 11, 2014 - 10:33 pm

interesting... it does seem possible to ADD a wp role to a user via the add_role function... however, it may or may not have any impact on the user capabilities, since a level check is done...

additionally, the user will now have multiple wp roles which could be construed as problematic since multiple wp roles may map to multiple sp usergroups... from a wp perspective you will just get the higher level of the two roles... but still have both levels...

there is a corresponding remove role function which can remove a specific level...

however, neither the add role function or the remove role function have applicable hooks fired by wp that lets other plugins know that roles were changing (which is probably why core uses set role)...  the set role replaces the current role with the new role such that the user maintains single wp role...

there is a level change hook that might could be tied into, but its potentially problematic in that a single level can belong to multiple roles... so from the level hook, I am not sure we can know which role was added (or removed)...

so, will have to do more research, but at this point, adding a role, vice setting the role, may not tell plugins about the role change...  and a user may end up with two roles which would cause an issue when mapping roles to user groups...

Avatar
Samantha
Member
sp_UserOfflineSmall Offline
Jan 12, 2015 - 5:47 pm

Hi -

I am reopening this thread because the fix I thought I had is not actually working.

I was able to get the MemberPress guys to modify the plug-in they provided so that it would call the set_user_role action, per your previous replies.  However, when I added a course to an existing site and forum user, the user's Forum roles were not updated to reflect the new permissions.  I can see in the Event Logger that the set_user_role was triggered (see attached screenshot), but the user's permissions were not updated (see second screenshot).

I am opening a new course for registration, and would really like to understand what is happening here, so I don't have to manually add permissions for every student.

Thanks!
SamanthaScreen-Shot-2015-01-12-at-2.40.07-PM.pngImage EnlargerScreen-Shot-2015-01-12-at-2.40.28-PM.pngImage Enlarger

Avatar
Samantha
Member
sp_UserOfflineSmall Offline
Jan 12, 2015 - 5:49 pm

I don't know if this is relevant or not, since I can see the set_user_role action in the SP event logger, but this is how the set roles action is being called:

do_action('set_user_role', $user->ID, 'participant_ur_jan2015', $old_roles);

//Doesn't actually change user's role -- just fires this hook for Simple Press' sake

 

Thx,

Samantha

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Jan 12, 2015 - 5:52 pm

Before looking any deeper I have to ask the obvious first question just to be sure. Did you create the new user group and map the new user group to this WordPress role before updating this particular user?

andy-signature.png
YELLOW
SWORDFISH
Avatar
Samantha
Member
sp_UserOfflineSmall Offline
Jan 12, 2015 - 6:07 pm

Hi again!

It's working now!  Sorry for the false alarm...  turns out I did not map the newest user role to a group, so once I fixed that, a new test transaction correctly updated the forum permissions.

Thanks!
Samantha

Avatar
Samantha
Member
sp_UserOfflineSmall Offline
Jan 12, 2015 - 6:08 pm

LOL, I just saw your reply.  Yep, you were spot on.  Thanks for the reply, I appreciate it.

Everything appears to be working now.

:)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Jan 12, 2015 - 6:12 pm

Easily done - there is lots to remember. Glad it was that easy!

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online: Julitsg
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17361
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625