Global var _wp_menu_nopriv contains edit.php
-
Helle there,
i have a custom post type “follow_ups”
heres my args$follow_up_args = array( 'label' => __( 'Follow up', 'lng' ), 'description' => __( '', 'lng' ), 'labels' => $follow_up_labels, 'menu_icon' => 'dashicons-image-rotate', 'supports' => array('custom-fields'), 'taxonomies' => array(), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => true, 'show_in_nav_menus' => false, 'can_export' => false, 'has_archive' => false, 'hierarchical' => false, 'exclude_from_search' => true, 'show_in_rest' => false, 'publicly_queryable' => false, 'capability_type' => array('follow_up', 'follow_ups'), 'capabilities' => array( 'edit_post' => 'edit_follow_up', 'read_post' => 'read_follow_up', 'delete_post' => 'delete_follow_up', 'edit_posts' => 'edit_follow_ups', 'edit_others_posts' => 'edit_others_follow_ups', 'publish_posts' => 'publish_follow_ups', 'read_private_posts' => 'read_private_follow_ups', 'delete_posts' => 'delete_follow_ups', 'delete_others_posts' => 'delete_others_follow_ups', ) );
than i have the map_meta_cap filter like that
function md_map_meta_cap( $caps, $cap, $user_id, $args ) { /* If editing, deleting, or reading a place, get the post and post type object. */ if ( 'edit_follow_up' == $cap || 'delete_follow_up' == $cap || 'read_follow_up' == $cap ) { $post = get_post( $args[0] ); $post_type = get_post_type_object( $post->post_type ); /* Set an empty array for the caps. */ $caps = array(); } if ( 'edit_follow_up' == $cap ) { // If editing a place, assign the required capability. if ( $user_id == $post->post_author ){ $caps[] = $post_type->cap->edit_posts; } else { $caps[] = $post_type->cap->edit_others_posts; } } elseif ( 'delete_follow_up' == $cap ) { // If deleting a place, assign the required capability. if ( $user_id == $post->post_author ){ $caps[] = $post_type->cap->delete_posts; } else { $caps[] = $post_type->cap->delete_others_posts; } } elseif ( 'read_follow_up' == $cap ) { // If reading a private place, assign the required capability. if ( 'private' != $post->post_status ){ $caps[] = 'read'; } else if ( $user_id == $post->post_author ){ $caps[] = 'read'; } else { $caps[] = $post_type->cap->read_private_posts; } } /* Return the capabilities required by the user. */ return $caps; } add_filter( 'map_meta_cap', 'md_map_meta_cap', 10, 4 );
now when a custom user role that has the below caps assign to him
1) publish_follow_ups
2) edit_follow_ups
3) edit_others_follow_upson custom post type update gets a “you do not have the permission to edit this post”
i tried to debug with “admin_page_access_denied” filter like that
function debug_page_access() { global $pagenow; global $menu; global $submenu; global $_wp_menu_nopriv; global $_wp_submenu_nopriv; global $plugin_page; global $_registered_pages; $parent = get_admin_page_parent(); $hookname = get_plugin_page_hookname($plugin_page, $parent); echo "Pagenow = " . $pagenow . "<br/>"; echo "Parent = " . $parent . "<br/>"; echo "Hookname = " . $hookname . "<br/>"; echo "Submenu = " . $submenu[$parent] . "<br/>"; echo '_wp_menu_nopriv:<br>'; print('<pre>'.print_r($_wp_menu_nopriv,true).'</pre>'); echo "Submenu nopriv = " . $_wp_submenu_nopriv[$parent][$plugin_page] . "<br/>"; echo "Plugin page = " . $plugin_page . "<br/>"; echo "Registered pages = " . $_registered_pages[$hookname] . "<br/>"; } add_action('admin_page_access_denied', 'debug_page_access');
and this is the output… the edit.php in _wp_menu_nopriv array. any idea? thanks
Pagenow = edit.php Parent = Hookname = admin_page_ Submenu = _wp_menu_nopriv: Array ( [upload.php] => 1 [link-manager.php] => 1 [edit.php] => 1 [edit.php?post_type=page] => 1 [edit.php?post_type=blocks] => 1 [themes.php] => 1 [plugins.php] => 1 [tools.php] => 1 [options-general.php] => 1 [aam] => 1 [formcraft-dashboard] => 1 ) Submenu nopriv = Plugin page = Registered pages =
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Global var _wp_menu_nopriv contains edit.php’ is closed to new replies.