Elem_Tokens::elem_possible_tokens( array $tokens = array(), array $args = array() )

Prepare tokens.


Parameters Parameters

$tokens

(array) (Optional) .

Default value: array()

$args

(array) (Optional) .

Default value: array()


Top ↑

Return Return

(array)


Source Source

File: src/integrations/elementor/tokens/elem-tokens.php

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

		if ( ! empty( $form_id ) ) {
			global $wpdb;
			$query      = "SELECT ms.meta_value  FROM {$wpdb->postmeta} ms JOIN {$wpdb->posts} p on p.ID = ms.post_id WHERE ms.meta_key LIKE '_elementor_data' AND ms.meta_value LIKE '%form_fields%' AND p.post_status = 'publish' ";
			$post_metas = $wpdb->get_results( $query );
			$fields     = array();
			if ( ! empty( $post_metas ) ) {
				foreach ( $post_metas as $post_meta ) {

					$inner_forms = Automator()->helpers->recipe->elementor->get_all_inner_forms( json_decode( $post_meta->meta_value ) );
					if ( ! empty( $inner_forms ) ) {
						foreach ( $inner_forms as $form ) {
							if ( $form->id == $form_id ) {
								if ( isset( $form->settings ) && ! empty( isset( $form->settings->form_fields ) ) ) {
									foreach ( $form->settings->form_fields as $field ) {
										$input_id = $field->custom_id;
										$token_id = "$form_id|$input_id";
										$fields[] = [
											'tokenId'         => $token_id,
											'tokenName'       => isset( $field->field_label ) ? $field->field_label : 'Unknown',
											'tokenType'       => isset( $field->field_type ) ? $field->field_type : 'text',
											'tokenIdentifier' => $trigger_meta,
										];
									}
								}
								$tokens = array_merge( $tokens, $fields );
							}
						}
					}
				}
			}
		}


		return $tokens;
	}