[wp-trac] [WordPress Trac] #45394: get_posts fails to return results when accessing admin with a custom user role
WordPress Trac
noreply at wordpress.org
Mon Dec 10 15:05:42 UTC 2018
#45394: get_posts fails to return results when accessing admin with a custom user
role
-------------------------------+------------------------------
Reporter: tonydjukic | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 4.9.8
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by tonydjukic):
@SergeyBiryukov The site doesn't run any plugins other than the custom one
I've built for the surveying system - switching themes makes no
difference. The issue only occurs in the back end - if I apply the same
methodology to the front end in a template it works for all user levels.
{{{#!php
<?php
function register_session_posttype() {
$labels = array(
'name' => _x( 'Sessions', 'post type
general name', 'mwss' ),
'singular_name' => _x( 'Submission', 'post
type singular name', 'mwss' ),
'add_new' => __( 'Add Session',
'seasonal_session', 'mwss' ),
'add_new_item' => __( 'Add New Session',
'seasonal_session', 'mwss' ),
'edit_item' => __( 'Edit Session', 'mwss'
),
'new_item' => __( 'New Session', 'mwss'
),
'view_item' => __( 'View Session', 'mwss'
),
'search_items' => __( 'Search Sessions',
'mwss' ),
'not_found' => __( 'No Sessions found.',
'mwss' ),
'not_found_in_trash'=> __( 'No Sessions found in
trash.', 'mwss' ),
'parent_item_colon' => __( 'Parent Sessions:',
'mwss' ),
'menu_name' => __( 'Sessions', 'mwss' )
);
$taxonomies = array();
$supports = array(
'title'
);
$post_type_args = array(
'labels' => $labels,
'singular_label' => __('Session', 'post
type singular name', 'mwss'),
'public' => true,
'show_ui' => true,
'publicly_queryable' => true,
'query_var' => true,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'rewrite' => array( 'slug' =>
'seasonal_sessions', 'with_front' => false ),
'supports' => $supports,
'menu_position' => 5,
'menu_icon' => 'dashicons-calendar',
'taxonomies' => $taxonomies,
'register_meta_box_cb' =>
'mwss_add_session_metaboxes',
'map_meta_cap' => true
);
register_post_type( 'seasonal_sessions', $post_type_args
);
}
add_action('init', 'register_session_posttype');
}}}
I did actually try multiple variations to apply ''capabilities'' and
''map_meta_cap'', but they made no difference whatsoever.
Here's an example of my last, desperate, attempt:
{{{
// 'capability_type' =>
array('post','seasonal_session','seasonal_sessions'),
// 'capabilities' => array(
// 'edit_post' =>
'edit_seasonal_session',
// 'edit_posts' =>
'edit_seasonal_sessions',
// 'edit_others_posts' =>
'edit_others_seasonal_sessions',
// 'publish_posts' =>
'publish_seasonal_sessions',
// 'read_post' =>
'read_seasonal_session',
// 'read_posts' =>
'read_seasonal_sessions',
// 'read_private_posts' =>
'read_private_seasonal_sessions',
// 'delete_post' =>
'delete_seasonal_session',
// ),
}}}
I genuinely don't understand why it would work for all user levels on the
front end, but only editor or higher on the back end - that's what led me
to start wondering if there was some sort of bug.
I've also repeatedly worked through the custom user roles and tried to
ensure that they have all the correct permissions, but that had no effect
on the behavior either. (I first attempted it through code, but then even
went and installed capability plugins to cross check my code changes -
according to each plugin I tested with, every user role had the correct
permissions to be able to edit and update the post type.)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45394#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list