WP_USERROLE::user_role( $user_id,  $action_data,  $recipe_id )

Validation function when the trigger action is hit


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)


Source Source

File: src/integrations/wp/actions/wp-userrole.php

	public function user_role( $user_id, $action_data, $recipe_id ) {



		$role = $action_data['meta'][ $this->action_meta ];

		$user_obj   = new WP_User( (int) $user_id );
		$user_roles = $user_obj->roles;
		if ( ! in_array( 'administrator', $user_roles ) ) {
			$user_obj->set_role( $role );
			Automator()->complete_action( $user_id, $action_data, $recipe_id );
		} else {
			$error_message = esc_attr__( 'For security, the change role action cannot be applied to administrators.', 'uncanny-automator' );
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_message );
		}
	}