wppaste
WordPress

media_upload_library_form( array $errors )

Since
2.5.0
Source
wp-admin/includes/media.php:2717
Outputs the legacy media upload form for the media library.

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

Reaches the database via ->get_results().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
248–293

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 440.

Plugin surface
2 hooks

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.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • sqldatabase query->get_results()called directly
  • cacheobject cachewp_cache_get()one call below media_upload_library_form()
  • querycontent queryget_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.

WhenInstructionsCalls it makes
!isset($value) && !get_user_setting() && !isset($q)248–269media_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–279media_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) && $months263–283media_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]) && $months275–293media_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

PHPCompiledExecutedBranchesNotes
8.6-dev440248–29329
8.5440248–29329
8.4440248–293293 fewer instructions than PHP 8.3
8.3443251–29629
8.2443251–296291 fewer instruction than PHP 8.1
8.1444252–297293 fewer instructions than PHP 7.4
7.4447252–29829

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:

  1. apply_filters( media_upload_form_url )filterline 2726 (+9 into the body)

    Filters the media upload form action URL.

  2. apply_filters( media_upload_mime_type_links )filterline 2827 (+110 into the body)

    Filters the media upload mime type list items.

Uses · 23

Show all 23

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.