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++;
}

1 Answer
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

Leave a Reply

Your email address will not be published. Required fields are marked *