WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 6 months ago

Last modified 5 months ago

#48039 closed defect (bug) (fixed)

Backport block styles server functions from Gutenberg to core

Reported by: jorgefilipecosta Owned by: jorgefilipecosta
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:

Description

This patch backports the block styles functionality added to the block editor in https://github.com/WordPress/gutenberg/pull/16356 to the core of WordPress.
Thew block editor was recently updated include this functionality only if it not available in core, so it is compatible with the last version of WordPress and trunk.

How to test

I added the following code to the functions.php file of the enabled theme and verified styles were registered as expected:

add_action(
        'enqueue_block_assets',
        function() {
                wp_register_style( 'myguten-style', get_template_directory_uri() . '/custom-style.css' );
        }
);

register_block_style(
        'core/quote',
        array(
                'name'         => 'fancy-quote',
                'label'        => 'Fancy Quote',
                'style_handle' => 'myguten-style',
        )
);

register_block_style(
        'core/quote',
        array(
                'name'         => 'not-fancy-quote',
                'label'        => 'Not Fancy Quote',
                'inline_style' => '.wp-block-quote.is-style-not-fancy-quote { color: blue; }',
        )
);

register_block_style(
        'core/quote',
        array(
                'name'         => 'unregistered-fancy-quote',
                'label'        => 'Unregistered Fancy Quote',
                'inline_style' => '.wp-block-quote.is-style-unregistered-fancy-quote { color: orange; }',
        )
);
unregister_block_style( 'core/quote', 'unregistered-fancy-quote' );

Attachments (1)

48039.diff (9.5 KB) - added by jorgefilipecosta 6 months ago.

Download all attachments as: .zip

Change History (8)

#1 @youknowriad
6 months ago

  • Keywords commit added

LGTM 👍

#2 @youknowriad
6 months ago

  • Milestone changed from Awaiting Review to 5.3

#3 @youknowriad
6 months ago

  • Component changed from General to Editor

#4 @jorgefilipecosta
6 months ago

  • Owner set to jorgefilipecosta
  • Resolution set to fixed
  • Status changed from new to closed

In 46111:

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.

#5 @jorgefilipecosta
6 months ago

  • Keywords commit removed

#6 @SergeyBiryukov
6 months ago

This is causing a fatal error in current trunk with the most recent version of the plugin (6.4.0):

Fatal error: Cannot declare class WP_Block_Styles_Registry, because the name is already in use in wp-content/plugins/gutenberg/lib/class-wp-block-styles-registry.php on line 14

Looks like this was already mentioned in comment:23:ticket:47843 and addressed in https://github.com/WordPress/gutenberg/pull/17429. Is there a timeline for 6.5.0?

#7 @jorgefilipecosta
5 months ago

Hi @SergeyBiryukov, Gutenberg 6.5 was released today and the problem should not happen anymore.

Note: See TracTickets for help on using tickets.