Give_Tokens::givewp_possible_tokens( array $tokens = array(), array $args = array() )


Parameters Parameters

$tokens

(array) (Optional)

Default value: array()

$args

(array) (Optional)

Default value: array()


Top ↑

Return Return

(array)


Source Source

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

	public function givewp_possible_tokens( $tokens = array(), $args = array() ) {
		$form_id = absint( $args['value'] );

		if ( empty( $form_id ) ) {
			return $tokens;
		}


		$form_fields = Automator()->helpers->recipe->give->get_form_fields_and_ffm( $form_id );

		if ( empty( $form_fields ) ) {
			return $tokens;
		}

		$fields = array();
		foreach ( $form_fields as $key => $_field ) {

			$input_id   = $key;
			$token_id   = "$form_id|$input_id";
			$token_type = 'text';
			if ( strpos( $_field['type'], 'email' ) || 'email*' === $_field['type'] || 'email' === $_field['type'] ) {
				$token_type = 'email';
			}

			$existing_tokens = array_column( $tokens, 'tokenId' );
			if ( ! in_array( $token_id, $existing_tokens, false ) ) {
				$fields[] = [
					'tokenId'         => $token_id,
					'tokenName'       => $_field['label'],
					'tokenType'       => $token_type,
					'tokenIdentifier' => 'DONATIONFORM',
				];
			}
		}

		$tokens = array_merge( $tokens, $fields );

		return $tokens;
	}