[wp-trac] [WordPress Trac] #56480: _add_post_type_submenus doesn't use WP_Post_Type::$menu_position
WordPress Trac
noreply at wordpress.org
Wed Aug 31 17:17:11 UTC 2022
#56480: _add_post_type_submenus doesn't use WP_Post_Type::$menu_position
-------------------------------+-----------------------------
Reporter: Rahmohn | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: trunk
Severity: normal | Keywords:
Focuses: administration |
-------------------------------+-----------------------------
Although it's possible to add a post type as a submenu when registering by
setting the property show_in_menu, it's not possible to set the position.
This is happening because in the function [https://github.com/WordPress
/wordpress-develop/blob/trunk/src/wp-includes/post.php#L2071
_add_post_type_submenus] (wp-includes/post.php) the function
add_submenu_page is called without passing the parameter $position.
{{{#!php
<?php
function _add_post_type_submenus() {
foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype )
{
$ptype_obj = get_post_type_object( $ptype );
// Sub-menus only.
if ( ! $ptype_obj->show_in_menu || true ===
$ptype_obj->show_in_menu ) {
continue;
}
add_submenu_page( $ptype_obj->show_in_menu,
$ptype_obj->labels->name, $ptype_obj->labels->all_items,
$ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
}
}
}}}
Steps to reproduce the issue:
1. Add the code snippet in the functions.php of the theme (notice the
'menu_position')
{{{#!php
<?php
register_post_type(
'foo',
array(
'labels' => array(
'name' => 'Foo',
),
'show_in_menu' => 'edit.php?post_type=page',
'menu_position' => 20,
'public' => true,
)
);
register_post_type(
'bar',
array(
'labels' => array(
'name' => 'Bar',
),
'show_in_menu' => 'edit.php?post_type=page',
'menu_position' => 10,
'public' => true,
)
);
}}}
2. Visit the Dashboard and check that under the menu Pages, "Foo" appears
**before** "Bar"
Expected behaviour: "Foo" appears **after** "Bar"
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56480>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list