wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_match_mime_types › WordPress Function
Seit2.5.0
Veraltetn/v
› wp_match_mime_types ( $wildcard_mime_types, $real_mime_types )
| Parameter: (2) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
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.Ähnliche Funktionen: wp_get_mime_types, wp_post_mime_type_where, _wp_batch_update_comment_type, wp_is_heic_image_mime_type, wp_mime_type_icon
Quellcode
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 ( ! str_contains( $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;
}