enqueue_block_styles_assets()
最后更新于:2021-11-26 04:01:52
enqueue_block_styles_assets()Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.
源文件
文件: gc-includes/script-loader.php
function enqueue_block_styles_assets() {
$block_styles = GC_Block_Styles_Registry::get_instance()->get_all_registered();
foreach ( $block_styles as $block_name => $styles ) {
foreach ( $styles as $style_properties ) {
if ( isset( $style_properties['style_handle'] ) ) {
// If the site loads separate styles per-block, enqueue the stylesheet on render.
if ( gc_should_load_separate_core_block_assets() ) {
add_filter(
'render_block',
function( $html, $block ) use ( $style_properties ) {
gc_enqueue_style( $style_properties['style_handle'] );
return $html;
}
);
} else {
gc_enqueue_style( $style_properties['style_handle'] );
}
}
if ( isset( $style_properties['inline_style'] ) ) {
// Default to "gc-block-library".
$handle = 'gc-block-library';
// If the site loads separate styles per-block, check if the block has a stylesheet registered.
if ( gc_should_load_separate_core_block_assets() ) {
$block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' );
global $gc_styles;
if ( isset( $gc_styles->registered[ $block_stylesheet_handle ] ) ) {
$handle = $block_stylesheet_handle;
}
}
// Add inline styles to the calculated handle.
gc_add_inline_style( $handle, $style_properties['inline_style'] );
}
}
}
}