WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#34637 closed defect (bug) (fixed)

CPT menu icon leakage

Reported by: obenland Owned by: obenland
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

When a Custom Post Type (CPT) that doesn't define menu_icon happens to be registered after a CPT that does define menu_icon, that icon will then be attached to both.

In wp-admin/menu.php we loop through all post types and check if the menu_icon property is a string, and if it's not, if the post type is built-in, to define the $menu_icon variable. If that is both not true (like when menu_icon was never set), $menu_icon stays unchanged from the previous loop.

Attachments (3)

34637.diff (689 bytes) - added by obenland 5 years ago.
34637.2.diff (761 bytes) - added by obenland 5 years ago.
Setting a true default menu icon.
34637.3.diff (709 bytes) - added by obenland 5 years ago.

Download all attachments as: .zip

Change History (7)

@obenland
5 years ago

#1 @obenland
5 years ago

Doing some more testing I noticed how there is no de facto default menu icon for CPT. The default icon just happens to be whatever icon was defined for the CPT before.

<?php
add_action('init', function(){
        register_post_type( 'weird', array(
                'label' => 'weird',
                'public' => true,
        ) );
});

On a trunk install, the above will use the page's icon, since it will be output right after it.
@DrewAPicture suggested to use the page icon for hierarchical CPTs and the post icon for non-hierarchical ones.

@obenland
5 years ago

Setting a true default menu icon.

#2 @obenland
5 years ago

  • Version set to trunk

Introduced in [33723].

@obenland
5 years ago

#3 @ocean90
5 years ago

In case 34637.2.diff wins: The description of $menu_icon for register_post_type() says "Defaults to use the posts icon.".

#4 @obenland
5 years ago

  • Owner set to obenland
  • Resolution set to fixed
  • Status changed from new to closed

In 35590:

Menu: Continue to use post dashicon as default menu icon.

Prevents a bug where custom post types without a specified menu icon would
adopt the menu icon of the preceding post type. Introduced in [33723].

See #16865.
Fixes #34637.

Note: See TracTickets for help on using tickets.