shivgre shivgre - 2 months ago 32
PHP Question

Wordpress subscriber role user cannot upload images from frontend

I am having permissions issue with wordpress website for users with role=

subscriber
.

A user with role=
administrator
can upload images via wp media uploader from frontend just fine from the same form. But whenever a user uploads image from that same form then in firebug console I see
/wp-admin/admin-ajax.php
ajax which returns
0
with status
200


And just after that ajax, another ajax is called
/wp-admin/async-upload.php
with a
302
which tries to redirect using ajax to
/wp-login.php?redirect_to=/wp-admin/async-upload.php&reauth=1


I have tried adding various permission levels in my themes function.php but still the same error :

###ROLE FIX FOR UPLOAD FILES
if ( current_user_can('subscriber') && !current_user_can('upload_files') )
add_action('init', 'allow_subscriber_uploads');


function allow_subscriber_uploads() {

$new_role = get_role('subscriber');
$new_role->add_cap('upload_files');
}


All I see on media upload screen is this error:
An error occurred in the upload. Please try again later.


Any help or hint would be much appreciated.

Wordpress Version of website is: 4.5.3

Answer

It was due to some plugin conflict and not due to permission issues for role=subscriber.

I also added members plugin after which the issue was fixed automatically.

I am still not clear how the issue was fixed but adding the members plugin seemed to help.

Comments