Home › Forums › ACF PRO › Gallery field hide media library › Reply To: Gallery field hide media library
I created a custom user role with capabilities similar to ‘author’. The code you posted limited the images visible in the Gallery field itself but not in the media library. I was able to get it working with the following:
function restrict_media_library_to_current_user( $wp_query_obj ) {
if ( ! current_user_can( 'level_5' ) ) {
global $current_user, $pagenow;
if ( ! is_a( $current_user, 'WP_User' ) || 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' ) {
return;
}
$wp_query_obj->set( 'author', $current_user->ID );
return;
}
}
add_action( 'pre_get_posts', 'restrict_media_library_to_current_user' );
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.