Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude specific files? #99

Open
joasag opened this issue Dec 29, 2019 · 6 comments
Open

Exclude specific files? #99

joasag opened this issue Dec 29, 2019 · 6 comments
Labels

Comments

@joasag
Copy link

joasag commented Dec 29, 2019

Hi,

I use your plugin to share media from one site in my Multisite network to all the others. It works great! But I would like to exclude a few files from being shared. Is it possible?
I have no problem modifying the source if necessary.

Thank you!

@widoz
Copy link
Collaborator

widoz commented Dec 30, 2019

@jockebq Exlude based on which criteria? Or would you like to exclude by defining your criteria via a filter callback?

@widoz widoz added the good first issue Good for newcomers label Dec 30, 2019
@joasag
Copy link
Author

joasag commented Dec 30, 2019

@widoz In this case I want to exclude a specific file, with a specific file name. Maybe it is better to exclude it via the ID it has in the database? The reason is because I need to upload a few images used on the site which contains the Global Media. But I don't want to bloat the Global Shared Media for the other users.

@joasag
Copy link
Author

joasag commented Jun 23, 2020

Is it possible to edit this function to exclude a specific media ID?

function global_media_user_cap($allcaps, $caps, $args, $user) {
    if( !in_array('upload_files', $args) )
        return $allcaps;
    if( defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] == 'query-attachments' ) {
        if( function_exists('MultisiteGlobalMedia\getSideId') ) {
            if( MultisiteGlobalMedia\getSideId() == get_current_blog_id() ) {
                $allcaps['upload_files'] = 1;
            }
        }
    }
    return $allcaps;
}
add_filter( 'user_has_cap', 'global_media_user_cap', 99, 4 );

@bueltge
Copy link
Owner

bueltge commented Jun 26, 2020

Would you define the criteria for an exclude?
Also send a PR with a hook (apply_filters() or similar) or other idea on the method to enhance this possibility. We will review them.

@joasag
Copy link
Author

joasag commented Jun 26, 2020

Would you define the criteria for an exclude?
Also send a PR with a hook (apply_filters() or similar) or other idea on the method to enhance this possibility. We will review them.

Maybe the criteria could be that the "Caption" of the file has the text "EXCLUDE" or something like that?

@joasag
Copy link
Author

joasag commented Aug 18, 2020

I actually managed to do this with this additional code:

add_filter('ajax_query_attachments_args', function($query){
    $query['meta_query'] = [
      'relation' => 'AND',
      [
        'key'     => '_wp_attached_file',
        'value'     => 'Title.png',
        'compare' => '!=',
      ]
    ];

    return $query;
});

The issue is that I have to manually add all the files I want to be hidden by their filename. I could not really figure out how to utilize one of the existing fields like Caption or ´Alternative Text´ or Description by looking for the text EXCLUDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants