$field['id'], 'type' => $field['type'], 'label' => $field['label'], 'value' => self::display( $field, $clean[ $field['id'] ] ), ); } if ( $items ) { $entries[] = array( 'title' => $step['title'], 'items' => $items, ); } } return $entries; } /** * Returns an answer as text. * * @param array $field Field. * @param mixed $value Clean answer. * @return string */ public static function display( $field, $value ) { switch ( $field['type'] ) { case 'choice': case 'select': $labels = wp_list_pluck( $field['options'], 'label', 'value' ); $shown = array(); foreach ( (array) $value as $one ) { $shown[] = isset( $labels[ $one ] ) ? $labels[ $one ] : $one; } return implode( ', ', $shown ); case 'yesno': return 'yes' === $value ? __( 'Yes', 'primiko' ) : __( 'No', 'primiko' ); case 'address': return trim( $value['street'] . ', ' . trim( $value['postcode'] . ' ' . $value['city'] ), ', ' ); case 'photos': /* translators: %d: number of photos. */ return sprintf( _n( '%d photo', '%d photos', (int) $value, 'primiko' ), (int) $value ); case 'number': $decimals = false === strpos( $value, '.' ) ? 0 : strlen( substr( strrchr( $value, '.' ), 1 ) ); $number = number_format_i18n( (float) $value, $decimals ); return empty( $field['unit'] ) ? $number : $number . ' ' . $field['unit']; case 'date': $time = strtotime( $value . ' 12:00:00' ); return $time ? date_i18n( get_option( 'date_format' ), $time ) : $value; default: return (string) $value; } } /** * Returns the entries as HTML tables, for emails and the request screen. * * @param array[] $entries Entries. * @param bool $links Whether the phone, email and address are links: * useful to the business, not in the copy the * visitor gets of their own details. * @return string Escaped HTML. */ public static function html( $entries, $links = true ) { $html = ''; foreach ( $entries as $step ) { $html .= '
| ' . esc_html( $item['label'] ) . ' | '; $html .= '' . ( $links ? self::value_html( $item ) : nl2br( esc_html( (string) $item['value'] ) ) ) . ' | '; $html .= '
|---|