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_field_label( array $token_info = array(), array $entry = array(), string $to_match = '' )
Retrieves the field choice label.
Parameters Parameters
- $token_info
-
(Optional)
Default value: array()
- $entry
-
(Optional)
Default value: array()
- $to_match
-
(Optional)
Default value: ''
Return Return
(string)
Source Source
File: src/integrations/wpforms/tokens/wpf-tokens.php
private function get_field_label( $token_info = array(), $entry = array(), $to_match = '' ) { // Get the enry. $entry_choice = $entry[ str_replace( '|label', '', $to_match ) ]; // Bail if no selection. if ( empty( $entry_choice ) ) { return ''; } // Get the form. $form = $this->get_wpforms_form( absint( $token_info[0] ) ); // Get the field type. $field_type = $form['fields'][ $token_info[1] ]['type']; // Check if there are choices. if ( ! empty( $form['fields'][ $token_info[1] ]['choices'] ) ) { $choices = $form['fields'][ $token_info[1] ]['choices']; foreach ( $choices as $choice ) { // Handle checkbox selections. if ( in_array( $field_type, array( 'checkbox' ), true ) ) { $entry_choice_arr = explode( ', ', $entry_choice ); $choices_column = array_column( $choices, 'label' ); $selections = array(); foreach ( $choices_column as $index => $choice_column ) { if ( in_array( $choice_column, $entry_choice_arr, true ) ) { $selections[] = $choices_column[ $index ]; } } if ( ! empty( $selections ) ) { return implode( ', ', $selections ); } } if ( $entry_choice === $choice['label'] || $entry_choice === $choice['value'] ) { return $choice['label']; } } } return ''; }
Expand full source code Collapse full source code View on Github