wp_widget_control( array $sidebar_args ): array
- Since
- 2.5.0
- Source
wp-admin/includes/widgets.php:190
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_argsparam.
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
- Scaling
- Constant
- Instructions
- 206–232
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 259.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
!$sidebar_args && !$wp_registered_widget_controls && !$control && !isset($control) | 206–230 | strip_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–232 | strip_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 258 | 206–232 | 22 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 259 | 206–232 | 22 | |
| 8.4 | 259 | 206–232 | 22 | |
| 8.3 | 259 | 206–232 | 22 | |
| 8.2 | 259 | 206–232 | 22 | |
| 8.1 | 259 | 206–232 | 22 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 260 | 207–232 | 22 |
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
- esc_html()Escaping for HTML blocks.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- add_query_arg()Retrieves a modified URL query string.
- _ex()Displays translated string with gettext context.
- esc_attr()Escaping for HTML attributes.
- _e()Displays translated text.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
- wp_widget_description()Retrieves description for widget.
Used by · 2
- WP_Customize_Widgets::get_widget_control()Retrieves the widget control markup.
- wp_list_widgets()Display list of the available widgets.
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.
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.