· 4 years ago · Jan 02, 2021, 08:52 PM
1<?php
2
3 /**
4 * @Description : Plugin main core
5 * @Package : Drag & Drop Multiple File Upload - Contact Form 7
6 * @Author : Glen Don L. Mongaya
7 */
8
9 if ( ! defined( 'ABSPATH' ) || ! defined('dnd_upload_cf7') ) {
10 exit;
11 }
12
13 /**
14 * Begin : begin plugin hooks
15 */
16
17 add_action( 'wpcf7_init', 'dnd_cf7_upload_add_form_tag_file' );
18 add_action( 'wpcf7_enqueue_scripts', 'dnd_cf7_scripts' );
19
20 // Hook on plugins loaded
21 add_action('plugins_loaded','dnd_cf7_upload_plugins_loaded');
22
23 // Ajax Upload
24 add_action( 'wp_ajax_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
25 add_action( 'wp_ajax_nopriv_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
26
27 // Hook - Ajax Delete
28 add_action('wp_ajax_nopriv_dnd_codedropz_upload_delete', 'dnd_codedropz_upload_delete');
29 add_action('wp_ajax_dnd_codedropz_upload_delete','dnd_codedropz_upload_delete');
30
31 // Hook mail cf7
32 add_filter('wpcf7_posted_data', 'dnd_wpcf7_posted_data', 10, 1);
33 add_action('wpcf7_before_send_mail','dnd_cf7_before_send_mail', 30, 1);
34 add_action('wpcf7_mail_components','dnd_cf7_mail_components', 50, 2);
35
36 // Auto clean up dir/files
37 add_action('template_redirect', 'dnd_cf7_auto_clean_dir', 20, 0 );
38
39 // Add row meta links
40 add_filter( 'plugin_row_meta', 'dnd_custom_plugin_row_meta', 10, 2 );
41
42 // Add custom mime-type
43 add_filter('upload_mimes', 'dnd_extra_mime_types', 1, 1);
44
45 // Add Submenu - Settings
46 add_action('admin_menu', 'dnd_admin_settings');
47
48 // Add custom script in footer
49 add_action('wp_footer','dnd_custom_scripts');
50
51 // Flamingo Hooks
52 add_action('before_delete_post', 'dnd_remove_uploaded_files');
53
54 // Load plugin text-domain
55 function dnd_cf7_upload_plugins_loaded() {
56
57 // Load language domain
58 load_plugin_textdomain( 'drag-and-drop-multiple-file-upload-contact-form-7', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages' );
59
60 // Create dir
61 $dir = dnd_get_upload_dir();
62 if( isset( $dir['upload_dir'] ) && is_dir( $dir['upload_dir'] ) ) {
63 // Generate .htaccess file`
64 $htaccess_file = path_join( dirname( $dir['upload_dir'] ), '.htaccess' );
65 if ( ! file_exists( $htaccess_file ) ) {
66 if ( $handle = fopen( $htaccess_file, 'w' ) ) {
67 fwrite( $handle, "Options -Indexes \n <Files *.php> \n deny from all \n </Files>" );
68 fclose( $handle );
69 }
70 }
71 }
72 }
73
74 // Remove uploaded files when item is deleted permanently.
75 function dnd_remove_uploaded_files( $post_id ) {
76 $post_type = get_post_type( $post_id );
77 $page = get_post( $post_id );
78 if( $post_type == 'flamingo_inbound' ) {
79 preg_match_all( '/(.*?)(\/'.wpcf7_dnd_dir.'\/wpcf7-files\/.*$)/m', $page->post_content, $matches );
80 if( $matches[0] && count( $matches[0] ) > 0 ) {
81 foreach( $matches[0] as $files ) {
82 $new_file = str_replace( site_url().'/', wp_normalize_path( ABSPATH ), $files );
83 if( file_exists( $new_file ) ) {
84 wp_delete_file( $new_file );
85 }
86 }
87 }
88 }
89 }
90
91 // Modify contact form posted_data
92 function dnd_wpcf7_posted_data( $posted_data ){
93
94 // Subbmisson instance from CF7
95 $submission = WPCF7_Submission::get_instance();
96
97 // Make sure we have the data
98 if ( ! $posted_data ) {
99 $posted_data = $submission->get_posted_data();
100 }
101
102 // Scan and get all form tags from cf7 generator
103 $forms_tags = $submission->get_contact_form();
104 $uploads_dir = dnd_get_upload_dir();
105
106 if( $forms = $forms_tags->scan_form_tags() ) {
107 foreach( $forms as $field ) {
108 $field_name = $field->name;
109 if( $field->basetype == 'mfile' && isset( $posted_data[$field_name] ) && ! empty( $posted_data[$field_name] ) ) {
110 foreach( $posted_data[$field_name] as $key => $file ) {
111 $posted_data[$field_name][$key] = trailingslashit( $uploads_dir['upload_url'] ) . wp_basename( $file );
112 }
113 }
114 }
115 }
116
117 return $posted_data;
118 }
119
120 // Hooks for admin settings
121 function dnd_admin_settings() {
122 add_submenu_page( 'wpcf7', 'Drag & Drop Uploader - Settings', 'Drag & Drop Upload', 'manage_options', 'drag-n-drop-upload','dnd_upload_admin_settings');
123 add_action('admin_init','dnd_upload_register_settings');
124 }
125
126 // Add custom mime-types
127 function dnd_extra_mime_types( $mime_types ){
128 $mime_types['xls'] = 'application/excel, application/vnd.ms-excel, application/x-excel, application/x-msexcel';
129 $mime_types['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
130 return $mime_types;
131 }
132
133 // Default Error Message
134 function dnd_cf7_error_msg( $error_key ) {
135
136 // Array of default error message
137 $errors = array(
138 'server_limit' => __('The uploaded file exceeds the maximum upload size of your server.','drag-and-drop-multiple-file-upload-contact-form-7'),
139 'failed_upload' => __('Uploading a file fails for any reason','drag-and-drop-multiple-file-upload-contact-form-7'),
140 'large_file' => __('Uploaded file is too large','drag-and-drop-multiple-file-upload-contact-form-7'),
141 'invalid_type' => __('Uploaded file is not allowed for file type','drag-and-drop-multiple-file-upload-contact-form-7'),
142 'max_file_limit' => __('Note : Some of the files are not uploaded ( Only %count% files allowed )','drag-and-drop-multiple-file-upload-contact-form-7'),
143 'required' => __('This field is required.', 'drag-and-drop-multiple-file-upload-contact-form-7' ),
144 'min_file' => __('Minimum file upload at least','drag-and-drop-multiple-file-upload-contact-form-7'),
145 );
146
147 // return error message based on $error_key request
148 if( isset( $errors[ $error_key ] ) ) {
149 return $errors[ $error_key ];
150 }
151
152 return false;
153 }
154
155 // Get folder path
156 function dnd_get_upload_dir() {
157 $upload = wp_upload_dir();
158 $uploads_dir = wpcf7_dnd_dir . '/wpcf7-files';
159
160 // If save as attachment ( also : Check if upload use year and month folders )
161 if( get_option('drag_n_drop_mail_attachment') == 'yes' ) {
162 $uploads_dir = ( get_option('uploads_use_yearmonth_folders') ? wpcf7_dnd_dir . $upload['subdir'] : wpcf7_dnd_dir );
163 }
164
165 // Create directory
166 if ( ! is_dir( trailingslashit( $upload['basedir'] ) . $uploads_dir ) ) {
167 wp_mkdir_p( trailingslashit( $upload['basedir'] ) . $uploads_dir );
168 }
169
170 // Make sure directory exist before returning
171 if( file_exists( trailingslashit( $upload['basedir'] ) . $uploads_dir ) ) {
172 return array(
173 'upload_dir' => trailingslashit( $upload['basedir'] ) . $uploads_dir,
174 'upload_url' => trailingslashit( $upload['baseurl'] ) . $uploads_dir
175 );
176 }
177
178 return trailingslashit( $upload['basedir'] ) . $uploads_dir;
179 }
180
181 // Clean up directory - From Contact Form 7
182 function dnd_cf7_auto_clean_dir( $seconds = 3600, $max = 60 ) {
183 if ( is_admin() || 'GET' != $_SERVER['REQUEST_METHOD'] || is_robots() || is_feed() || is_trackback() ) {
184 return;
185 }
186
187 // Setup dirctory path
188 $upload = wp_upload_dir();
189 $dir = trailingslashit( $upload['basedir'] ) . wpcf7_dnd_dir . '/wpcf7-files/';
190
191 // Make sure dir is readable or writable
192 if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! wp_is_writable( $dir ) ) {
193 return;
194 }
195
196 $seconds = apply_filters( 'dnd_cf7_auto_delete_files', $seconds );
197 $max = absint( $max );
198 $count = 0;
199
200 if ( $handle = @opendir( $dir ) ) {
201 while ( false !== ( $file = readdir( $handle ) ) ) {
202 if ( $file == "." || $file == ".." ) {
203 continue;
204 }
205
206 // Get file time of files OLD files.
207 $mtime = @filemtime( $dir . $file );
208
209 if ( $mtime && time() < $mtime + absint( $seconds ) ) { // less than $seconds old
210 continue;
211 }
212
213 // Delete files from dir
214 if( $file != '.htaccess' ) {
215 wp_delete_file( $dir . $file );
216 }
217
218 $count += 1;
219
220 if ( $max <= $count ) {
221 break;
222 }
223 }
224 @closedir( $handle );
225 }
226 @rmdir( $dir );
227 }
228
229 // Hooks before sending the email - ( append links to body email )
230 function dnd_cf7_before_send_mail( $wpcf7 ){
231 global $_mail;
232
233 // Get upload path / dir
234 $upload_path = dnd_get_upload_dir();
235
236 // Mail Counter
237 $_mail = 0;
238
239 // Check If send attachment as link
240 if( ! get_option('drag_n_drop_mail_attachment') ) {
241 return $wpcf7;
242 }
243
244 // cf7 instance
245 $submission = WPCF7_Submission::get_instance();
246
247 // Check for submission
248 if( $submission ) {
249
250 // Get posted data
251 $submitted['posted_data'] = $submission->get_posted_data();
252
253 // Parse fields
254 $fields = $wpcf7->scan_form_tags();
255
256 // Links
257 $links = array();
258
259 // Prop email
260 $mail = $wpcf7->prop('mail');
261 $mail_2 = $wpcf7->prop('mail_2');
262
263 // Default upload path
264 $simple_path = dirname( $upload_path['upload_url'] ); // dirname - remove duplicate form dir (/wpcf-dnd-uploads/wpcf7-dnd-uploads/example.jpg)
265
266 // Loop fields and replace mfile code
267 foreach( $fields as $field ) {
268 if( $field->basetype == 'mfile') {
269 if( isset( $submitted['posted_data'][$field->name] ) && ! empty( $submitted['posted_data'][$field->name] ) ) {
270
271 // Get posted_data files
272 $files = $submitted['posted_data'][$field->name];
273
274 // Links - 1
275 $mail_links = dnd_cf7_links( $files, $mail['use_html'] );
276 $mail['body'] = str_replace( "[$field->name]", "\n" . implode( "\n", $mail_links ), $mail['body'] );
277
278 // Links - 2
279 if( $mail_2['active'] ) {
280 $mail_links_2 = dnd_cf7_links( $files, $mail_2['use_html'] );
281 $mail_2['body'] = str_replace( "[$field->name]", "\n" . implode( "\n", $mail_links_2 ), $mail_2['body'] );
282 }
283 }
284 }
285 }
286
287 // Save the email body
288 $wpcf7->set_properties( array("mail" => $mail) );
289
290 // if mail 2
291 if( $mail_2['active'] ) {
292 $wpcf7->set_properties( array("mail_2" => $mail_2) );
293 }
294 }
295
296 return $wpcf7;
297 }
298
299 // Get file links.
300 function dnd_cf7_links( $files, $use_html = false) {
301
302 // check and make sure we have files
303 if( ! $files ) {
304 return;
305 }
306
307 // Setup html links
308 $links = array();
309 foreach( $files as $file ) {
310 $links[] = ( $use_html ? '<a href="'. esc_url( $file ) .'">'. wp_basename( $file ) .'</a>' : $file );
311 }
312
313 // Allow other themes/plugin to modify data.
314 return apply_filters('dndcf7_before_send_files', $links, $files );
315 }
316
317 // Log message...
318 function dnd_logs( $message, $email = false ) {
319 $uploads_dir = dnd_get_upload_dir();
320 $file = fopen( $uploads_dir['upload_dir']."/logs.txt", "a") or die("Unable to open file!");
321 fwrite( $file, "\n". ( is_array( $message ) ? print_r( $message, true ) : $message ) );
322 fclose( $file );
323 }
324
325 // hooks - Custom cf7 Mail components ( Attached File on Email )
326 function dnd_cf7_mail_components( $components, $form ) {
327 global $_mail;
328
329 if( ! $form ) {
330 return;
331 }
332
333 // Get upload directory
334 $uploads_dir = dnd_get_upload_dir();
335
336 // cf7 - Submission Object
337 $submission = WPCF7_Submission::get_instance();
338
339 // get all form fields
340 $fields = $form->scan_form_tags();
341
342 // Send email link as an attachment.
343 if( get_option('drag_n_drop_mail_attachment') == 'yes' ) {
344 return $components;
345 }
346
347 // Get mail,mail_2 attachment [tags]
348 $mail = array('mail','mail_2');
349 $props_mail = array();
350
351 foreach( $mail as $single_mail ) {
352 $props_mail[] = $form->prop( $single_mail );
353 }
354
355 // Get email attachments (mail, mail_2)
356 $mail = $props_mail[ $_mail ];
357 if( $mail['active'] && $mail['attachments'] ) {
358
359 // Loop fields get mfile only.
360 foreach( $fields as $field ) {
361
362 // If field type equal to mfile which our default field.
363 if( $field->basetype == 'mfile') {
364
365 // Make sure we have files to attach
366 if( isset( $_POST[ $field->name ] ) && count( $_POST[ $field->name ] ) > 0 ) {
367
368 // Check and make sure [upload-file-xxx] exists in attachments - fields
369 if ( false !== strpos( $mail['attachments'], "[{$field->name}]" ) ) {
370
371 // Loop all the files and attach to cf7 components
372 foreach( $_POST[ $field->name ] as $_file ) {
373
374 // Join dir and a new file name ( get from <input type="hidden" name="upload-file-333"> )
375 $new_file_name = trailingslashit( $uploads_dir['upload_dir'] ) . wp_basename( $_file );
376
377 // Check if submitted and file exists then file is ready.
378 if ( $submission && file_exists( $new_file_name ) ) {
379 $components['attachments'][] = $new_file_name;
380 }
381 }
382
383 }
384 }
385 }
386 }
387
388 }
389
390 // Increment mail counter
391 $_mail = $_mail + 1;
392
393 // Return setup components
394 return $components;
395 }
396
397 // Load js and css
398 function dnd_cf7_scripts() {
399
400 // Get plugin version
401 $version = dnd_upload_cf7_version;
402
403 // enque script
404 wp_enqueue_script( 'codedropz-uploader', plugins_url ('/assets/js/codedropz-uploader-min.js', dirname(__FILE__) ), array('jquery'), $version, true );
405 wp_enqueue_script( 'dnd-upload-cf7', plugins_url ('/assets/js/dnd-upload-cf7.js', dirname(__FILE__) ), array('jquery','codedropz-uploader','contact-form-7'), $version, true );
406
407 // registered script with data for a JavaScript variable.
408 wp_localize_script( 'dnd-upload-cf7', 'dnd_cf7_uploader',
409 array(
410 'ajax_url' => admin_url( 'admin-ajax.php' ),
411 'ajax_nonce' => wp_create_nonce( "dnd-cf7-security-nonce" ),
412 'drag_n_drop_upload' => array(
413 'tag' => ( get_option('drag_n_drop_heading_tag') ? get_option('drag_n_drop_heading_tag') : 'h3' ),
414 'text' => ( get_option('drag_n_drop_text') ? get_option('drag_n_drop_text') : __('Drag & Drop Files Here','drag-and-drop-multiple-file-upload-contact-form-7') ),
415 'or_separator' => ( get_option('drag_n_drop_separator') ? get_option('drag_n_drop_separator') : __('or','drag-and-drop-multiple-file-upload-contact-form-7') ),
416 'browse' => ( get_option('drag_n_drop_browse_text') ? get_option('drag_n_drop_browse_text') : __('Browse Files','drag-and-drop-multiple-file-upload-contact-form-7') ),
417 'server_max_error' => ( get_option('drag_n_drop_error_server_limit') ? get_option('drag_n_drop_error_server_limit') : dnd_cf7_error_msg('server_limit') ),
418 'large_file' => ( get_option('drag_n_drop_error_files_too_large') ? get_option('drag_n_drop_error_files_too_large') : dnd_cf7_error_msg('large_file') ),
419 'inavalid_type' => ( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') ),
420 'max_file_limit' => ( get_option('drag_n_drop_error_max_file') ? get_option('drag_n_drop_error_max_file') : dnd_cf7_error_msg('max_file_limit') ),
421 'required' => dnd_cf7_error_msg('required'),
422 'delete' => array(
423 'text' => __('deleting','drag-and-drop-multiple-file-upload-contact-form-7'),
424 'title' => __('Remove','drag-and-drop-multiple-file-upload-contact-form-7')
425 )
426 ),
427 'dnd_text_counter' => __('of','drag-and-drop-multiple-file-upload-contact-form-7'),
428 'disable_btn' => ( get_option('drag_n_drop_disable_btn') == 'yes' ? true : false )
429 )
430 );
431
432 // enque style
433 wp_enqueue_style( 'dnd-upload-cf7', plugins_url ('/assets/css/dnd-upload-cf7.css', dirname(__FILE__) ), '', $version );
434 }
435
436 // Generate tag
437 function dnd_cf7_upload_add_form_tag_file() {
438 wpcf7_add_form_tag( array( 'mfile ', 'mfile*'), 'dnd_cf7_upload_form_tag_handler', array( 'name-attr' => true ) );
439 }
440
441 // Form tag handler from the tag - callback
442 function dnd_cf7_upload_form_tag_handler( $tag ) {
443
444 // check and make sure tag name is not empty
445 if ( empty( $tag->name ) ) {
446 return '';
447 }
448
449 // Validate our fields
450 $validation_error = wpcf7_get_validation_error( $tag->name );
451
452 // Generate class
453 $class = wpcf7_form_controls_class( 'drag-n-drop-file d-none' );
454
455 // Add not-valid class if there's an error.
456 if ( $validation_error ) {
457 $class .= ' wpcf7-not-valid';
458 }
459
460 // Get current form Object
461 $form = WPCF7_ContactForm::get_current();
462
463 // Setup element attributes
464 $atts = array();
465
466 $atts['size'] = $tag->get_size_option( '40' );
467 $atts['class'] = $tag->get_class_option( $class );
468 $atts['id'] = $tag->get_id_option();
469 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
470
471 // If file is required
472 if ( $tag->is_required() ) {
473 $atts['aria-required'] = 'true';
474 }
475
476 // Set invalid attributes if there's validation error
477 $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
478
479 // Set input type and name
480 $atts['type'] = 'file';
481 $atts['multiple'] = 'multiple';
482 $atts['data-name'] = $tag->name;
483 $atts['data-type'] = $tag->get_option( 'filetypes','', true);
484 $atts['data-limit'] = $tag->get_option( 'limit','', true);
485 $atts['data-max'] = $tag->get_option( 'max-file','', true);
486 $atts['data-id'] = ( $form->id() ? $form->id() : 0 );
487
488 // Combine and format attrbiutes
489 $atts = wpcf7_format_atts( $atts );
490
491 // Return our element and attributes
492 return sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class( $tag->name ), $atts, $validation_error );
493 }
494
495 // Encode type filter to support multipart since this is input type file
496 add_filter( 'wpcf7_form_enctype', 'dnd_upload_cf7_form_enctype_filter' );
497
498 function dnd_upload_cf7_form_enctype_filter( $enctype ) {
499 $multipart = (bool) wpcf7_scan_form_tags( array( 'type' => array( 'drag_drop_file', 'drag_drop_file*' ) ) );
500
501 if ( $multipart ) {
502 $enctype = 'multipart/form-data';
503 }
504
505 return $enctype;
506 }
507
508 // 3rd party compatability...
509 function dnd_cf7_conditional_fields( $form_id ) {
510
511 if( ! $form_id ) {
512 return false;
513 }
514
515 // Get visible groups
516 $groups = array();
517
518 // Get current form object
519 $cf7_post = get_post( $form_id );
520
521 // Extract group shortcode
522 $regex = get_shortcode_regex( array('group') );
523
524 // Match pattern
525 preg_match_all( '/'. $regex .'/s', $cf7_post->post_content, $matches );
526
527 if( array_key_exists( 3, $matches )) {
528 foreach( $matches[3] as $index => $group_name ) {
529 $name = array_filter( explode(" ", $group_name ) );
530 preg_match('/\[mfile[*|\s].*?\]/', $matches[0][$index], $file_matches );
531 if( $file_matches ) {
532 $field_name = shortcode_parse_atts( $file_matches[0] );
533 $field_name = preg_replace( '/[^a-zA-Z0-9-_]/','', $field_name[1] );
534 $groups[ $field_name ] = $name[1];
535 }
536 }
537 }
538
539 return $groups;
540 }
541
542 // Validation + upload handling filter
543 add_filter( 'wpcf7_validate_mfile', 'dnd_upload_cf7_validation_filter', 10, 2 );
544 add_filter( 'wpcf7_validate_mfile*', 'dnd_upload_cf7_validation_filter', 10, 2 );
545
546 function dnd_upload_cf7_validation_filter( $result, $tag ) {
547 $name = $tag->name;
548 $id = $tag->get_id_option();
549 $multiple_files = ( ( isset( $_POST[ $name ] ) && count( $_POST[ $name ] ) > 0 ) ? $_POST[ $name ] : null );
550 $min_file = $tag->get_option( 'min-file','', true);
551
552 // Cf7 Conditional Field
553 if( in_array('cf7-conditional-fields/contact-form-7-conditional-fields.php', get_option('active_plugins') ) ){
554
555 $hidden_groups = json_decode( stripslashes( $_POST['_wpcf7cf_hidden_groups'] ) );
556 $form_id = WPCF7_ContactForm::get_current()->id();
557 $group_fields = dnd_cf7_conditional_fields( $form_id );
558
559 if( is_null( $multiple_files ) && $tag->is_required() ) {
560 if( isset( $group_fields[ $name ] ) && ! in_array( $group_fields[ $name ], $hidden_groups ) ) {
561 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
562 }elseif( ! array_key_exists( $name, $group_fields ) ) {
563 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
564 }
565 return $result;
566 }
567
568 return $result;
569 }
570
571 // Check if we have files or if it's empty
572 if( is_null( $multiple_files ) && $tag->is_required() ) {
573 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
574 return $result;
575 }
576
577 // Check minimum upload
578 if( $multiple_files && count( $multiple_files ) < (int) $min_file ) {
579 $min_file_error = ( get_option('drag_n_drop_error_min_file') ? get_option('drag_n_drop_error_min_file') : dnd_cf7_error_msg('min_file') );
580 $result->invalidate( $tag, $min_file_error .' '. (int)$min_file );
581 return $result;
582 }
583
584 return $result;
585 }
586
587 // Generate Admin From Tag
588 add_action( 'wpcf7_admin_init', 'dnd_upload_cf7_add_tag_generator', 50 );
589
590 function dnd_upload_cf7_add_tag_generator() {
591 $tag_generator = WPCF7_TagGenerator::get_instance();
592 $tag_generator->add( 'upload-file', __( 'multiple file upload', 'drag-and-drop-multiple-file-upload-contact-form-7' ),'dnd_upload_cf7_tag_generator_file' );
593 }
594
595 // Display form in admin
596 function dnd_upload_cf7_tag_generator_file( $contact_form, $args = '' ) {
597
598 // Parse data and get our options
599 $args = wp_parse_args( $args, array() );
600
601 // Our multiple upload field
602 $type = 'mfile';
603
604 $description = __( "Generate a form-tag for a file uploading field. For more details, see %s.", 'contact-form-7' );
605 $desc_link = wpcf7_link( __( 'https://contactform7.com/file-uploading-and-attachment/', 'contact-form-7' ), __( 'File Uploading and Attachment', 'contact-form-7' ) );
606
607 ?>
608
609 <div class="control-box">
610 <fieldset>
611 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
612 <table class="form-table">
613 <tbody>
614 <tr>
615 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
616 <td>
617 <fieldset>
618 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
619 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
620 </fieldset>
621 </td>
622 </tr>
623 <tr>
624 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
625 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
626 </tr>
627 <tr>
628 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-limit' ); ?>"><?php echo esc_html( __( "File size limit (bytes)", 'contact-form-7' ) ); ?></label></th>
629 <td><input type="text" name="limit" class="filesize oneline option" id="<?php echo esc_attr( $args['content'] . '-limit' ); ?>" /></td>
630 </tr>
631 <tr>
632 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>"><?php echo esc_html( __( 'Acceptable file types', 'contact-form-7' ) ); ?></label></th>
633 <td><input type="text" name="filetypes" class="filetype oneline option" placeholder="jpeg|png|jpg|gif" id="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>" /></td>
634 </tr>
635 <tr>
636 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-min-file' ); ?>"><?php echo esc_html( __( 'Minimum file upload', 'contact-form-7' ) ); ?></label></th>
637 <td><input type="text" name="min-file" class="filetype oneline option" placeholder="5" id="<?php echo esc_attr( $args['content'] . '-min-file' ); ?>" /></td>
638 </tr>
639 <tr>
640 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-max-file' ); ?>"><?php echo esc_html( __( 'Max file upload', 'contact-form-7' ) ); ?></label></th>
641 <td><input type="text" name="max-file" class="filetype oneline option" placeholder="10" id="<?php echo esc_attr( $args['content'] . '-max-file' ); ?>" /></td>
642 </tr>
643 <tr>
644 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
645 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
646 </tr>
647 <tr>
648 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
649 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
650 </tr>
651 </tbody>
652 </table>
653 </fieldset>
654 </div>
655
656 <div class="insert-box">
657 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
658 <div class="submitbox">
659 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
660 </div>
661 <br class="clear" />
662 <p class="description mail-tag">
663 <label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To attach the file uploaded through this field to mail, you need to insert the corresponding mail-tag (%s) into the File Attachments field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label>
664 </p>
665 </div>
666
667 <?php
668 }
669
670 // Get allowed types
671 function dnd_cf7_get_allowed_types( $form_id ) {
672
673 // Initialize contact form instance
674 $form = WPCF7_ContactForm::get_instance( $form_id );
675
676 // Check if not valid object and null
677 if( ! $form && ! is_object( $form ) ) {
678 return false;
679 }
680
681 // Get specific tag (mfile is for dnd file upload)
682 $tags = $form->scan_form_tags( array( 'type' => array('mfile', 'mfile*') ) );
683 $supported_types = array();
684
685 // Loop all upload tags
686 if( $tags && is_array( $tags ) ) {
687 foreach( $tags as $tag ) {
688
689 // Get file types option & remove not allowed character..
690 $types = preg_replace( '/[^a-zA-Z0-9|\']/', '', $tag->get_option('filetypes','', true ) );
691
692 // Assign if filetypes is present otherwise use the default ext list.
693 $supported_types[ $tag->name ] = ( $types ? $types : dnd_upload_default_ext() );
694 }
695 }
696
697 return $supported_types;
698 }
699
700 // Begin process upload
701 function dnd_upload_cf7_upload() {
702
703 // cf7 form id & upload name
704 $cf7_id = sanitize_text_field( (int)$_POST['form_id']);
705
706 // Get the name of upload field.
707 $cf7_upload_name = sanitize_text_field( $_POST['upload_name'] );
708
709 // Get allowed ext list @expected : png|jpeg|jpg
710 $allowed_types = dnd_cf7_get_allowed_types( $cf7_id );
711
712 // check and verify ajax request
713 if( is_user_logged_in() ) {
714 check_ajax_referer( 'dnd-cf7-security-nonce', 'security' );
715 }
716
717 // Get upload dir
718 $path = dnd_get_upload_dir();
719
720 // input type file 'name'
721 $name = 'upload-file';
722
723 // Get File ( name, type, tmp_name, size, error )
724 $file = isset( $_FILES[$name] ) ? $_FILES[$name] : null;
725
726 // Tells whether the file was uploaded via HTTP POST
727 if ( ! is_uploaded_file( $file['tmp_name'] ) ) {
728 $failed_error = get_option('drag_n_drop_error_failed_to_upload');
729 wp_send_json_error( '('. $file['error'] .') ' . ( $failed_error ? $failed_error : dnd_cf7_error_msg('failed_upload') ) );
730 }
731
732 /* Get allowed extension */
733 $supported_type = ( isset( $allowed_types["$cf7_upload_name"] ) ? $allowed_types["$cf7_upload_name"] : dnd_upload_default_ext() );
734
735 // Create type pattern for anti script
736 $file_type_pattern = dnd_upload_cf7_filetypes( $supported_type );
737
738 // Get file extension
739 $extension = strtolower( pathinfo( $file['name'], PATHINFO_EXTENSION ) );
740
741 // validate file type
742 if ( ! preg_match( $file_type_pattern, $file['name'] ) || ! dnd_cf7_validate_type( $extension, $supported_type ) ) {
743 wp_send_json_error( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') );
744 }
745
746 // validate file size limit
747 if( $file['size'] > (int)$_POST['size_limit'] ) {
748 wp_send_json_error( get_option('drag_n_drop_error_files_too_large') ? get_option('drag_n_drop_error_files_too_large') : dnd_cf7_error_msg('large_file') );
749 }
750
751 // Create file name
752 $filename = wp_basename( $file['name'] );
753 $filename = wpcf7_canonicalize( $filename, 'as-is' );
754
755 // Check if string is ascii then proceed with antiscript function ( remove or clean filename )
756 if( dnd_cf7_check_ascii( $filename ) ){
757 $filename = wpcf7_antiscript_file_name( $filename );
758 }
759
760 // Add filter on upload file name
761 $filename = apply_filters( 'wpcf7_upload_file_name', $filename, $file['name'] );
762
763 // Generate new filename
764 $filename = wp_unique_filename( $path['upload_dir'], $filename );
765 $new_file = path_join( $path['upload_dir'], $filename );
766
767 // Upload File
768 if ( false === move_uploaded_file( $file['tmp_name'], $new_file ) ) {
769 $failed_error = get_option('drag_n_drop_error_failed_to_upload');
770 wp_send_json_error( '('. $file['error'] .') ' . ( $failed_error ? $failed_error : dnd_cf7_error_msg('failed_upload') ) );
771 }else{
772
773 $files = array(
774 'path' => basename( $path['upload_dir'] ),
775 'file' => str_replace('/','-', $filename)
776 );
777
778 // Change file permission to 0400
779 chmod( $new_file, 0644 );
780
781 wp_send_json_success( $files );
782 }
783
784 die;
785 }
786
787 // Check if a string is ASCII.
788 function dnd_cf7_check_ascii( $string ) {
789 if ( function_exists( 'mb_check_encoding' ) ) {
790 if ( mb_check_encoding( $string, 'ASCII' ) ) {
791 return true;
792 }
793 } elseif ( ! preg_match( '/[^\x00-\x7F]/', $string ) ) {
794 return true;
795 }
796
797 return false;
798 }
799
800 // Delete file
801 function dnd_codedropz_upload_delete() {
802
803 // Get folder directory
804 $dir = dnd_get_upload_dir();
805
806 // check and verify ajax request
807 if( is_user_logged_in() ) {
808 check_ajax_referer( 'dnd-cf7-security-nonce', 'security' );
809 }
810
811 // Sanitize Path
812 $get_path = ( isset( $_POST['path'] ) ? sanitize_text_field( $_POST['path'] ) : null );
813
814 //limit the user input to a file name and to ignore injected path names
815 $path = basename( $get_path );
816
817 // Make sure path is set
818 if( ! is_null( $path ) ) {
819
820 // Check valid filename & extensions
821 if( preg_match_all('/wp-|(\.php|\.exe|\.js|\.phtml|\.cgi|\.aspx|\.asp|\.bat)/', $path ) ) {
822 die('File not safe');
823 }
824
825 // Concatenate path and upload directory
826 $file_path = realpath( trailingslashit( $dir['upload_dir'] ) . trim( $path ) );
827
828 // Check if is in the correct upload_dir
829 if( ! preg_match("/". wpcf7_dnd_dir ."/i", $file_path ) ) {
830 die('It\'s not a valid upload directory');
831 }
832
833 // Check if file exists
834 if( file_exists( $file_path ) ){
835 wp_delete_file( $file_path );
836 if( ! file_exists( $file_path ) ) {
837 wp_send_json_success('File Deleted!');
838 }
839 }
840 }
841
842 die;
843 }
844
845 // Setup file type pattern for validation
846 function dnd_upload_cf7_filetypes( $types ) {
847 $file_type_pattern = '';
848
849 // If contact form 7 5.0 and up
850 if( function_exists('wpcf7_acceptable_filetypes') ) {
851 $file_type_pattern = wpcf7_acceptable_filetypes( $types, 'regex' );
852 $file_type_pattern = '/\.(' . $file_type_pattern . ')$/i';
853 }else{
854 $allowed_file_types = array();
855 $file_types = explode( '|', $types );
856
857 foreach ( $file_types as $file_type ) {
858 $file_type = trim( $file_type, '.' );
859 $file_type = str_replace( array( '.', '+', '*', '?' ), array( '\.', '\+', '\*', '\?' ), $file_type );
860 $allowed_file_types[] = $file_type;
861 }
862
863 $allowed_file_types = array_unique( $allowed_file_types );
864 $file_type_pattern = implode( '|', $allowed_file_types );
865
866 $file_type_pattern = trim( $file_type_pattern, '|' );
867 $file_type_pattern = '(' . $file_type_pattern . ')';
868 $file_type_pattern = '/\.' . $file_type_pattern . '$/i';
869 }
870
871 return $file_type_pattern;
872 }
873
874 // Add more validation for file extension
875 function dnd_cf7_validate_type( $extension, $supported_types ) {
876 $valid = true;
877 $extension = preg_replace( '/[^A-Za-z0-9,|]/', '', $extension );
878
879 // not allowed file types
880 $not_allowed = array( 'php', 'php3','php4','phtml','exe','script', 'app', 'asp', 'bas', 'bat', 'cer', 'cgi', 'chm', 'cmd', 'com', 'cpl', 'crt', 'csh', 'csr', 'dll', 'drv', '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', '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' );
881
882 // Search in $not_allowed extension and match
883 foreach( $not_allowed as $single_ext ) {
884 if ( strpos( $single_ext, $extension ) !== false ) {
885 $valid = false;
886 break;
887 }
888 }
889
890 // If pass on first validation - check extension if exists in allowed types
891 if( $valid === true ) {
892 $extensions = explode('|', strtolower( $supported_types ) );
893 if( ! in_array( $extension, $extensions ) ) {
894 $valid = false;
895 }
896 }
897
898 return $valid;
899 }
900
901 // Admin Settings
902 function dnd_upload_admin_settings( ) {
903 echo '<div class="wrap">';
904 echo '<h1>Drag & Drop Uploader - Settings</h1>';
905
906 echo '<div class="update-nag notice" style="width: 98%;padding: 0px 10px;margin-bottom: 5px;">';
907 echo '<p>Checkout more features on <a href="https://codedropz.com/purchase-plugin/" target="_blank">Pro Version</a></p>';
908 echo '</div>';
909
910 // Error settings
911 settings_errors();
912
913 echo '<form method="post" action="options.php"> ';
914 settings_fields( 'drag-n-drop-upload-file-cf7' );
915 do_settings_sections( 'drag-n-drop-upload-file-cf7' );
916 ?>
917
918 <table class="form-table">
919 <tr valign="top">
920 <th scope="row"><?php _e('Send Attachment as links?','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
921 <td><input name="drag_n_drop_mail_attachment" type="checkbox" value="yes" <?php checked('yes', get_option('drag_n_drop_mail_attachment')); ?>></td>
922 </tr>
923 </table>
924
925 <h2><?php _e('Uploader Info','drag-and-drop-multiple-file-upload-contact-form-7'); ?></h2>
926
927 <table class="form-table">
928 <tr valign="top">
929 <th scope="row"><?php _e('Heading Tag','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
930 <td>
931 <select name="drag_n_drop_heading_tag">
932 <option value="h1" <?php selected( get_option('drag_n_drop_heading_tag'), 'h1'); ?>>H1</option>
933 <option value="h2" <?php selected( get_option('drag_n_drop_heading_tag'), 'h2'); ?>>H2</option>
934 <option value="h3" <?php selected( get_option('drag_n_drop_heading_tag','h3'), 'h3'); ?>>H3</option>
935 <option value="h4" <?php selected( get_option('drag_n_drop_heading_tag'), 'h4'); ?>>H4</option>
936 <option value="h5" <?php selected( get_option('drag_n_drop_heading_tag'), 'h5'); ?>>H5</option>
937 <option value="h6" <?php selected( get_option('drag_n_drop_heading_tag'), 'h6'); ?>>H6</option>
938 </select>
939 </td>
940 </tr>
941 <tr valign="top">
942 <th scope="row"><?php _e('Drag & Drop Text','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
943 <td><input type="text" name="drag_n_drop_text" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_text') ); ?>" placeholder="Drag & Drop Files Here" /></td>
944 </tr>
945 <tr valign="top">
946 <th scope="row"></th>
947 <td><input type="text" name="drag_n_drop_separator" value="<?php echo esc_attr( get_option('drag_n_drop_separator') ); ?>" placeholder="or" /></td>
948 </tr>
949 <tr valign="top">
950 <th scope="row"><?php _e('Browse Text','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
951 <td><input type="text" name="drag_n_drop_browse_text" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_browse_text') ); ?>" placeholder="Browse Files" /></td>
952 </tr>
953 </table>
954
955 <h2><?php _e('Error Message','drag-and-drop-multiple-file-upload-contact-form-7'); ?></h2>
956
957 <table class="form-table">
958 <tr valign="top">
959 <th scope="row"><?php _e('File exceeds server limit','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
960 <td><input type="text" name="drag_n_drop_error_server_limit" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_server_limit') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('server_limit'); ?>" /></td>
961 </tr>
962 <tr valign="top">
963 <th scope="row"><?php _e('Failed to Upload','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
964 <td><input type="text" name="drag_n_drop_error_failed_to_upload" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_failed_to_upload') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('failed_upload'); ?>" /></td>
965 </tr>
966 <tr valign="top">
967 <th scope="row"><?php _e('Files too large','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
968 <td><input type="text" name="drag_n_drop_error_files_too_large" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_files_too_large') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('large_file'); ?>" /></td>
969 </tr>
970 <tr valign="top">
971 <th scope="row"><?php _e('Invalid file Type','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
972 <td><input type="text" name="drag_n_drop_error_invalid_file" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_invalid_file') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('invalid_type'); ?>" /></td>
973 </tr>
974 <tr valign="top">
975 <th scope="row"><?php _e('Max File Limit','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
976 <td><input type="text" name="drag_n_drop_error_max_file" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_max_file') ); ?>" placeholder="" /><p class="description">Example: `Note : Some of the files are not uploaded ( Only %count% files allowed )`</p></td>
977 </tr>
978 <tr valign="top">
979 <th scope="row"><?php _e('Minimum File','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
980 <td><input type="text" name="drag_n_drop_error_min_file" placeholder="" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_min_file') ); ?>" placeholder="" /></td>
981 </tr>
982 </table>
983
984 <h2 style="display:none;"><?php _e('Disable Button','drag-and-drop-multiple-file-upload-contact-form-7'); ?></h2>
985
986 <table style="display:none;" class="form-table">
987 <tr valign="top">
988 <th scope="row"><?php _e('Disable Submit button','drag-and-drop-multiple-file-upload-contact-form-7'); ?></th>
989 <td><input type="checkbox" name="drag_n_drop_disable_btn" value="yes" <?php checked('yes', get_option('drag_n_drop_disable_btn')); ?>> Yes <p class="description">Disable submit button if there's an error.</p></td>
990 </tr>
991 </table>
992
993 <?php submit_button(); ?>
994
995 <?php
996 echo '</form>';
997 echo '</div>';
998 }
999
1000 // Add script in footer
1001 function dnd_custom_scripts() {
1002 if( ! in_array('jquery-validation-for-contact-form-7/jquery-validation-for-contact-form-7.php', get_option('active_plugins') ) ){
1003 return;
1004 }
1005 ?>
1006 <script type="text/javascript">
1007 // Contact form 7 - Jquery validation
1008 jQuery(document).ready(function($){
1009 jQuery('.wpcf7-form-control.wpcf7-submit').click(function(e){
1010 var uploadFields = $(this).parents('form').find('.wpcf7-drag-n-drop-file');
1011 var valid = true;
1012 if( uploadFields.length > 0 ) {
1013 jQuery.each(uploadFields, function(i,field){
1014 if( $(field).attr('aria-required') == 'true' ) {
1015 parentsWrap = $(field).parents('.codedropz-upload-wrapper');
1016 parentsWrap.removeClass('invalid');
1017 parentsWrap.find('label').remove();
1018 if( $('[type="hidden"][name="'+$(field).attr('data-name')+'[]"]').length == 0 ) {
1019 parentsWrap.append('<label class="error-new">'+ dnd_cf7_uploader.drag_n_drop_upload.required +'</label>').addClass('invalid');
1020 valid = false;
1021 }
1022 }
1023 });
1024 if( ! valid ) {
1025 return false;
1026 }
1027 }
1028 return true;
1029 });
1030 });
1031 </script>
1032 <?php
1033 }
1034
1035 // Define custom (safe) file extension.
1036 function dnd_upload_default_ext() {
1037 return apply_filters('dnd_cf7_default_ext', 'jpg|jpeg|JPG|png|gif|pdf|doc|docx|ppt|svg|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv|xls' );
1038 }
1039
1040 // Add custom links
1041 function dnd_custom_plugin_row_meta( $links, $file ) {
1042 if ( strpos( $file, 'drag-n-drop-upload-cf7.php' ) !== false ) {
1043 $new_links = array('pro-version' => '<a href="https://codedropz.com/purchase-plugin/" target="_blank" style="font-weight:bold; color:#f4a647;">Pro Version</a>');
1044 $links = array_merge( $links, $new_links );
1045 }
1046 return $links;
1047 }
1048
1049 // Save admin settings
1050 function dnd_upload_register_settings() {
1051 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_heading_tag','sanitize_text_field' );
1052 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_mail_attachment','sanitize_text_field' );
1053 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_text','sanitize_text_field' );
1054 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_separator','sanitize_text_field' );
1055 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_browse_text','sanitize_text_field' );
1056 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_server_limit','sanitize_text_field' );
1057 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_failed_to_upload','sanitize_text_field' );
1058 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_files_too_large','sanitize_text_field' );
1059 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_invalid_file','sanitize_text_field' );
1060 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_max_file','sanitize_text_field' );
1061 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_min_file','sanitize_text_field' );
1062 register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_disable_btn','sanitize_text_field' );
1063 }