media_upload_form( array $errors = null )
- Since
- 2.5.0
- Source
wp-admin/includes/media.php:2112
Compatibility
- WordPress
- since 2.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
$errorsarrayoptional- Default:
null
Performance profile
How much work a call to media_upload_form() 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
- Moderate
- Scaling
- Constant
- Instructions
- 40–209
- Plugin surface
- 10 hooks
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 231.
Third-party callbacks on 'upload_ui_over_quota', 'pre-upload-ui', 'upload_post_params' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below media_upload_form() - serializeserialisation
maybe_unserialize()one call below media_upload_form()
Further down the call graph this can also reach transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 15 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost media_upload_form() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
_device_can_upload() && !isset($value) && !isset($errors) && is_multisite() && !is_upload_space_available() | 40–42 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_multisite(), is_upload_space_available(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && !is_wp_error() && is_multisite() && !is_upload_space_available() | 46–48 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), is_multisite(), is_upload_space_available(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && is_wp_error() && is_multisite() && !is_upload_space_available() | 50–52 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), ->get_error_message(), is_multisite(), is_upload_space_available(), do_action() |
_device_can_upload() && !isset($value) && !isset($errors) && !is_multisite() | 170–184 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_multisite(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && !isset($errors) && is_multisite() && is_upload_space_available() | 173–187 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_multisite(), is_upload_space_available(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && !is_wp_error() && !is_multisite() | 176–190 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), is_multisite(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && !isset($errors) && !is_multisite() | 178–196 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_multisite(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), wp_image_editor_supports(), wp_image_editor_supports(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && !is_wp_error() && is_multisite() && is_upload_space_available() | 179–193 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), is_multisite(), is_upload_space_available(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && is_wp_error() && !is_multisite() | 180–194 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), ->get_error_message(), is_multisite(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && !isset($errors) && is_multisite() && is_upload_space_available() | 181–199 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_multisite(), is_upload_space_available(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), wp_image_editor_supports(), wp_image_editor_supports(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && is_wp_error() && is_multisite() && is_upload_space_available() | 183–197 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), ->get_error_message(), is_multisite(), is_upload_space_available(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && !is_wp_error() && !is_multisite() | 184–202 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), is_multisite(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), wp_image_editor_supports(), wp_image_editor_supports(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
3 further outcomes, up to 209 instructions
_device_can_upload() && !isset($value) && isset($errors) && !is_wp_error() && is_multisite() && is_upload_space_available() | 187–205 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), is_multisite(), is_upload_space_available(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), wp_image_editor_supports(), wp_image_editor_supports(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && is_wp_error() && !is_multisite() | 188–206 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), ->get_error_message(), is_multisite(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), wp_image_editor_supports(), wp_image_editor_supports(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
_device_can_upload() && !isset($value) && isset($errors) && is_wp_error() && is_multisite() && is_upload_space_available() | 191–209 | _device_can_upload(), admin_url(), wp_max_upload_size(), is_wp_error(), ->get_error_message(), is_multisite(), is_upload_space_available(), do_action(), wp_create_nonce(), apply_filters(), wp_is_mobile(), apply_filters(), wp_image_editor_supports(), wp_image_editor_supports(), apply_filters(), get_option(), absint(), get_option(), absint(), wp_json_encode(), do_action(), _e(), _ex(), esc_attr_e(), do_action(), do_action(), _ex(), _x(), submit_button(), _e(), do_action(), __(), size_format(), esc_html(), printf(), do_action() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 231 | 40–209 | 18 | |
| 8.5 | 231 | 40–209 | 18 | |
| 8.4 | 231 | 40–209 | 18 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 237 | 40–215 | 18 | |
| 8.2 | 237 | 40–215 | 18 | |
| 8.1 | 237 | 40–215 | 18 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 240 | 40–217 | 18 |
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 · 10
10 hooks fire while media_upload_form() runs, in this order:
- do_action( upload_ui_over_quota )actionline 2161 (+49 into the body)
Fires when an upload will exceed the defined upload space quota for a network site.
- do_action( pre-upload-ui )actionline 2170 (+58 into the body)
Fires just before the legacy (pre-3.5.0) upload interface is loaded.
- apply_filters( upload_post_params )filterline 2188 (+76 into the body)
Filters the media upload post parameters.
- apply_filters( wp_prevent_unsupported_mime_type_uploads )filterline 2218 (+106 into the body)
Filter whether the server should prevent uploads for image types it doesn't support. Default true.
- apply_filters( plupload_init )filterline 2239 (+127 into the body)
Filters the default Plupload settings.
- do_action( pre-plupload-upload-ui )actionline 2270 (+158 into the body)
Fires before the upload interface loads.
- do_action( post-plupload-upload-ui )actionline 2287 (+175 into the body)
Fires after the upload interface loads.
- do_action( pre-html-upload-ui )actionline 2298 (+186 into the body)
Fires before the upload button in the media upload interface.
- do_action( post-html-upload-ui )actionline 2319 (+207 into the body)
Fires after the upload button in the media upload interface.
Uses · 23
- _device_can_upload()Tests if the current device has the capability to upload files.
- __()Retrieves the translation of $text.
- admin_url()Retrieves the URL to the admin area for the current site.
- wp_max_upload_size()Determines the maximum upload size allowed in php.ini.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- is_multisite()Determines whether Multisite is enabled.
- is_upload_space_available()Determines if there is any upload space left in the current blog's quota.
- do_action()Calls the callback functions that have been added to an action hook.
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_is_mobile()Test if the current browser runs on a mobile device (smart phone, tablet, etc.).
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
Show all 23
- wp_image_editor_supports()Tests whether there is an editor that supports a given mime type or methods.
- absint()Converts a value to non-negative integer.
- get_option()Retrieves an option value based on an option name.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- _e()Displays translated text.
- _ex()Displays translated string with gettext context.
- esc_attr_e()Displays translated text that has been escaped for safe use in an attribute.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
- _x()Retrieves translated string with gettext context.
- esc_html()Escaping for HTML blocks.
- size_format()Converts a number of bytes to the largest unit the bytes will fit into.
Used by · 1
- media_upload_type_form()Outputs the legacy media upload form for a given media type.
Source code
function media_upload_form( $errors = null ) { global $type, $tab; if ( ! _device_can_upload() ) { echo '<p>' . sprintf( /* translators: %s: https://apps.wordpress.org/ */ __( 'The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.' ), 'https://apps.wordpress.org/' ) . '</p>'; return; } $upload_action_url = admin_url( 'async-upload.php' ); $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; $_type = $type ?? ''; $_tab = $tab ?? ''; $max_upload_size = wp_max_upload_size(); if ( ! $max_upload_size ) { $max_upload_size = 0; } ?> <div id="media-upload-notice"> <?php if ( isset( $errors['upload_notice'] ) ) { echo $errors['upload_notice']; } ?> </div> <div id="media-upload-error"> <?php if ( isset( $errors['upload_error'] ) && is_wp_error( $errors['upload_error'] ) ) { echo $errors['upload_error']->get_error_message(); } ?> </div> <?php if ( is_multisite() && ! is_upload_space_available() ) { /** * Fires when an upload will exceed the defined upload space quota for a network site. * * @since 3.5.0 */ do_action( 'upload_ui_over_quota' ); return; } /** * Fires just before the legacy (pre-3.5.0) upload interface is loaded. * * @since 2.6.0 */ do_action( 'pre-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores $post_params = array( 'post_id' => $post_id, '_wpnonce' => wp_create_nonce( 'media-form' ), 'type' => $_type, 'tab' => $_tab, 'short' => '1', ); /** * Filters the media upload post parameters. * * @since 3.1.0 As 'swfupload_post_params' * @since 3.3.0 * * @param array $post_params An array of media upload parameters used by Plupload. */ $post_params = apply_filters( 'upload_post_params', $post_params ); /* * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,Changelog
Introduced in 2.5.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-admin/includes/media.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.