class-evf-field-address.php
1 week ago
class-evf-field-ai.php
1 year ago
class-evf-field-captcha.php
1 month ago
class-evf-field-checkbox.php
3 months ago
class-evf-field-color.php
1 month ago
class-evf-field-country.php
3 months ago
class-evf-field-credit-card.php
1 month ago
class-evf-field-date-time.php
1 month ago
class-evf-field-divider.php
2 years ago
class-evf-field-email.php
1 year ago
class-evf-field-file-upload.php
1 year ago
class-evf-field-first-name.php
1 year ago
class-evf-field-hcaptcha.php
5 months ago
class-evf-field-hidden.php
1 year ago
class-evf-field-html.php
10 months ago
class-evf-field-image-upload.php
1 year ago
class-evf-field-last-name.php
1 year ago
class-evf-field-likert.php
1 year ago
class-evf-field-lookup.php
1 month ago
class-evf-field-number.php
1 year ago
class-evf-field-password.php
1 month ago
class-evf-field-payment-authorize-net.php
1 month ago
class-evf-field-payment-checkbox.php
1 month ago
class-evf-field-payment-coupon.php
1 month ago
class-evf-field-payment-gateway-selector.php
1 month ago
class-evf-field-payment-quantity.php
1 month ago
class-evf-field-payment-radio.php
1 month ago
class-evf-field-payment-single.php
1 month ago
class-evf-field-payment-square.php
2 years ago
class-evf-field-payment-subscription-plan.php
1 month ago
class-evf-field-payment-subtotal.php
1 month ago
class-evf-field-payment-total.php
1 month ago
class-evf-field-phone.php
1 year ago
class-evf-field-privacy-policy.php
3 months ago
class-evf-field-private-note.php
1 year ago
class-evf-field-progress.php
1 month ago
class-evf-field-radio.php
3 months ago
class-evf-field-range-slider.php
1 month ago
class-evf-field-rating.php
3 months ago
class-evf-field-recaptcha.php
5 months ago
class-evf-field-repeater.php
1 month ago
class-evf-field-reset.php
1 month ago
class-evf-field-scale-rating.php
1 year ago
class-evf-field-select.php
1 year ago
class-evf-field-signature.php
1 month ago
class-evf-field-text.php
1 year ago
class-evf-field-textarea.php
1 year ago
class-evf-field-title.php
2 years ago
class-evf-field-turnstile.php
5 months ago
class-evf-field-url.php
1 year ago
class-evf-field-wysiwyg.php
3 months ago
class-evf-field-yes-no.php
1 year ago
payment-amount-helpers.php
1 month ago
class-evf-field-wysiwyg.php
228 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WysiWyg field. |
| 4 | * |
| 5 | * @package EverestForms\Fields |
| 6 | * @since 3.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Field_wysiwyg class. |
| 13 | */ |
| 14 | class EVF_Field_Wysiwyg extends EVF_Form_Fields { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->name = esc_html__( 'WYSIWYG', 'everest-forms' ); |
| 21 | $this->type = 'wysiwyg'; |
| 22 | $this->icon = 'evf-icon evf-icon-wysiwyg'; |
| 23 | $this->order = 170; |
| 24 | $this->group = 'advanced'; |
| 25 | $this->settings = array( |
| 26 | 'basic-options' => array( |
| 27 | 'field_options' => array( |
| 28 | 'label', |
| 29 | 'description', |
| 30 | 'required', |
| 31 | 'required_field_message_setting', |
| 32 | 'required_field_message', |
| 33 | ), |
| 34 | ), |
| 35 | 'advanced-options' => array( |
| 36 | 'field_options' => array( |
| 37 | 'meta', |
| 38 | 'size', |
| 39 | 'placeholder', |
| 40 | 'label_hide', |
| 41 | 'default_value', |
| 42 | 'css', |
| 43 | ), |
| 44 | ), |
| 45 | ); |
| 46 | |
| 47 | parent::__construct(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Hook in tabs. |
| 52 | */ |
| 53 | public function init_hooks() { |
| 54 | add_filter( 'everest_forms_html_field_value', array( $this, 'html_field_value' ), 10, 4 ); |
| 55 | add_filter( 'everest_forms_entry_single_data', array( $this, 'entry_single_data' ), 10, 2 ); |
| 56 | add_filter( 'everest_forms_field_exporter_' . $this->type, array( $this, 'field_exporter' ) ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns values for single form entries. |
| 61 | * |
| 62 | * @since 1.4.8 |
| 63 | * |
| 64 | * @param string $value Field value. |
| 65 | * @param array $field Field settings. |
| 66 | * @param array $form_data Form data and settings. |
| 67 | * @param string $context Value display context. |
| 68 | * |
| 69 | * @return string HTML Field Value to show in the single entries. |
| 70 | */ |
| 71 | public function html_field_value( $value, $field, $form_data = array(), $context = '' ) { |
| 72 | if ( is_serialized( $field ) || in_array( $context, array( 'email-html', 'export-pdf' ), true ) ) { |
| 73 | $field_value = evf_maybe_unserialize( $field ); |
| 74 | |
| 75 | if ( |
| 76 | is_array( $field_value ) |
| 77 | && ! empty( $field_value['type'] ) |
| 78 | && $this->type === sanitize_text_field( wp_unslash( (string) $field_value['type'] ) ) |
| 79 | ) { |
| 80 | return ! empty( $field_value['value'] ) |
| 81 | ? wp_kses_post( wp_unslash( (string) $field_value['value'] ) ) |
| 82 | : ''; |
| 83 | } |
| 84 | } |
| 85 | return $value; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Hook in tabs. |
| 90 | * |
| 91 | * @since 1.4.8 |
| 92 | * |
| 93 | * @param String $meta Meta Value. |
| 94 | * @param mixed $entry Entry. |
| 95 | */ |
| 96 | public function entry_single_data( $meta, $entry ) { |
| 97 | foreach ( evf_decode( $entry->fields ) as $key => $entry ) { |
| 98 | if ( $this->type === $entry['type'] ) { |
| 99 | $meta[ $entry['meta_key'] ] = serialize( |
| 100 | array( |
| 101 | 'type' => $this->type, |
| 102 | 'value' => $entry['value_raw'], |
| 103 | ) |
| 104 | ); |
| 105 | } |
| 106 | } |
| 107 | return $meta; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * Field preview inside the builder. |
| 113 | * |
| 114 | * @since 1.8.2.4 |
| 115 | * |
| 116 | * @param array $field Field data and settings. |
| 117 | */ |
| 118 | public function field_preview( $field ) { |
| 119 | $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : ''; |
| 120 | |
| 121 | // Label. |
| 122 | $this->field_preview_option( 'label', $field ); |
| 123 | |
| 124 | // Primary input. |
| 125 | $settings = array( |
| 126 | 'media_buttons' => false, |
| 127 | 'editor_class' => 'wysiwyg input-text widefat ', |
| 128 | ); |
| 129 | wp_editor( '', 'evf-input-type-wysiwyg', $settings ); |
| 130 | |
| 131 | // Description. |
| 132 | $this->field_preview_option( 'description', $field ); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Field display on the form front-end. |
| 137 | * |
| 138 | * @since 1.8.2.4 |
| 139 | * |
| 140 | * @param array $field Field Data. |
| 141 | * @param array $field_atts Field attributes. |
| 142 | * @param array $form_data All Form Data. |
| 143 | */ |
| 144 | public function field_display( $field, $field_atts, $form_data ) { |
| 145 | // Define data. |
| 146 | $value = ''; |
| 147 | $primary = $field['properties']['inputs']['primary']; |
| 148 | $conditional_id = isset( $field['properties']['inputs']['primary']['attr']['conditional_id'] ) ? $field['properties']['inputs']['primary']['attr']['conditional_id'] : ''; |
| 149 | $conditional_rules = isset( $field['properties']['inputs']['primary']['attr']['conditional_rules'] ) ? $field['properties']['inputs']['primary']['attr']['conditional_rules'] : ''; |
| 150 | |
| 151 | if ( isset( $primary['attr']['value'] ) ) { |
| 152 | $value = evf_sanitize_textarea_field( $primary['attr']['value'] ); |
| 153 | unset( $primary['attr']['value'] ); |
| 154 | } |
| 155 | |
| 156 | printf( |
| 157 | '<div id="everest_form_wysiwyg_%s" class="input-text" data-form-id="%s" data-field-id="%s" conditional_rules="%s" conditional_id="%s">', |
| 158 | esc_html( $field['id'] ), |
| 159 | esc_html( $form_data['id'] ), |
| 160 | esc_html( $field['id'] ), |
| 161 | esc_attr( $conditional_rules ), |
| 162 | esc_attr( $conditional_id ) |
| 163 | ); |
| 164 | // Primary field. |
| 165 | $settings = array( |
| 166 | 'media_buttons' => false, |
| 167 | 'editor_class' => 'evf-wysiwyg ' . implode( ' ', $primary['class'] ), |
| 168 | 'textarea_name' => $primary['attr']['name'], |
| 169 | ); |
| 170 | ob_start(); |
| 171 | wp_editor( $value, $primary['id'], $settings ); |
| 172 | $output = ob_get_clean(); |
| 173 | printf( $output ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 174 | printf( '</div>' ); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Formats and sanitizes field. |
| 179 | * |
| 180 | * @since 1.4.8 |
| 181 | * |
| 182 | * @param string $field_id Field Id. |
| 183 | * @param array $field_submit Submitted Field. |
| 184 | * @param array $form_data All Form Data. |
| 185 | * @param string $meta_key Field Meta Key. |
| 186 | * @return void |
| 187 | */ |
| 188 | public function format( $field_id, $field_submit, $form_data, $meta_key ) { |
| 189 | $field = $form_data['form_fields'][ $field_id ]; |
| 190 | $name = make_clickable( $field['label'] ); |
| 191 | evf()->task->form_fields[ $field_id ] = array( |
| 192 | 'name' => $name, |
| 193 | 'value' => evf_sanitize_textarea( $field_submit ), |
| 194 | 'value_raw' => wp_kses_post( $field_submit ), |
| 195 | 'id' => $field_id, |
| 196 | 'type' => $this->type, |
| 197 | 'meta_key' => $meta_key, |
| 198 | ); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Filter callback for outputting formatted data. |
| 203 | * |
| 204 | * @since 1.4.8 |
| 205 | * |
| 206 | * @param array $field Field Data. |
| 207 | * @return array Data for field exporter PDF or Email. |
| 208 | */ |
| 209 | public function field_exporter( $field ) { |
| 210 | $empty_message = '<em>' . __( '(empty)', 'everest-forms' ) . '</em>'; |
| 211 | $field_value = evf_maybe_unserialize( $field ); |
| 212 | $field_type = isset( $field_value['type'] ) ? sanitize_text_field( $field_value['type'] ) : $this->type; |
| 213 | |
| 214 | if ( array_key_exists( 'value_raw', $field_value ) && ! empty( $field_value['value_raw'] ) ) { |
| 215 | |
| 216 | if ( ! in_array( $field['meta_key'], apply_filters( 'everest_forms_hidden_entry_fields', array() ), true ) ) { |
| 217 | $output = $field['value_raw']; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return array( |
| 222 | 'label' => ! empty( $field['name'] ) ? $field['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}", |
| 223 | 'value' => ! empty( $output ) ? $output : false, |
| 224 | ); |
| 225 | } |
| 226 | |
| 227 | } |
| 228 |