WP_Customize_Widgets::export_preview_data()publicWP 3.9.0

Communicates the sidebars that appeared on the page at the very end of the page, and at the very end of the wp_footer,

Метод класса: WP_Customize_Widgets{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WP_Customize_Widgets = new WP_Customize_Widgets();
$WP_Customize_Widgets->export_preview_data();

Заметки

  • Global. Массив. $wp_registered_sidebars
  • Global. Массив. $wp_registered_widgets

Список изменений

С версии 3.9.0 Введена.

Код WP_Customize_Widgets::export_preview_data() WP 6.6

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