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