enqueue_editor_block_styles_assets()

最后更新于:2021-11-26 04:02:09

enqueue_editor_block_styles_assets()

Function responsible for enqueuing the assets required for block styles functionality on the editor.

源文件

文件: gc-includes/script-loader.php

function enqueue_editor_block_styles_assets() {
	$block_styles = GC_Block_Styles_Registry::get_instance()->get_all_registered();

	$register_script_lines = array( '( function() {' );
	foreach ( $block_styles as $block_name => $styles ) {
		foreach ( $styles as $style_properties ) {
			$block_style = array(
				'name'  => $style_properties['name'],
				'label' => $style_properties['label'],
			);
			if ( isset( $style_properties['is_default'] ) ) {
				$block_style['isDefault'] = $style_properties['is_default'];
			}
			$register_script_lines[] = sprintf(
				'	gc.blocks.registerBlockStyle( '%s', %s );',
				$block_name,
				gc_json_encode( $block_style )
			);
		}
	}
	$register_script_lines[] = '} )();';
	$inline_script           = implode( "n", $register_script_lines );

	gc_register_script( 'gc-block-styles', false, array( 'gc-blocks' ), true, true );
	gc_add_inline_script( 'gc-block-styles', $inline_script );
	gc_enqueue_script( 'gc-block-styles' );
}