Description

This filter is applied to entry field values in various places. It’s used to make the field value more visual when viewing the entry value.

Parameters

$value
(string) The value.
$field
(array) The field.
$form_data
(array) Processed form settings/data, prepared to be used later.
$context
(string) Context usage.

Source

pro/includes/admin/entries/class-entries-list-table.php
pro/includes/admin/entries/class-entries-single.php
src/Pro/Admin/Entries/Edit.php
src/Pro/Admin/Entries/PrintPreview.php
includes/emails/class-emails.php

More Information

The filter is used to display a more visual graphic in the Entries list rather than just the pure HTML value that is stored in the database.

Examples

The Rating field value is stored as an integer. If a reader provides a 4 out of 5 star rating, the value saved is in the entry is 4.

When viewing the entry information (entries table, single entry details) and when notification emails are generated, this filter converts the value and returns a visual representation,

/**
 * Filter used to convert a given entry value to a more robust visual format.
 *
 * In this example, if a hex color code is given in a text value, it's coverted
 * to a link to view more details about the color.
 *
 * @link  https://wpforms.com/developers/wpforms_html_field_value/
 *
 * @param  string  $value      The value.
 * @param  array   $field      The field.
 * @param  array   $form_data  Processed form settings/data, prepared to be used later.
 * @param  string  $context    Context usage.
 *
 * @return string 
 */
function wpf_dev_html_field_value( $value, $field, $form_data, $context = '' ) {
	
	// Limit this customization the text field values.
	if ( ! empty( $field['value'] ) && 'text' === $field['type'] ) {

		// Check if field value appears to be hex color format, eg #FFFFFF.
		$hex_code = sanitize_hex_color( $field['value'] );
		
		if ( ! empty( $hex_code ) ) {

			// Remove pound sign.
			$hex_code = str_replace( '#', '', $field['value'] );

			return '<a href="https://www.color-hex.com/color/' . $hex_code . '" target="_blank">#' . $hex_code . '</a>';
		}
	}

	return $value;
}
add_filter( 'wpforms_html_field_value', 'wpf_dev_html_field_value', 10, 4 );

Using the wpforms_html_field_value filter

Snippet Reference: How to Display Form Entries