media_upload_library_form( array $errors )
- Since
- 2.5.0
- Source
wp-admin/includes/media.php:2736
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
$errorsarray
Performance profile
How much work a call to media_upload_library_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
- Heavy
- Scaling
- Scales with input
- Instructions
- 248–293
- Plugin surface
- 2 hooks
- Called by
- 0
Reaches the database via ->get_results().
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 440.
Third-party callbacks on 'media_upload_form_url', 'media_upload_mime_type_links' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - sqldatabase query
->get_results()called directly - cacheobject cache
wp_cache_get()one call below media_upload_library_form() - querycontent query
get_post()one call below media_upload_library_form()
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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost media_upload_library_form() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) && !get_user_setting() && !isset($q) | 248–269 | media_upload_header(), admin_url(), apply_filters(), get_user_setting(), wp_edit_attachments_query(), esc_attr(), esc_attr(), _e(), the_search_query(), __(), submit_button(), wp_count_attachments(), array_keys(), array_keys(), wp_match_mime_types(), add_query_arg(), esc_url(), __(), apply_filters(), add_query_arg(), __(), __(), ceil(), base(), ->get_results(), __(), submit_button(), esc_url(), wp_nonce_field(), add_filter(), get_media_items(), __(), submit_button() |
!isset($value) && !get_user_setting() && !isset($q) && empty($value) && !empty($num_posts[$type]) | 260–279 | media_upload_header(), admin_url(), apply_filters(), get_user_setting(), wp_edit_attachments_query(), esc_attr(), esc_attr(), _e(), the_search_query(), __(), submit_button(), wp_count_attachments(), array_keys(), array_keys(), wp_match_mime_types(), wp_edit_attachments_query(), add_query_arg(), esc_url(), __(), apply_filters(), add_query_arg(), __(), __(), ceil(), base(), ->get_results(), __(), submit_button(), esc_url(), wp_nonce_field(), add_filter(), get_media_items(), __(), submit_button() |
!isset($value) && !get_user_setting() && !isset($q) && $months | 263–283 | media_upload_header(), admin_url(), apply_filters(), get_user_setting(), wp_edit_attachments_query(), esc_attr(), esc_attr(), _e(), the_search_query(), __(), submit_button(), wp_count_attachments(), array_keys(), array_keys(), wp_match_mime_types(), add_query_arg(), esc_url(), __(), apply_filters(), add_query_arg(), __(), __(), ceil(), base(), ->get_results(), selected(), _e(), __(), submit_button(), esc_url(), wp_nonce_field(), add_filter(), get_media_items(), __(), submit_button() |
!isset($value) && !get_user_setting() && !isset($q) && empty($value) && !empty($num_posts[$type]) && $months | 275–293 | media_upload_header(), admin_url(), apply_filters(), get_user_setting(), wp_edit_attachments_query(), esc_attr(), esc_attr(), _e(), the_search_query(), __(), submit_button(), wp_count_attachments(), array_keys(), array_keys(), wp_match_mime_types(), wp_edit_attachments_query(), add_query_arg(), esc_url(), __(), apply_filters(), add_query_arg(), __(), __(), ceil(), base(), ->get_results(), selected(), _e(), __(), submit_button(), esc_url(), wp_nonce_field(), add_filter(), get_media_items(), __(), submit_button() |
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 | 440 | 248–293 | 29 | |
| 8.5 | 440 | 248–293 | 29 | |
| 8.4 | 440 | 248–293 | 29 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 443 | 251–296 | 29 | |
| 8.2 | 443 | 251–296 | 29 | 1 fewer instruction than PHP 8.1 |
| 8.1 | 444 | 252–297 | 29 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 447 | 252–298 | 29 |
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 · 2
2 hooks fire while media_upload_library_form() runs, in this order:
- apply_filters( media_upload_form_url )filterline 2745 (+9 into the body)
Filters the media upload form action URL.
- apply_filters( media_upload_mime_type_links )filterline 2846 (+110 into the body)
Filters the media upload mime type list items.
Uses · 23
- media_upload_header()Outputs the legacy media upload header.
- admin_url()Retrieves the URL to the admin area for the current site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_user_setting()Retrieves user interface setting value based on setting name.
- 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.
- esc_attr()Escaping for HTML attributes.
- _e()Displays translated text.
- the_search_query()Displays the contents of the search query variable.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
- __()Retrieves the translation of $text.
- wp_count_attachments()Counts number of attachments for the mime type(s).
- wp_match_mime_types()Checks a MIME-Type against a list.
Show all 23
- esc_url()Checks and cleans a URL.
- add_query_arg()Retrieves a modified URL query string.
- translate_nooped_plural()Translates and returns the singular or plural form of a string that's been registered with _n_noop() or _nx_noop().
- number_format_i18n()Converts float number to format based on the locale.
- paginate_links()Retrieves paginated links for archive post pages.
- selected()Outputs the HTML selected attribute.
- zeroise()Add leading zeros when necessary.
- esc_html()Escaping for HTML blocks.
- wp_nonce_field()Retrieves or display nonce hidden field for forms.
- add_filter()Adds a callback function to a filter hook.
- get_media_items()Retrieves HTML for media items of post gallery.
Source code
function media_upload_library_form( $errors ) { global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; media_upload_header(); $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; $form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" ); /** This filter is documented in wp-admin/includes/media.php */ $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); $form_class = 'media-upload-form validate'; if ( get_user_setting( 'uploader' ) ) { $form_class .= ' html-uploader'; } $q = $_GET; $q['posts_per_page'] = 10; $q['paged'] = isset( $q['paged'] ) ? (int) $q['paged'] : 0; if ( $q['paged'] < 1 ) { $q['paged'] = 1; } $q['offset'] = ( $q['paged'] - 1 ) * 10; if ( $q['offset'] < 1 ) { $q['offset'] = 0; } list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); ?> <form id="filter" method="get"> <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> <p id="media-search" class="search-box"> <label class="screen-reader-text" for="media-search-input"> <?php /* translators: Hidden accessibility text. */ _e( 'Search Media:' ); ?> </label> <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> <?php submit_button( __( 'Search Media' ), '', '', false ); ?> </p> <ul class="subsubsub"> <?php $type_links = array(); $_num_posts = (array) wp_count_attachments(); $matches = wp_match_mime_types( array_keys( $post_mime_types ), array_keys( $_num_posts ) ); foreach ( $matches as $_type => $reals ) { foreach ( $reals as $real ) { if ( isset( $num_posts[ $_type ] ) ) { $num_posts[ $_type ] += $_num_posts[ $real ]; } else { $num_posts[ $_type ] = $_num_posts[ $real ]; } } } // If available type specified by media button clicked, filter by that type. if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { $_GET['post_mime_type'] = $type; list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); } if ( empty( $_GET['post_mime_type'] ) || 'all' === $_GET['post_mime_type'] ) { $class = ' class="current"'; } else { $class = ''; } $type_links[] = '<li><a href="' . esc_url( add_query_arg( array( 'post_mime_type' => 'all', 'paged' => false, 'm' => false, ) )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.0.4 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.