Skip to content

Instantly share code, notes, and snippets.

@nextendweb-laszlo
Created December 13, 2024 17:34
Show Gist options
  • Save nextendweb-laszlo/7f11a34d9d23a142da46d17d538e350d to your computer and use it in GitHub Desktop.
Save nextendweb-laszlo/7f11a34d9d23a142da46d17d538e350d to your computer and use it in GitHub Desktop.
NSL - Hide Avatars in List view based on the "Display avatars in "All media items"" setting
<?php
add_action('pre_get_posts', function ($query) {
if (is_admin() && $query->is_main_query() && $query->get('post_type') === 'attachment') {
global $pagenow;
if (in_array($pagenow, array(
'upload.php',
'media-upload.php'
), true)) {
$meta_query = $query->get('meta_query') ?: array();
$avatars_in_all_media = NextendSocialLogin::$settings->get('avatars_in_all_media');
if (!$avatars_in_all_media) {
$meta_query[] = array(
'key' => '_wp_attachment_wp_user_avatar',
'compare' => 'NOT EXISTS',
);
$query->set('meta_query', $meta_query);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment