PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.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 All 404 releases
← All changes | build/scripts/block-library/icon.php +61 -24 23.2.2 → 24.1.0 View file →
@@ -18,13 +18,15 @@
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;
22 + // Icons in non-public collections are not available in the editor, so do not render them either.
23 + $registered_icon = WP_Icons_Registry::get_instance()->get_registered_icon( $attributes['icon'] );
24 + if ( null !== $registered_icon ) {
25 + $icon_collection = WP_Icon_Collections_Registry::get_instance()->get_registered( $registered_icon['collection'] );
26 + if ( null !== $icon_collection && ! $icon_collection['public'] ) {
27 + return;
28 + }
27 29 }
28 30
29 31 // Text color and background color.
30 32 $color_styles = array();
@@ -85,33 +87,68 @@
85 87 'dimensions' => $dimensions_styles,
86 88 ),
87 89 );
88 90
89 - $processor = new WP_HTML_Tag_Processor( $icon['content'] );
90 - $processor->next_tag( 'svg' );
91 + $svg = wp_get_icon(
92 + $attributes['icon'],
93 + array(
94 + // Width is applied via the dimensions block support styles below.
95 + 'size' => null,
96 + 'class' => $styles['classnames'] ?? '',
97 + 'label' => $attributes['ariaLabel'] ?? '',
98 + )
99 + );
91 100
92 - if ( ! empty( $styles['css'] ) ) {
93 - $processor->set_attribute( 'style', $styles['css'] );
101 + if ( '' === $svg ) {
102 + return;
94 103 }
95 - if ( ! empty( $styles['classnames'] ) ) {
96 - $processor->add_class( $styles['classnames'] );
97 - }
98 104
99 - $aria_label = ! empty( $attributes['ariaLabel'] ) ? $attributes['ariaLabel'] : '';
105 + $processor = new WP_HTML_Tag_Processor( $svg );
106 + if ( $processor->next_tag( 'svg' ) ) {
107 + if ( ! empty( $styles['css'] ) ) {
108 + // Merge with the SVG's intrinsic style (e.g. `fill: none` on
109 + // stroke-based icons) so it is preserved. The block styles come last
110 + // so they win on any conflicting property.
111 + $existing_style = $processor->get_attribute( 'style' );
112 + $trimmed_style = is_string( $existing_style )
113 + ? rtrim( trim( $existing_style ), ';' )
114 + : '';
115 + $merged_style = '' !== $trimmed_style
116 + ? $trimmed_style . '; ' . $styles['css']
117 + : $styles['css'];
118 + $processor->set_attribute( 'style', $merged_style );
119 + }
100 120
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 );
121 + // Apply flip classes to the SVG.
122 + $flip_horizontal = $attributes['flipHorizontal'] ?? false;
123 + $flip_vertical = $attributes['flipVertical'] ?? false;
124 +
125 + if ( $flip_horizontal ) {
126 + $processor->add_class( 'is-flip-horizontal' );
127 + }
128 + if ( $flip_vertical ) {
129 + $processor->add_class( 'is-flip-vertical' );
130 + }
131 +
132 + $rotation = isset( $attributes['rotation'] ) ? (int) $attributes['rotation'] : 0;
133 +
134 + if ( $rotation ) {
135 + $current_style = $processor->get_attribute( 'style' ) ?? '';
136 + $rotation_css = 'rotate: ' . $rotation . 'deg;';
137 + $trimmed_style = is_string( $current_style )
138 + ? rtrim( trim( $current_style ), ';' )
139 + : '';
140 + $merged_style = '' !== $trimmed_style
141 + ? $trimmed_style . '; ' . $rotation_css
142 + : $rotation_css;
143 + $processor->set_attribute( 'style', $merged_style );
144 + }
145 +
146 + $svg = $processor->get_updated_html();
108 147 }
109 148
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 );
149 + $wrapper_attributes = get_block_wrapper_attributes();
150 + return sprintf( '<div %s>%s</div>', $wrapper_attributes, $svg );
114 151 }
115 152
116 153
117 154 /**