Undefined property: stdClass::$edit_published_posts
-
When I have a custom post type without the ‘edit_published_posts’ capability defined, I get a php notice (in debug mode) when viewing the edit posts admin page for that post type: “Notice: Undefined property: stdClass::$edit_published_posts.” Not a huge issue. I’m just reporting it, and happy to have feedback for a better resolution than below. Here’s my setup.
- WP debug mode
- Co-Authors Plus 3.0.2
- Twenty Eleven 1.4
- WP 3.4.2
- no other plugins
Some code to replicate the problem:
// in wp-config.php: define('WP_DEBUG', true); add_action( 'init', 'sample_cpt' ); function sample_cpt() { // Register New Post Type $args = array( 'public' => true, 'label' => 'Events', 'supports' => array('title', 'editor', 'page-attributes'), 'capabilities' => array( 'edit_post' => 'edit_event', 'read_post' => 'read_event', 'delete_post' => 'delete_event', // etc. //'edit_published_posts' => 'edit_published_events' ) ); register_post_type( 'events', $args ); // normally might add_cap() to roles here // Create example post $example_post_exists = get_page_by_title('example post', 'object', 'events'); if ( !$example_post_exists ) { $example_post = array( 'post_content' => 'example post content', 'post_status' => 'publish', 'post_title' => 'example post', 'post_type' => 'events' ); wp_insert_post($example_post); } } // Go view php notice on admin edit posts page for new Events cpt
As expected, the notice does not display if you uncomment the
'edit_published_posts' => 'edit_published_events'
in the ‘capabilities’ code above. I think the capability'edit_published_posts'
would normally be set by default, unless omitted in an explicit declaration of the capabilities, like my example above. I’ve come across a plugin for which this was the case.To get rid of the notice, I’ve altered the file co-authors-plus.php on line 1075
if ( 'publish' == get_post_status( $post_id ) /*&& ! empty( $obj->cap->edit_published_posts)*/ && ! empty( $current_user->allcaps[$obj->cap->edit_published_posts] ) )
I added the conditional inside the commented section (/*conditional*/). Uncomment it and the notice no longer displays. The same thing could probably be done on line 1077.
Feedback welcome. Thanks for a great plugin!
- The topic ‘Undefined property: stdClass::$edit_published_posts’ is closed to new replies.