January 9, 2018

Restrict users to view only their uploads while using ACF

Restrict users to view only their uploads while using ACF

add_filter( 'ajax_query_attachments_args', 'lb_show_current_user_attachments' );
function lb_show_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;
}

Last updated: January 9, 2018