get_allowed_mime_types( int|WP_User $user = null ): string[]
- Since
- 2.8.6
- Source
wp-includes/functions.php:3693
Compatibility
- WordPress
- since 2.8.6
- 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
$userint|WP_Useroptional- User to check. Defaults to current user.Default:
null
Return value
string[]- Array of mime types keyed by the file extension regex corresponding to those types.
Performance profile
How much work a call to get_allowed_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
- Trivial
- Scaling
- Constant
- Instructions
- 18–28
- Plugin surface
- 1 hook
- Called by
- 10
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 32.
Third-party callbacks on 'upload_mimes' run inside this call, and their cost is not bounded by anything here.
10 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. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_allowed_mime_types() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!function_exists() | 18–20 | wp_get_mime_types(), function_exists(), apply_filters() |
function_exists() | 24–26 | wp_get_mime_types(), function_exists(), current_user_can(), apply_filters() |
function_exists() | 26–28 | wp_get_mime_types(), function_exists(), user_can(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 30 | 18–27 | 3 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 32 | 18–28 | 3 | |
| 8.4 | 32 | 18–28 | 3 | |
| 8.3 | 32 | 18–28 | 3 | |
| 8.2 | 32 | 18–28 | 3 | |
| 8.1 | 32 | 18–28 | 3 | |
| 7.4 | 32 | 18–28 | 3 |
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_allowed_mime_types() runs, in this order:
- apply_filters( upload_mimes )filterline 3713 (+20 into the body)
Filters the list of allowed mime types and file extensions.
Uses · 4
- wp_get_mime_types()Retrieves the list of mime types and file extensions.
- user_can()Returns whether a particular user has the specified capability.
- current_user_can()Returns whether the current user has the specified capability.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 10
- WP_REST_Attachments_Controller::get_media_types()Retrieves the supported media types.
- atom_enclosure()Displays the atom enclosure for the current post.
- download_url()Downloads a URL to a local temporary file using the WordPress HTTP API.
- get_default_block_editor_settings()Returns the default block editor settings.
- populate_network_meta()Creates WordPress network meta and sets the default values.
- sanitize_file_name()Sanitizes a filename, replacing whitespace with dashes.
- wp_check_filetype()Retrieves the file type from the file name.
- wp_check_filetype_and_ext()Attempts to determine the real file type of a file.
- wp_enqueue_media()Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.
- wp_plupload_default_settings()Prints default Plupload arguments.
Source code
function get_allowed_mime_types( $user = null ) { $t = wp_get_mime_types(); unset( $t['swf'], $t['exe'] ); if ( function_exists( 'current_user_can' ) ) { $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' ); } if ( empty( $unfiltered ) ) { unset( $t['htm|html'], $t['js'] ); } /** * Filters the list of allowed mime types and file extensions. * * @since 2.0.0 * * @param array $t Mime types keyed by the file extension regex corresponding to those types. * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user). */ return apply_filters( 'upload_mimes', $t, $user );}Changelog
Introduced in 2.8.6. 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/functions.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.