Automator_Send_Webhook_Fields::options_group( $action_meta, bool $data_format_required = true, null $default = null, array $allowed = array() )

Return options Group for all outgoing webhooks


Parameters Parameters

$action_meta

(Required)

$data_format_required

(Optional)

Default value: true

$default

(Optional)

Default value: null

$allowed

(Optional)

Default value: array()


Top ↑

Return Return

(array)


Source Source

File: src/core/lib/webhooks/class-automator-send-webhook-fields.php

	public function options_group( $action_meta, $data_format_required = true, $default = null, $allowed = array() ) {
		if ( null === $default ) {
			$default = 'x-www-form-urlencoded';
		}
		$fields = array();
		// Webhook URL
		$fields[] = array(
			'input_type'      => 'url',
			'option_code'     => 'WEBHOOK_URL',
			'label'           => esc_attr__( 'URL', 'uncanny-automator' ),
			'supports_tokens' => true,
			'required'        => true,
			'description'     => esc_attr__( 'Enter the URL of the destination webhook.', 'uncanny-automator' ),
		);
		// Action event
		$fields[] = array(
			'input_type'    => 'select',
			'option_code'   => 'ACTION_EVENT',
			/* translators: HTTP request method */
			'label'         => esc_attr__( 'Request method', 'uncanny-automator' ),
			'description'   => esc_attr__( 'Select the HTTP request method supported by the webhook destination. If you are unsure, leave this value unchanged unless you are experiencing issues.', 'uncanny-automator' ),
			'required'      => true,
			'default_value' => 'POST',
			'options'       => array(
				'GET'    => 'GET',
				'PUT'    => 'PUT',
				'POST'   => 'POST',
				'DELETE' => 'DELETE',
				'HEAD'   => 'HEAD',
			),
		);
		// Data format field
		if ( $data_format_required ) {
			$options  = $this->data_format_types;
			$new_list = array();
			if ( ! empty( $allowed ) ) {
				foreach ( $allowed as $allow ) {
					$value              = isset( $this->data_format_types[ $allow ] ) ? $this->data_format_types[ $allow ] : strtoupper( $allow );
					$new_list[ $allow ] = $value;
				}
				$options = $new_list;
			}
			$data_formats = array(
				'input_type'            => 'select',
				'option_code'           => 'DATA_FORMAT',
				/* translators: HTTP request method */
				'label'                 => esc_attr__( 'Data format', 'uncanny-automator' ),
				'description'           => esc_attr__( 'Select the data format supported by the webhook destination. If you are unsure, leave this value unchanged unless you are experiencing issues.', 'uncanny-automator' ),
				'required'              => false,
				'supports_custom_value' => false,
				'default_value'         => $default,
				'options'               => $options,
			);
			$fields[]     = $data_formats;
		}

		// Header
		$fields[] = array(
			'input_type'        => 'repeater',
			'option_code'       => 'WEBHOOK_HEADERS',
			'label'             => esc_attr__( 'Headers', 'uncanny-automator' ),
			'description'       => esc_attr__( 'Add any HTTP request headers required by the webhook destination.', 'uncanny-automator' ),
			'required'          => false,
			'default_value'     => array(
				array(
					'NAME'  => 'Accept',
					'VALUE' => 'application/json',
				),
			),
			'fields'            => array(
				array(
					'input_type'      => 'text',
					'option_code'     => 'NAME',
					'label'           => esc_attr__( 'Name', 'uncanny-automator' ),
					'supports_tokens' => true,
					'required'        => true,
				),
				array(
					'input_type'      => 'text',
					'option_code'     => 'VALUE',
					'label'           => esc_attr__( 'Value', 'uncanny-automator' ),
					'supports_tokens' => true,
					'required'        => true,
				),
			),

			/* translators: Non-personal infinitive verb */
			'add_row_button'    => esc_attr__( 'Add header', 'uncanny-automator' ),
			/* translators: Non-personal infinitive verb */
			'remove_row_button' => esc_attr__( 'Remove header', 'uncanny-automator' ),
		);
		// Fields
		$fields[] = array(
			'input_type'        => 'repeater',
			'option_code'       => 'WEBHOOK_FIELDS',
			'label'             => esc_attr__( 'Body', 'uncanny-automator' ),
			'required'          => true,
			'fields'            => array(
				array(
					'input_type'      => 'text',
					'option_code'     => 'KEY',
					'label'           => esc_attr__( 'Key', 'uncanny-automator' ),
					'supports_tokens' => true,
					'required'        => true,
					'placeholder'     => __( 'first_name', 'uncanny-automator' ),
					'description'     => sprintf( '<i>%s</i>', esc_html__( 'Separate keys with / to build nested data.', 'uncanny-automator' ) ),
				),
				array(
					'input_type'      => 'text',
					'option_code'     => 'VALUE',
					'label'           => esc_attr__( 'Value', 'uncanny-automator' ),
					'supports_tokens' => true,
					'required'        => true,
				),
			),

			/* translators: Non-personal infinitive verb */
			'add_row_button'    => esc_attr__( 'Add pair', 'uncanny-automator' ),
			/* translators: Non-personal infinitive verb */
			'remove_row_button' => esc_attr__( 'Remove pair', 'uncanny-automator' ),
		);

		return array( $action_meta => $fields );
	}