wppaste
WordPress

WP_Customize_Widgets::customize_register()

Since
3.9.0
Source
wp-includes/class-wp-customize-widgets.php:370
Registers Customizer settings and controls for all sidebars and widgets.

Compatibility

WordPress
since 3.9.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.

Performance profile

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

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

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
67–83

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

Plugin surface
1 hook

Third-party callbacks on 'customizer_widgets_section_args' run inside this call, and their cost is not bounded by anything here.

Called by
1

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

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below WP_Customize_Widgets::customize_register()

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 · 2 distinct outcomes

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

WhenInstructionsCalls it makes
->is_theme_active()67–72wp_use_widgets_block_editor(), array_keys(), array_fill_keys(), wp_get_sidebars_widgets(), array_merge(), array_keys(), ->is_theme_active(), __(), __(), ->settings_previewed()
!->is_theme_active()78–83wp_use_widgets_block_editor(), array_keys(), array_fill_keys(), wp_get_sidebars_widgets(), array_merge(), array_keys(), ->is_theme_active(), ->get_setting_args(), ->add_setting(), __(), __(), ->settings_previewed()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev27867–8323
8.527867–8323
8.427867–83234 fewer instructions than PHP 8.3
8.328267–8323
8.228267–8323
8.128267–8323
7.428267–8323

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

  1. apply_filters( customizer_widgets_section_args )filterline 475 (+105 into the body)

    Filters Customizer widget section arguments for a given sidebar.

Uses · 13

Show all 13

Used by · 1

Source code

	public function customize_register() {		global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars; 		$use_widgets_block_editor = wp_use_widgets_block_editor(); 		add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 ); 		$sidebars_widgets = array_merge(			array( 'wp_inactive_widgets' => array() ),			array_fill_keys( array_keys( $wp_registered_sidebars ), array() ),			wp_get_sidebars_widgets()		); 		$new_setting_ids = array(); 		/*		 * Register a setting for all widgets, including those which are active,		 * inactive, and orphaned since a widget may get suppressed from a sidebar		 * via a plugin (like Widget Visibility).		 */		foreach ( array_keys( $wp_registered_widgets ) as $widget_id ) {			$setting_id   = $this->get_setting_id( $widget_id );			$setting_args = $this->get_setting_args( $setting_id );			if ( ! $this->manager->get_setting( $setting_id ) ) {				$this->manager->add_setting( $setting_id, $setting_args );			}			$new_setting_ids[] = $setting_id;		} 		/*		 * Add a setting which will be supplied for the theme's sidebars_widgets		 * theme_mod when the theme is switched.		 */		if ( ! $this->manager->is_theme_active() ) {			$setting_id   = 'old_sidebars_widgets_data';			$setting_args = $this->get_setting_args(				$setting_id,				array(					'type'  => 'global_variable',					'dirty' => true,				)			);			$this->manager->add_setting( $setting_id, $setting_args );		} 		$this->manager->add_panel(			'widgets',			array(				'type'                     => 'widgets',				'title'                    => __( 'Widgets' ),				'description'              => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ),				'priority'                 => 110,				'active_callback'          => array( $this, 'is_panel_active' ),				'auto_expand_sole_section' => true,				'theme_supports'           => 'widgets',			)		); 		foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) {			if ( empty( $sidebar_widget_ids ) ) {				$sidebar_widget_ids = array();			} 			$is_registered_sidebar = is_registered_sidebar( $sidebar_id );			$is_inactive_widgets   = ( 'wp_inactive_widgets' === $sidebar_id );			$is_active_sidebar     = ( $is_registered_sidebar && ! $is_inactive_widgets ); 			// Add setting for managing the sidebar's widgets.			if ( $is_registered_sidebar || $is_inactive_widgets ) {				$setting_id   = sprintf( 'sidebars_widgets[%s]', $sidebar_id );				$setting_args = $this->get_setting_args( $setting_id );				if ( ! $this->manager->get_setting( $setting_id ) ) {					if ( ! $this->manager->is_theme_active() ) {						$setting_args['dirty'] = true;					}					$this->manager->add_setting( $setting_id, $setting_args );				}				$new_setting_ids[] = $setting_id; 				// Add section to contain controls.

Changelog

Introduced in 3.9.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-includes/class-wp-customize-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.