acf_enqueue_block_assets()ACF 5.7.13

acf_enqueue_block_assets

Enqueues and localizes block scripts and styles.

Хуков нет.

Возвращает

null. Ничего.

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

acf_enqueue_block_assets();

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

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

Код acf_enqueue_block_assets() ACF 5.10.2

function acf_enqueue_block_assets() {

	// Localize text.
	acf_localize_text(
		array(
			'Switch to Edit'           => __( 'Switch to Edit', 'acf' ),
			'Switch to Preview'        => __( 'Switch to Preview', 'acf' ),
			'Change content alignment' => __( 'Change content alignment', 'acf' ),

			/* translators: %s: Block type title */
			'%s settings'              => __( '%s settings', 'acf' ),
		)
	);

	// Get block types.
	$block_types = acf_get_block_types();

	// Localize data.
	acf_localize_data(
		array(
			'blockTypes' => array_values( $block_types ),
			'postType'   => get_post_type(),
		)
	);

	// Enqueue script.
	$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';


	if ( acf_version_compare( 'wp', '<', '5.6' ) ) {
		$blocks_js_path = acf_get_url( "assets/build/js/pro/acf-pro-blocks-legacy{$min}.js" );
	} else {
		$blocks_js_path = acf_get_url( "assets/build/js/pro/acf-pro-blocks{$min}.js" );
	}

	wp_enqueue_script( 'acf-blocks', $blocks_js_path, array( 'acf-input', 'wp-blocks' ), ACF_VERSION, true );

	// Enqueue block assets.
	array_map( 'acf_enqueue_block_type_assets', $block_types );

	// During the edit screen loading, WordPress renders all blocks in its own attempt to preload data.
	// Retrieve any cached block HTML and include this in the localized data.
	$preloaded_blocks = acf_get_store( 'block-cache' )->get_data();
	acf_localize_data(
		array(
			'preloadedBlocks' => $preloaded_blocks,
		)
	);
}