WP_Customize_Widgets::enqueue_scripts()
- Since
- 3.9.0
- Source
wp-includes/class-wp-customize-widgets.php:699
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
- Scaling
- Scales with input
- Instructions
- 168–249
- Plugin surface
- 2 hooks
- Called by
- 0
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 303.
Third-party callbacks on 'admin_enqueue_scripts', 'enqueue_block_editor_assets' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!$non_rendered_count && $registered_sidebar_count === 1 && !wp_use_widgets_block_editor() | 168–170 | wp_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() | 173–175 | wp_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) | 228–230 | wp_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) | 233–235 | wp_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) | 241–244 | wp_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) | 246–249 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 303 | 168–249 | 10 | |
| 8.5 | 303 | 168–249 | 10 | |
| 8.4 | 303 | 168–249 | 10 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 312 | 173–258 | 10 | |
| 8.2 | 312 | 173–258 | 10 | |
| 8.1 | 312 | 173–258 | 10 | |
| 7.4 | 312 | 173–258 | 10 |
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:
- do_action( admin_enqueue_scripts )actionline 706 (+7 into the body)
Fires when enqueuing scripts for all admin pages.
- do_action( enqueue_block_editor_assets )actionline 900 (+201 into the body)
Fires after block assets have been enqueued for the editing interface.
Uses · 20
- wp_enqueue_style()Enqueues a CSS stylesheet.
- wp_enqueue_script()Enqueues a script.
- do_action()Calls the callback functions that have been added to an action hook.
- __()Retrieves the translation of $text.
- _x()Retrieves translated string with gettext context.
- get_bloginfo()Retrieves information about the current site.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- number_format_i18n()Converts float number to format based on the locale.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- wp_use_widgets_block_editor()Determines whether or not to use the block editor to manage widgets.
- get_block_editor_settings()Returns the contextualized block editor settings for a selected editor context.
Show all 20
- get_legacy_widget_block_editor_settings()Returns the block editor settings needed to use the Legacy Widget block which is not registered by default.
- wp_add_inline_script()Adds extra code to a registered script.
- get_block_editor_server_block_settings()Prepares server-registered blocks for the block editor.
- get_all_registered_block_bindings_sources()Retrieves the list of all registered block bindings sources.
- get_block_categories()Returns all the categories for block types that will be shown in the block editor.
- WP_Customize_Widgets::get_available_widgets()Builds up an index of all available widgets for use in Backbone models.
- WP_Customize_Widgets::get_selective_refreshable_widgets()List whether each registered widget can be use selective refresh.
- WP_Block_Editor_Context::__construct()Constructor.
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…' ), __( '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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.