Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/everest-forms/everest-forms.php
+++ b/everest-forms/everest-forms.php
@@ -3,7 +3,7 @@
* Plugin Name: Everest Forms
* Plugin URI: https://everestforms.net/
* Description: Easily create contact form, payment form, conversational form, calculator, multi-step form, registration form, quiz form, survey form etc.
- * Version: 3.6.2
+ * Version: 3.6.3
* Author: Everest Forms
* Author URI: https://everestforms.net/
* Text Domain: everest-forms
--- a/everest-forms/includes/abstracts/class-evf-form-fields-upload.php
+++ b/everest-forms/includes/abstracts/class-evf-form-fields-upload.php
@@ -21,7 +21,7 @@
*
* @var array
*/
- protected $blacklist = array( 'ade', 'adp', 'app', 'asp', 'bas', 'bat', 'cer', 'cgi', 'chm', 'cmd', 'com', 'cpl', 'crt', 'csh', 'csr', 'dll', 'drv', 'exe', 'fxp', 'flv', 'hlp', 'hta', 'htaccess', 'htm', 'htpasswd', 'inf', 'ins', 'isp', 'jar', 'js', 'jse', 'jsp', 'ksh', 'lnk', 'mdb', 'mde', 'mdt', 'mdw', 'msc', 'msi', 'msp', 'mst', 'ops', 'pcd', 'php', 'pif', 'pl', 'prg', 'ps1', 'ps2', 'py', 'rb', 'reg', 'scr', 'sct', 'sh', 'shb', 'shs', 'sys', 'swf', 'tmp', 'torrent', 'url', 'vb', 'vbe', 'vbs', 'vbscript', 'wsc', 'wsf', 'wsf', 'wsh' );
+ protected $blacklist = array( 'ade', 'adp', 'app', 'asp', 'bas', 'bat', 'cer', 'cgi', 'chm', 'cmd', 'com', 'cpl', 'crt', 'csh', 'csr', 'dll', 'drv', 'exe', 'fxp', 'flv', 'hlp', 'hta', 'htaccess', 'htm', 'html', 'xhtml', 'shtml', 'phtml', 'htpasswd', 'inf', 'ins', 'isp', 'jar', 'js', 'jse', 'jsp', 'ksh', 'lnk', 'mdb', 'mde', 'mdt', 'mdw', 'msc', 'msi', 'msp', 'mst', 'ops', 'pcd', 'php', 'pif', 'pl', 'prg', 'ps1', 'ps2', 'py', 'rb', 'reg', 'scr', 'sct', 'sh', 'shb', 'shs', 'sys', 'swf', 'tmp', 'torrent', 'url', 'vb', 'vbe', 'vbs', 'vbscript', 'wsc', 'wsf', 'wsf', 'wsh' );
/**
* Files that are not allowed to be deleted.
@@ -31,6 +31,13 @@
protected $protected_files = array( 'index.html', 'index.php', '.htaccess', '.htpasswd' );
/**
+ * Real paths of files moved into the form uploads folder during this request.
+ *
+ * @var array
+ */
+ protected $request_files = array();
+
+ /**
* Hook in tabs.
*/
public function init_hooks() {
@@ -532,6 +539,16 @@
return array();
}
+ // The field must exist in the form and be an upload field, otherwise field-specific restrictions would be bypassed.
+ if (
+ empty( $form_data['form_fields'][ $field_id ] ) ||
+ ! is_array( $form_data['form_fields'][ $field_id ] ) ||
+ empty( $form_data['form_fields'][ $field_id ]['type'] ) ||
+ ! in_array( $form_data['form_fields'][ $field_id ]['type'], array( 'file-upload', 'image-upload' ), true )
+ ) {
+ return array();
+ }
+
return array(
'form_data' => $form_data,
'field_id' => $field_id,
@@ -1376,6 +1393,12 @@
$this->create_dir( dirname( $file['path'] ) );
@rename( $file['tmp_path'], $file['path'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$this->set_file_fs_permissions( $file['path'] );
+
+ $real_path = realpath( $file['path'] );
+
+ if ( false !== $real_path ) {
+ $this->request_files[] = wp_normalize_path( $real_path );
+ }
}
$data[] = $this->generate_file_data( $file );
@@ -1659,31 +1682,12 @@
public function remove_csv_file_after_email_send( $attachment, $entry, $form_data, $context, $connection_id, $entry_id ) {
if ( isset( $form_data['settings']['disabled_entries'] ) && '1' === $form_data['settings']['disabled_entries'] ) {
- if ( ! empty( $entry ) && is_array( $entry ) ) {
- foreach ( $entry as $meta_key => $meta_value ) {
- if ( empty( $meta_value ) ) {
- continue;
- }
-
- if ( preg_match( '/signature_/', $meta_key ) && file_exists( $meta_value ) ) {
- unlink( $meta_value );
- }
-
- if ( isset( $meta_value['type'] ) && ( 'file-upload' === $meta_value['type'] && ! empty( $meta_value['value_raw'] ) || 'image-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) ) {
-
- foreach ( $meta_value['value_raw'] as $file_data ) {
- if ( isset( $file_data['value'] ) ) {
- $file_url = $file_data['value'];
-
- $uploaded_file = ABSPATH . preg_replace( '/.*wp-content/', 'wp-content', wp_parse_url( $file_url, PHP_URL_PATH ) );
- if ( file_exists( $uploaded_file ) ) {
- unlink( $uploaded_file );
- }
- }
- }
- }
- }
+ // File URLs in the entry can come from the request (old_files), so only delete what this request uploaded.
+ foreach ( $this->request_files as $file_path ) {
+ wp_delete_file( $file_path );
}
+
+ $this->request_files = array();
}
if ( ! $entry_id ) {
@@ -1756,7 +1760,7 @@
}
if ( preg_match( '/signature_/', $meta_key ) ) {
- if ( file_exists( $meta_value ) ) {
+ if ( is_string( $meta_value ) && file_exists( $meta_value ) ) {
$entry_files[] = $meta_value;
}
} elseif ( isset( $meta_value['type'] ) && ( 'file-upload' === $meta_value['type'] && ! empty( $meta_value['value_raw'] ) || 'image-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) ) {
--- a/everest-forms/includes/admin/class-evf-admin-entries-table-list.php
+++ b/everest-forms/includes/admin/class-evf-admin-entries-table-list.php
@@ -434,6 +434,15 @@
$value = (string) $value;
+ // The list shows a short plain-text excerpt; the full WYSIWYG markup is shown on the single entry screen.
+ if ( 'wysiwyg' === $field_type ) {
+ $text = trim( wp_strip_all_tags( $value ) );
+ $value = esc_html( wp_html_excerpt( $text, 75 ) ) . ( mb_strlen( $text ) > 75 ? '…' : '' );
+ $value = apply_filters( 'everest_forms_html_field_value', $value, $entry->meta[ $meta_key ], $entry, 'entry-table', $meta_key );
+
+ return wp_kses_post( $value );
+ }
+
if ( false === strpos( $value, 'http' ) ) {
$lines = explode( "n", $value );
$value = array_slice( $lines, 0, 4 );
@@ -444,12 +453,16 @@
} elseif ( strlen( $value ) > 75 ) {
$value = substr( $value, 0, 75 ) . '…';
}
-
- $value = nl2br( wp_strip_all_tags( trim( $value ) ) );
}
+
+ // Strip tags unconditionally -- the branches below never escape their output themselves,
+ // so a value must never reach them still carrying markup, whether or not it contains 'http'.
+ // nl2br() is left to each branch below so a value isn't line-break-converted twice.
+ $value = wp_strip_all_tags( trim( $value ) );
+
$value = apply_filters( 'everest_forms_html_field_value', $value, $entry->meta[ $meta_key ], $entry, 'entry-table', $meta_key );
- if ( in_array( $field_type, array( 'file-upload', 'image-upload', 'signature', 'wysiwyg', 'color', 'rating', 'country', 'likert', 'checkbox', 'radio', 'repeater-fields', 'payment-checkbox' ), true ) ) {
+ if ( in_array( $field_type, array( 'file-upload', 'image-upload', 'signature', 'color', 'rating', 'country', 'likert', 'checkbox', 'radio', 'repeater-fields', 'payment-checkbox' ), true ) ) {
return nl2br( make_clickable( $value ) );
}elseif( 'address' === $field_type ){
$allowed_tags = array(
--- a/everest-forms/includes/admin/class-evf-admin-forms-table-list.php
+++ b/everest-forms/includes/admin/class-evf-admin-forms-table-list.php
@@ -160,7 +160,7 @@
}
if ( current_user_can( 'everest_forms_view_form_entries', $posts->ID ) ) {
- $name = '<a href="' . esc_url( esc_url( admin_url( 'admin.php?page=evf-entries&form_id=' . $posts->ID ) ) ) . '" title="' . esc_html__( 'View Entries', 'everest-forms' ) . '" class="row-title">' . esc_html( $title ) . '</a>';
+ $name = '<a href="' . esc_url( admin_url( 'admin.php?page=evf-entries&form_id=' . $posts->ID ) ) . '" title="' . esc_html__( 'View Entries', 'everest-forms' ) . '" class="row-title">' . esc_html( $title ) . '</a>';
}
if ( current_user_can( 'everest_forms_edit_form', $posts->ID ) ) {
--- a/everest-forms/includes/admin/class-evf-admin.php
+++ b/everest-forms/includes/admin/class-evf-admin.php
@@ -72,7 +72,7 @@
if ( 'evf-addons-refresh' === $action ) {
if ( empty( $_GET['evf-addons-nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['evf-addons-nonce'] ) ), 'refresh' ) ) {
- wp_die( esc_html_e( 'Could not verify nonce', 'everest-forms' ) );
+ wp_die( esc_html__( 'Could not verify nonce', 'everest-forms' ) );
}
foreach ( array( 'evf_pro_license_plan', 'evf_addons_sections_list', 'evf_extensions_section_list' ) as $transient ) {
delete_transient( $transient );
@@ -119,7 +119,7 @@
$templates = is_array( $templates ) ? $templates : array();
if ( 'evf-template-refresh' === $action ) {
if ( empty( $_GET['evf-template-nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['evf-template-nonce'] ) ), 'refresh' ) ) {
- wp_die( esc_html_e( 'Could not verify nonce', 'everest-forms' ) );
+ wp_die( esc_html__( 'Could not verify nonce', 'everest-forms' ) );
}
foreach ( array( 'evf_pro_license_plan', 'evf_template_sections', 'evf_template_section', 'evf_template_section_list' ) as $transient ) {
--- a/everest-forms/includes/class-everest-forms.php
+++ b/everest-forms/includes/class-everest-forms.php
@@ -23,7 +23,7 @@
*
* @var string
*/
- public $version = '3.6.2';
+ public $version = '3.6.3';
/**
* The single instance of the class.
--- a/everest-forms/includes/class-evf-form-task.php
+++ b/everest-forms/includes/class-evf-form-task.php
@@ -722,14 +722,27 @@
$logger->notice( sprintf( 'Everest Form Process After: %s', evf_print_r( $this->form_fields, true ) ) );
/**
- * Apply smart tags to form fields values.
+ * Apply smart tags to form fields values.
+ *
+ * Resolved strictly from the field's own admin-configured default_value
+ * (the trusted form definition), never from the submitted value, so a
+ * crafted request body cannot inject arbitrary smart tags such as
+ * {post_meta key=...}. See https://github.com/themegrill/everest-forms/pull/1667.
*
* @since 3.2.3
*/
foreach ( $this->form_fields as $key => $value ) {
- if ( 'hidden' === $value['type'] && ! empty( $value['value'] ) && is_string( $value['value'] ) && strpos( $value['value'], '{' ) !== false ) {
- $this->form_fields[ $key ]['value'] = apply_filters( 'everest_forms_process_smart_tags', $value['value'], $this->form_data, $this->form_fields );
+ if ( 'hidden' !== $value['type'] ) {
+ continue;
+ }
+
+ if ( ! isset( $value['value'] ) || ! is_string( $value['value'] ) ) {
+ continue;
}
+
+ $default_value = isset( $this->form_data['form_fields'][ $key ]['default_value'] ) ? $this->form_data['form_fields'][ $key ]['default_value'] : '';
+
+ $this->form_fields[ $key ]['value'] = $this->resolve_hidden_field_default_tags( $value['value'], $default_value, $this->form_data, $this->form_fields );
}
// One last error check - don't proceed if there are any errors.
@@ -1550,7 +1563,7 @@
// Create meta data.
if ( $entry_id ) {
- foreach ( $fields as $field ) {
+ foreach ( $fields as $field_key => $field ) {
$field = apply_filters( 'everest_forms_entry_save_fields', $field, $form_data, $entry_id );
// Add only whitelisted fields to entry meta.
if ( in_array( $field['type'], array( 'html', 'title' ), true ) ) {
@@ -1578,8 +1591,12 @@
}
if ( isset( $field['meta_key'], $field['value'] ) && '' !== $field['value'] ) {
- if ( 'hidden' === $field['type'] && ! empty( $field['value'] ) && is_string( $field['value'] ) && strpos( $field['value'], '{' ) !== false ) {
- $field['value'] = apply_filters( 'everest_forms_process_smart_tags', $field['value'], $form_data, $fields, $entry_id );
+ // Resolved strictly from the field's own admin-configured default_value
+ // (never the submitted value) -- see the matching fix in do_task().
+ if ( 'hidden' === $field['type'] && is_string( $field['value'] ) ) {
+ $field_id = isset( $field['id'] ) ? $field['id'] : $field_key;
+ $default_value = isset( $form_data['form_fields'][ $field_id ]['default_value'] ) ? $form_data['form_fields'][ $field_id ]['default_value'] : '';
+ $field['value'] = $this->resolve_hidden_field_default_tags( $field['value'], $default_value, $form_data, $fields, $entry_id );
}
$entry_metadata = array(
'entry_id' => $entry_id,
@@ -2306,6 +2323,35 @@
}
/**
+ * Resolve the hidden field default's own smart tags that are still unresolved in the submitted value.
+ *
+ * @since 3.6.3
+ *
+ * @param string $value Submitted value.
+ * @param string $default_value Admin-configured default value.
+ * @param array $form_data Form data.
+ * @param array $fields Form fields.
+ * @param int|string $entry_id Entry ID.
+ * @return string
+ */
+ private function resolve_hidden_field_default_tags( $value, $default_value, $form_data, $fields, $entry_id = '' ) {
+ if ( ! is_string( $default_value ) || ! preg_match_all( '/{[^{}]+}/', $default_value, $tags ) ) {
+ return $value;
+ }
+
+ $replacements = array();
+
+ foreach ( array_unique( $tags[0] ) as $tag ) {
+ if ( false !== strpos( $value, $tag ) ) {
+ $replacements[ $tag ] = (string) apply_filters( 'everest_forms_process_smart_tags', $tag, $form_data, $fields, $entry_id );
+ }
+ }
+
+ // strtr() replaces in one pass, so text inserted by a resolved tag is never parsed again.
+ return $replacements ? strtr( $value, $replacements ) : $value;
+ }
+
+ /**
* Securely delete a file with path validation
*
* @param string $path File path to delete
--- a/everest-forms/includes/class-evf-smart-tags.php
+++ b/everest-forms/includes/class-evf-smart-tags.php
@@ -215,139 +215,16 @@
* @return string
*/
public function process( $content, $form_data, $fields = '', $entry_id = '' ) {
- // Field smart tags (settings, etc).
- preg_match_all( '/{field_id="(.+?)"}/', $content, $ids );
-
- // We can only process field smart tags if we have $fields.
- if ( ! empty( $ids[1] ) && ! empty( $fields ) ) {
-
- foreach ( $ids[1] as $key => $field_id ) {
- $mixed_field_id = explode( '_', $field_id );
- $uploads = wp_upload_dir();
-
- if ( count( $mixed_field_id ) > 1 && 'fullname' !== $field_id && 'email' !== $field_id && 'subject' !== $field_id && 'message' !== $field_id ) {
- $value = isset( $fields[ $mixed_field_id[1] ]['value'] ) && ! empty( $fields[ $mixed_field_id[1] ]['value'] ) ? evf_sanitize_textarea_field( $fields[ $mixed_field_id[1] ]['value'] ) : '';
- } else {
- $value = isset( $fields[ $field_id ]['value'] ) && ! empty( $fields[ $field_id ]['value'] ) ? evf_sanitize_textarea_field( $fields[ $field_id ]['value'] ) : '';
- }
-
- $value = apply_filters( 'everest_forms_smart_tags_value', $value, $field_id, $fields, $form_data );
-
- if ( count( $mixed_field_id ) > 1 && ! empty( $fields[ $mixed_field_id[1] ] ) ) {
- // Properly display signature field in smart tag.
- if ( 'signature' === $fields[ $mixed_field_id[1] ]['type'] ) {
- if ( ! is_array( $value ) && false !== strpos( $value, $uploads['basedir'] ) ) {
- $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $value );
- }
-
- if ( ! empty( $value ) ) {
- $styles = array(
- 'width' => '150px',
- 'height' => '80px',
- 'max-width' => '100px',
- 'max-height' => '200px',
- );
-
- $styles = apply_filters( 'everest_forms_export_signature_style', $styles, $fields[ $mixed_field_id[1] ] );
-
- // Convert styles array to inline style string
- $style_string = '';
- foreach ( $styles as $key => $val ) {
- $style_string .= $key . ':' . $val . ';';
- }
-
- $value = sprintf(
- '<img src="%s" style="%s"/>',
- esc_url( $value ),
- esc_attr( $style_string )
- );
- }
- }
-
- // Properly display Radio field in smart tag.
- if ( isset( $value['image'] ) && 'radio' === $fields[ $mixed_field_id[1] ]['type'] ) {
- if ( ! is_array( $value ) && false !== strpos( $value['image'], $uploads['basedir'] ) ) {
- $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $value['image'] );
- }
-
- if ( ! empty( $value ) ) {
- $value = sprintf(
- "n" . '<img src="%s" style="width:150px;height:80px;max-height:200px;max-width:100px;"/>' . "n" . '%s',
- $value['image'],
- $value['label']
- );
- }
- }
-
- // Properly display Checkboxes field in smart tag.
- if ( isset( $value['images'] ) && ( 'checkbox' === $fields[ $mixed_field_id[1] ]['type'] ) ) {
- $checkbox_images = '';
- foreach ( $value['images'] as $image_key => $image_value ) {
- if ( ! is_array( $image_value ) && false !== strpos( $image_value, $uploads['basedir'] ) ) {
- $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $image_value );
- }
-
- if ( ! empty( $value ) ) {
- $checkbox_images .= sprintf(
- "n" . '<img src="%s" style="width:150px;height:80px;max-height:200px;max-width:100px;"/>' . "n" . '%s',
- $image_value,
- $value['label'][ $image_key ]
- );
- }
- }
- $value = $checkbox_images;
- }
-
- // Properly display Files and Image Upload field in smart tag.
- if ( 'image-upload' === $fields[ $mixed_field_id[1] ]['type'] || 'file-upload' === $fields[ $mixed_field_id[1] ]['type'] ) {
- $files = '';
-
- if ( ! empty( $fields[ $mixed_field_id[1] ]['value_raw'] ) ) {
- foreach ( $fields[ $mixed_field_id[1] ]['value_raw'] as $files_key => $files_value ) {
- if ( ! is_array( $files_value['value'] ) && false !== strpos( $files_value['value'], $uploads['basedir'] ) ) {
- $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $files_value['value'] );
- }
-
- if ( ! empty( $value ) ) {
- $files .= sprintf(
- apply_filters(
- 'everest_forms_smart_tags_file_upload',
- '<a href="%s">%s</a>' . "n",
- $files_value
- ),
- esc_url( $files_value['value'] ),
- esc_html( $files_value['name'] )
- );
- }
- }
- $value = $files;
- }
- }
- }
-
- if ( ! is_array( $value ) ) {
- $content = str_replace( '{field_id="' . $field_id . '"}', $value, $content );
- } else {
- if ( isset( $value['type'], $value['label'] ) ) {
- if ( in_array( $value['type'], array( 'radio', 'payment-multiple' ), true ) ) {
- $value = $value['label'];
- } elseif ( in_array( $value['type'], array( 'checkbox', 'payment-checkbox' ), true ) ) {
- $value = implode( ',', $value['label'] );
-
- }
- } elseif ( isset( $value['number_of_rating'], $value['value'] ) ) {
- $value = (string) $value['value'] . '/' . (string) $value['number_of_rating'];
- } elseif ( isset( $value['type'], $value['country_code'] ) && 'country' === $value['type'] ) {
- $value = $value['country_code'];
- } else {
- $value = $value[0];
- }
-
- $content = str_replace( '{field_id="' . $field_id . '"}', $value, $content );
- }
- }
- }
-
+ /**
+ * Other smart tags (post_meta, user_meta, admin_email, etc.) are resolved
+ * first, against the original admin-authored $content, and {field_id="..."}
+ * placeholders are substituted last. If field values were merged in first,
+ * a submitter typing tag syntax (e.g. {post_meta key=...}) into an ordinary
+ * field referenced by a {field_id} smart tag would get it re-resolved by
+ * the pass below, letting an unauthenticated submitter read arbitrary
+ * server-side data back through any notification/confirmation that embeds
+ * that field. See https://github.com/themegrill/everest-forms/pull/1667.
+ */
// Other Smart tags.
preg_match_all( '/{(.+?)}/', $content, $other_tags );
if ( ! empty( $other_tags[1] ) ) {
@@ -580,6 +457,139 @@
}
}
}
+
+ // Field smart tags (settings, etc).
+ preg_match_all( '/{field_id="(.+?)"}/', $content, $ids );
+
+ // We can only process field smart tags if we have $fields.
+ if ( ! empty( $ids[1] ) && ! empty( $fields ) ) {
+
+ foreach ( $ids[1] as $key => $field_id ) {
+ $mixed_field_id = explode( '_', $field_id );
+ $uploads = wp_upload_dir();
+
+ if ( count( $mixed_field_id ) > 1 && 'fullname' !== $field_id && 'email' !== $field_id && 'subject' !== $field_id && 'message' !== $field_id ) {
+ $value = isset( $fields[ $mixed_field_id[1] ]['value'] ) && ! empty( $fields[ $mixed_field_id[1] ]['value'] ) ? evf_sanitize_textarea_field( $fields[ $mixed_field_id[1] ]['value'] ) : '';
+ } else {
+ $value = isset( $fields[ $field_id ]['value'] ) && ! empty( $fields[ $field_id ]['value'] ) ? evf_sanitize_textarea_field( $fields[ $field_id ]['value'] ) : '';
+ }
+
+ $value = apply_filters( 'everest_forms_smart_tags_value', $value, $field_id, $fields, $form_data );
+
+ if ( count( $mixed_field_id ) > 1 && ! empty( $fields[ $mixed_field_id[1] ] ) ) {
+ // Properly display signature field in smart tag.
+ if ( 'signature' === $fields[ $mixed_field_id[1] ]['type'] ) {
+ if ( ! is_array( $value ) && false !== strpos( $value, $uploads['basedir'] ) ) {
+ $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $value );
+ }
+
+ if ( ! empty( $value ) ) {
+ $styles = array(
+ 'width' => '150px',
+ 'height' => '80px',
+ 'max-width' => '100px',
+ 'max-height' => '200px',
+ );
+
+ $styles = apply_filters( 'everest_forms_export_signature_style', $styles, $fields[ $mixed_field_id[1] ] );
+
+ // Convert styles array to inline style string
+ $style_string = '';
+ foreach ( $styles as $key => $val ) {
+ $style_string .= $key . ':' . $val . ';';
+ }
+
+ $value = sprintf(
+ '<img src="%s" style="%s"/>',
+ esc_url( $value ),
+ esc_attr( $style_string )
+ );
+ }
+ }
+
+ // Properly display Radio field in smart tag.
+ if ( isset( $value['image'] ) && 'radio' === $fields[ $mixed_field_id[1] ]['type'] ) {
+ if ( ! is_array( $value ) && false !== strpos( $value['image'], $uploads['basedir'] ) ) {
+ $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $value['image'] );
+ }
+
+ if ( ! empty( $value ) ) {
+ $value = sprintf(
+ "n" . '<img src="%s" style="width:150px;height:80px;max-height:200px;max-width:100px;"/>' . "n" . '%s',
+ $value['image'],
+ $value['label']
+ );
+ }
+ }
+
+ // Properly display Checkboxes field in smart tag.
+ if ( isset( $value['images'] ) && ( 'checkbox' === $fields[ $mixed_field_id[1] ]['type'] ) ) {
+ $checkbox_images = '';
+ foreach ( $value['images'] as $image_key => $image_value ) {
+ if ( ! is_array( $image_value ) && false !== strpos( $image_value, $uploads['basedir'] ) ) {
+ $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $image_value );
+ }
+
+ if ( ! empty( $value ) ) {
+ $checkbox_images .= sprintf(
+ "n" . '<img src="%s" style="width:150px;height:80px;max-height:200px;max-width:100px;"/>' . "n" . '%s',
+ $image_value,
+ $value['label'][ $image_key ]
+ );
+ }
+ }
+ $value = $checkbox_images;
+ }
+
+ // Properly display Files and Image Upload field in smart tag.
+ if ( 'image-upload' === $fields[ $mixed_field_id[1] ]['type'] || 'file-upload' === $fields[ $mixed_field_id[1] ]['type'] ) {
+ $files = '';
+
+ if ( ! empty( $fields[ $mixed_field_id[1] ]['value_raw'] ) ) {
+ foreach ( $fields[ $mixed_field_id[1] ]['value_raw'] as $files_key => $files_value ) {
+ if ( ! is_array( $files_value['value'] ) && false !== strpos( $files_value['value'], $uploads['basedir'] ) ) {
+ $value = trailingslashit( content_url() ) . str_replace( str_replace( 'uploads', '', $uploads['basedir'] ), '', $files_value['value'] );
+ }
+
+ if ( ! empty( $value ) ) {
+ $files .= sprintf(
+ apply_filters(
+ 'everest_forms_smart_tags_file_upload',
+ '<a href="%s">%s</a>' . "n",
+ $files_value
+ ),
+ esc_url( $files_value['value'] ),
+ esc_html( $files_value['name'] )
+ );
+ }
+ }
+ $value = $files;
+ }
+ }
+ }
+
+ if ( ! is_array( $value ) ) {
+ $content = str_replace( '{field_id="' . $field_id . '"}', $value, $content );
+ } else {
+ if ( isset( $value['type'], $value['label'] ) ) {
+ if ( in_array( $value['type'], array( 'radio', 'payment-multiple' ), true ) ) {
+ $value = $value['label'];
+ } elseif ( in_array( $value['type'], array( 'checkbox', 'payment-checkbox' ), true ) ) {
+ $value = implode( ',', $value['label'] );
+
+ }
+ } elseif ( isset( $value['number_of_rating'], $value['value'] ) ) {
+ $value = (string) $value['value'] . '/' . (string) $value['number_of_rating'];
+ } elseif ( isset( $value['type'], $value['country_code'] ) && 'country' === $value['type'] ) {
+ $value = $value['country_code'];
+ } else {
+ $value = $value[0];
+ }
+
+ $content = str_replace( '{field_id="' . $field_id . '"}', $value, $content );
+ }
+ }
+ }
return $content;
}
--- a/everest-forms/includes/evf-core-functions.php
+++ b/everest-forms/includes/evf-core-functions.php
@@ -1295,6 +1295,7 @@
$bname = 'Unknown';
$platform = 'Unknown';
$version = '';
+ $ub = 'other';
// First get the platform.
if (preg_match('/linux/i', $u_agent)) {
@@ -1341,13 +1342,15 @@
// See how many we have.
$i = count($matches['browser']);
- if (1 !== $i) {
+ if (0 === $i) {
+ $version = '';
+ } elseif (1 !== $i) {
// we will have two since we are not using 'other' argument yet.
// see if version is before or after the name.
if (strripos($u_agent, 'Version') < strripos($u_agent, $ub)) {
$version = $matches['version'][0];
} else {
- $version = $matches['version'][1];
+ $version = isset($matches['version'][1]) ? $matches['version'][1] : $matches['version'][0];
}
} else {
$version = $matches['version'][0];
@@ -4779,7 +4782,7 @@
$name = sanitize_text_field( $data->name );
if ( preg_match( '/<.*>/', $data->value ) ) {
$value = wp_kses_post( $data->value );
- } elseif ( 'settings[external_url]' === $data->name ) {
+ } elseif ( 'settings[external_url]' === $data->name || preg_match( '/[webhook_url]$/', $data->name ) ) {
$value = esc_url_raw( $data->value );
} elseif ( preg_match( '/evf_email_message/', $data->name ) || preg_match( '/telegram_message/', $data->name ) || preg_match( '/slack_message/', $data->name ) ) {
$value = wp_kses_post( $data->value );
@@ -4853,8 +4856,9 @@
case 'textarea':
case 'html':
case 'privacy-policy':
- case 'wysiwug':
- $entry['form_fields'][$key] = wp_kses_post($entry['form_fields'][$key]);
+ case 'wysiwyg':
+ // A request can submit this field as an array (e.g. form_fields[<id>][]); wp_kses_post() expects a string and fatals on anything else.
+ $entry['form_fields'][$key] = wp_kses_post( is_scalar( $entry['form_fields'][$key] ) ? $entry['form_fields'][$key] : '' );
break;
case 'repeater-fields':
$entry['form_fields'][$key] = $entry['form_fields'][$key];
--- a/everest-forms/includes/fields/class-evf-field-address.php
+++ b/everest-forms/includes/fields/class-evf-field-address.php
@@ -1011,8 +1011,19 @@
'<span class="%s">',
esc_attr( $state['id'] )
);
- $country_options = ! empty( $country['attr']['value'] ) ? $country['attr']['value'] : 'AF';
- $state_options = isset( $state['options'][ $country_options ] ) ? $state['options'][ $country_options ] : '';
+ $country_options = ! empty( $country['attr']['value'] ) ? $country['attr']['value'] : '';
+
+ // With no default or placeholder the country dropdown shows its first allowed country, so list that country's states.
+ if ( '' === $country_options && empty( $country['hidden'] ) && empty( $country['attr']['placeholder'] ) && ! empty( $country['options'] ) ) {
+ foreach ( array_keys( $country['options'] ) as $country_key ) {
+ if ( empty( $selected_country ) || ! is_array( $selected_country ) || in_array( $country_key, $selected_country, true ) ) {
+ $country_options = $country_key;
+ break;
+ }
+ }
+ }
+
+ $state_options = isset( $state['options'][ $country_options ] ) ? $state['options'][ $country_options ] : '';
if ( isset( $state_options ) && ! empty( $state_options ) ) {
printf(
--- a/everest-forms/includes/fields/class-evf-field-wysiwyg.php
+++ b/everest-forms/includes/fields/class-evf-field-wysiwyg.php
@@ -142,17 +142,49 @@
* @param array $form_data All Form Data.
*/
public function field_display( $field, $field_atts, $form_data ) {
- // Define data.
- $value = '';
- $primary = $field['properties']['inputs']['primary'];
- $conditional_id = isset( $field['properties']['inputs']['primary']['attr']['conditional_id'] ) ? $field['properties']['inputs']['primary']['attr']['conditional_id'] : '';
- $conditional_rules = isset( $field['properties']['inputs']['primary']['attr']['conditional_rules'] ) ? $field['properties']['inputs']['primary']['attr']['conditional_rules'] : '';
+ $value = '';
+
+ if ( isset( $field['properties']['inputs']['primary']['attr']['value'] ) ) {
+ $value = evf_sanitize_textarea_field( $field['properties']['inputs']['primary']['attr']['value'] );
+ }
+
+ $this->display_editor( $field, $form_data, $value );
+ }
- if ( isset( $primary['attr']['value'] ) ) {
- $value = evf_sanitize_textarea_field( $primary['attr']['value'] );
- unset( $primary['attr']['value'] );
+ /**
+ * Edit form field display on the entry back-end.
+ *
+ * @since 3.6.3
+ *
+ * @param array $entry_field Entry field data.
+ * @param array $field Field data.
+ * @param array $form_data Form data and settings.
+ */
+ public function edit_form_field_display( $entry_field, $field, $form_data ) {
+ // value_raw keeps the saved markup (an image-only answer has an empty plain value), so the editor must load it.
+ if ( ! empty( $entry_field['value_raw'] ) && is_string( $entry_field['value_raw'] ) ) {
+ $value = $entry_field['value_raw'];
+ } else {
+ $value = isset( $entry_field['value'] ) && is_string( $entry_field['value'] ) ? $entry_field['value'] : '';
}
+ $this->display_editor( $field, $form_data, wp_kses_post( $value ) );
+ }
+
+ /**
+ * Output the rich text editor.
+ *
+ * @since 3.6.3
+ *
+ * @param array $field Field data.
+ * @param array $form_data Form data.
+ * @param string $value Sanitized editor content.
+ */
+ private function display_editor( $field, $form_data, $value ) {
+ $primary = $field['properties']['inputs']['primary'];
+ $conditional_id = isset( $primary['attr']['conditional_id'] ) ? $primary['attr']['conditional_id'] : '';
+ $conditional_rules = isset( $primary['attr']['conditional_rules'] ) ? $primary['attr']['conditional_rules'] : '';
+
printf(
'<div id="everest_form_wysiwyg_%s" class="input-text" data-form-id="%s" data-field-id="%s" conditional_rules="%s" conditional_id="%s">',
esc_html( $field['id'] ),
@@ -170,7 +202,7 @@
ob_start();
wp_editor( $value, $primary['id'], $settings );
$output = ob_get_clean();
- printf( $output ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ echo $output; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
printf( '</div>' );
}