• Resolved ostetaan

    (@ostetaan)


    Hi!

    I am trying to add subscriber users automatically to the same group of the contributor after subscriber users have been created, but do_shortcode in hook seems not working. Please help!!!

    This is my code

    
    add_action( 'user_register', array($this, 'create_user'), 10, 1 );
    
    function create_user($user_id) {
    
    global $wpdb;
    
    	//Get current user group id from database
    	
    	$getValue = $wpdb->get_results("SELECT user_id , wp_groups_group.group_id, wp_groups_user_group.group_id, name  FROM  wp_groups_group, wp_groups_user_group WHERE wp_groups_group.group_id =  wp_groups_user_group.group_id");
    
    	$currentUser = wp_get_current_user();
    	$currentUserID = $currentUser->ID;
    	$groupID = "";
    	$groupName = "";
    	foreach ($getValue as $key => $value) {
    		if ($currentUserID == $value->user_id  && $value->group_id > 1) {
    			$groupID = $value->group_id;
    			$groupName = $value->name;
    
    		}else{
    		}
    	}
    
    	do_shortcode('[groups_join group="'.$groupName.'"]');
    
    }
    
Viewing 1 replies (of 1 total)
  • Hi ostetaan,

    Although I haven’t checked your code, you can add a user to a group with the method Groups_User_Group::create( $map ) as described here.

    The link goes to Groups API which you are welcome to use for your own custom implementations.

    Kind regards,
    George

Viewing 1 replies (of 1 total)

The topic ‘do_shortcode groups_join not working in hook’ is closed to new replies.