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::get_non_dynamic_choice_index( mixed $value, array $field )

Retrieves the checkbox value ( index of choice ).


Parameters Parameters

$value

(Required) The value.

$field

(Required) The current field config.


Top ↑

Return Return

(string) The selected value.


Source Source

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

	private function get_non_dynamic_choice_index( $value, $field ) {
		// Skip if payment field.
		if ( strpos( $field['type'], 'payment' ) === 0 ) {
			return apply_filters( 'automator_wpforms_non_dynamic_choice_value', $value, $field );
		}
		$choices     = $field['choices'];
		$value_array = array_map( 'trim', explode( ', ', $value ) );
		$selected    = array();
		foreach ( $choices as $key => $choice ) {
			// Strip whitespace for single space.
			$label = preg_replace( '/\s+/', ' ', $choice['label'] );
			// Check if label is in value array.
			if ( in_array( $label, $value_array, true ) ) {
				$selected[] = $key;
			}
		}
		$value = ! empty( $selected ) ? implode( ', ', $selected ) : '';
		return apply_filters( 'automator_wpforms_non_dynamic_choice_value', $value, $field );
	}