Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#39351 new defect (bug)

Passing 'none' to menu_icon of custom post type displays broken image in admin menu

Reported by: mensmaximus's profile mensmaximus Owned by:
Milestone: Future Release Priority: normal
Severity: minor Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: administration Cc:

Description

According to the inline documentation of class WP_Post_Type you have to pass 'none' for the menu_icon parameter to leave div.wp-menu-image empty to be able to add an icon via CSS.

However passing none (or div) as menu_icon while registering a post type result in a broken image because instead of 'none' you get 'http://none'.

The following condition in line 120 of menu-header.php does not match:

if ( 'none' === $item[6] || 'div' === $item[6] ) {
	$img = '<br />';
}

The conditional statement in line 103 of /wp-admin/menu.php url escapes any value of menu_icon that is neither a dashicons class nor a svg data:

if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) {
		$menu_icon = $ptype_obj->menu_icon;
} else {
		$menu_icon = esc_url( $ptype_obj->menu_icon );
}

To make 'none' and 'div' (deprecated) work as documented either the first condition has to be extended or an additional elseif statement has to be included. I have opted for the second statement for better readability and documentation.

Attachments (1)

menu.patch (720 bytes) - added by mensmaximus 7 years ago.
Fix for custom post type menu_icon with value 'none' or 'div'

Download all attachments as: .zip

Change History (9)

@mensmaximus
7 years ago

Fix for custom post type menu_icon with value 'none' or 'div'

#1 @mensmaximus
7 years ago

  • Keywords has-patch added

#2 @mensmaximus
7 years ago

  • Severity changed from normal to major

Still no answers?

#3 @mensmaximus
7 years ago

4 month and not a single reaction although I have provided a patch is strange. Can someone please comment on this issue? What can I do to get the bug fixed?

#4 @lukecavanagh
7 years ago

menu.patch Applies cleanly.

#5 @swissspidy
7 years ago

  • Milestone changed from Awaiting Review to 4.8
  • Severity changed from major to minor
  • Version 4.7 deleted

Moving to the milestone for consideration.

Note that the patch would need to be cleaned up a bit as we do not write multi-line comments like this. Also, backward compatibility needs to be considered.

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


7 years ago

This ticket was mentioned in Slack in #core by obenland. View the logs.


7 years ago

#8 @obenland
7 years ago

  • Milestone changed from 4.8 to Future Release
Note: See TracTickets for help on using tickets.