wppaste
WordPress

WP_Customize_Widgets::export_preview_data()

Since
3.9.0
Source
wp-includes/class-wp-customize-widgets.php:1302
Communicates the sidebars that appeared on the page at the very end of the page, and at the very end of the wp_footer,

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

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
62–65

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

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.

WhenInstructionsCalls it makes
always62–63get_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()
always64–65get_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

PHPCompiledExecutedBranchesNotes
8.6-dev6762–653
8.56762–653
8.46762–6531 fewer instruction than PHP 8.3
8.36863–663
8.26863–663
8.16863–663
7.46863–663

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

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 ) )		);	}

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