Introduce wp_get_mime_types() for fetching the complete list of mime types. Remove the static caching of the types so that filters other than the first filter work. Use wp_get_mime_types() in do_enclose(). fixes #21299 #21594

git-svn-id: http://core.svn.wordpress.org/trunk@21541 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-08-17 17:25:19 +00:00
parent 9b3bb27a48
commit 02dc348b57
1 changed files with 101 additions and 92 deletions

View File

@ -458,7 +458,7 @@ function do_enclose( $content, $post_ID ) {
if ( false !== $url_parts ) {
$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
if ( !empty( $extension ) ) {
foreach ( get_allowed_mime_types( ) as $exts => $mime ) {
foreach ( wp_get_mime_types() as $exts => $mime ) {
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
$type = $mime;
break;
@ -1754,19 +1754,18 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
}
/**
* Retrieve list of allowed mime types and file extensions.
* Retrieve list of mime types and file extensions.
*
* @since 2.8.6
* @since 3.5.0
*
* @uses apply_filters() Calls 'mime_types' on returned array. This filter should
* be used to add types, not remove them. To remove types use the upload_mimes filter.
*
* @uses apply_filters() Calls 'upload_mimes' on returned array
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function get_allowed_mime_types() {
static $mimes = false;
if ( !$mimes ) {
function wp_get_mime_types() {
// Accepted MIME types are set here as PCRE unless provided.
$mimes = apply_filters( 'upload_mimes', array(
return apply_filters( 'mime_types', array(
// Image formats
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
@ -1851,8 +1850,18 @@ function get_allowed_mime_types() {
'wp|wpd' => 'application/wordperfect',
) );
}
return $mimes;
/**
* Retrieve list of allowed mime types and file extensions.
*
* @since 2.8.6
*
* @uses apply_filters() Calls 'upload_mimes' on returned array
* @uses wp_get_upload_mime_types() to fetch the list of mime types
*
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function get_allowed_mime_types() {
return apply_filters( 'upload_mimes', wp_get_mime_types() );
}
/**