Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Wpf_Tokens::handle_non_dynamic_labels( array $field, string $entry_choice )

Handles label token for non-dynamic fields.


Parameters Parameters

$field

(Required) The field configuration.

$entry_choice

(Required) The entry choice.


Top ↑

Return Return

(string) The label.


Source Source

File: src/integrations/wpforms/tokens/wpf-tokens.php

	private function handle_non_dynamic_labels( $field, $entry_choice ) {
		$choices                 = $field['choices'];
		$type                    = $field['type'];
		$entry_choice_arr        = array_map( 'trim', explode( ',', $entry_choice ) );
		$is_payment_field        = strpos( $type, 'payment' ) === 0;
		$show_price_after_labels = isset( $field['show_price_after_labels'] ) ? (bool) $field['show_price_after_labels'] : false;
		$labels                  = array();
		foreach ( $entry_choice_arr as $entry_choice_arr_item ) {
			foreach ( $choices as $key => $choice ) {
				// Payment Fields.
				if ( $is_payment_field ) {
					if ( (int) $key === (int) $entry_choice_arr_item ) {
						$labels[] = $show_price_after_labels ? $choice['label'] . ' - ' . wpforms_format_amount( trim( $choice['value'] ), true ) : $choice['label'];
					}
				} else {
					// Non-Payment Fields.
					if ( $choice['label'] === $entry_choice_arr_item || $choice['value'] === $entry_choice_arr_item ) {
						$labels[] = $choice['label'];
					}
				}
			}
		}
		return implode( ', ', $labels );
	}