WP_Customize_Widgets::customize_register()
- Since
- 3.9.0
- Source
wp-includes/class-wp-customize-widgets.php:370
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
- Scaling
- Scales with input
- Instructions
- 67–83
- Plugin surface
- 1 hook
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 278.
Third-party callbacks on 'customizer_widgets_section_args' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
->is_theme_active() | 67–72 | wp_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–83 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 278 | 67–83 | 23 | |
| 8.5 | 278 | 67–83 | 23 | |
| 8.4 | 278 | 67–83 | 23 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 282 | 67–83 | 23 | |
| 8.2 | 282 | 67–83 | 23 | |
| 8.1 | 282 | 67–83 | 23 | |
| 7.4 | 282 | 67–83 | 23 |
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:
- apply_filters( customizer_widgets_section_args )filterline 475 (+105 into the body)
Filters Customizer widget section arguments for a given sidebar.
Uses · 13
- wp_use_widgets_block_editor()Determines whether or not to use the block editor to manage widgets.
- add_filter()Adds a callback function to a filter hook.
- wp_get_sidebars_widgets()Retrieves the full list of sidebars and their widget instance IDs.
- __()Retrieves the translation of $text.
- is_registered_sidebar()Checks if a sidebar is registered.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Customize_Widgets::get_setting_id()Converts a widget_id into its corresponding Customizer setting ID (option name).
- WP_Customize_Widgets::get_setting_args()Retrieves common arguments to supply when constructing a Customizer setting.
- WP_Customize_Sidebar_Section::__construct()
- WP_Sidebar_Block_Editor_Control::__construct()
- WP_Widget_Area_Customize_Control::__construct()
- WP_Widget_Form_Customize_Control::__construct()
Show all 13
- WP_Customize_Widgets::is_wide_widget()Determines whether the widget is considered "wide".
Used by · 1
- WP_Customize_Widgets::schedule_customize_register()Ensures widgets are available for all types of previews.
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.
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.