WP_Customize_Selective_Refresh::export_preview_data() WordPress Method

The WP_Customize_Selective_Refresh::export_preview_data() method allows you to selectively refresh your WordPress site. This can be useful for making small changes to your site without having to reload the entire page.

WP_Customize_Selective_Refresh::export_preview_data() #

Exports data in preview after it has finished rendering so that partials can be added at runtime.


Source

File: wp-includes/customize/class-wp-customize-selective-refresh.php

	public function export_preview_data() {
		$partials = array();

		foreach ( $this->partials() as $partial ) {
			if ( $partial->check_capabilities() ) {
				$partials[ $partial->id ] = $partial->json();
			}
		}

		$switched_locale = switch_to_locale( get_user_locale() );
		$l10n            = array(
			'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
			'clickEditMenu'    => __( 'Click to edit this menu.' ),
			'clickEditWidget'  => __( 'Click to edit this widget.' ),
			'clickEditTitle'   => __( 'Click to edit the site title.' ),
			'clickEditMisc'    => __( 'Click to edit this element.' ),
			/* translators: %s: document.write() */
			'badDocumentWrite' => sprintf( __( '%s is forbidden' ), 'document.write()' ),
		);
		if ( $switched_locale ) {
			restore_previous_locale();
		}

		$exports = array(
			'partials'       => $partials,
			'renderQueryVar' => self::RENDER_QUERY_VAR,
			'l10n'           => $l10n,
		);

		// Export data to JS.
		printf( '<script>var _customizePartialRefreshExports = %s;</script>', wp_json_encode( $exports ) );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.