builder
2 months ago
form-migrator
3 months ago
plugin-updates
8 years ago
settings
2 months ago
views
2 months ago
class-evf-admin-addons.php
5 months ago
class-evf-admin-assets.php
2 months ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
3 months ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
3 months ago
class-evf-admin-forms-table-list.php
5 months ago
class-evf-admin-forms.php
5 months ago
class-evf-admin-import-export.php
4 years ago
class-evf-admin-menus.php
3 months ago
class-evf-admin-notices.php
5 months ago
class-evf-admin-preview-confirmation.php
1 year ago
class-evf-admin-settings.php
3 months ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
5 months ago
evf-admin-functions.php
2 months ago
evf-admin-functions.php
663 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * EverestForms Admin Functions |
| 5 | * |
| 6 | * @package EverestForms/Admin/Functions |
| 7 | * @version 1.0.0 |
| 8 | */ |
| 9 | |
| 10 | defined('ABSPATH') || exit; |
| 11 | |
| 12 | /** |
| 13 | * Get all EverestForms screen ids. |
| 14 | * |
| 15 | * @return array |
| 16 | */ |
| 17 | function evf_get_screen_ids() |
| 18 | { |
| 19 | $evf_screen_id = sanitize_title(esc_html__('Everest Forms', 'everest-forms')); |
| 20 | $screen_ids = array( |
| 21 | 'toplevel_page_' . $evf_screen_id, |
| 22 | $evf_screen_id . '_page_evf-dashboard', |
| 23 | $evf_screen_id . '_page_evf-builder', |
| 24 | $evf_screen_id . '_page_evf-entries', |
| 25 | $evf_screen_id . '_page_evf-settings', |
| 26 | $evf_screen_id . '_page_evf-tools', |
| 27 | $evf_screen_id . '_page_evf-addons', |
| 28 | $evf_screen_id . '_page_evf-email-templates', |
| 29 | $evf_screen_id . '_page_smart-smtp', |
| 30 | $evf_screen_id . '_page_evf-smart-smtp', |
| 31 | $evf_screen_id . '_page_evf-analytics', |
| 32 | ); |
| 33 | |
| 34 | return apply_filters('everest_forms_screen_ids', $screen_ids); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Create a page and store the ID in an option. |
| 39 | * |
| 40 | * @param mixed $slug Slug for the new page. |
| 41 | * @param string $option Option name to store the page's ID. |
| 42 | * @param string $page_title (default: '') Title for the new page. |
| 43 | * @param string $page_content (default: '') Content for the new page. |
| 44 | * @param int $post_parent (default: 0) Parent for the new page. |
| 45 | * |
| 46 | * @return int page ID |
| 47 | */ |
| 48 | function evf_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) |
| 49 | { |
| 50 | global $wpdb; |
| 51 | |
| 52 | $option_value = get_option($option); |
| 53 | $page_object = get_post($option_value); |
| 54 | |
| 55 | if ($option_value > 0 && $page_object) { |
| 56 | if ('page' === $page_object->post_type && ! in_array( |
| 57 | $page_object->post_status, |
| 58 | array( |
| 59 | 'pending', |
| 60 | 'trash', |
| 61 | 'future', |
| 62 | 'auto-draft', |
| 63 | ), |
| 64 | true |
| 65 | )) { |
| 66 | // Valid page is already in place. |
| 67 | return $page_object->ID; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (strlen($page_content) > 0) { |
| 72 | // Search for an existing page with the specified page content (typically a shortcode). |
| 73 | $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
| 74 | } else { |
| 75 | // Search for an existing page with the specified page slug. |
| 76 | $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
| 77 | } |
| 78 | |
| 79 | $valid_page_found = apply_filters('everest_forms_create_page_id', $valid_page_found, $slug, $page_content); |
| 80 | |
| 81 | if ($valid_page_found) { |
| 82 | if ($option) { |
| 83 | update_option($option, $valid_page_found); |
| 84 | } |
| 85 | |
| 86 | return $valid_page_found; |
| 87 | } |
| 88 | |
| 89 | // Search for a matching valid trashed page. |
| 90 | if (strlen($page_content) > 0) { |
| 91 | // Search for an existing page with the specified page content (typically a shortcode). |
| 92 | $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
| 93 | } else { |
| 94 | // Search for an existing page with the specified page slug. |
| 95 | $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
| 96 | } |
| 97 | |
| 98 | if ($trashed_page_found) { |
| 99 | $page_id = $trashed_page_found; |
| 100 | $page_data = array( |
| 101 | 'ID' => $page_id, |
| 102 | 'post_status' => 'publish', |
| 103 | ); |
| 104 | wp_update_post($page_data); |
| 105 | } else { |
| 106 | $page_data = array( |
| 107 | 'post_status' => 'publish', |
| 108 | 'post_type' => 'page', |
| 109 | 'post_author' => 1, |
| 110 | 'post_name' => $slug, |
| 111 | 'post_title' => $page_title, |
| 112 | 'post_content' => $page_content, |
| 113 | 'post_parent' => $post_parent, |
| 114 | 'comment_status' => 'closed', |
| 115 | ); |
| 116 | $page_id = wp_insert_post($page_data); |
| 117 | } |
| 118 | |
| 119 | if ($option) { |
| 120 | update_option($option, $page_id); |
| 121 | } |
| 122 | |
| 123 | return $page_id; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Output admin fields. |
| 128 | * |
| 129 | * Loops though the EverestFormsoptions array and outputs each field. |
| 130 | * |
| 131 | * @param array[] $options Opens array to output. |
| 132 | */ |
| 133 | function everest_forms_admin_fields($options) |
| 134 | { |
| 135 | if (! class_exists('EVF_Admin_Settings', false)) { |
| 136 | include __DIR__ . '/class-evf-admin-settings.php'; |
| 137 | } |
| 138 | |
| 139 | EVF_Admin_Settings::output_fields($options); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Update all settings which are passed. |
| 144 | * |
| 145 | * @param array $options Options array to output. |
| 146 | * @param array $data Optional. Data to use for saving. Defaults to $_POST. |
| 147 | */ |
| 148 | function everest_forms_update_options($options, $data = null) |
| 149 | { |
| 150 | if (! class_exists('EVF_Admin_Settings', false)) { |
| 151 | include __DIR__ . '/class-evf-admin-settings.php'; |
| 152 | } |
| 153 | |
| 154 | EVF_Admin_Settings::save_fields($options, $data); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Get a setting from the settings API. |
| 159 | * |
| 160 | * @param string $option_name Option name. |
| 161 | * @param mixed $default Default value. |
| 162 | * |
| 163 | * @return string |
| 164 | */ |
| 165 | function everest_forms_settings_get_option($option_name, $default = '') |
| 166 | { |
| 167 | if (! class_exists('EVF_Admin_Settings', false)) { |
| 168 | include __DIR__ . '/class-evf-admin-settings.php'; |
| 169 | } |
| 170 | |
| 171 | return EVF_Admin_Settings::get_option($option_name, $default); |
| 172 | } |
| 173 | /** |
| 174 | * Resolve the parent path. |
| 175 | * like 'settings' or 'settings['conneciton']. |
| 176 | * |
| 177 | * @since 3.4.0 |
| 178 | * |
| 179 | * @param [type] $form_data The form data. |
| 180 | * @param [type] $parent The parent. |
| 181 | */ |
| 182 | function resolve_parent_path($form_data, $parent) |
| 183 | { |
| 184 | $keys = array(); |
| 185 | |
| 186 | if (strpos($parent, '[') !== false) { |
| 187 | // Handle 'settings[connection]' to ['settings', 'connection'] |
| 188 | $parent = str_replace(']', '', $parent); |
| 189 | $keys = explode('[', $parent); |
| 190 | } else { |
| 191 | $keys[] = $parent; |
| 192 | } |
| 193 | |
| 194 | // Traverse the form_data with the resolved keys |
| 195 | foreach ($keys as $key) { |
| 196 | if (is_array($form_data) && isset($form_data[$key])) { |
| 197 | $form_data = $form_data[$key]; |
| 198 | } else { |
| 199 | return null; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return $form_data; |
| 204 | } |
| 205 | /** |
| 206 | * Outputs fields to be used on panels (settings etc). |
| 207 | * |
| 208 | * @param string $option Option. |
| 209 | * @param string $panel Panel. |
| 210 | * @param string $field Field. |
| 211 | * @param array $form_data Form data. |
| 212 | * @param string $label Label. |
| 213 | * @param array $args Arguments. |
| 214 | * @param boolean $echo True to echo else return. |
| 215 | * |
| 216 | * @return string |
| 217 | */ |
| 218 | function everest_forms_panel_field($option, $panel, $field, $form_data, $label, $args = array(), $echo = true) |
| 219 | { |
| 220 | // Required params. |
| 221 | if (empty($option) || empty($panel) || empty($field)) { |
| 222 | return ''; |
| 223 | } |
| 224 | // Setup basic vars. |
| 225 | $panel = esc_attr($panel); |
| 226 | $field = esc_attr($field); |
| 227 | $panel_id = sanitize_html_class($panel); |
| 228 | $parent = ! empty($args['parent']) ? esc_attr($args['parent']) : ''; |
| 229 | $subsection = ! empty($args['subsection']) ? esc_attr($args['subsection']) : ''; |
| 230 | $label = ! empty($label) ? $label : ''; |
| 231 | $class = ! empty($args['class']) ? esc_attr($args['class']) : ''; |
| 232 | $input_class = ! empty($args['input_class']) ? esc_attr($args['input_class']) : ''; |
| 233 | $default = isset($args['default']) ? $args['default'] : ''; |
| 234 | $tinymce = isset($args['tinymce']) ? $args['tinymce'] : ''; |
| 235 | $placeholder = ! empty($args['placeholder']) ? esc_attr($args['placeholder']) : ''; |
| 236 | $min_value = ! empty($args['min_value']) ? esc_attr($args['min_value']) : ''; |
| 237 | $data_attr = ''; |
| 238 | $output = ''; |
| 239 | |
| 240 | // Check if we should store values in a parent array. |
| 241 | if (! empty($parent)) { |
| 242 | $parent_data = resolve_parent_path($form_data, $parent); |
| 243 | if (! empty($subsection)) { |
| 244 | $field_name = sprintf('%s[%s][%s][%s]', $parent, $panel, $subsection, $field); |
| 245 | |
| 246 | if (isset($parent_data[$panel][$subsection][$field])) { |
| 247 | $value = $parent_data[$panel][$subsection][$field]; |
| 248 | } else { |
| 249 | $value = $default; |
| 250 | } |
| 251 | |
| 252 | $panel_id = sanitize_html_class($panel . '-' . $subsection); |
| 253 | } else { |
| 254 | $field_name = sprintf('%s[%s][%s]', $parent, $panel, $field); |
| 255 | |
| 256 | if (isset($parent_data[$panel][$field])) { |
| 257 | $value = $parent_data[$panel][$field]; |
| 258 | } else { |
| 259 | $value = $default; |
| 260 | } |
| 261 | } |
| 262 | } else { |
| 263 | |
| 264 | $field_name = sprintf('%s[%s]', $panel, $field); |
| 265 | $value = isset($form_data[$panel][$field]) ? $form_data[$panel][$field] : $default; |
| 266 | } |
| 267 | |
| 268 | // Check for data attributes. |
| 269 | if (! empty($args['data'])) { |
| 270 | foreach ($args['data'] as $key => $val) { |
| 271 | if (is_array($val)) { |
| 272 | $val = wp_json_encode($val); |
| 273 | } |
| 274 | $data_attr .= ' data-' . $key . '=\'' . $val . '\''; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // Check for the custom attributes. |
| 279 | $custom_attributes = ''; |
| 280 | if (! empty($args['custom_attributes'])) { |
| 281 | foreach ($args['custom_attributes'] as $attribute => $attribute_value) { |
| 282 | if (is_array($attribute_value)) { |
| 283 | $attribute_value = wp_json_encode($attribute_value); |
| 284 | } |
| 285 | $custom_attributes .= ' ' . $attribute . '=\'' . $attribute_value . '\''; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Determine what field type to output. |
| 290 | switch ($option) { |
| 291 | |
| 292 | // Text input. |
| 293 | case 'number': |
| 294 | case 'text': |
| 295 | $output = sprintf( |
| 296 | '<input type="%s" id="everest-forms-panel-field-%s-%s" name="%s" value="%s" placeholder="%s" min=%d class="widefat %s" %s %s>', |
| 297 | $option, |
| 298 | sanitize_html_class($panel_id), |
| 299 | sanitize_html_class($field), |
| 300 | $field_name, |
| 301 | esc_attr($value), |
| 302 | $placeholder, |
| 303 | $min_value, |
| 304 | $input_class, |
| 305 | $data_attr, |
| 306 | $custom_attributes |
| 307 | ); |
| 308 | break; |
| 309 | |
| 310 | // Textarea. |
| 311 | case 'textarea': |
| 312 | $rows = ! empty($args['rows']) ? (int) $args['rows'] : '3'; |
| 313 | $output = sprintf( |
| 314 | '<textarea id="everest-forms-panel-field-%s-%s" name="%s" rows="%d" placeholder="%s" class="widefat %s" %s>%s</textarea>', |
| 315 | sanitize_html_class($panel_id), |
| 316 | sanitize_html_class($field), |
| 317 | $field_name, |
| 318 | $rows, |
| 319 | $placeholder, |
| 320 | $input_class, |
| 321 | $data_attr, |
| 322 | esc_textarea($value) |
| 323 | ); |
| 324 | break; |
| 325 | |
| 326 | // TinyMCE. |
| 327 | case 'tinymce': |
| 328 | $arguments = wp_parse_args( |
| 329 | $tinymce, |
| 330 | array( |
| 331 | 'media_buttons' => false, |
| 332 | 'tinymce' => false, |
| 333 | ) |
| 334 | ); |
| 335 | $arguments['textarea_name'] = $field_name; |
| 336 | $arguments['teeny'] = true; |
| 337 | $id = 'everest-forms-panel-field-' . sanitize_html_class($panel_id) . '-' . sanitize_html_class($field); |
| 338 | $id = str_replace('-', '_', $id); |
| 339 | ob_start(); |
| 340 | wp_editor($value, $id, $arguments); |
| 341 | $output = ob_get_clean(); |
| 342 | if ( ! empty( $args['after'] ) ) { |
| 343 | $pos = strrpos( $output, '</div>' ); |
| 344 | if ( false !== $pos ) { |
| 345 | $output = substr( $output, 0, $pos ) . $args['after'] . substr( $output, $pos ); |
| 346 | } |
| 347 | $args['after'] = ''; |
| 348 | } |
| 349 | break; |
| 350 | |
| 351 | // Checkbox. |
| 352 | case 'checkbox': |
| 353 | $checked = checked('1', $value, false); |
| 354 | $checkbox = sprintf( |
| 355 | '<input type="hidden" name="%s" value="0" class="widefat %s" %s %s>', |
| 356 | $field_name, |
| 357 | $input_class, |
| 358 | $checked, |
| 359 | $data_attr |
| 360 | ); |
| 361 | $checkbox .= sprintf( |
| 362 | '<input type="checkbox" id="everest-forms-panel-field-%s-%s" name="%s" value="1" class="%s" %s %s>', |
| 363 | sanitize_html_class($panel_id), |
| 364 | sanitize_html_class($field), |
| 365 | $field_name, |
| 366 | $input_class, |
| 367 | $checked, |
| 368 | $data_attr |
| 369 | ); |
| 370 | $output = sprintf( |
| 371 | '<label for="everest-forms-panel-field-%s-%s" class="inline">%s', |
| 372 | sanitize_html_class($panel_id), |
| 373 | sanitize_html_class($field), |
| 374 | $checkbox . $label |
| 375 | ); |
| 376 | if (! empty($args['tooltip'])) { |
| 377 | $output .= sprintf(' <i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr($args['tooltip'])); |
| 378 | } |
| 379 | $output .= '</label>'; |
| 380 | break; |
| 381 | |
| 382 | // Radio. |
| 383 | case 'radio': |
| 384 | $options = $args['options']; |
| 385 | $x = 1; |
| 386 | $output = ''; |
| 387 | foreach ($options as $key => $item) { |
| 388 | if (empty($item['label'])) { |
| 389 | continue; |
| 390 | } |
| 391 | $checked = checked($key, $value, false); |
| 392 | $output .= sprintf( |
| 393 | '<span class="row"><input type="radio" id="everest-forms-panel-field-%s-%s-%d" name="%s" value="%s" class="widefat %s" %s %s>', |
| 394 | sanitize_html_class($panel_id), |
| 395 | sanitize_html_class($field), |
| 396 | $x, |
| 397 | $field_name, |
| 398 | $key, |
| 399 | $input_class, |
| 400 | $checked, |
| 401 | $data_attr |
| 402 | ); |
| 403 | $output .= sprintf( |
| 404 | '<label for="everest-forms-panel-field-%s-%s-%d" class="inline">%s', |
| 405 | sanitize_html_class($panel_id), |
| 406 | sanitize_html_class($field), |
| 407 | $x, |
| 408 | $item['label'] |
| 409 | ); |
| 410 | if (! empty($item['tooltip'])) { |
| 411 | $output .= sprintf(' <i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr($item['tooltip'])); |
| 412 | } |
| 413 | $output .= '</label></span>'; |
| 414 | ++$x; |
| 415 | } |
| 416 | break; |
| 417 | |
| 418 | // Select. |
| 419 | case 'select': |
| 420 | $is_multiple = isset($args['multiple']) && true === $args['multiple']; |
| 421 | |
| 422 | $input_class = isset( $args['input_class'] ) ? (string) $args['input_class'] : ''; |
| 423 | $is_tags_select = false !== strpos( $input_class, 'form-tags-select2' ); |
| 424 | |
| 425 | if ( ! $is_tags_select && empty( $args['options'] ) && empty( $args['field_map'] ) ) { |
| 426 | return ''; |
| 427 | } |
| 428 | |
| 429 | if (true === $is_multiple && is_string($value)) { |
| 430 | $value = ! empty($value) ? json_decode($value, true) : array(); |
| 431 | } |
| 432 | |
| 433 | if (! empty($args['field_map'])) { |
| 434 | $options = array(); |
| 435 | $available_fields = evf_get_form_fields($form_data, $args['field_map']); |
| 436 | if (! empty($available_fields)) { |
| 437 | foreach ($available_fields as $id => $available_field) { |
| 438 | $lbl = ! empty($available_field['label']) ? esc_attr($available_field['label']) : esc_html__('Field #', 'everest-forms') . $id; |
| 439 | $options[$id] = $lbl; |
| 440 | } |
| 441 | } |
| 442 | $input_class .= ' everest-forms-field-map-select'; |
| 443 | $data_attr .= ' data-field-map-allowed="' . implode(' ', $args['field_map']) . '"'; |
| 444 | if (! empty($placeholder)) { |
| 445 | $data_attr .= ' data-field-map-placeholder="' . esc_attr($placeholder) . '"'; |
| 446 | } |
| 447 | } else { |
| 448 | $options = $args['options']; |
| 449 | } |
| 450 | |
| 451 | if (true === $is_multiple) { |
| 452 | $multiple = 'multiple'; |
| 453 | $field_name .= '[]'; |
| 454 | } else { |
| 455 | $multiple = ''; |
| 456 | } |
| 457 | |
| 458 | $output = sprintf( |
| 459 | '<select id="everest-forms-panel-field-%s-%s" name="%s" class="widefat %s" %s ' . $multiple . '>', |
| 460 | sanitize_html_class($panel_id), |
| 461 | sanitize_html_class($field), |
| 462 | $field_name, |
| 463 | $input_class, |
| 464 | $data_attr |
| 465 | ); |
| 466 | |
| 467 | if (! empty($placeholder)) { |
| 468 | $output .= '<option value="">' . $placeholder . '</option>'; |
| 469 | } |
| 470 | |
| 471 | foreach ($options as $key => $item) { |
| 472 | if (true === $is_multiple && is_array($value)) { |
| 473 | $output .= sprintf('<option value="%s" %s>%s</option>', esc_attr($key), selected(in_array($key, $value, true), true, false), $item); |
| 474 | } else { |
| 475 | $output .= sprintf('<option value="%s" %s>%s</option>', esc_attr($key), selected($key, $value, false), $item); |
| 476 | } |
| 477 | } |
| 478 | $output .= '</select>'; |
| 479 | break; |
| 480 | // Toggle input. |
| 481 | case 'toggle': |
| 482 | if ('yes' === $value) { |
| 483 | $checked = checked('yes', $value, false); |
| 484 | } else { |
| 485 | $checked = checked('1', $value, false); |
| 486 | } |
| 487 | $output = sprintf( |
| 488 | '<div class="evf-toggle-section"><span class="everest-forms-toggle-form"><input type="hidden" name="%s" value="0" class="widefat %s" %s %s>', |
| 489 | $field_name, |
| 490 | $input_class, |
| 491 | $checked, |
| 492 | $data_attr |
| 493 | ); |
| 494 | $output .= sprintf( |
| 495 | '<input type="checkbox" id="everest-forms-panel-field-%s-%s" name="%s" value="1" placeholder="%s" class="widefat %s" %s %s><span class="slider round"></span></span></div>', |
| 496 | sanitize_html_class($panel_id), |
| 497 | sanitize_html_class($field), |
| 498 | $field_name, |
| 499 | $placeholder, |
| 500 | $input_class, |
| 501 | $data_attr, |
| 502 | $checked |
| 503 | ); |
| 504 | break; |
| 505 | |
| 506 | // Radio image inputs. |
| 507 | case 'radio-image': |
| 508 | $options = $args['options']; |
| 509 | $x = 1; |
| 510 | $output = '<div class="everest-forms-layout">'; |
| 511 | foreach ($options as $key => $item) { |
| 512 | $checked = checked($key, $value, false); |
| 513 | $output .= sprintf( |
| 514 | '<label for="everest-forms-panel-field-%s-%s-%d" class="inline">', |
| 515 | sanitize_html_class($panel_id), |
| 516 | sanitize_html_class($field), |
| 517 | $x |
| 518 | ); |
| 519 | if (! empty($item['tooltip'])) { |
| 520 | $output .= sprintf(' <i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr($item['tooltip'])); |
| 521 | } |
| 522 | $output .= sprintf( |
| 523 | '<input type="radio" id="everest-forms-panel-field-%s-%s-%d" name="%s" value="%s" class="widefat %s" %s %s><img src="%s">', |
| 524 | sanitize_html_class($panel_id), |
| 525 | sanitize_html_class($field), |
| 526 | $x, |
| 527 | $field_name, |
| 528 | $key, |
| 529 | $input_class, |
| 530 | $checked, |
| 531 | $data_attr, |
| 532 | esc_html($item['image']) |
| 533 | ); |
| 534 | $output .= '</label>'; |
| 535 | ++$x; |
| 536 | } |
| 537 | $output .= '</div>'; |
| 538 | break; |
| 539 | case 'image': |
| 540 | if ('' !== $value) { |
| 541 | $headers = get_headers($value, 1); |
| 542 | $content_type = is_array($headers['Content-Type']) ? implode(' ', $headers['Content-Type']) : $headers['Content-Type']; |
| 543 | |
| 544 | if (strpos($content_type, 'image/') === false) { |
| 545 | $value = ''; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | $hidden_class = empty($value) ? 'everest-forms-hidden' : ''; |
| 550 | $alt = isset($args['image']['alt']) ? $args['image']['alt'] : 'Unknown'; |
| 551 | $button_text = isset($args['image']['button-text']) ? $args['image']['button-text'] : 'Upload Image'; |
| 552 | $output = sprintf('<div class="everest-forms-custom-image-container ' . esc_attr($hidden_class) . '">'); |
| 553 | /* translators: %2$s : Image Alt Text. */ |
| 554 | $output .= sprintf('<a href="#" class="everest-forms-custom-image-delete"><i class="evf-icon evf-icon-delete"></i><img src="%1$s" alt="' . __(' %2$s', 'everest-forms') . '" class="evf-custom-image-uploader %3$s" height="100" width="auto">', esc_attr($value), esc_attr($alt), (empty($value) ? 'everest-forms-hidden' : '')); // phpcs:ignore |
| 555 | $output .= sprintf('</a></div>'); |
| 556 | /* translators: %2$s : Upload Image button Text. */ |
| 557 | $output .= sprintf('<div class="everest-forms-custom-image-button"><button type="button" class="evf-custom-image-uploader-button evf-custom-image-button %1$s">' . __('%2$s', 'everest-forms') . '</button>', (empty($value) ? 'button-secondary' : 'everest-forms-hidden'), esc_html($button_text)); // phpcs:ignore |
| 558 | $output .= sprintf( |
| 559 | '<input type="hidden" id="everest-forms-panel-field-%s-%s" name="%s" value="%s" placeholder="%s" class="widefat %s" %s></div>', |
| 560 | sanitize_html_class($panel_id), |
| 561 | sanitize_html_class($field), |
| 562 | $field_name, |
| 563 | esc_attr($value), |
| 564 | $placeholder, |
| 565 | $input_class, |
| 566 | $data_attr |
| 567 | ); |
| 568 | wp_enqueue_script('jquery'); |
| 569 | wp_enqueue_media(); |
| 570 | wp_enqueue_script('evf-file-uploader'); |
| 571 | break; |
| 572 | } |
| 573 | |
| 574 | $smarttags_class = ! empty($args['smarttags']) ? 'evf_smart_tag' : ''; |
| 575 | |
| 576 | // Put the pieces together.... |
| 577 | $field_open = sprintf( |
| 578 | '<div id="everest-forms-panel-field-%s-%s-wrap" class="everest-forms-panel-field %s %s %s">', |
| 579 | sanitize_html_class($panel_id), |
| 580 | sanitize_html_class($field), |
| 581 | $class, |
| 582 | $smarttags_class, |
| 583 | 'everest-forms-panel-field-' . sanitize_html_class($option) |
| 584 | ); |
| 585 | $field_open .= ! empty($args['before']) ? $args['before'] : ''; |
| 586 | if (! in_array($option, array('checkbox'), true) && ! empty($label)) { |
| 587 | $field_label = sprintf( |
| 588 | '<label for="everest-forms-panel-field-%s-%s">%s', |
| 589 | sanitize_html_class($panel_id), |
| 590 | sanitize_html_class($field), |
| 591 | $label |
| 592 | ); |
| 593 | if (! empty($args['tooltip'])) { |
| 594 | $field_label .= sprintf(' <i class="dashicons dashicons-editor-help everest-forms-help-tooltip" title="%s"></i>', esc_attr($args['tooltip'])); |
| 595 | } |
| 596 | if (! empty($args['after_tooltip'])) { |
| 597 | $field_label .= $args['after_tooltip']; |
| 598 | } |
| 599 | if (! empty($args['smarttags'])) { |
| 600 | $smart_tag = ''; |
| 601 | |
| 602 | $type = ! empty($args['smarttags']['type']) ? esc_attr($args['smarttags']['type']) : 'form_fields'; |
| 603 | $form_fields = ! empty($args['smarttags']['form_fields']) ? esc_attr($args['smarttags']['form_fields']) : ''; |
| 604 | |
| 605 | $smart_tag .= '<a href="#" class="evf-toggle-smart-tag-display" data-type="' . $type . '" data-fields="' . $form_fields . '"><span class="dashicons dashicons-editor-code"></span></a>'; |
| 606 | $smart_tag .= '<div class="evf-smart-tag-lists" style="display: none">'; |
| 607 | $smart_tag .= '<div class="smart-tag-title">'; |
| 608 | $smart_tag .= esc_html__('Available Fields', 'everest-forms'); |
| 609 | $smart_tag .= '</div><ul class="evf-fields"></ul>'; |
| 610 | if ('all' === $type || 'other' === $type) { |
| 611 | $smart_tag .= '<div class="smart-tag-title other-tag-title">'; |
| 612 | $smart_tag .= esc_html__('Others', 'everest-forms'); |
| 613 | $smart_tag .= '</div><ul class="evf-others"></ul>'; |
| 614 | } |
| 615 | $smart_tag .= '</div>'; |
| 616 | } else { |
| 617 | $smart_tag = ''; |
| 618 | } |
| 619 | |
| 620 | $field_label .= '</label>'; |
| 621 | if (! empty($args['after_label'])) { |
| 622 | $field_label .= $args['after_label']; |
| 623 | } |
| 624 | } else { |
| 625 | $field_label = ''; |
| 626 | $smart_tag = ''; |
| 627 | } |
| 628 | $field_close = ! empty($args['after']) ? $args['after'] : ''; |
| 629 | $field_close .= '</div>'; |
| 630 | $output = $field_open . $field_label . $output . $smart_tag . $field_close; |
| 631 | |
| 632 | // Wash our hands. |
| 633 | if ($echo) { |
| 634 | echo wp_kses($output, evf_get_allowed_html_tags('builder')); |
| 635 | } else { |
| 636 | return $output; |
| 637 | } |
| 638 | } |
| 639 | add_action('admin_init', 'check_version_compatibility_for_form_confirmation'); |
| 640 | |
| 641 | /** |
| 642 | * Check the version compatibility for form confirmation. |
| 643 | */ |
| 644 | function check_version_compatibility_for_form_confirmation() |
| 645 | { |
| 646 | if (! defined('EFP_VERSION')) { |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | if (version_compare(EFP_VERSION, '1.9.6', '<')) { |
| 651 | add_action( |
| 652 | 'admin_notices', |
| 653 | function () { |
| 654 | echo '<div class="notice notice-error is-dismissible">'; |
| 655 | echo '<p>' . sprintf( |
| 656 | __('Everest Forms is up to date, but Everest Forms Pro is not. Please update Everest Forms Pro to v1.9.6 or higher to avoid compatibility issues.', 'everest-forms') |
| 657 | ) . '</p>'; |
| 658 | echo '</div>'; |
| 659 | } |
| 660 | ); |
| 661 | } |
| 662 | } |
| 663 |