is_elementor_media_upload() && $this->is_enabled() ) { $existing_mimes[ $this->get_file_type() ] = $this->get_mime_type(); } return $existing_mimes; } /** * handle_upload_prefilter * @param $file * * @return mixed */ public function handle_upload_prefilter( $file ) { if ( ! $this->is_file_should_handled( $file ) ) { return $file; } $ext = pathinfo( $file['name'], PATHINFO_EXTENSION ); $file_type = $this->get_file_type(); $display_type = strtoupper( $file_type ); if ( $file_type !== $ext ) { $file['error'] = sprintf( esc_html__( 'The uploaded %1$s file is not supported. Please upload a valid %2$s file', 'elementor' ), $ext, $display_type ); return $file; } if ( ! self::is_enabled() ) { $file['error'] = sprintf( esc_html__( '%1$s file is not allowed for security reasons', 'elementor' ), $display_type ); return $file; } return $file; } protected function is_file_should_handled( $file ) { $ext = pathinfo( $file['name'], PATHINFO_EXTENSION ); return $this->is_elementor_media_upload() && $this->get_file_type() === $ext; } /** * file_sanitizer_can_run * @return bool */ public static function file_sanitizer_can_run() { return class_exists( 'DOMDocument' ) && class_exists( 'SimpleXMLElement' ); } /** * Check filetype and ext * * A workaround for upload validation which relies on a PHP extension (fileinfo) * with inconsistent reporting behaviour. * ref: https://core.trac.wordpress.org/ticket/39550 * ref: https://core.trac.wordpress.org/ticket/40175 * * @param $data * @param $file * @param $filename * @param $mimes * * @return mixed */ public function check_filetype_and_ext( $data, $file, $filename, $mimes ) { if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) { return $data; } $wp_file_type = wp_check_filetype( $filename, $mimes ); $file_type = strtolower( $this->get_file_type() ); if ( $file_type === $wp_file_type['ext'] ) { $data['ext'] = $file_type; $data['type'] = $this->get_mime_type(); } return $data; } }