Automattic\WooCommerce\Blocks\Assets
AssetDataRegistry::enqueue_asset_data()
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.
Method of the class: AssetDataRegistry{}
No Hooks.
Return
null
. Nothing (null).
Usage
$AssetDataRegistry = new AssetDataRegistry(); $AssetDataRegistry->enqueue_asset_data();
AssetDataRegistry::enqueue_asset_data() AssetDataRegistry::enqueue asset data code WC 9.2.3
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' ); } }