Divi_Tokens::divi_possible_tokens( array $tokens = array(), array $args = array() )

Prepare tokens.


Parameters Parameters

$tokens

(Optional) .

Default value: array()

$args

(Optional) .

Default value: array()


Top ↑

Return Return

(array)


Source Source

File: src/integrations/divi/tokens/divi-tokens.php

	public function divi_possible_tokens( $tokens = array(), $args = array() ) {
		if ( ! automator_do_identify_tokens() ) {
			return $tokens;
		}
		$form_id      = $args['value'];
		$trigger_meta = $args['meta'];
		$form_fields  = array(
			array(
				'field_id'    => 'name',
				'field_title' => __( 'Name (if available)', 'uncanny-automator' ),
				'field_type'  => 'text',
			),
			array(
				'field_id'    => 'email',
				'field_title' => __( 'Email address (if available)', 'uncanny-automator' ),
				'field_type'  => 'email',
			),
			array(
				'field_id'    => 'message',
				'field_title' => __( 'Message (if available)', 'uncanny-automator' ),
				'field_type'  => 'text',
			),
		);

		if ( intval( '-1' ) !== intval( $form_id ) ) {
			$form_fields = Divi_Helpers::get_form_by_id( $form_id );
			if ( empty( $form_fields ) ) {
				return $tokens;
			}
		}
		$fields = array();
		foreach ( $form_fields as $form_field ) {
			$input_id   = $form_field['field_id'];
			$token_type = $form_field['field_type'];
			$token_id   = "$form_id|$input_id";
			$fields[]   = array(
				'tokenId'         => $token_id,
				'tokenName'       => $form_field['field_title'],
				'tokenType'       => $token_type,
				'tokenIdentifier' => $trigger_meta,
			);
		}

		return array_merge( $tokens, $fields );
	}