PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.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 +26 -42 23.6.2 → 22.7.0 View file →
@@ -18,8 +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;
27 + }
28 +
22 29 // Text color and background color.
23 30 $color_styles = array();
24 31
25 32 $preset_text_color = array_key_exists( 'textColor', $attributes ) ? "var:preset|color|{$attributes['textColor']}" : null;
@@ -78,56 +85,33 @@
78 85 'dimensions' => $dimensions_styles,
79 86 ),
80 87 );
81 88
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 - );
89 + $processor = new WP_HTML_Tag_Processor( $icon['content'] );
90 + $processor->next_tag( 'svg' );
91 91
92 - if ( '' === $svg ) {
93 - return;
92 + if ( ! empty( $styles['css'] ) ) {
93 + $processor->set_attribute( 'style', $styles['css'] );
94 94 }
95 + if ( ! empty( $styles['classnames'] ) ) {
96 + $processor->add_class( $styles['classnames'] );
97 + }
95 98
96 - $processor = new WP_HTML_Tag_Processor( $svg );
97 - if ( $processor->next_tag( 'svg' ) ) {
98 - if ( ! empty( $styles['css'] ) ) {
99 - $processor->set_attribute( 'style', $styles['css'] );
100 - }
99 + $aria_label = ! empty( $attributes['ariaLabel'] ) ? $attributes['ariaLabel'] : '';
101 100
102 - // Apply flip classes to the SVG.
103 - $flip_horizontal = $attributes['flipHorizontal'] ?? false;
104 - $flip_vertical = $attributes['flipVertical'] ?? false;
105 -
106 - if ( $flip_horizontal ) {
107 - $processor->add_class( 'is-flip-horizontal' );
108 - }
109 - if ( $flip_vertical ) {
110 - $processor->add_class( 'is-flip-vertical' );
111 - }
112 -
113 - $rotation = isset( $attributes['rotation'] ) ? (int) $attributes['rotation'] : 0;
114 -
115 - if ( $rotation ) {
116 - $current_style = $processor->get_attribute( 'style' ) ?? '';
117 - $rotation_css = 'rotate: ' . $rotation . 'deg;';
118 - if ( $current_style ) {
119 - $processor->set_attribute( 'style', $current_style . ' ' . $rotation_css );
120 - } else {
121 - $processor->set_attribute( 'style', $rotation_css );
122 - }
123 - }
124 -
125 - $svg = $processor->get_updated_html();
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 );
126 108 }
127 109
128 - $wrapper_attributes = get_block_wrapper_attributes();
129 - return sprintf( '<div %s>%s</div>', $wrapper_attributes, $svg );
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 );
130 114 }
131 115
132 116
133 117 /**