2

I got the wp_die error message:

Sorry, you are not allowed to move this item to the Trash.

on trying to put the post in trash, but when I tried to put it in trash again the wp_die error message:

Error in moving to Trash.

showed up and on refresh I see that the post was deleted. I have the administrator role, so I have the delete_post capability. According to this code snippet in wp-admin/edit.php, the role with admin should not get any of these errors.

foreach ( (array) $post_ids as $post_id ) {
    if ( !current_user_can( 'delete_post', $post_id) )
        wp_die( __('Sorry, you are not allowed to move this item to the Trash.') );

    if ( wp_check_post_lock( $post_id ) ) {
        $locked++;
        continue;
    }

    if ( !wp_trash_post($post_id) )
        wp_die( __('Error in moving to Trash.') );

    $trashed++;
}
2
  • is the problem with a regular post and not a custom post type created by a plugin ?
    – mmm
    Commented Apr 3, 2017 at 11:17
  • it's with a custom post
    – IAmDhar
    Commented Apr 3, 2017 at 11:18

1 Answer 1

1

When you use map_meta_cap with a custom post type (e.g. CPT book), the capability delete_book is not automatiqualy added to administrators.

then you need to use add_cap to add it

https://codex.wordpress.org/Function_Reference/add_cap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.