mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 04:34:31 +00:00
Block Editor: Backport block styles server functions from block editor.
This commit backports the block styles functionality added to the block editor in https://github.com/WordPress/gutenberg/pull/16356. Props: youknowriad, aduth, swissspidy. Fixes #48039. git-svn-id: https://develop.svn.wordpress.org/trunk@46111 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2780,3 +2780,54 @@ function wp_enqueue_registered_block_scripts_and_styles() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*/
|
||||
function enqueue_block_styles_assets() {
|
||||
$block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
|
||||
|
||||
foreach ( $block_styles as $styles ) {
|
||||
foreach ( $styles as $style_properties ) {
|
||||
if ( isset( $style_properties['style_handle'] ) ) {
|
||||
wp_enqueue_style( $style_properties['style_handle'] );
|
||||
}
|
||||
if ( isset( $style_properties['inline_style'] ) ) {
|
||||
wp_add_inline_style( 'wp-block-library', $style_properties['inline_style'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function responsible for enqueuing the assets required for block styles functionality on the editor.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*/
|
||||
function enqueue_editor_block_styles_assets() {
|
||||
$block_styles = WP_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 ) {
|
||||
$register_script_lines[] = sprintf(
|
||||
' wp.blocks.registerBlockStyle( \'%s\', %s );',
|
||||
$block_name,
|
||||
wp_json_encode(
|
||||
array(
|
||||
'name' => $style_properties['name'],
|
||||
'label' => $style_properties['label'],
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$register_script_lines[] = '} )();';
|
||||
$inline_script = implode( "\n", $register_script_lines );
|
||||
|
||||
wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, true );
|
||||
wp_add_inline_script( 'wp-block-styles', $inline_script );
|
||||
wp_enqueue_script( 'wp-block-styles' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user