[wp-trac] [WordPress Trac] #56644: Global styles don't work for most blocks (paragraphs, headings, buttons etc).

WordPress Trac noreply at wordpress.org
Fri Sep 23 23:52:30 UTC 2022


#56644: Global styles don't work for most blocks (paragraphs, headings, buttons
etc).
------------------------------+-------------------------
 Reporter:  jorgefilipecosta  |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  high              |  Milestone:  6.1
Component:  Editor            |    Version:  trunk
 Severity:  major             |   Keywords:  needs-patch
  Focuses:                    |
------------------------------+-------------------------
 With WordPress 6.1 beta one and the latest version on the trunk, global
 styles don't work for some blocks.

 Things work well when the Gutenberg plugin is enabled, so this is a core-
 only issue.

 == Replicate

 - Go to the site editor.
 - Open the global styles sidebar.
 - Open the blocks section.
 - Navigate to the paragraph block (or button, heading, etc, I think most
 static blocks).
 - Apply a background color.
 - Save the global styles.
 - The background color is wholly discarded on save.

 == What's happening
 === WP_Theme_JSON::get_blocks_metadata() is not returning all the blocks
 Can be checked with the following debug code:

 {{{#!php
 <?php
 $r = new ReflectionMethod('WP_Theme_JSON', 'get_blocks_metadata');
 $r->setAccessible(true);
 var_dump( $r->invoke(new WP_Theme_JSON() ) );
 exit;
 }}}


 Blocks like paragraphs, heading, and buttons are missing.
 As the blocks are not known to the global styles system during the
 sanitization static::sanitize( $theme_json, $valid_block_names,
 $valid_element_names ); the styles of these blocks are removed and not
 saved.

 === There is a call to WP_Theme_JSON::get_blocks_metadata() before all the
 blocks are registed
 WP_Theme_JSON::get_blocks_metadata() has a caching mechanism and not does
 its computations multiple times.
 On the first call that happens to the function, the blocks are not all
 registered yet.

 {{{#!php
 <?php
         $registry = WP_Block_Type_Registry::get_instance();
         $blocks   = $registry->get_all_registered();

 }}}

 On the first call of get_blocks_metadata blocks do not yet contain all the
 blocks. As the function is cached, some blocks don't exist at all for the
 global styles system.

 It seems there was a change in how blocks are registered that is causing
 this issue.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56644>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list