GTT_UNREGISTERUSER::gtt_unregister_user( $user_id,  $action_data,  $recipe_id,  $args )

Validation function when the action is hit


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)


Source Source

File: src/integrations/gototraining/actions/gtt-unregisteruser.php

	public function gtt_unregister_user( $user_id, $action_data, $recipe_id, $args ) {

		try {

			$training_key = Automator()->parse->text( $action_data['meta'][ $this->action_meta ], $recipe_id, $user_id, $args );

			if ( empty( $user_id ) ) {
				throw new \Exception( __( 'User not found.', 'uncanny-automator' ) );
			}

			if ( empty( $training_key ) ) {
				throw new \Exception( __( 'Training not found.', 'uncanny-automator' ) );
			}

			$training_key = str_replace( '-objectkey', '', $training_key );

			$user_registrant_key = get_user_meta( $user_id, '_uncannyowl_gtt_training_' . $training_key . '_registrantKey', true );

			if ( empty( $user_registrant_key ) ) {
				throw new \Exception( __( 'User was not registered for training session.', 'uncanny-automator' ) );
			}

			$result = Automator()->helpers->recipe->gototraining->gtt_unregister_user( $user_id, $training_key, $action_data );

			Automator()->complete_action( $user_id, $action_data, $recipe_id );

		} catch ( \Exception $e ) {

			$action_data['do-nothing'] = true;
	
			$action_data['complete_with_errors'] = true;
	
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $e->getMessage() );
		}
	}