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

WordPress Trac noreply at wordpress.org
Sat Nov 11 02:50:26 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:  3.0
 Severity:  minor                                |  Resolution:
 Keywords:  has-patch needs-testing dev-         |     Focuses:
  feedback                                       |
-------------------------------------------------+-------------------------
Changes (by ironprogrammer):

 * keywords:  reporter-feedback => has-patch needs-testing dev-feedback
 * version:  6.2.1 => 3.0


Comment:

 I understand now, thanks, @andrewleap 👍🏻 The patch looks good for
 addressing this issue, and I've made some slight formatting adjustments
 for readability, reflected in attachment:58361.3.diff.

 I've most often seen the div's background set for custom menu icons (and
 using `display: none` on the img), but I suppose there's a chance an
 extender has tried to "fix" the broken img by setting a valid src 🤔
 Unsure what backward compatibility implications this might have, since the
 use of `esc_url( $ptype_obj->menu_icon )` has been around
 [https://github.com/WordPress/wordpress-
 develop/commit/697e807eb03abd2ac51d9ea2981592ae7e1dab2b since WP 3.0].
 Additional input from a committer would be helpful here. CC @azaozz in
 case he has a chance to take a look.

 == Test Report
 Patch tested: attachment:58361.3.diff

 === Steps to Reproduce or Test
 1. Register a custom post type, setting the `menu_icon` argument to
 `'none'`
 ([https://gist.github.com/ironprogrammer/24fbeedc186e7e85a45711932bf94b8a
 e.g. this example gist] to use as mu-plugin).
 2. Load WP admin and inspect the HTML for the "Books" menu item.
 3. Observe the markup in `div.wp-menu-image`.

 === Expected Results
 When reproducing the bug:
 - 🐛 A broken image, `<img src="http://none" alt="">` is rendered in the
 div.

 When testing a patch to validate it works as expected:
 - 👍🏻 A line break, `<br>`, should be rendered in the div when
 `menu_icon` is set to 'none' or 'div'.

 === Environment
 - Hardware: MacBook Pro Apple M1 Pro
 - OS: macOS 13.6
 - Browser: Safari 17.0
 - Server: nginx/1.25.3
 - PHP: 8.2.12
 - WordPress: 6.5-alpha-56966-src
 - Theme: twentytwentyfour v1.0
 - Active Plugins:
  - gutenberg v17.0.0
  - test-cpt (the CPT test plugin noted in steps to repro above)

 === Actual Results
 When reproducing the bug:
 - ✅ I was able to reproduce this issue.
 {{{
 <div class="wp-menu-image dashicons-before" aria-hidden="true">
     <img src="http://none" alt="">
 </div>
 <div class="wp-menu-name">Books</div>
 }}}

 When testing the patch:
 - ✅ Issue was resolved with patch.
 {{{
 <div class="wp-menu-image dashicons-before" aria-hidden="true">
     <br>
 </div>
 <div class="wp-menu-name">Books</div>
 }}}

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


More information about the wp-trac mailing list