Home › Forums › Front-end Issues › Front-End Media Upload Capabilities Issue
I am using the front end for to allow users to edit a custom post type. There are are whole lot of fields on the post type, and it is really pretty incredible how easy it was to set this front end form up.
This issue is that I need to allow users of the subscriber role to upload media, but those users are not allowed. I have added the ‘upload_files’ capability to the subscriber role:
add_action('wp', 'allow_subscriber_uploads');
function allow_subscriber_uploads() {
$subscriber = get_role('subscriber');
$subscriber->add_cap('upload_files');
}
That works great. It allows the subscribers to use the ajax upload window. Very spiffy. The ajax modal window comes up, but when you upload something it returns this error: You don’t have permission to attach files to this post.
I do not have any javascript errors in the console.
Does anyone have any suggestions as to what to try next?
Hi @fitzryland
I believe you need to add other capabilities for your subscriber role like edit_others_posts, edit_posts, edit_published_posts. This page should give you more idea about it: https://codex.wordpress.org/Roles_and_Capabilities.
Hope this helps!
Thanks for the nudge in the right direction. I think I was just a little lost in the weeds last night. Here is what I ended up with:
add_action('wp', 'allow_subscriber_uploads');
function allow_subscriber_uploads() {
$subscriber = get_role('subscriber');
// author caps
$subscriber->add_cap('edit_published_posts');
$subscriber->add_cap('delete_posts');
$subscriber->add_cap('edit_posts');
$subscriber->add_cap('upload_files');
// editor caps
$subscriber->add_cap('edit_others_posts');
}
That allows subscribers to upload and delete media.
This still doesn’t for me. I changed the permission to like this:
add_action('wp', 'allow_employer_uploads');
function allow_employer_uploads() {
$employer = get_role('employer');
// author caps
$employer->add_cap('edit_published_posts');
$employer->add_cap('delete_posts');
$employer->add_cap('edit_posts');
$employer->add_cap('upload_files');
// editor caps
$employer->add_cap('edit_others_posts');
}
The topic ‘Front-End Media Upload Capabilities Issue’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.