Home › Forums › General Issues › Gallery Upload on Front end form › Reply To: Gallery Upload on Front end form
I’ve restricted my users with a custom role, granting the ability to manage_photos (their own ones) or manage_others_photos:
add_filter( 'ajax_query_attachments_args', 'show_only_current_user_attachments', 10 );
function show_only_current_user_attachments( $query ) {
$user_id = get_current_user_id();
if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts') && !current_user_can('manage_others_photos') ) {
$query['author'] = $user_id;
$query['post_parent'] = 0;
} elseif ($user_id && !current_user_can('activate_plugins')) {
$query['post_parent'] = 0;
}
return $query;
}
I also didn’t want to display images that were already attached to other posts, so I’ve filtered those out too in the version above.
If you want a basic version without my additions:
add_filter( 'ajax_query_attachments_args', 'show_only_current_user_attachments', 10 );
function show_only_current_user_attachments( $query ) {
$user_id = get_current_user_id();
if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts') ) {
$query['author'] = $user_id;
}
return $query;
}
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.