wp_mime_type_icon [ WordPress Function ]
wp_mime_type_icon ( $mime = 0 )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: wp_match_mime_types, wp_post_mime_type_where, wp_image_editor, get_post_mime_type, get_post_mime_types
Retrieve the icon for a MIME type.
Source
<?php
function wp_mime_type_icon( $mime = 0 ) {
if ( !is_numeric($mime) )
$icon = wp_cache_get("mime_type_icon_$mime");
if ( empty($icon) ) {
$post_id = 0;
$post_mimes = array();
if ( is_numeric($mime) ) {
$mime = (int) $mime;
if ( $post =& get_post( $mime ) ) {
$post_id = (int) $post->ID;
$ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
if ( !empty($ext) ) {
$post_mimes[] = $ext;
if ( $ext_type = wp_ext2type( $ext ) )
$post_mimes[] = $ext_type;
}
$mime = $post->post_mime_type;
} else {
$mime = 0;
}
} else {
$post_mimes[] = $mime;
}
$icon_files = wp_cache_get('icon_files');
if ( !is_array($icon_files) ) {
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
$icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url('images/crystal') );
$dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) );
$icon_files = array();
while ( $dirs ) {
$keys = array_keys( $dirs );
$dir = array_shift( $keys );
$uri = array_shift($dirs);
if ( $dh = opendir($dir) ) {
while ( false !== $file = readdir($dh) ) {
$file = basename($file);
if ( substr($file, 0, 1) == '.' )
continue;
if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) {
if ( is_dir("$dir/$file") )
$dirs["$dir/$file"] = "$uri/$file";
continue;
}
$icon_files["$dir/$file"] = "$uri/$file";
}
closedir($dh);
}
}
wp_cache_set('icon_files', $icon_files, 600);
}
// Icon basename - extension = MIME wildcard
foreach ( $icon_files as $file => $uri )
$types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file];
if ( ! empty($mime) ) {
$post_mimes[] = substr($mime, 0, strpos($mime, '/'));
$post_mimes[] = substr($mime, strpos($mime, '/') + 1);
$post_mimes[] = str_replace('/', '_', $mime);
}
$matches = wp_match_mime_types(array_keys($types), $post_mimes);
$matches['default'] = array('default');
foreach ( $matches as $match => $wilds ) {
if ( isset($types[$wilds[0]])) {
$icon = $types[$wilds[0]];
if ( !is_numeric($mime) )
wp_cache_set("mime_type_icon_$mime", $icon);
break;
}
}
}
return apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id ); // Last arg is 0 if function pass mime type.
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp mime type icon « WordPress Codex
Function Reference/wp mime type icon ... <?php wp_mime_type_icon( $mime ) ? > ... Uses: apply_filters calls 'wp_mime_type_icon' on $icon, $mime and $ ...
codex.wordpress.org - #6751 (wp_mime_type_icon() no longer supports custom media ...
Support for custom media icons, as described here, has been gutted from wp_mime_type_icon(). The crystal icons are hard coded. ADDITIONAL DETAILS (to ...
core.trac.wordpress.org - wp_mime_type_icon Wordpress hook details -- Adam Brown, BYU ...
Applied to the MIME type icon for an attachment calculated by the wp_mime_type_icon function. Filter function arguments: icon URI calculated, MIME type, post ...
adambrown.info - wp_mime_type_icon | A HitchHackers guide through WordPress
Feb 12, 2011 ... function wp_mime_type_icon( $mime = 0 ) { if ( !is_numeric($mime) ) $icon = wp_cache_get("mime_type_icon_$mime"); if ( empty($icon) ) ...
hitchhackerguide.com