wp_match_mime_types
函数
wp_match_mime_types ( $wildcard_mime_types, $real_mime_types )
- 参数
-
-
(string|string[])
$wildcard_mime_types
Mime types, e.g. `audio/mpeg`, `image` (same as `image/*`), or `flash` (same as `*flash*`).- Required: 是
-
(string|string[])
$real_mime_types
Real post mime type values.- Required: 是
-
(string|string[])
- 返回值
-
- (array) array(wildcard=>array(real types)).
- 定义位置
-
-
wp-includes/post.php
, line 3242
-
wp-includes/post.php
- 引入
- 2.5.0
- 弃用
- –
Checks a MIME-Type against a list.
If the `$wildcard_mime_types` parameter is a string, it must be comma separated
list. If the `$real_mime_types` is a string, it is also comma separated to
create the list.
function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
$matches = array();
if ( is_string( $wildcard_mime_types ) ) {
$wildcard_mime_types = array_map( 'trim', explode( ',', $wildcard_mime_types ) );
}
if ( is_string( $real_mime_types ) ) {
$real_mime_types = array_map( 'trim', explode( ',', $real_mime_types ) );
}
$patternses = array();
$wild = '[-._a-z0-9]*';
foreach ( (array) $wildcard_mime_types as $type ) {
$mimes = array_map( 'trim', explode( ',', $type ) );
foreach ( $mimes as $mime ) {
$regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
$patternses[][ $type ] = "^$regex$";
if ( false === strpos( $mime, '/' ) ) {
$patternses[][ $type ] = "^$regex/";
$patternses[][ $type ] = $regex;
}
}
}
asort( $patternses );
foreach ( $patternses as $patterns ) {
foreach ( $patterns as $type => $pattern ) {
foreach ( (array) $real_mime_types as $real ) {
if ( preg_match( "#$pattern#", $real )
&& ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ], true ) )
) {
$matches[ $type ][] = $real;
}
}
}
}
return $matches;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。