wppaste
WordPress

wp_widget_control( array $sidebar_args ): array

Since
2.5.0
Source
wp-admin/includes/widgets.php:190
Meta widget used to display the control form for a widget.

Description

Called from dynamic_sidebar().

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

$sidebar_argsarray

Return value

array
Passed through value of $sidebar_args param.

Performance profile

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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
206–232

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

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

What it touches

  • hookthird-party callbacksapply_filters()one call below wp_widget_control()

Further down the call graph this can also reach option, 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 · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_widget_control() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$sidebar_args && !$wp_registered_widget_controls && !$control && !isset($control)206–230strip_tags(), esc_html(), __(), printf(), __(), printf(), add_query_arg(), esc_url(), _ex(), _ex(), __(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), _e(), _e(), __(), esc_attr(), id(), wp_widget_description()
!$sidebar_args && !$wp_registered_widget_controls && !$control && isset($control)208–232strip_tags(), esc_html(), __(), printf(), __(), printf(), add_query_arg(), esc_url(), _ex(), _ex(), call_user_func_array(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), _e(), _e(), __(), esc_attr(), id(), wp_widget_description()

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-dev258206–232221 fewer instruction than PHP 8.5
8.5259206–23222
8.4259206–23222
8.3259206–23222
8.2259206–23222
8.1259206–232221 fewer instruction than PHP 7.4
7.4260207–23222

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.

Uses · 9

Used by · 2

Source code

function wp_widget_control( $sidebar_args ) {	global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets; 	$widget_id  = $sidebar_args['widget_id'];	$sidebar_id = $sidebar_args['id'] ?? false;	$key        = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[ $sidebar_id ], true ) : '-1'; // Position of widget in sidebar.	$control    = $wp_registered_widget_controls[ $widget_id ] ?? array();	$widget     = $wp_registered_widgets[ $widget_id ]; 	$id_format     = $widget['id'];	$widget_number = $control['params'][0]['number'] ?? '';	$id_base       = $control['id_base'] ?? $widget_id;	$width         = $control['width'] ?? '';	$height        = $control['height'] ?? '';	$multi_number  = $sidebar_args['_multi_num'] ?? '';	$add_new       = $sidebar_args['_add'] ?? ''; 	$before_form           = $sidebar_args['before_form'] ?? '<form method="post">';	$after_form            = $sidebar_args['after_form'] ?? '</form>';	$before_widget_content = $sidebar_args['before_widget_content'] ?? '<div class="widget-content">';	$after_widget_content  = $sidebar_args['after_widget_content'] ?? '</div>'; 	$query_arg = array( 'editwidget' => $widget['id'] );	if ( $add_new ) {		$query_arg['addnew'] = 1;		if ( $multi_number ) {			$query_arg['num']  = $multi_number;			$query_arg['base'] = $id_base;		}	} else {		$query_arg['sidebar'] = $sidebar_id;		$query_arg['key']     = $key;	} 	/*	 * We aren't showing a widget control, we're outputting a template	 * for a multi-widget control.	 */	if ( isset( $sidebar_args['_display'] ) && 'template' === $sidebar_args['_display'] && $widget_number ) {		// number == -1 implies a template where id numbers are replaced by a generic '__i__'.		$control['params'][0]['number'] = -1;		// With id_base widget ID's are constructed like {$id_base}-{$id_number}.		if ( isset( $control['id_base'] ) ) {			$id_format = $control['id_base'] . '-__i__';		}	} 	$wp_registered_widgets[ $widget_id ]['callback'] = $wp_registered_widgets[ $widget_id ]['_callback'];	unset( $wp_registered_widgets[ $widget_id ]['_callback'] ); 	$widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) );	$has_form     = 'noform'; 	echo $sidebar_args['before_widget'];	?>	<div class="widget-top">	<div class="widget-title-action">		<button type="button" class="widget-action hide-if-no-js" aria-expanded="false">			<span class="screen-reader-text edit">				<?php				/* translators: Hidden accessibility text. %s: Widget title. */				printf( __( 'Edit widget: %s' ), $widget_title );				?>			</span>			<span class="screen-reader-text add">				<?php				/* translators: Hidden accessibility text. %s: Widget title. */				printf( __( 'Add widget: %s' ), $widget_title );				?>			</span>			<span class="toggle-indicator" aria-hidden="true"></span>		</button>		<a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>">			<span class="edit"><?php _ex( 'Edit', 'widget' ); ?></span>			<span class="add"><?php _ex( 'Add', 'widget' ); ?></span>			<span class="screen-reader-text"><?php echo $widget_title; ?></span>		</a>	</div>	<div class="widget-title"><h3><?php echo $widget_title; ?><span class="in-widget-title"></span></h3></div>	</div>

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 7.1.0 tag, from src/wp-admin/includes/widgets.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.