• Would it be possible to use an “add_action” code snippet to have users automatically assigned a secondary role upon a certain action?

    I’ve got an add_action that assigns a role upon adding or changing a membership level, and I’d like to be able change that to assign a secondary role upon adding or changing a membership level.

    Here’s the code I’m using successfully to assign a role:

    <?php add_action( 'ms_model_relationship_create_ms_relationship_before', 'ms_controller_member_assign_memberships_done_cb', 99, 4 );
    function ms_controller_member_assign_memberships_done_cb( $membership_id, $user_id, $gateway_id, $move_from_id ) {
    	$user = new WP_User( $user_id );
    	switch( $membership_id ){
    		case 280:
    			$user->set_role( 'client' );
    			break;
    		case 330:
    			$user->set_role( 'ward_client' );
    			break;
    	}
    }

    Could this be altered to do secondary roles instead (or in addition to)?

    Thanks,
    Scott

    https://www.ads-software.com/plugins/wpfront-user-role-editor/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Scott,

    Like you, I am looking for a way to have users automatically assigned a secondary role upon a certain action.

    Nobody replied to your post here.

    Did you meanwhile find a way to realize it?

    Thankful for any inspiration you might have.

    Thanks a lot,
    Max

    Thread Starter Scott McCulloch

    (@sinemac)

    Hi Max,

    No, I didn’t find a way to auto-assign secondary roles — everything I tried resulted in either nothing, or changing the primary role rather than adding a secondary. ??

    I ended up going a different route to achieve what I needed – making more use of a membership plugin, and using code like above to auto-enroll in a course at the same time as assigning the role.

    Sorry I can’t offer any inspiration for getting the secondary roles auto-assigned.

    Scott

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘an add_action to auto-assign secondary role?’ is closed to new replies.