[wp-trac] [WordPress Trac] #16808: Insufficient permissions for custom post type management and custom role/caps

WordPress Trac noreply at wordpress.org
Thu Aug 11 06:36:50 UTC 2016


#16808: Insufficient permissions for custom post type management and custom
role/caps
-----------------------------+------------------------------
 Reporter:  Genesis2001      |       Owner:
     Type:  defect (bug)     |      Status:  reopened
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Role/Capability  |     Version:  3.1
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by bynicolas):

 This also happens on the {{{edit.php}}} page when a CPT is set not to use
 the {{{ Add New}}} UI when registered using
 {{{
 'capabilities' => array(
   'create_posts' => false
   ),
 }}}

 and no other menu item is created (no custom tax, settings, etc.)
 This happens for custom roles that don't have WP core capabilities (at
 least {{{edit_posts}}} and {{{publish_posts}}}) enabled.

 The issue is similar but the workaround needed to be updated since in this
 case it did not fail at line 1703 (now line 1725 in WP 4.5.3) but rather
 at line 1716

 This worked for me

 {{{#!php
 add_action( 'admin_menu', 'trac16808_add_post_type_submenus_edit', 99 );
 function trac16808_add_post_type_submenus_edit() {
   foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) {

           $ptype_obj = get_post_type_object( $ptype );

           if ( $ptype_obj->cap->create_posts )
             continue;

           add_submenu_page( $ptype_obj->show_in_menu,
 $ptype_obj->labels->all_items, $ptype_obj->labels->all_items,
 $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
   }
 }

 }}}

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


More information about the wp-trac mailing list