WC_Product_Download::is_allowed_filetype()
Check if file is allowed.
Method of the class: WC_Product_Download{}
No Hooks.
Return
true|false
.
Usage
$WC_Product_Download = new WC_Product_Download(); $WC_Product_Download->is_allowed_filetype();
WC_Product_Download::is_allowed_filetype() WC Product Download::is allowed filetype code WC 8.6.1
public function is_allowed_filetype() { $file_path = $this->get_file(); // File types for URL-based files located on the server should get validated. $parsed_file_path = WC_Download_Handler::parse_file_path( $file_path ); $is_file_on_server = ! $parsed_file_path['remote_file']; $file_path_type = $this->get_type_of_file_path( $file_path ); // Shortcodes are allowed, validations should be done by the shortcode provider in this case. if ( 'shortcode' === $file_path_type ) { return true; } // Remote paths are allowed. if ( ! $is_file_on_server && 'relative' !== $file_path_type ) { return true; } // On windows system, local files ending with `.` are not allowed. // @link https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#naming-conventions. if ( $is_file_on_server && ! $this->get_file_extension() && 'WIN' === strtoupper( substr( Constants::get_constant( 'PHP_OS' ), 0, 3 ) ) ) { if ( '.' === substr( $file_path, -1 ) ) { return false; } } return ! $this->get_file_extension() || in_array( $this->get_file_type(), $this->get_allowed_mime_types(), true ); }