Automattic\WooCommerce\Blocks\Assets

AssetDataRegistry::enqueue_asset_data()publicWC 1.0

Callback for enqueuing asset data via the WP api.

Note: while this is hooked into print/admin_print_scripts, it still only happens if the script attached to wc-settings handle is enqueued. This is done to allow for any potentially expensive data generation to only happen for routes that need it.

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

Хуков нет.

Возвращает

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

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

$AssetDataRegistry = new AssetDataRegistry();
$AssetDataRegistry->enqueue_asset_data();

Код AssetDataRegistry::enqueue_asset_data() WC 8.7.0

public function enqueue_asset_data() {
	if ( wp_script_is( $this->handle, 'enqueued' ) ) {
		$this->initialize_core_data();
		$this->execute_lazy_data();

		$data                          = rawurlencode( wp_json_encode( $this->data ) );
		$wc_settings_script            = "var wcSettings = wcSettings || JSON.parse( decodeURIComponent( '" . esc_js( $data ) . "' ) );";
		$preloaded_api_requests_script = '';

		if ( count( $this->preloaded_api_requests ) > 0 ) {
			$preloaded_api_requests        = rawurlencode( wp_json_encode( $this->preloaded_api_requests ) );
			$preloaded_api_requests_script = "wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( JSON.parse( decodeURIComponent( '" . esc_js( $preloaded_api_requests ) . "' ) ) ) );";
		}

		wp_add_inline_script(
			$this->handle,
			$wc_settings_script . $preloaded_api_requests_script,
			'before'
		);
	}
}