Cf7_Tokens::cf7_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/contact-form7/tokens/cf7-tokens.php

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

		if ( empty( $form_id ) ) {
			return $tokens;
		}
		$contact_form7 = WPCF7_ContactForm::get_instance( $form_id );
		if ( ! $contact_form7 instanceof WPCF7_ContactForm ) {
			return $tokens;
		}

		$cf7_tags = $contact_form7->scan_form_tags();
		if ( $cf7_tags ) {
			$fields = array();
			foreach ( $cf7_tags as $tag ) {
				if ( empty( $tag->name ) ) {
					continue;
				}
				$input_id = $tag->name;
				//convert your-name to Your Name, your-email to Your Email
				$input_title = ucwords( str_replace( [ '-', '_' ], ' ', $tag->name ) );
				$token_id    = "$form_id|$input_id";
				$token_type  = 'text';
				if ( strpos( $tag->type, 'email' ) || 'email*' === $tag->type || 'email' === $tag->type ) {
					$token_type = 'email';
				}

				$fields[] = [
					'tokenId'         => $token_id,
					'tokenName'       => $input_title,
					'tokenType'       => $token_type,
					'tokenIdentifier' => $trigger_meta,
				];
			}

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

		return $tokens;
	}