WC_Product_Download::get_type_of_file_path
Get type of file path set.
Method of the class: WC_Product_Download{}
No Hooks.
Returns
String. absolute, relative, or shortcode.
Usage
$WC_Product_Download = new WC_Product_Download(); $WC_Product_Download->get_type_of_file_path( $file_path );
- $file_path(string)
- optional.
Default:''
WC_Product_Download::get_type_of_file_path() WC Product Download::get type of file path code WC 10.6.2
public function get_type_of_file_path( $file_path = '' ) {
$file_path = $file_path ? $file_path : $this->get_file();
$parsed_url = wp_parse_url( $file_path );
if (
$parsed_url &&
isset( $parsed_url['host'] ) && // Absolute url means that it has a host.
( // Theoretically we could permit any scheme (like ftp as well), but that has not been the case before. So we allow none or http(s).
! isset( $parsed_url['scheme'] ) ||
in_array( $parsed_url['scheme'], array( 'http', 'https' ), true )
)
) {
return 'absolute';
} elseif ( '[' === substr( $file_path, 0, 1 ) && ']' === substr( $file_path, -1 ) ) {
return 'shortcode';
} else {
return 'relative';
}
}