wppaste
WordPress

wp_iframe( callable $content_func, mixed $args )

Since
2.5.0, 5.3.0
Source
wp-admin/includes/media.php:535
Outputs the iframe to display the media upload page.

Compatibility

WordPress
since 5.3.0
PHP
7.4–8.6-dev
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$content_funccallable
Function that outputs the content.
$argsmixed
Optional additional parameters to pass to the callback function when it's called.

Performance profile

How much work a call to wp_iframe() 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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

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

Instructions
79–97

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

Plugin surface
9 hooks

Third-party callbacks on 'admin_enqueue_scripts', 'admin_print_styles-media-upload-popup', 'admin_print_styles' run inside this call, and their cost is not bounded by anything here.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly
  • optionoption read or writeget_option()one call below wp_iframe()

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

WhenInstructionsCalls it makes
!is_string($content_func)79–90_wp_admin_html_begin(), bloginfo(), _e(), _e(), wp_enqueue_style(), admin_url(), esc_js(), is_rtl(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), call_user_func_array(), do_action()
is_string($content_func)83–94_wp_admin_html_begin(), bloginfo(), _e(), _e(), wp_enqueue_style(), admin_url(), esc_js(), is_rtl(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), call_user_func_array(), do_action()
!is_string($content_func)84–93_wp_admin_html_begin(), bloginfo(), _e(), _e(), wp_enqueue_style(), wp_enqueue_style(), admin_url(), esc_js(), is_rtl(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), call_user_func_array(), do_action()
is_string($content_func)88–97_wp_admin_html_begin(), bloginfo(), _e(), _e(), wp_enqueue_style(), wp_enqueue_style(), admin_url(), esc_js(), is_rtl(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), do_action(), call_user_func_array(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev9779–977
8.59779–977
8.49779–9776 fewer instructions than PHP 8.3
8.310379–1037
8.210379–1037
8.110379–10371 more instruction than PHP 7.4
7.410278–1027

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 · 9

9 hooks fire while wp_iframe() runs, in this order:

  1. do_action( admin_enqueue_scripts )actionline 560 (+25 into the body)

    Fires when enqueuing scripts for all admin pages.

  2. do_action( admin_print_styles-media-upload-popup )actionline 567 (+32 into the body)

    Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.

  3. do_action( admin_print_styles )actionline 570 (+35 into the body)

    Fires when styles are printed for all admin pages.

  4. do_action( admin_print_scripts-media-upload-popup )actionline 577 (+42 into the body)

    Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed.

  5. do_action( admin_print_scripts )actionline 580 (+45 into the body)

    Fires when scripts are printed for all admin pages.

  6. do_action( admin_head-media-upload-popup )actionline 588 (+53 into the body)

    Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) media upload popup are printed.

  7. do_action( admin_head )actionline 591 (+56 into the body)

    Fires in head section for all admin pages.

  8. do_action( admin_head_{$content_func} )actionline 603 (+68 into the body)

    Fires in the admin header for each specific form tab in the legacy (pre-3.5.0) media upload popup.

  9. do_action( admin_print_footer_scripts )actionline 623 (+88 into the body)

    Prints any scripts and data queued for the footer.

Uses · 9

  • _wp_admin_html_begin()Prints out the beginning of the admin HTML header.
  • bloginfo()Displays information about the current site.
  • _e()Displays translated text.
  • wp_enqueue_style()Enqueues a CSS stylesheet.
  • str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
  • esc_js()Escapes single quotes, `"`, ``, `&`, and fixes line endings.
  • admin_url()Retrieves the URL to the admin area for the current site.
  • is_rtl()Determines whether the current locale is right-to-left (RTL).
  • do_action()Calls the callback functions that have been added to an action hook.

Used by · 3

Source code

function wp_iframe( $content_func, ...$args ) {	global $body_id; 	_wp_admin_html_begin();	?>	<title><?php bloginfo( 'name' ); ?> &rsaquo; <?php _e( 'Uploads' ); ?> &#8212; <?php _e( 'WordPress' ); ?></title>	<?php 	wp_enqueue_style( 'colors' );	// Check callback name for 'media'.	if (		( is_array( $content_func ) && ! empty( $content_func[1] ) && str_starts_with( (string) $content_func[1], 'media' ) ) ||		( ! is_array( $content_func ) && str_starts_with( $content_func, 'media' ) )	) {		wp_enqueue_style( 'deprecated-media' );	} 	?>	<script type="text/javascript">	addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};	var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',	isRtl = <?php echo (int) is_rtl(); ?>;	</script>	<?php	/** This action is documented in wp-admin/admin-header.php */	do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); 	/**	 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.	 *	 * @since 2.9.0	 */	do_action( 'admin_print_styles-media-upload-popup' );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 	/** This action is documented in wp-admin/admin-header.php */	do_action( 'admin_print_styles' ); 	/**	 * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed.	 *	 * @since 2.9.0	 */	do_action( 'admin_print_scripts-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 	/** This action is documented in wp-admin/admin-header.php */	do_action( 'admin_print_scripts' ); 	/**	 * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0)	 * media upload popup are printed.	 *	 * @since 2.9.0	 */	do_action( 'admin_head-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 	/** This action is documented in wp-admin/admin-header.php */	do_action( 'admin_head' ); 	if ( is_string( $content_func ) ) {		/**		 * Fires in the admin header for each specific form tab in the legacy		 * (pre-3.5.0) media upload popup.		 *		 * The dynamic portion of the hook name, `$content_func`, refers to the form		 * callback for the media upload type.		 *		 * @since 2.5.0		 */		do_action( "admin_head_{$content_func}" );	} 	$body_id_attr = ''; 	if ( isset( $body_id ) ) {		$body_id_attr = ' id="' . $body_id . '"';	} 	?>	</head>	<body<?php echo $body_id_attr; ?> class="wp-core-ui no-js">

Changelog

Introduced in 2.5.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

5.3.0
Formalized the existing and already documented ...$args parameter by adding it to the function signature.from the docblock
2.5.0
Introduced.from the docblock

About this page

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