• Resolved Marcelo Herrera

    (@rafadizeo)


    I am trying to assign a role after registration based on email. For example, employees at my company have email accounts of type [email protected]. What I am looking for is that according to the name a specific role is assigned.

    This is my code:

    if ( ! function_exists( 'actualizar_rol' ) ) {
    	function actualizar_rol(int $user_id) {
    		list($usuario, $dominio) = explode('@', $args['user_email'] );
    		if ($usuario == 'marcelo.herrera') {
    			wp_update_user(
    				[
    					'ID'	=> $user_id,
    					'role'  => 'rrhh',
    				]
    			);
    		}
    	}
    	add_action( 'rtcamp.google_user_created', 'actualizar_rol', 10, 2 );
    }

    What am I doing wrong?`

Viewing 1 replies (of 1 total)
  • Thread Starter Marcelo Herrera

    (@rafadizeo)

    Solved, this is the code

    if ( ! function_exists( 'actualizar_datos' ) ) {
    	function actualizar_datos( int $user_id, \stdClass $user ): void {
    		if( !is_null( $user->email ?? '' ) ){
    			list($usuario, $dominio) = explode('@', $user->email );
    			if ($usuario == 'marcelo.herrera') {
    				wp_update_user(
    					[
    						'ID'         => $user_id,
    						'first_name' => $user->given_name ?? '',
    						'last_name'  => $user->family_name ?? '',
    						'role'		 => 'rrhh',
    					]
    				);
    			}
    		}
    	}
    	add_action( 'rtcamp.google_user_created', 'actualizar_datos', 10, 2 );
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Assign role based on email’ is closed to new replies.