wppaste
WordPress

WP_Customize_Widgets::enqueue_scripts()

Since
3.9.0
Source
wp-includes/class-wp-customize-widgets.php:700
Enqueues scripts and styles for Customizer panel and export data to JavaScript.

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::enqueue_scripts() 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
169–254

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

Plugin surface
2 hooks

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

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

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

Further down the call graph this can also reach cache, serialize, http, 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 · 6 distinct outcomes

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

WhenInstructionsCalls it makes
!$non_rendered_count && $registered_sidebar_count === 1 && !wp_use_widgets_block_editor()169–171wp_enqueue_style(), wp_enqueue_script(), do_action(), ->get_available_widgets(), __(), __(), __(), sprintf(), __(), _x(), __(), get_bloginfo(), html_entity_decode(), __(), sprintf(), get_bloginfo(), html_entity_decode(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), __(), __(), ->get_selective_refreshable_widgets(), wp_json_encode(), ->add_data(), wp_use_widgets_block_editor()
!$non_rendered_count && $registered_sidebar_count !== 1 && !wp_use_widgets_block_editor()174–176wp_enqueue_style(), wp_enqueue_script(), do_action(), ->get_available_widgets(), __(), __(), __(), sprintf(), __(), _x(), __(), get_bloginfo(), html_entity_decode(), _n(), number_format_i18n(), sprintf(), get_bloginfo(), html_entity_decode(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), __(), __(), ->get_selective_refreshable_widgets(), wp_json_encode(), ->add_data(), wp_use_widgets_block_editor()
!$non_rendered_count && $registered_sidebar_count === 1 && wp_use_widgets_block_editor() && empty($registered_sources)232–234wp_enqueue_style(), wp_enqueue_script(), do_action(), ->get_available_widgets(), __(), __(), __(), sprintf(), __(), _x(), __(), get_bloginfo(), html_entity_decode(), __(), sprintf(), get_bloginfo(), html_entity_decode(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), __(), __(), ->get_selective_refreshable_widgets(), wp_json_encode(), ->add_data(), wp_use_widgets_block_editor(), widgetReorderNav(), get_legacy_widget_block_editor_settings(), get_block_editor_settings(), wp_json_encode(), wp_add_inline_script(), get_block_editor_server_block_settings(), wp_json_encode(), wp_add_inline_script(), get_all_registered_block_bindings_sources(), get_block_categories(), wp_json_encode(), wp_add_inline_script(), wp_enqueue_script(), wp_enqueue_style(), do_action()
!$non_rendered_count && $registered_sidebar_count !== 1 && wp_use_widgets_block_editor() && empty($registered_sources)237–239wp_enqueue_style(), wp_enqueue_script(), do_action(), ->get_available_widgets(), __(), __(), __(), sprintf(), __(), _x(), __(), get_bloginfo(), html_entity_decode(), _n(), number_format_i18n(), sprintf(), get_bloginfo(), html_entity_decode(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), __(), __(), ->get_selective_refreshable_widgets(), wp_json_encode(), ->add_data(), wp_use_widgets_block_editor(), widgetReorderNav(), get_legacy_widget_block_editor_settings(), get_block_editor_settings(), wp_json_encode(), wp_add_inline_script(), get_block_editor_server_block_settings(), wp_json_encode(), wp_add_inline_script(), get_all_registered_block_bindings_sources(), get_block_categories(), wp_json_encode(), wp_add_inline_script(), wp_enqueue_script(), wp_enqueue_style(), do_action()
!$non_rendered_count && $registered_sidebar_count === 1 && wp_use_widgets_block_editor() && !empty($registered_sources)246–249wp_enqueue_style(), wp_enqueue_script(), do_action(), ->get_available_widgets(), __(), __(), __(), sprintf(), __(), _x(), __(), get_bloginfo(), html_entity_decode(), __(), sprintf(), get_bloginfo(), html_entity_decode(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), __(), __(), ->get_selective_refreshable_widgets(), wp_json_encode(), ->add_data(), wp_use_widgets_block_editor(), widgetReorderNav(), get_legacy_widget_block_editor_settings(), get_block_editor_settings(), wp_json_encode(), wp_add_inline_script(), get_block_editor_server_block_settings(), wp_json_encode(), wp_add_inline_script(), get_all_registered_block_bindings_sources(), wp_json_encode(), wp_add_inline_script(), get_block_categories(), wp_json_encode(), wp_add_inline_script(), wp_enqueue_script(), wp_enqueue_style(), do_action()
!$non_rendered_count && $registered_sidebar_count !== 1 && wp_use_widgets_block_editor() && !empty($registered_sources)251–254wp_enqueue_style(), wp_enqueue_script(), do_action(), ->get_available_widgets(), __(), __(), __(), sprintf(), __(), _x(), __(), get_bloginfo(), html_entity_decode(), _n(), number_format_i18n(), sprintf(), get_bloginfo(), html_entity_decode(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), esc_attr__(), __(), __(), ->get_selective_refreshable_widgets(), wp_json_encode(), ->add_data(), wp_use_widgets_block_editor(), widgetReorderNav(), get_legacy_widget_block_editor_settings(), get_block_editor_settings(), wp_json_encode(), wp_add_inline_script(), get_block_editor_server_block_settings(), wp_json_encode(), wp_add_inline_script(), get_all_registered_block_bindings_sources(), wp_json_encode(), wp_add_inline_script(), get_block_categories(), wp_json_encode(), wp_add_inline_script(), wp_enqueue_script(), wp_enqueue_style(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev308169–25410
8.5308169–25410
8.4308169–254109 fewer instructions than PHP 8.3
8.3317174–26310
8.2317174–26310
8.1317174–26310
7.4317174–26310

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

2 hooks fire while WP_Customize_Widgets::enqueue_scripts() runs, in this order:

  1. do_action( admin_enqueue_scripts )actionline 707 (+7 into the body)

    Fires when enqueuing scripts for all admin pages.

  2. do_action( enqueue_block_editor_assets )actionline 901 (+201 into the body)

    Fires after block assets have been enqueued for the editing interface.

Uses · 20

Show all 20

Source code

	public function enqueue_scripts() {		global $wp_scripts, $wp_registered_sidebars, $wp_registered_widgets; 		wp_enqueue_style( 'customize-widgets' );		wp_enqueue_script( 'customize-widgets' ); 		/** This action is documented in wp-admin/admin-header.php */		do_action( 'admin_enqueue_scripts', 'widgets.php' ); 		/*		 * Export available widgets with control_tpl removed from model		 * since plugins need templates to be in the DOM.		 */		$available_widgets = array(); 		foreach ( $this->get_available_widgets() as $available_widget ) {			unset( $available_widget['control_tpl'] );			$available_widgets[] = $available_widget;		} 		$widget_reorder_nav_tpl = sprintf(			'<div class="widget-reorder-nav"><span class="move-widget" tabindex="0">%1$s</span><span class="move-widget-down" tabindex="0">%2$s</span><span class="move-widget-up" tabindex="0">%3$s</span></div>',			__( 'Move to another area&hellip;' ),			__( 'Move down' ),			__( 'Move up' )		); 		$move_widget_area_tpl = str_replace(			array( '{description}', '{btn}' ),			array(				__( 'Select an area to move this widget into:' ),				_x( 'Move', 'Move widget' ),			),			'<div class="move-widget-area">				<p class="description">{description}</p>				<ul class="widget-area-select">					<% _.each( sidebars, function ( sidebar ){ %>						<li class="" data-id="<%- sidebar.id %>" tabindex="0">							<div><strong><%- sidebar.name %></strong></div>							<div><%- sidebar.description %></div>						</li>					<% }); %>				</ul>				<div class="move-widget-actions">					<button class="move-widget-btn button" type="button">{btn}</button>				</div>			</div>'		); 		/*		 * Gather all strings in PHP that may be needed by JS on the client.		 * Once JS i18n is implemented (in #20491), this can be removed.		 */		$some_non_rendered_areas_messages    = array();		$some_non_rendered_areas_messages[1] = html_entity_decode(			__( 'Your theme has 1 other widget area, but this particular page does not display it.' ),			ENT_QUOTES,			get_bloginfo( 'charset' )		);		$registered_sidebar_count            = count( $wp_registered_sidebars );		for ( $non_rendered_count = 2; $non_rendered_count < $registered_sidebar_count; $non_rendered_count++ ) {			$some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode(				sprintf(					/* translators: %s: The number of other widget areas registered but not rendered. */					_n(						'Your theme has %s other widget area, but this particular page does not display it.',						'Your theme has %s other widget areas, but this particular page does not display them.',						$non_rendered_count					),					number_format_i18n( $non_rendered_count )				),				ENT_QUOTES,				get_bloginfo( 'charset' )			);		} 		if ( 1 === $registered_sidebar_count ) {			$no_areas_shown_message = html_entity_decode(				sprintf(					__( 'Your theme has 1 widget area, but this particular page does not display it.' )

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 6.9.7 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.