Fi_Tokens::fi_token( string $value, array $pieces, string $recipe_id,  $trigger_data,  $user_id,  $replace_args )

Parse the token.


Parameters Parameters

$value

(string) (Required) .

$pieces

(array) (Required) .

$recipe_id

(string) (Required) .


Top ↑

Return Return

(null|string)


Source Source

File: src/integrations/formidable/tokens/fi-tokens.php

	public function fi_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
		if ( $pieces ) {

			if ( in_array( 'FIFORM', $pieces, true ) ) {

				if ( 'FIFORM' === $pieces[2] ) {
					if ( isset( $trigger_data[0]['meta']['FIFORM_readable'] ) ) {
						$value = $trigger_data[0]['meta']['FIFORM_readable'];
					}
				} else {
					$token_info = explode( '|', $pieces[2] );

					$form_id  = $token_info[0];
					$meta_key = $token_info[1];
					//$user_id               = get_current_user_id();
					$s_query               = array();
					$s_query['it.form_id'] = $form_id;
					$s_query['it.user_id'] = $user_id;
					$order                 = ' ORDER BY id DESC ';
					$enrties               = FrmEntry::getAll( $s_query, $order, 1, true, false );
					$fields                = FrmField::get_all_for_form( $form_id );

					// Collect all file field types
					$file_fields = array();
					foreach ( $fields as $field ) {
						if ( isset( $field->type ) && 'file' === $field->type ) {
							$file_fields[] = $field->id;
						}
					}

					if ( ! empty( $enrties ) ) {
						foreach ( $enrties as $enrty ) {
							if ( isset( $enrty->metas )
							     && isset( $enrty->metas[ $meta_key ] )
							) {

								if ( is_array( $enrty->metas[ $meta_key ] ) ) {
									$value = implode( ', ', $enrty->metas[ $meta_key ] );
								} elseif ( in_array( $meta_key, $file_fields ) ) {

									$media_id = $enrty->metas[ $meta_key ];

									$attachment = get_post( $media_id );
									if ( ! $attachment ) {
										$value = $enrty->metas[ $meta_key ];
									}

									$image = $orig_image = wp_get_attachment_image( $media_id, 'thumbnail', true );

									//if this is a mime type icon
									if ( $image && ! preg_match( '/wp-content\/uploads/', $image ) ) {
										$label = basename( $attachment->guid );
									}
									if ( $image ) {
										$value = '<a href="' . esc_url( wp_get_attachment_url( $media_id ) ) . '">' . $label . '</a>';
									}
								} else {
									$value = $enrty->metas[ $meta_key ];
								}
								break;
							}
						}
					}
				}
			}
		}

		return $value;
	}