Automator_Registration::action( null $uap_action = null, null|string $integration_code = null, null $integration = null )

Register a new uap action and creates a type if defined and the type does not exist


Parameters Parameters

$uap_action

(null) (Optional)

Default value: null

$integration_code

(null|string) (Optional)

Default value: null

$integration

(null) (Optional)

Default value: null


Top ↑

Return Return

(null) |true


Source Source

File: src/core/lib/utilities/class-automator-registration.php

	public function action( $uap_action = null, $integration_code = null, $integration = null ) {

		// Sanity check that there was a trigger passed
		if ( null === $uap_action || ! is_array( $uap_action ) ) {
			throw new Automator_Exception( 'You are trying to register an action without passing a action object.', 1003 );
		}

		/**
		 * Use this hook the stop specific actions from being registered by returning true
		 */
		$skip_uap_action_registration = false;
		$skip_uap_action_registration = apply_filters_deprecated(
			'skip_uap_action_registration',
			array( $skip_uap_action_registration, $uap_action, $integration_code, $integration ),
			'3.0',
			'automator_skip_action_registration'
		);
		$skip_uap_action_registration = apply_filters( 'automator_skip_action_registration', $skip_uap_action_registration, $uap_action, $integration_code, $integration );

		if ( true === $skip_uap_action_registration ) {
			return null;
		}

		/**
		 * Use this hook to modify the uap action before it it error checked and registered
		 */
		$uap_action = apply_filters_deprecated(
			'uap_register_action',
			array( $uap_action, $integration_code, $integration ),
			'3.0',
			'automator_register_action'
		);
		$uap_action = apply_filters( 'automator_register_action', $uap_action, $integration_code, $integration );

		/**
		 * Use this hook to modify the integration_code before it is error checked and registered
		 */
		$integration_code = apply_filters_deprecated(
			'uap_register_action_integration_code',
			array( $integration_code, $uap_action, $integration ),
			'3.0',
			'automator_register_action_integration_code'
		);
		$integration_code = apply_filters( 'automator_register_action_integration_code', $integration_code, $uap_action, $integration );

		/**
		 * Use this hook to modify the integration_code before it is error checked and registered
		 */
		$integration = apply_filters_deprecated(
			'uap_register_action_integration',
			array( $integration, $uap_action, $integration_code ),
			'3.0',
			'automator_register_action_integration'
		);
		$integration = apply_filters( 'automator_register_action_integration', $integration, $uap_action, $integration_code );

		// Integration was passed in, lets try to register it
		if ( null !== $integration_code ) {
			if ( ! is_string( $integration_code ) ) {
				throw new Automator_Exception( 'You are trying to register an action without passing an proper integration code.', 1003 );
			}
			if ( null === $integration && is_array( $integration ) ) {
				throw new Automator_Exception( 'You are trying to register an action without passing an proper integration object.', 1003 );
			}                    // Sanity check that the integration code does not exist already
			if ( ! key_exists( $integration_code, Automator()->get_integrations() ) ) {
				Automator()->register->integration( $integration_code, $integration );
			}
		}

		// Sanity check that trigger_integration isset
		if ( ! isset( $uap_action['integration'] ) ) {
			throw new Automator_Exception( 'You are trying to register an action without setting its action_integration.', 1003 );
		}

		// Sanity check that the trigger has a integration that is defined
		if ( ! key_exists( $uap_action['integration'], Automator()->get_integrations() ) ) {
			throw new Automator_Exception( 'You are trying to register an action to an integration that does not exist.', 1003 );
		}

		// Sanity check that trigger_code isset
		if ( ! isset( $uap_action['code'] ) ) {
			throw new Automator_Exception( 'You are trying to register an action without setting its action_code.', 1003 );
		}

		// Sanity check that execution_function isset
		if ( ! isset( $uap_action['execution_function'] ) ) {
			throw new Automator_Exception( 'You are trying to register an action without setting its execution_function.', 1003 );
		}

		// Loop through existing to force only unique values for action_code and action_name
		foreach ( Automator()->get_actions() as $existing_action ) {
			// Sanity check that action_code is unique
			if ( $existing_action['code'] === $uap_action['code'] ) {
				// Already exists. Bail.
				return null;
			}
		}

		Automator()->set_actions( Automator()->utilities->keep_order_of_options( $uap_action ) );

		return true;
	}