get_post_mime_types(): array
- Since
- 2.9.0, 5.3.0
- Source
wp-includes/post.php:3602
Compatibility
- WordPress
- since 5.3.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.
Return value
array- List of post mime types.
Performance profile
How much work a call to get_post_mime_types() 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
- Light
- Scaling
- Scales with input
- Instructions
- 101–102
- Plugin surface
- 1 hook
- Called by
- 4
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 134.
Third-party callbacks on 'post_mime_types' run inside this call, and their cost is not bounded by anything here.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, option, cache, 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_post_mime_types() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 101–102 | __(), __(), _n_noop(), _x(), __(), _n_noop(), _x(), __(), _n_noop(), __(), __(), _n_noop(), __(), __(), _n_noop(), _x(), __(), _n_noop(), wp_get_ext_types(), wp_get_mime_types(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 134 | 101–102 | 9 | |
| 8.5 | 134 | 101–102 | 9 | |
| 8.4 | 134 | 101–102 | 9 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 140 | 101–102 | 9 | |
| 8.2 | 140 | 101–102 | 9 | |
| 8.1 | 140 | 101–102 | 9 | |
| 7.4 | 140 | 101–102 | 9 |
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 · 1
One hook fires while get_post_mime_types() runs, in this order:
- apply_filters( post_mime_types )filterline 3695 (+93 into the body)
Filters the default list of post mime types.
Uses · 6
- __()Retrieves the translation of $text.
- _n_noop()Registers plural strings in POT file, but does not translate them.
- _x()Retrieves translated string with gettext context.
- wp_get_ext_types()Retrieves the list of common file extensions and their types.
- wp_get_mime_types()Retrieves the list of mime types and file extensions.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 4
- get_media_item()Retrieves HTML form for modifying the image attachment.
- wp_edit_attachments_query()Executes a query for attachments. An array of WP_Query arguments can be passed in, which will override the arguments set by this function.
- wp_edit_attachments_query_vars()Returns the query variables for the current attachments request.
- wp_enqueue_media()Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.
Source code
function get_post_mime_types() { $post_mime_types = array( // array( adj, noun ) 'image' => array( __( 'Images' ), __( 'Manage Images' ), /* translators: %s: Number of images. */ _n_noop( 'Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>' ), ), 'audio' => array( _x( 'Audio', 'file type group' ), __( 'Manage Audio' ), /* translators: %s: Number of audio files. */ _n_noop( 'Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>' ), ), 'video' => array( _x( 'Video', 'file type group' ), __( 'Manage Video' ), /* translators: %s: Number of video files. */ _n_noop( 'Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>' ), ), 'document' => array( __( 'Documents' ), __( 'Manage Documents' ), /* translators: %s: Number of documents. */ _n_noop( 'Document <span class="count">(%s)</span>', 'Documents <span class="count">(%s)</span>' ), ), 'spreadsheet' => array( __( 'Spreadsheets' ), __( 'Manage Spreadsheets' ), /* translators: %s: Number of spreadsheets. */ _n_noop( 'Spreadsheet <span class="count">(%s)</span>', 'Spreadsheets <span class="count">(%s)</span>' ), ), 'archive' => array( _x( 'Archives', 'file type group' ), __( 'Manage Archives' ), /* translators: %s: Number of archives. */ _n_noop( 'Archive <span class="count">(%s)</span>', 'Archives <span class="count">(%s)</span>' ), ), ); $ext_types = wp_get_ext_types(); $mime_types = wp_get_mime_types(); foreach ( $post_mime_types as $group => $labels ) { if ( in_array( $group, array( 'image', 'audio', 'video' ), true ) ) { continue; } if ( ! isset( $ext_types[ $group ] ) ) { unset( $post_mime_types[ $group ] ); continue; } $group_mime_types = array(); foreach ( $ext_types[ $group ] as $extension ) { foreach ( $mime_types as $exts => $mime ) { if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { $group_mime_types[] = $mime; break; } } }Changelog
Introduced in 2.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.