wp_mime_type_icon( string|int $mime = 0, string $preferred_ext = '.png' ): string|false
- Since
- 2.1.0, 6.5.0
- Source
wp-includes/post.php:7043
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$mimestring|intoptional- MIME type or attachment ID.Default:
0 $preferred_extstringoptional- File format to prefer in return. Default '.png'.Default:
'.png'
Return value
string|false- Icon, false otherwise.
Performance profile
How much work a call to wp_mime_type_icon() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 16–153
- Plugin surface
- 4 hooks
- Called by
- 5
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 244.
Third-party callbacks on 'icon_dir', 'icon_dir_uri', 'icon_dirs' run inside this call, and their cost is not bounded by anything here.
5 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_get()called directly - querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 68 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_mime_type_icon() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$mime && !empty($icon) | 16–20 | apply_filters() |
!$mime && !empty($icon) | 21–25 | wp_cache_get(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && !empty($icon) | 25 | strtolower(), apply_filters() |
!$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && !empty($icon) | 30 | wp_cache_get(), strtolower(), apply_filters() |
empty($icon) && is_array($icon_files) | 44–75 | wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!$mime && empty($icon) && is_array($icon_files) | 49–80 | wp_cache_get(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
$mime && empty($icon) && is_array($icon_files) | 51–82 | get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) | 53–80 | strtolower(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && is_array($icon_files) | 56–87 | wp_cache_get(), get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) | 58–85 | wp_cache_get(), strtolower(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) | 60–87 | strtolower(), get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 61–80 | wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
56 further outcomes, up to 153 instructions
$mime && empty($icon) && empty($ext) && is_array($icon_files) | 62–93 | get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) | 65–92 | wp_cache_get(), strtolower(), get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!$mime && empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 66–85 | wp_cache_get(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && empty($ext) && is_array($icon_files) | 67–98 | wp_cache_get(), get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 68–87 | get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && empty($icon) && !empty($ext) && is_array($icon_files) | 69–102 | get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 70–85 | strtolower(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && is_array($icon_files) | 71–98 | strtolower(), get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 73–92 | wp_cache_get(), get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && !empty($ext) && is_array($icon_files) | 74–107 | wp_cache_get(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 75–90 | wp_cache_get(), strtolower(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && is_array($icon_files) | 76–103 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 77–92 | strtolower(), get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && is_array($icon_files) | 78–107 | strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 79–98 | get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && !is_array($icon_files) | 79–111 | wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 82–97 | wp_cache_get(), strtolower(), get_post(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && is_array($icon_files) | 83–112 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 84–103 | wp_cache_get(), get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!$mime && empty($icon) && !is_array($icon_files) | 84–116 | wp_cache_get(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && !empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 86–107 | get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && empty($icon) && !is_array($icon_files) | 86–118 | get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 88–103 | strtolower(), get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) | 88–116 | strtolower(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && !empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 91–112 | wp_cache_get(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && !is_array($icon_files) | 91–123 | wp_cache_get(), get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 93–108 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) | 93–121 | wp_cache_get(), strtolower(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 95–112 | strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) | 95–123 | strtolower(), get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 96–116 | wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && empty($icon) && empty($ext) && !is_array($icon_files) | 97–129 | get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 100–117 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) | 100–128 | wp_cache_get(), strtolower(), get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!$mime && empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 101–121 | wp_cache_get(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && empty($ext) && !is_array($icon_files) | 102–134 | wp_cache_get(), get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 103–123 | get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && empty($icon) && !empty($ext) && !is_array($icon_files) | 104–138 | get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 105–121 | strtolower(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && !is_array($icon_files) | 106–134 | strtolower(), get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 108–128 | wp_cache_get(), get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && !empty($ext) && !is_array($icon_files) | 109–143 | wp_cache_get(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 110–126 | wp_cache_get(), strtolower(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && !is_array($icon_files) | 111–139 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 112–128 | strtolower(), get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
$mime && !empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && !is_array($icon_files) | 113–143 | strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 114–134 | get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 117–133 | wp_cache_get(), strtolower(), get_post(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && !is_array($icon_files) | 118–148 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), apply_filters() |
empty($icon) && empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 119–139 | wp_cache_get(), get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && !empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 121–143 | get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 123–139 | strtolower(), get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
empty($icon) && !empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 126–148 | wp_cache_get(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 128–144 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 130–148 | strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
!empty($preferred_ext) && is_string($preferred_ext) && !$preferred_ext && empty($icon) && !empty($ext) && !is_array($icon_files) && !$matches && !$wilds && isset($types[$wild]) | 135–153 | wp_cache_get(), strtolower(), get_post(), get_attached_file(), wp_ext2type(), wp_cache_get(), apply_filters(), includes_url(), apply_filters(), wp_cache_add(), array_keys(), wp_match_mime_types(), wp_cache_add(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 244 | 16–153 | 27 | |
| 8.5 | 244 | 16–153 | 27 | |
| 8.4 | 244 | 16–153 | 27 | 37 fewer instructions than PHP 8.3 |
| 8.3 | 281 | 18–181 | 27 | |
| 8.2 | 281 | 18–181 | 27 | 1 more instruction than PHP 8.1 |
| 8.1 | 280 | 18–181 | 27 | |
| 7.4 | 280 | 18–181 | 27 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 4
4 hooks fire while wp_mime_type_icon() runs, in this order:
- apply_filters( icon_dirs )filterline 7106 (+63 into the body)
Filters the array of icon directory URIs.
Uses · 10
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- get_post()Retrieves post data given a post ID or post object.
- get_attached_file()Retrieves attached file path based on attachment ID.
- wp_ext2type()Retrieves the file type based on the extension name.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- includes_url()Retrieves the URL to the includes directory.
- wp_basename()i18n-friendly version of basename().
- wp_cache_add()Adds data to the cache, if the cache key doesn't already exist.
- wp_match_mime_types()Checks a MIME-Type against a list.
Used by · 5
- WP_Customize_Media_Control::to_json()Refresh the parameters passed to the JavaScript via JSON.
- get_attachment_icon_src()Retrieve icon URL and Path.
- wp_get_attachment_image_src()Retrieves an image to represent an attachment.
- wp_playlist_shortcode()Builds the Playlist shortcode output.
- wp_prepare_attachment_for_js()Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.
Source code
function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) { if ( ! is_numeric( $mime ) ) { $icon = wp_cache_get( "mime_type_icon_$mime" ); } // Check if preferred file format variable is present and is a validly formatted file extension. if ( ! empty( $preferred_ext ) && is_string( $preferred_ext ) && ! str_starts_with( $preferred_ext, '.' ) ) { $preferred_ext = '.' . strtolower( $preferred_ext ); } $post_id = 0; if ( empty( $icon ) ) { $post_mimes = array(); if ( is_numeric( $mime ) ) { $mime = (int) $mime; $post = get_post( $mime ); if ( $post ) { $post_id = (int) $post->ID; $file = get_attached_file( $post_id ); $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $file ); if ( ! empty( $ext ) ) { $post_mimes[] = $ext; $ext_type = wp_ext2type( $ext ); if ( $ext_type ) { $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 ) ) { /** * Filters the icon directory path. * * @since 2.0.0 * * @param string $path Icon directory absolute path. */ $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); /** * Filters the icon directory URI. * * @since 2.0.0 * * @param string $uri Icon directory URI. */ $icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url( 'images/media' ) ); /** * Filters the array of icon directory URIs. * * @since 2.5.0 * * @param string[] $uris Array of icon directory URIs keyed by directory absolute path. */ $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) ); $icon_files = array(); $all_icons = array(); while ( $dirs ) { $keys = array_keys( $dirs ); $dir = array_shift( $keys ); $uri = array_shift( $dirs ); $dh = opendir( $dir ); if ( $dh ) { while ( false !== $file = readdir( $dh ) ) { $file = wp_basename( $file ); if ( str_starts_with( $file, '.' ) ) { continue; } $ext = strtolower( substr( $file, -4 ) ); if ( ! in_array( $ext, array( '.svg', '.png', '.gif', '.jpg' ), true ) ) {Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$preferred_ext parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.