返回介绍

wp_match_mime_types()

发布于 2017-09-11 12:24:19 字数 3113 浏览 968 评论 0 收藏 0

wp_match_mime_types( string|array $wildcard_mime_types,  string|array $real_mime_types )

Check a MIME-Type against a list.


description

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.


参数

$wildcard_mime_types

(string|array) (Required) Mime types, e.g. audio/mpeg or image (same as image/*) or flash (same as *flash*).

$real_mime_types

(string|array) (Required) Real post mime type values.


返回值

(array) array(wildcard=>array(real types)).


源代码

File: wp-includes/post.php

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] ) ) ) {
					$matches[$type][] = $real;
				}
			}
		}
	}
	return $matches;
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Used By

  • wp-admin/includes/media.php: media_upload_library_form()
  • wp-admin/includes/media.php: get_media_item()
  • wp-admin/includes/ajax-actions.php: wp_ajax_upload_attachment()
  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::get_views()
  • wp-admin/custom-header.php: Custom_Image_Header::step_2_manage_upload()
  • wp-admin/custom-background.php: Custom_Background::handle_upload()
  • wp-includes/post.php: wp_mime_type_icon()
  • Show 2 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文