• Resolved gonmial

    (@gonmial)


    Would you be so kind to tell me how I can create new Agent (support staff) programmatically from other wordpress module?

    • This topic was modified 1 year, 1 month ago by gonmial.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter gonmial

    (@gonmial)

    If someone interested in this, I solve this problem with this code:

    use FluentSupport\App\Modules\PermissionManager;
    	
    function CreateNewAgentInFluentSupport($email){
    		
    	$data = array();
    	$data['email'] = $email;
    	$user = get_user_by('email', $data['email']);
    	$data['user_id'] = $user->ID;
    	
    	if (empty($data['first_name'])) {
    		$data['first_name'] = $user->first_name;
    	}
    
    	if (empty($data['last_name'])) {
    		$data['last_name'] = $user->last_name;
    	}
    	
    	$permissions = array('fst_manage_own_tickets');
    	
    	try {
    				
    		$agentsApi = FluentSupportApi('agents');
    		$newAgent = $agentsApi->createAgentWithOrWithoutWpUser($data);
    		
    		if (!$newAgent==false) {
    			PermissionManager::attachPermissions($user, $permissions);
    		}
    		else {
    			return 'User not created';
    		}
    				
    	} catch (Throwable $e) {
    		return 'Get error: '.$e->getMessage();
    	}
    		
    }
    Plugin Support Ahsan Chowdhury

    (@ahsannayem)

    Hello @gonmial ,

    Thank you for sharing the code and contribution to the community.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Create agent programmatically’ is closed to new replies.