Changeset 56807 for trunk/src/wp-includes/block-supports/elements.php
- Timestamp:
- 10/09/2023 05:05:31 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/elements.php
r56709 r56807 32 32 */ 33 33 function wp_render_elements_support( $block_content, $block ) { 34 if ( ! $block_content || empty( $block['attrs'] ) ) {34 if ( ! $block_content || ! isset( $block['attrs']['style']['elements'] ) ) { 35 35 return $block_content; 36 36 } … … 42 42 'skip' => wp_should_skip_block_supports_serialization( $block_type, 'color', 'button' ), 43 43 'paths' => array( 44 'style.elements.button.color.text',45 'style.elements.button.color.background',46 'style.elements.button.color.gradient',44 array( 'button', 'color', 'text' ), 45 array( 'button', 'color', 'background' ), 46 array( 'button', 'color', 'gradient' ), 47 47 ), 48 48 ), … … 50 50 'skip' => wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' ), 51 51 'paths' => array( 52 'style.elements.link.color.text',53 'style.elements.link.:hover.color.text',52 array( 'link', 'color', 'text' ), 53 array( 'link', ':hover', 'color', 'text' ), 54 54 ), 55 55 ), … … 57 57 'skip' => wp_should_skip_block_supports_serialization( $block_type, 'color', 'heading' ), 58 58 'paths' => array( 59 'style.elements.heading.color.text',60 'style.elements.heading.color.background',61 'style.elements.heading.color.gradient',62 'style.elements.h1.color.text',63 'style.elements.h1.color.background',64 'style.elements.h1.color.gradient',65 'style.elements.h2.color.text',66 'style.elements.h2.color.background',67 'style.elements.h2.color.gradient',68 'style.elements.h3.color.text',69 'style.elements.h3.color.background',70 'style.elements.h3.color.gradient',71 'style.elements.h4.color.text',72 'style.elements.h4.color.background',73 'style.elements.h4.color.gradient',74 'style.elements.h5.color.text',75 'style.elements.h5.color.background',76 'style.elements.h5.color.gradient',77 'style.elements.h6.color.text',78 'style.elements.h6.color.background',79 'style.elements.h6.color.gradient',59 array( 'heading', 'color', 'text' ), 60 array( 'heading', 'color', 'background' ), 61 array( 'heading', 'color', 'gradient' ), 62 array( 'h1', 'color', 'text' ), 63 array( 'h1', 'color', 'background' ), 64 array( 'h1', 'color', 'gradient' ), 65 array( 'h2', 'color', 'text' ), 66 array( 'h2', 'color', 'background' ), 67 array( 'h2', 'color', 'gradient' ), 68 array( 'h3', 'color', 'text' ), 69 array( 'h3', 'color', 'background' ), 70 array( 'h3', 'color', 'gradient' ), 71 array( 'h4', 'color', 'text' ), 72 array( 'h4', 'color', 'background' ), 73 array( 'h4', 'color', 'gradient' ), 74 array( 'h5', 'color', 'text' ), 75 array( 'h5', 'color', 'background' ), 76 array( 'h5', 'color', 'gradient' ), 77 array( 'h6', 'color', 'text' ), 78 array( 'h6', 'color', 'background' ), 79 array( 'h6', 'color', 'gradient' ), 80 80 ), 81 81 ), … … 90 90 } 91 91 92 $element _colors_set = 0;92 $elements_style_attributes = $block['attrs']['style']['elements']; 93 93 94 94 foreach ( $element_color_properties as $element_config ) { … … 98 98 99 99 foreach ( $element_config['paths'] as $path ) { 100 if ( null !== _wp_array_get( $block['attrs'], explode( '.', $path ), null ) ) { 101 ++$element_colors_set; 100 if ( null !== _wp_array_get( $elements_style_attributes, $path, null ) ) { 101 /* 102 * It only takes a single custom attribute to require that the custom 103 * class name be added to the block, so once one is found there's no 104 * need to continue looking for others. 105 * 106 * As is done with the layout hook, this code assumes that the block 107 * contains a single wrapper and that it's the first element in the 108 * rendered output. That first element, if it exists, gets the class. 109 */ 110 $tags = new WP_HTML_Tag_Processor( $block_content ); 111 if ( $tags->next_tag() ) { 112 $tags->add_class( wp_get_elements_class_name( $block ) ); 113 } 114 115 return $tags->get_updated_html(); 102 116 } 103 117 } 104 118 } 105 119 106 if ( ! $element_colors_set ) { 107 return $block_content; 108 } 109 110 // Like the layout hook this assumes the hook only applies to blocks with a single wrapper. 111 // Add the class name to the first element, presuming it's the wrapper, if it exists. 112 $tags = new WP_HTML_Tag_Processor( $block_content ); 113 if ( $tags->next_tag() ) { 114 $tags->add_class( wp_get_elements_class_name( $block ) ); 115 } 116 117 return $tags->get_updated_html(); 120 // If no custom attributes were found then there's nothing to modify. 121 return $block_content; 118 122 } 119 123
Note: See TracChangeset
for help on using the changeset viewer.