[wp-trac] [WordPress Trac] #58361: Passing 'none' as 'menu_icon' to 'register_post_type' is not working correctly

WordPress Trac noreply at wordpress.org
Thu Oct 26 18:48:48 UTC 2023


#58361: Passing 'none' as 'menu_icon' to 'register_post_type' is not working
correctly
-------------------------------+------------------------------
 Reporter:  andrewleap         |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Administration     |     Version:  6.2.1
 Severity:  minor              |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by andrewleap):

 Replying to [comment:2 ironprogrammer]:
 > Thanks for the report, @andrewleap, and welcome back to Trac!
 >
 > `register_post_type()` expects that `menu_icon` is a URL, Dashicon, or
 base64-encoded SVG. Please see
 https://developer.wordpress.org/reference/functions/register_post_type/#menu_icon.
 Is your intent to not display any icon at all for the menu?
 >
 > === Background
 > `esc_url( $ptype_obj->menu_icon )` has existed since
 https://core.trac.wordpress.org/browser/trunk/wp-
 admin/menu.php?rev=14097#L119, and provided a way to add a menu icon by
 URL.
 >
 > Looking deeper into the intent behind `wp-admin/menu-header.php`'s check
 for `none` or `div` (see r21877), it seems these values were to be
 assigned internally by `wp-admin/menu.php` in the case that `menu_icon`
 was **null**. That behavior has since evolved to
 [https://developer.wordpress.org/reference/functions/register_post_type/#menu_icon
 display the default posts icon].

 The intention was to include an icon from Goole material icons via css
 using by passing the "none" option as documented here:
 https://developer.wordpress.org/reference/functions/register_post_type/#parameters
 but it does not work. Rather than emitting and empty div, it emits `<img
 src="http://none" alt="">`

 This is because `$menu_icon` is escaped with `esc_url`, so when checking
 to see if it is equal to `'none'`, this check fails

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58361#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list