When non-admin users upload media, They get the following error:
Things i have checked:
Core capabilities and custom for a test user ( who gets this error) is set for yes for media_upload Refer to the image below:
Deactivated all plugins, issue remains same.
If anyone has had a similar issue, I'm open for suggestions. Thanks.
UPDATE From wp-admin/includes/ ajax-action.php, I removed the following part:
if ( isset( $_REQUEST['post_id'] ) ) {
$post_id = $_REQUEST['post_id'];
if ( ! current_user_can( 'edit_post', $post_id ) ) {
echo wp_json_encode( array(
'success' => false,
'data' => array(
'message' => __( "You don't have permission to attach files to this post." ),
'filename' => $_FILES['async-upload']['name'],
)
) );
wp_die();
}
}
I realize that this is just sort of a checkpoint to see user capabilities but I dont fully understand why removing this part helped solve the issue. Now test user can upload media successfully ( media upload was successful earlier too) and there is no permission error and "UPLOAD MEDIA" button at the bottom is not greyed any more so I can upload as normal. Thanks
Removing core WP code isn't recommended at all!
The cause of this kind of error is often a PHP upload limit in your hosting environment. See here an example of how to change your PHP values : Change the maximum upload file size
But looking at your capabilities screenshot for posts Post Type, it seems your Role doesn't even enable to edit a post. I would first at least enable this Capability : edit_posts
. And maybe some other posts-related Capabitilies.
For reference, here is a useful table to help understand Wordress Roles and Capabilities : Capability vs. Role Table