acf_enqueue_block_assets()
Enqueues and localizes block scripts and styles.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
acf_enqueue_block_assets();
Список изменений
| С версии 5.7.13 | Введена. |
Код acf_enqueue_block_assets() acf enqueue block assets ACF 6.4.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' ),
'Error previewing block' => __( 'An error occurred when loading the preview for this block.', 'acf' ),
'Error loading block form' => __( 'An error occurred when loading the block in edit mode.', 'acf' ),
/* translators: %s: Block type title */
'%s settings' => __( '%s settings', 'acf' ),
)
);
// Get block types.
$block_types = array_map(
function ( $block ) {
// Render Callback may contain a incompatible class for JSON encoding. Turn it into a boolean for the frontend.
$block['render_callback'] = ! empty( $block['render_callback'] );
return $block;
},
acf_get_block_types()
);
// Localize data.
acf_localize_data(
array(
'blockTypes' => array_values( $block_types ),
'postType' => get_post_type(),
)
);
// Enqueue script.
$min = defined( 'ACF_DEVELOPMENT_MODE' ) && ACF_DEVELOPMENT_MODE ? '' : '.min';
$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.
if ( acf_get_setting( 'preload_blocks' ) ) {
$preloaded_blocks = acf_get_store( 'block-cache' )->get_data();
acf_localize_data(
array(
'preloadedBlocks' => $preloaded_blocks,
)
);
}
}