change role on status change
-
Since UM’s various restrictions and so forth are based on roles rather than status, I need to change a user’s role upon status change (e.g., immediately after being approved for membership).
I tried this:add_action( 'um_after_user_is_approved', 'set_role_upon_approval', 10, 1 ); function set_role_upon_approval( $user_id ) { um_fetch_user ( $user_id ); UM()->roles()->set_role( um_user, 'um_newrole' ); // also tried UM()->roles()->set_role( um_user, 'New Role' ); just in case it wasn't keying on the actual slug }
It does nothing. No errors and no effect. Role remains unchanged.
I also tried this in the add_action function, from your docs:global $ultimatemember; um_fetch_user( $user_id ); $ultimatemember->user->set_role( 'um_newrole' );
That results in a site critical error.
I also tried it direct:$user_id->set_role('um_newrole'); // also tried $user_id->set_role('newrole'); after creating a non-UM role slug
Nothing works! I didn’t find a different hook that looked more appropriate, but is there one? What am I doing wrong?
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘change role on status change’ is closed to new replies.