WordPress.org

Make WordPress Core

Changes between Initial Version and Version 5 of Ticket #32088


Ignore:
Timestamp:
06/29/2017 07:41:57 PM (2 years ago)
Author:
ocean90
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32088

    • Property Keywords needs-patch added
    • Property Component changed from General to Menus
    • Property Focuses administration added
    • Property Type changed from enhancement to defect (bug)
  • Ticket #32088 – Description

    initial v5  
    11Hello,
    22
    3 {{{function get_admin_page_parent( $parent = '' ) }}} seems buggy.
     3`function get_admin_page_parent( $parent = '' ) ` seems buggy.
    44
    55My Goal:
     
    77
    88What I do:
    9 -       I have a custom post type (CPT)  with 2 Default builtin Taxonomies (category/post_tags). But The user has no Capability to access them. So effectively this CPT has 2 Sub-Menu-Items by default: „Listing All“ and „Add New“ (Note: I have no English installation, so the namings might slightly be different in original English).
    10 -       I remove the „Add New“ Menu item in the {{{„_admin_menu“}}} Hook by unsetting the respective {{{$submenu}}} item array entry: {{{unset($GLOBALS['submenu']['edit.php?post_type=mycpt'][10]);}}}
    11 -       I have debugged it: As there is only one Sub-Menu-Item left („Listing All“), Wordpress now tests if the single left Sub-Menu Item is identical to the Main-Menu Item. If yes, it will remove the Sub-Menu-Item. This works ok. Now the global {{{$submenu}}} array does no longer contain any Submenu Items. And the global {{{$menu}}} item still contains the Main-Menu Item for the CPT with the „Listing All“ link ({{{wp-admin/edit.php?post_type=mycpt}}}).
     9-       I have a custom post type (CPT)  with 2 Default builtin Taxonomies (category/post_tags). But The user has no Capability to access them. So effectively this CPT has 2 Sub-Menu-Items by default: "Listing All" and "Add New" (Note: I have no English installation, so the namings might slightly be different in original English).
     10-       I remove the "Add New" Menu item in the `"_admin_menu"` Hook by unsetting the respective `$submenu` item array entry: `unset($GLOBALS['submenu']['edit.php?post_type=mycpt'][10]);`
     11-       I have debugged it: As there is only one Sub-Menu-Item left ("Listing All"), Wordpress now tests if the single left Sub-Menu Item is identical to the Main-Menu Item. If yes, it will remove the Sub-Menu-Item. This works ok. Now the global `$submenu` array does no longer contain any Submenu Items. And the global `$menu` item still contains the Main-Menu Item for the CPT with the "Listing All" link (`wp-admin/edit.php?post_type=mycpt`).
    1212
    1313Bug:
    14 -       But when I acces the {{{http://localhost/super/wp-admin/edit.php?post_type=mycpt}}} page by clicking on the Main-Menu Item, I get an „no appropriate rights“ error
    15 -       It turns out that the {{{get_admin_page_parent( $parent = '' )}}}  function does return an empty (!) result instead of {{{edit.php?post_type=mycpt}}}. (I tested this by enabling the second submenu item and in this case the function returns {{{„edit.php?post_type=mycpt“}}}.
    16 -       When the function returns empty, than it will trigger (in {{{ user_can_access_admin_page()) }}}
    17 {{{ if ( empty( $parent) ) {
    18 if ( isset( $_wp_menu_nopriv[$pagenow] ) )}}}
    19 -       And this will deny access! The reason this is triggered is {{{$pagenow}}} is {{{„edit.php“}}}. And I do NOT allow users access to the build in Default WP Post type! So {{{$_wp_menu_nopriv}}} contains {{{„edit.php“}}}.
     14-       But when I acces the `http://localhost/super/wp-admin/edit.php?post_type=mycpt` page by clicking on the Main-Menu Item, I get an "no appropriate rights" error
     15-       It turns out that the `get_admin_page_parent( $parent = '' )`  function does return an empty (!) result instead of `edit.php?post_type=mycpt`. (I tested this by enabling the second submenu item and in this case the function returns `"edit.php?post_type=mycpt"`.
     16-       When the function returns empty, than it will trigger (in ` user_can_access_admin_page()`)
     17{{{
     18if ( empty( $parent) ) {
     19if ( isset( $_wp_menu_nopriv[$pagenow] ) )
     20}}}
     21-       And this will deny access! The reason this is triggered is `$pagenow` is `"edit.php"`. And I do NOT allow users access to the build in Default WP Post type! So `$_wp_menu_nopriv` contains `"edit.php"`.
    2022
    21 As I can judge this, this is  bug in {{{get_admin_page_parent( $parent = '' )}}}  that will be triggered for all(!) Custom Post types with only one Submenuitem. But will only be visible, in practice if you additionally disable the build in standard „post“ type. 
     23As I can judge this, this is  bug in `get_admin_page_parent( $parent = '' )`  that will be triggered for all(!) Custom Post types with only one Submenuitem. But will only be visible, in practice if you additionally disable the build in standard "post" type. 
    2224
    2325Thanks!