Home Forums Add-ons Gallery Field ACF PRO Gallery: restrict view own Media


ACF PRO Gallery: restrict view own Media

  • Hey Guys,

    we are using ACF for expand a single blog post with extra VIDEO-Upload + PHOT-Upload + GALLERY. On Top we restrict any user to see their own media and POST – all works perfect!

    Another function we added in function.php is to duplicate a POST for another Author.
    – so the function is using the current POST ID to COPY the full posts with some new Author
    – in the second action ALL META DATA is duplicated

    Now the new post is duplicated perfectly for the new Author INCLUDING the PHOTO and VIDEO…
    ALSO the Gallery Images are duplicated in DB but didn’t Show up in the backed of the new Author based on the media restrict.

    Why the Photo + Video is shown perfectly (image owner is still the old author) and only the gallery items are empty? So how a ACF picture differs from a ACF gallery item in the DB that the new Author can’t see anything inside the Gallery?

    Any Idea do understand the difference?

    Attached the Postmeta (Photo and Video works fine – Gallery is empty instead of having data in DB )

  • This really is not to do with ACF, it is due to your limiting of seeing media files to the person that uploaded them.

    The the database description for WP here

    An image, or other type of file is saved as an “attachment” post type in the posts table. When you limit a user to see only their media you are actually limiting them to see only their own post of this post type by the “post_author” column in the database. This column can only have one value and that value is the person that uploaded it.

    In order to allow another user to see these media files you would also need to duplicate all of the “attachment” “posts” and apply the new user ID to them. This would also mean duplicating the actual media files.

  • Also, I just thought of this.

    When ACF stores the association, it is only saving the ID value of the attachment post. So when duplicating the ACF field you would first need to duplicate the attachment and then you’d need to replace the ACF field value with the new post ID of the attachment you just duplicated.

  • Thx John… copy that – you are absolutely right. But why I’m wondering was the fact that the new Post will show the image from another author but not the gallery items.

    we are using the following action to restrict users fro their own media/posts:

     if( is_admin() && !current_user_can('edit_others_posts') ) {
            $wp_query->set( 'author', $current_user->ID )...

    With this function we normale did’t see the ACF groups in a post too.
    so we were using this snippet

    if (isset($wp_query->query_vars['post_type']) && 
        ($wp_query->query_vars['post_type'] == 'acf-field' || 
         $wp_query->query_vars['post_type'] == 'acf-field-group'
        )) { return; }

    and to fix the problem with the Gallery we were adding on more condition:

    if (isset($wp_query->query_vars['post_type']) && 
        ($wp_query->query_vars['post_type'] == 'acf-field' || 
         $wp_query->query_vars['post_type'] == 'acf-field-group' || 
         ($pagenow == 'post.php')
        )) {return; }


Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘ACF PRO Gallery: restrict view own Media’ is closed to new replies.