[wp-trac] [WordPress Trac] #50284: A fix to the CPT-no-create-when-submenu-child problem.
WordPress Trac
noreply at wordpress.org
Fri May 29 23:04:21 UTC 2020
#50284: A fix to the CPT-no-create-when-submenu-child problem.
-------------------------------------------------+-------------------------
Reporter: mort1305 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Administration | Version: 5.4.1
Severity: major | Keywords: has-fix
Focuses: ui, administration, rest-api, |
performance, coding-standards |
-------------------------------------------------+-------------------------
Here's a bug and a work around solution. (It is something that coders try
to implement, but back away from when they see it's broken.) Code is
traced ready to be altered. Please see
[StackExchange](https://wordpress.stackexchange.com/questions/367822/how-
to-allow-add-new-capability-of-cpt-when-links-to-its-ui-are-placed-
as-a-su) for the bloodsucking work.
Short is that users with the `edit_{post-type}` custom capability for a
custom post type cannot create that particular post type if the UI is
accessible by way of a submenu. The fix is to **NOT POPULATE THE POST
MENU WITH post-new.php** if the user does not possess the `edit_posts`
capability. [This
line](https://core.trac.wordpress.org/browser/tags/5.4/src/wp-
admin/menu.php#L170) is the problem child: it needs to go sit in the
corner with a pointy hat on.
I'm new to the whole playing with other WordPressers in the sandbox kind
of thing. If I knew how to make changes to the core for upgrades, I would
have submitted a file change with that line 170 in wp-admin/menu.php
looking like this: `if( current_user_can($ptype_obj->cap->create_posts) )
{ $submenu[ $ptype_file ][10] = array( $ptype_obj->labels->add_new,
$ptype_obj->cap->create_posts, $post_new_file ); }` ... well, formatted
nicely into three lines, obviously.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50284>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list