wppaste
WordPress

media_upload_gallery_form( array $errors )

Since
2.5.0
Source
wp-admin/includes/media.php:2549
Adds gallery form to upload iframe.

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_gallery_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_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
183–184

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

Plugin surface
1 hook

Third-party callbacks on 'media_upload_form_url' 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
  • querycontent queryget_post()one call below media_upload_gallery_form()

Further down the call graph this can also reach 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 media_upload_gallery_form() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always183–184media_upload_header(), admin_url(), apply_filters(), get_user_setting(), _e(), _e(), _e(), _e(), _e(), _e(), _ex(), esc_url(), wp_nonce_field(), _e(), _e(), _e(), add_filter(), get_media_items(), __(), submit_button(), esc_attr(), esc_attr(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_attr_e(), esc_attr_e()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev184183–1841
8.5184183–1841
8.4184183–1841
8.3184183–1841
8.2184183–1841
8.1184183–18412 fewer instructions than PHP 7.4
7.4186185–1861

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 media_upload_gallery_form() runs, in this order:

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

    Filters the media upload form action URL.

Uses · 14

Show all 14
  • esc_attr()Escaping for HTML attributes.
  • esc_attr_e()Displays translated text that has been escaped for safe use in an attribute.

Source code

function media_upload_gallery_form( $errors ) {	global $redir_tab, $type; 	$redir_tab = 'gallery';	media_upload_header(); 	$post_id         = (int) $_REQUEST['post_id'];	$form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&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';	} 	?>	<script type="text/javascript">	jQuery(function($){		var preloaded = $(".media-item.preloaded");		if ( preloaded.length > 0 ) {			preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});			updateMediaForm();		}	});	</script>	<div id="sort-buttons" class="hide-if-no-js">	<span>		<?php _e( 'All Tabs:' ); ?>	<a href="#" id="showall"><?php _e( 'Show' ); ?></a>	<a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a>	</span>		<?php _e( 'Sort Order:' ); ?>	<a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> |	<a href="#" id="desc"><?php _e( 'Descending' ); ?></a> |	<a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a>	</div>	<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">		<?php wp_nonce_field( 'media-form' ); ?>	<table class="widefat">	<thead><tr>	<th><?php _e( 'Media' ); ?></th>	<th class="order-head"><?php _e( 'Order' ); ?></th>	<th class="actions-head"><?php _e( 'Actions' ); ?></th>	</tr></thead>	</table>	<div id="media-items">		<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?>		<?php echo get_media_items( $post_id, $errors ); ?>	</div> 	<p class="ml-submit">		<?php		submit_button(			__( 'Save all changes' ),			'savebutton',			'save',			false,			array(				'id'    => 'save-all',				'style' => 'display: none;',			)		);		?>	<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />	<input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />	<input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />	</p> 	<div id="gallery-settings" style="display:none;">	<div class="title"><?php _e( 'Gallery Settings' ); ?></div>	<table id="basic" class="describe"><tbody>		<tr>		<th scope="row" class="label">			<label>			<span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span>			</label>		</th>		<td class="field">			<input type="radio" name="linkto" id="linkto-file" value="file" />

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.7.7 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.