PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.8
Elementor Website Builder – more than just a page builder v3.35.8
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / files / uploads-manager.php

uploads-manager.php in Elementor Website Builder – more than just a page builder 3.35.8, at core/files/uploads-manager.php

771 lines 20.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Files;
3
4 use Elementor\Core\Base\Base_Object;
5 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
6 use Elementor\Core\Files\File_Types\Base as File_Type_Base;
7 use Elementor\Core\Files\File_Types\Json;
8 use Elementor\Core\Files\File_Types\Svg;
9 use Elementor\Core\Files\File_Types\Zip;
10 use Elementor\Core\Files\Fonts\Google_Font;
11 use Elementor\Core\Utils\Exceptions;
12 use Elementor\Fonts;
13 use Elementor\User;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Elementor uploads manager.
21 *
22 * Elementor uploads manager handler class is responsible for handling file uploads that are not done with WP Media.
23 *
24 * @since 3.3.0
25 */
26 class Uploads_Manager extends Base_Object {
27
28 const UNFILTERED_FILE_UPLOADS_KEY = 'elementor_unfiltered_files_upload';
29 const INVALID_FILE_CONTENT = 'Invalid Content In File';
30 const ELEMENTOR_UPLOAD_DIR = 'elementor';
31
32 /**
33 * @var File_Type_Base[]
34 */
35 private $file_type_handlers = [];
36
37 private $allowed_file_extensions;
38
39 /**
40 * @var bool
41 */
42 private $is_elementor_upload = false;
43
44 /**
45 * @var string
46 */
47 private $temp_dir;
48
49 /**
50 * Register File Types
51 *
52 * To Add a new file type to Elementor, with its own handling logic, you need to add it to the $file_types array here.
53 *
54 * @since 3.3.0
55 * @access public
56 */
57 public function register_file_types() {
58 // All file types that have handlers should be included here.
59 $file_types = [
60 'json' => new Json(),
61 'zip' => new Zip(),
62 'svg' => new Svg(),
63 ];
64
65 foreach ( $file_types as $file_type => $file_handler ) {
66 $this->file_type_handlers[ $file_type ] = $file_handler;
67 }
68 }
69
70 /**
71 * Extract and Validate Zip
72 *
73 * This method accepts a $file array (which minimally should include a 'tmp_name')
74 *
75 * @since 3.3.0
76 * @access public
77 *
78 * @param string $file_path
79 * @param array $allowed_file_types
80 * @return array|\WP_Error
81 */
82 public function extract_and_validate_zip( $file_path, $allowed_file_types = null ) {
83 $result = [];
84
85 /** @var Zip $zip_handler - File Type */
86 $zip_handler = $this->file_type_handlers['zip'];
87
88 // Returns an array of file paths.
89 $extracted = $zip_handler->extract( $file_path, $allowed_file_types );
90
91 if ( is_wp_error( $extracted ) ) {
92 return $extracted;
93 }
94
95 // If there are no extracted file names, no files passed the extraction validation.
96 if ( empty( $extracted['files'] ) ) {
97 // TODO: Decide what to do if no files passed the extraction validation
98 return new \WP_Error( 'file_error', self::INVALID_FILE_CONTENT );
99 }
100
101 $result['extraction_directory'] = $extracted['extraction_directory'];
102
103 foreach ( $extracted['files'] as $extracted_file_path ) {
104 // Each file is an array with a 'name' (file path) property.
105 if ( ! is_wp_error( $this->validate_file( [ 'tmp_name' => $extracted_file_path ] ) ) ) {
106 $result['files'][] = $extracted_file_path;
107 }
108 }
109
110 return $result;
111 }
112
113 /**
114 * Handle Elementor Upload
115 *
116 * This method receives a $file array. If the received file is a Base64 string, the $file array should include a
117 * 'fileData' property containing the string, which is decoded and has its contents stored in a temporary file.
118 * If the $file parameter passed is a standard $file array, the 'name' and 'tmp_name' properties are used for
119 * validation.
120 *
121 * The file goes through validation; if it passes validation, the file is returned. Otherwise, an error is returned.
122 *
123 * @since 3.3.0
124 * @access public
125 *
126 * @param array $data
127 * @param array $allowed_file_extensions Optional. an array of file types that are allowed to pass validation for each
128 * upload.
129 * @return array|\WP_Error
130 */
131 public function handle_elementor_upload( array $data, $allowed_file_extensions = null ) {
132 // If $file['fileData'] is set, it signals that the passed file is a Base64 string that needs to be decoded and
133 // saved to a temporary file.
134 if ( isset( $data['fileData'] ) ) {
135 $data = $this->save_base64_to_tmp_file( $data, $allowed_file_extensions );
136 }
137
138 if ( is_wp_error( $data ) ) {
139 return $data;
140 }
141
142 if ( ! isset( $data['fileData'] ) ) {
143 if ( empty( $data['tmp_name'] ) ) {
144 return new \WP_Error( 'file_error', esc_html__( 'Invalid temporary file path.', 'elementor' ) );
145 }
146
147 if ( ! $this->is_path_in_allowed_dir( $data['tmp_name'] ) ) {
148 return new \WP_Error( 'file_error', esc_html__( 'Invalid temporary file path.', 'elementor' ) );
149 }
150 }
151
152 $validation_result = $this->validate_file( $data, $allowed_file_extensions );
153
154 if ( is_wp_error( $validation_result ) ) {
155 if ( ! empty( $data['tmp_name'] ) ) {
156 $this->remove_file_or_dir( dirname( $data['tmp_name'] ) );
157 }
158
159 return $validation_result;
160 }
161
162 return $data;
163 }
164
165 /**
166 * Is Unfiltered Uploads Enabled
167 *
168 * @since 3.5.0
169 * @access public
170 *
171 * @return bool
172 */
173 final public static function are_unfiltered_uploads_enabled() {
174 $enabled = (bool) get_option( self::UNFILTERED_FILE_UPLOADS_KEY )
175 && Svg::file_sanitizer_can_run()
176 && User::is_current_user_can_upload_json();
177
178 /**
179 * Allow Unfiltered Files Upload.
180 *
181 * Determines whether to enable unfiltered file uploads.
182 *
183 * @since 3.0.0
184 *
185 * @param bool $enabled Whether upload is enabled or not.
186 */
187 $enabled = apply_filters( 'elementor/files/allow_unfiltered_upload', $enabled );
188
189 return $enabled;
190 }
191
192 /**
193 * Handle Elementor WP Media Upload
194 *
195 * Runs on the 'wp_handle_upload_prefilter' filter.
196 *
197 * @since 3.2.0
198 * @access public
199 *
200 * @param $file
201 * @return mixed
202 */
203 public function handle_elementor_wp_media_upload( $file ) {
204 // If it isn't a file uploaded by Elementor, we do not intervene.
205 if ( ! $this->is_elementor_wp_media_upload() ) {
206 return $file;
207 }
208
209 $result = $this->validate_file( $file );
210
211 if ( is_wp_error( $result ) ) {
212 $file['error'] = $result->get_error_message();
213 }
214
215 return $file;
216 }
217
218 /**
219 * Get File Type Handler
220 *
221 * Initialize the proper file type handler according to the file extension
222 * and assign it to the file type handlers array.
223 *
224 * @since 3.3.0
225 * @access public
226 *
227 * @param string|null $file_extension - file extension
228 * @return File_Type_Base[]|File_Type_Base
229 */
230 public function get_file_type_handlers( $file_extension = null ) {
231 return self::get_items( $this->file_type_handlers, $file_extension );
232 }
233
234 /**
235 * Check filetype and ext
236 *
237 * A workaround for upload validation which relies on a PHP extension (fileinfo)
238 * with inconsistent reporting behaviour.
239 * ref: https://core.trac.wordpress.org/ticket/39550
240 * ref: https://core.trac.wordpress.org/ticket/40175
241 *
242 * @since 3.5.0
243 * @access public
244 *
245 * @param $data
246 * @param $file
247 * @param $filename
248 * @param $mimes
249 *
250 * @return mixed
251 */
252 public function check_filetype_and_ext( $data, $file, $filename, $mimes ) {
253 if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
254 return $data;
255 }
256
257 $wp_file_type = wp_check_filetype( $filename, $mimes );
258
259 $file_type_handlers = $this->get_file_type_handlers();
260
261 if ( isset( $file_type_handlers[ $wp_file_type['ext'] ] ) ) {
262 $file_type_handler = $file_type_handlers[ $wp_file_type['ext'] ];
263
264 $data['ext'] = $file_type_handler->get_file_extension();
265 $data['type'] = $file_type_handler->get_mime_type();
266 }
267
268 return $data;
269 }
270
271 /**
272 * Check if path is within the allowed Elementor uploads directory.
273 *
274 * Prevents path traversal and arbitrary directory deletion by ensuring the path
275 * resolves under wp-content/uploads/elementor/ or under the configured temp dir
276 * (elementor/files/temp-dir filter), so that cleanup works when temp dir is customized.
277 *
278 * @since 3.35.4
279 * @access private
280 *
281 * @param string $path
282 * @return bool
283 */
284 private function is_path_in_allowed_dir( $path ) {
285 if ( ! is_string( $path ) || '' === $path ) {
286 return false;
287 }
288
289 $real_path = realpath( $path );
290
291 if ( false === $real_path ) {
292 $real_path = realpath( dirname( $path ) );
293 if ( false === $real_path ) {
294 return false;
295 }
296 }
297
298 $wp_upload_dir = wp_upload_dir();
299 $elementor_base = realpath( $wp_upload_dir['basedir'] . DIRECTORY_SEPARATOR . self::ELEMENTOR_UPLOAD_DIR );
300
301 if ( false !== $elementor_base ) {
302 $allowed = $real_path === $elementor_base || 0 === strpos( $real_path, $elementor_base . DIRECTORY_SEPARATOR );
303 if ( $allowed ) {
304 return true;
305 }
306 }
307
308 $temp_dir = realpath( $this->get_temp_dir() );
309 if ( false !== $temp_dir ) {
310 $temp_dir = rtrim( $temp_dir, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
311 return 0 === strpos( $real_path, $temp_dir );
312 }
313
314 return false;
315 }
316
317 /**
318 * Remove File Or Directory
319 *
320 * Directory is deleted recursively with all of its contents (subdirectories and files).
321 * Only paths under wp-content/uploads/elementor/ are allowed (security: prevents arbitrary directory deletion).
322 *
323 * @since 3.3.0
324 * @access public
325 *
326 * @param string $path
327 */
328 public function remove_file_or_dir( $path ) {
329 if ( ! $this->is_path_in_allowed_dir( $path ) ) {
330 return;
331 }
332
333 if ( is_dir( $path ) ) {
334 $this->remove_directory_with_files( $path );
335 } elseif ( is_file( $path ) ) {
336 unlink( $path );
337 }
338 }
339
340 /**
341 * Create Temp File
342 *
343 * Create a random temporary file.
344 *
345 * @since 3.3.0
346 * @access public
347 *
348 * @param string $file_content
349 * @param string $file_name
350 * @return string|\WP_Error
351 */
352 public function create_temp_file( $file_content, $file_name ) {
353 $file_name = str_replace( ' ', '', sanitize_file_name( $file_name ) );
354
355 if ( empty( $file_name ) ) {
356 return new \WP_Error( 'invalid_file_name', esc_html__( 'Invalid file name.', 'elementor' ) );
357 }
358
359 $temp_filename = $this->create_unique_dir() . $file_name;
360
361 /**
362 * Temp File Path
363 *
364 * Allows modifying the full path of the temporary file.
365 *
366 * @since 3.7.0
367 *
368 * @param string full path to file
369 */
370 $temp_filename = apply_filters( 'elementor/files/temp-file-path', $temp_filename );
371
372 file_put_contents( $temp_filename, $file_content ); // phpcs:ignore
373
374 return $temp_filename;
375 }
376
377 /**
378 * Get Temp Directory
379 *
380 * Get the temporary files directory path. If the directory does not exist, this method creates it.
381 *
382 * @since 3.3.0
383 * @access public
384 *
385 * @return string $temp_dir
386 */
387 public function get_temp_dir() {
388 if ( ! $this->temp_dir ) {
389 $wp_upload_dir = wp_upload_dir();
390
391 $temp_dir = implode( DIRECTORY_SEPARATOR, [ $wp_upload_dir['basedir'], self::ELEMENTOR_UPLOAD_DIR, 'tmp' ] ) . DIRECTORY_SEPARATOR;
392
393 /**
394 * Temp File Path
395 *
396 * Allows modifying the full path of the temporary file.
397 *
398 * @since 3.7.0
399 *
400 * @param string temporary directory
401 */
402 $this->temp_dir = apply_filters( 'elementor/files/temp-dir', $temp_dir );
403
404 if ( ! is_dir( $this->temp_dir ) ) {
405 wp_mkdir_p( $this->temp_dir );
406 }
407 }
408
409 return $this->temp_dir;
410 }
411
412 /**
413 * Create Unique Temp Dir
414 *
415 * Create a unique temporary directory
416 *
417 * @since 3.3.0
418 * @access public
419 *
420 * @return string the new directory path
421 */
422 public function create_unique_dir() {
423 $unique_dir_path = $this->get_temp_dir() . uniqid() . DIRECTORY_SEPARATOR;
424
425 wp_mkdir_p( $unique_dir_path );
426
427 return $unique_dir_path;
428 }
429
430 /**
431 * Register Ajax Actions
432 *
433 * Runs on the 'elementor/ajax/register_actions' hook. Receives the AJAX module as a parameter and registers
434 * callbacks for specified action IDs.
435 *
436 * @since 3.5.0
437 * @access public
438 *
439 * @param Ajax $ajax
440 */
441 public function register_ajax_actions( Ajax $ajax ) {
442 $ajax->register_ajax_action( 'enable_unfiltered_files_upload', [ $this, 'enable_unfiltered_files_upload' ] );
443 $ajax->register_ajax_action( 'enqueue_google_fonts', [ $this, 'ajax_enqueue_google_fonts' ] );
444 }
445
446 /**
447 * Set Unfiltered Files Upload
448 *
449 * @since 3.5.0
450 * @access public
451 */
452 public function enable_unfiltered_files_upload() {
453 if ( ! current_user_can( 'manage_options' ) ) {
454 return;
455 }
456
457 update_option( self::UNFILTERED_FILE_UPLOADS_KEY, 1 );
458 }
459
460 public function ajax_enqueue_google_fonts( $data ): bool {
461 if ( empty( $data['font_name'] ) ) {
462 return false;
463 }
464
465 $font_type = Fonts::get_font_type( $data['font_name'] );
466
467 if ( Fonts::GOOGLE !== $font_type ) {
468 return false;
469 }
470
471 Google_Font::enqueue( $data['font_name'] );
472
473 return true;
474 }
475
476 /**
477 * Support Unfiltered File Uploads
478 *
479 * When uploading a file within Elementor, this method adds the registered
480 * file types to WordPress' allowed mimes list. This will only happen if the user allowed unfiltered file uploads
481 * in Elementor's settings in the admin dashboard.
482 *
483 * @since 3.5.0
484 * @access public
485 *
486 * @param array $allowed_mimes
487 * @return array allowed mime types
488 */
489 final public function support_unfiltered_elementor_file_uploads( $allowed_mimes ) {
490 if ( $this->is_elementor_upload() && $this->are_unfiltered_uploads_enabled() ) {
491 foreach ( $this->file_type_handlers as $file_type_handler ) {
492 $allowed_mimes[ $file_type_handler->get_file_extension() ] = $file_type_handler->get_mime_type();
493 }
494 }
495
496 return $allowed_mimes;
497 }
498
499 /**
500 * Set Elementor Upload State
501 *
502 * @since 3.5.0
503 * @access public
504 *
505 * @param $state
506 */
507 public function set_elementor_upload_state( $state ) {
508 $this->is_elementor_upload = $state;
509 }
510
511 /**
512 * Is Elementor Upload
513 *
514 * This method checks if the current session includes a request to upload files made via Elementor.
515 *
516 * @since 3.5.0
517 * @access private
518 *
519 * @return bool
520 */
521 private function is_elementor_upload() {
522 return $this->is_elementor_upload || $this->is_elementor_media_upload() || $this->is_elementor_wp_media_upload();
523 }
524
525 /**
526 * Is Elementor Media Upload
527 *
528 * Checks whether the current request includes uploading files via Elementor which are not destined for the Media
529 * Library.
530 *
531 * @since 3.5.0
532 * @access public
533 *
534 * @return bool
535 */
536 public function is_elementor_media_upload() {
537 // Sometimes `uploadTypeCaller` passed as a GET parameter when using the WP Media Library REST API, where the
538 // whole request body is occupied by the uploaded file.
539 return isset( $_REQUEST['uploadTypeCaller'] ) && 'elementor-media-upload' === $_REQUEST['uploadTypeCaller']; // phpcs:ignore
540 }
541
542 /**
543 * Is Elementor WP Media Upload
544 *
545 * Checks whether the current request is a request to upload files into the WP Media Library via Elementor.
546 *
547 * @since 3.3.0
548 * @access private
549 *
550 * @return bool
551 */
552 private function is_elementor_wp_media_upload() {
553 return isset( $_REQUEST['uploadTypeCaller'] ) && 'elementor-wp-media-upload' === $_REQUEST['uploadTypeCaller']; // phpcs:ignore
554 }
555
556 /**
557 * Add File Extension To Allowed Extensions List
558 *
559 * @since 3.3.0
560 * @access private
561 *
562 * @param string $file_type
563 */
564 private function add_file_extension_to_allowed_extensions_list( $file_type ) {
565 $file_handler = $this->file_type_handlers[ $file_type ];
566
567 $file_extension = $file_handler->get_file_extension();
568
569 // Only add the file extension to the list if it doesn't already exist in it.
570 if ( ! in_array( $file_extension, $this->allowed_file_extensions, true ) ) {
571 $this->allowed_file_extensions[] = $file_extension;
572 }
573 }
574
575 /**
576 * Save Base64 as File
577 *
578 * Saves a Base64 string as a .tmp file in Elementor's temporary files directory.
579 *
580 * @since 3.3.0
581 * @access private
582 *
583 * @param $file
584 * @param array|null $allowed_file_extensions
585 *
586 * @return array|\WP_Error
587 */
588 private function save_base64_to_tmp_file( $file, $allowed_file_extensions = null ) {
589 if ( empty( $file['fileName'] ) || empty( $file['fileData'] ) ) {
590 return new \WP_Error( 'file_error', self::INVALID_FILE_CONTENT );
591 }
592
593 $file_extension = pathinfo( $file['fileName'], PATHINFO_EXTENSION );
594 $is_file_type_allowed = $this->is_file_type_allowed( $file_extension, $allowed_file_extensions );
595
596 if ( is_wp_error( $is_file_type_allowed ) ) {
597 return $is_file_type_allowed;
598 }
599
600 $file_content = base64_decode( $file['fileData'] ); // phpcs:ignore
601
602 // If the decode fails
603 if ( ! $file_content ) {
604 return new \WP_Error( 'file_error', self::INVALID_FILE_CONTENT );
605 }
606
607 $temp_filename = $this->create_temp_file( $file_content, $file['fileName'] );
608
609 if ( is_wp_error( $temp_filename ) ) {
610 return $temp_filename;
611 }
612
613 return [
614 // the original uploaded file name
615 'name' => $file['fileName'],
616 // The path to the temporary file
617 'tmp_name' => $temp_filename,
618 ];
619 }
620
621 /**
622 * Validate File
623 *
624 * @since 3.3.0
625 * @access private
626 *
627 * @param array $file
628 * @param array $file_extensions Optional
629 * @return bool|\WP_Error
630 */
631 private function validate_file( array $file, $file_extensions = [] ) {
632 $uploaded_file_name = isset( $file['name'] ) ? $file['name'] : $file['tmp_name'];
633
634 $file_extension = pathinfo( $uploaded_file_name, PATHINFO_EXTENSION );
635
636 if ( ! $this->is_elementor_wp_media_upload() ) {
637 $is_file_type_allowed = $this->is_file_type_allowed( $file_extension, $file_extensions );
638
639 if ( is_wp_error( $is_file_type_allowed ) ) {
640 return $is_file_type_allowed;
641 }
642 }
643
644 $file_type_handler = $this->get_file_type_handlers( $file_extension );
645
646 // If Elementor does not have a handler for this file type, don't block it.
647 if ( ! $file_type_handler ) {
648 return true;
649 }
650
651 // If there is a File Type Handler for the uploaded file, it means it is a non-standard file type. In this case,
652 // we check if unfiltered file uploads are enabled or not before allowing it.
653 if ( ! self::are_unfiltered_uploads_enabled() ) {
654 $error = 'json' === $file_extension
655 ? esc_html__( 'You do not have permission to upload JSON files.', 'elementor' )
656 : esc_html__( 'This file is not allowed for security reasons.', 'elementor' );
657 return new \WP_Error( Exceptions::FORBIDDEN, $error );
658 }
659
660 // Here is each file type handler's chance to run its own specific validations
661 return $file_type_handler->validate_file( $file );
662 }
663
664 /**
665 * Is File Type Allowed
666 *
667 * Checks whether the passed file extension is allowed for upload.
668 *
669 * @since 3.5.0
670 * @access private
671 *
672 * @param $file_extension
673 * @param $filtered_file_extensions
674 * @return bool|\WP_Error
675 */
676 private function is_file_type_allowed( $file_extension, $filtered_file_extensions ) {
677 $allowed_file_extensions = $this->get_allowed_file_extensions();
678
679 if ( $filtered_file_extensions ) {
680 $allowed_file_extensions = array_intersect( $allowed_file_extensions, $filtered_file_extensions );
681 }
682
683 $is_allowed = false;
684
685 // Check if the file type (extension) is in the allowed extensions list. If it is a non-standard file type (not
686 // enabled by default in WordPress) and unfiltered file uploads are not enabled, it will not be in the allowed
687 // file extensions list.
688 foreach ( $allowed_file_extensions as $allowed_extension ) {
689 if ( preg_match( '/' . $allowed_extension . '/', $file_extension ) ) {
690 $is_allowed = true;
691
692 break;
693 }
694 }
695
696 if ( ! $is_allowed ) {
697 $is_allowed = new \WP_Error( Exceptions::FORBIDDEN, 'Uploading this file type is not allowed.' );
698 }
699
700 /**
701 * Elementor File Type Allowed
702 *
703 * Allows setting file types
704 *
705 * @since 3.5.0
706 *
707 * @param bool|\WP_Error $is_allowed
708 */
709 return apply_filters( 'elementor/files/allow-file-type/' . $file_extension, $is_allowed );
710 }
711
712 /**
713 * Remove Directory with Files
714 *
715 * @since 3.3.0
716 * @access private
717 *
718 * @param string $dir
719 * @return bool
720 */
721 private function remove_directory_with_files( $dir ) {
722 $dir_iterator = new \RecursiveDirectoryIterator( $dir, \RecursiveDirectoryIterator::SKIP_DOTS );
723
724 foreach ( new \RecursiveIteratorIterator( $dir_iterator, \RecursiveIteratorIterator::CHILD_FIRST ) as $name => $item ) {
725 if ( is_dir( $name ) ) {
726 rmdir( $name );
727 } elseif ( is_file( $name ) ) {
728 unlink( $name );
729 }
730 }
731
732 return rmdir( $dir );
733 }
734
735 /**
736 * Get Allowed File Extensions
737 *
738 * Retrieve an array containing the list of file extensions allowed for upload.
739 *
740 * @since 3.3.0
741 * @access private
742 *
743 * @return array file extension/s
744 */
745 private function get_allowed_file_extensions() {
746 if ( ! $this->allowed_file_extensions ) {
747 $this->allowed_file_extensions = array_keys( get_allowed_mime_types() );
748
749 foreach ( $this->get_file_type_handlers() as $file_type => $handler ) {
750 if ( $handler->is_upload_allowed() ) {
751 // Add the file extension to the allowed extensions list only if unfiltered files upload is enabled.
752 $this->add_file_extension_to_allowed_extensions_list( $file_type );
753 }
754 }
755 }
756
757 return $this->allowed_file_extensions;
758 }
759
760 public function __construct() {
761 $this->register_file_types();
762
763 add_filter( 'upload_mimes', [ $this, 'support_unfiltered_elementor_file_uploads' ] );
764 add_filter( 'wp_handle_upload_prefilter', [ $this, 'handle_elementor_wp_media_upload' ] );
765 add_filter( 'wp_check_filetype_and_ext', [ $this, 'check_filetype_and_ext' ], 10, 4 );
766
767 // Ajax.
768 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
769 }
770 }
771