Skip to content

Commit 1aab75b

Browse files
committed
Don't render non-public icon on frontend
1 parent 1fa4107 commit 1aab75b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎packages/block-library/src/icon/index.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ function render_block_core_icon( $attributes ) {
1919
return;
2020
}
2121

22+
// Non-public icons 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 ( false === ( $registered_icon['public'] ?? true ) ) {
25+
return;
26+
}
27+
2228
// Text color and background color.
2329
$color_styles = array();
2430

‎phpunit/blocks/render-block-icon-test.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function set_up() {
3131
if ( ! WP_Icon_Collections_Registry::get_instance()->is_registered( 'core' ) ) {
3232
gutenberg_register_default_icon_collections();
3333
}
34-
if ( empty( WP_Icons_Registry::get_instance()->get_registered_icons() ) ) {
34+
if ( empty( WP_Icons_Registry_Gutenberg::get_instance()->get_registered_icons() ) ) {
3535
gutenberg_register_default_icons();
3636
}
3737
}
@@ -42,6 +42,11 @@ public function tear_down() {
4242
parent::tear_down();
4343
}
4444

45+
public function test_does_not_render_non_public_icon() {
46+
$this->assertNotEmpty( wp_get_icon( 'core/wordpress' ) );
47+
$this->assertEmpty( gutenberg_render_block_core_icon( array( 'icon' => 'core/wordpress' ) ) );
48+
}
49+
4550
public function test_preserves_intrinsic_svg_style_when_applying_block_styles() {
4651
$output = gutenberg_render_block_core_icon(
4752
array(

0 commit comments

Comments
 (0)