PluginProbe
Gutenberg / 24.0.0
Gutenberg v24.0.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/scripts/block-library/icon.php +54 -26 23.2.2 → 24.0.0 View file →
@@ -18,15 +18,8 @@
18 18 if ( empty( $attributes['icon'] ) ) {
19 19 return;
20 20 }
21 21
22 - $registry = WP_Icons_Registry::get_instance();
23 - $icon = $registry->get_registered_icon( $attributes['icon'] );
24 -
25 - if ( is_null( $icon ) ) {
26 - return;
27 - }
28 -
29 22 // Text color and background color.
30 23 $color_styles = array();
31 24
32 25 $preset_text_color = array_key_exists( 'textColor', $attributes ) ? "var:preset|color|{$attributes['textColor']}" : null;
@@ -85,33 +78,68 @@
85 78 'dimensions' => $dimensions_styles,
86 79 ),
87 80 );
88 81
89 - $processor = new WP_HTML_Tag_Processor( $icon['content'] );
90 - $processor->next_tag( 'svg' );
82 + $svg = wp_get_icon(
83 + $attributes['icon'],
84 + array(
85 + // Width is applied via the dimensions block support styles below.
86 + 'size' => null,
87 + 'class' => $styles['classnames'] ?? '',
88 + 'label' => $attributes['ariaLabel'] ?? '',
89 + )
90 + );
91 91
92 - if ( ! empty( $styles['css'] ) ) {
93 - $processor->set_attribute( 'style', $styles['css'] );
92 + if ( '' === $svg ) {
93 + return;
94 94 }
95 - if ( ! empty( $styles['classnames'] ) ) {
96 - $processor->add_class( $styles['classnames'] );
97 - }
98 95
99 - $aria_label = ! empty( $attributes['ariaLabel'] ) ? $attributes['ariaLabel'] : '';
96 + $processor = new WP_HTML_Tag_Processor( $svg );
97 + if ( $processor->next_tag( 'svg' ) ) {
98 + if ( ! empty( $styles['css'] ) ) {
99 + // Merge with the SVG's intrinsic style (e.g. `fill: none` on
100 + // stroke-based icons) so it is preserved. The block styles come last
101 + // so they win on any conflicting property.
102 + $existing_style = $processor->get_attribute( 'style' );
103 + $trimmed_style = is_string( $existing_style )
104 + ? rtrim( trim( $existing_style ), ';' )
105 + : '';
106 + $merged_style = '' !== $trimmed_style
107 + ? $trimmed_style . '; ' . $styles['css']
108 + : $styles['css'];
109 + $processor->set_attribute( 'style', $merged_style );
110 + }
100 111
101 - if ( ! $aria_label ) {
102 - // Icon is decorative, hide it from screen readers.
103 - $processor->set_attribute( 'aria-hidden', 'true' );
104 - $processor->set_attribute( 'focusable', 'false' );
105 - } else {
106 - $processor->set_attribute( 'role', 'img' );
107 - $processor->set_attribute( 'aria-label', $aria_label );
112 + // Apply flip classes to the SVG.
113 + $flip_horizontal = $attributes['flipHorizontal'] ?? false;
114 + $flip_vertical = $attributes['flipVertical'] ?? false;
115 +
116 + if ( $flip_horizontal ) {
117 + $processor->add_class( 'is-flip-horizontal' );
118 + }
119 + if ( $flip_vertical ) {
120 + $processor->add_class( 'is-flip-vertical' );
121 + }
122 +
123 + $rotation = isset( $attributes['rotation'] ) ? (int) $attributes['rotation'] : 0;
124 +
125 + if ( $rotation ) {
126 + $current_style = $processor->get_attribute( 'style' ) ?? '';
127 + $rotation_css = 'rotate: ' . $rotation . 'deg;';
128 + $trimmed_style = is_string( $current_style )
129 + ? rtrim( trim( $current_style ), ';' )
130 + : '';
131 + $merged_style = '' !== $trimmed_style
132 + ? $trimmed_style . '; ' . $rotation_css
133 + : $rotation_css;
134 + $processor->set_attribute( 'style', $merged_style );
135 + }
136 +
137 + $svg = $processor->get_updated_html();
108 138 }
109 139
110 - // Return the updated SVG markup.
111 - $svg = $processor->get_updated_html();
112 - $attributes = get_block_wrapper_attributes();
113 - return sprintf( '<div %s>%s</div>', $attributes, $svg );
140 + $wrapper_attributes = get_block_wrapper_attributes();
141 + return sprintf( '<div %s>%s</div>', $wrapper_attributes, $svg );
114 142 }
115 143
116 144
117 145 /**