WP_Customize_Widgets::export_preview_data()
- Since
- 3.9.0
- Source
wp-includes/class-wp-customize-widgets.php:1308
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::export_preview_data() 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
- Light
- Scaling
- Scales with input
- Instructions
- 65–68
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
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 70.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
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::export_preview_data() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 65–66 | get_current_user_id(), switch_to_user_locale(), __(), array_filter(), array_filter(), array_keys(), array_fill_keys(), array_keys(), array_fill_keys(), array_values(), ->get_selective_refreshable_widgets(), wp_json_encode(), wp_print_inline_script_tag() |
| always | 67–68 | get_current_user_id(), switch_to_user_locale(), __(), restore_previous_locale(), array_filter(), array_filter(), array_keys(), array_fill_keys(), array_keys(), array_fill_keys(), array_values(), ->get_selective_refreshable_widgets(), wp_json_encode(), wp_print_inline_script_tag() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 70 | 65–68 | 3 | |
| 8.5 | 70 | 65–68 | 3 | |
| 8.4 | 70 | 65–68 | 3 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 71 | 66–69 | 3 | |
| 8.2 | 71 | 66–69 | 3 | |
| 8.1 | 71 | 66–69 | 3 | |
| 7.4 | 71 | 66–69 | 3 |
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 · 7
- switch_to_user_locale()Switches the translations according to the given user's locale.
- get_current_user_id()Gets the current user's ID.
- __()Retrieves the translation of $text.
- restore_previous_locale()Restores the translations according to the previous locale.
- wp_print_inline_script_tag()Prints an inline script tag.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- WP_Customize_Widgets::get_selective_refreshable_widgets()List whether each registered widget can be use selective refresh.
Source code
public function export_preview_data() { global $wp_registered_sidebars, $wp_registered_widgets; $switched_locale = switch_to_user_locale( get_current_user_id() ); $l10n = array( 'widgetTooltip' => __( 'Shift-click to edit this widget.' ), ); if ( $switched_locale ) { restore_previous_locale(); } $rendered_sidebars = array_filter( $this->rendered_sidebars ); $rendered_widgets = array_filter( $this->rendered_widgets ); // Prepare Customizer settings to pass to JavaScript. $settings = array( 'renderedSidebars' => array_fill_keys( array_keys( $rendered_sidebars ), true ), 'renderedWidgets' => array_fill_keys( array_keys( $rendered_widgets ), true ), 'registeredSidebars' => array_values( $wp_registered_sidebars ), 'registeredWidgets' => $wp_registered_widgets, 'l10n' => $l10n, 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), ); foreach ( $settings['registeredWidgets'] as &$registered_widget ) { unset( $registered_widget['callback'] ); // May not be JSON-serializable. } wp_print_inline_script_tag( sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) ); }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.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.