Prevent a folder from being shown within the media library


We have a folder of secure files which are currently PW protected through htpassword with NGNIX.
Those files are currently inside the/wp-content/uploads/ directory /wp-content/uploads/secure-files/.

This works fine as the files are not accessible publicly, but the media library is prompting admins who utilize the media library for the PW and username as i assume the application is requesting the media from the secured URL and is trying to build the thumbnail with it. This is a massive inconvenience, as when this system was built, this prompt while using the media library never happened — only when you manually tried to browse to the physical file paths.

The question I am asking, is there a way to modify the default file path so that the files are uploaded to the server, but not shown in the media library? Is there a better way to exclude a particular folder from the /uploads/ directory in WP so that is does not show up in the Media Library? The admins will never have to manage those files through media library so it’s ideal if they do not go there. I am simply looking for a solution that exludes a particular folder from the media library, or changes the upload directory so the media library does not see the files.

This is the pseudo code that is being used to modify the upload path for the ACF field.

add_filter('acf/upload_prefilter/key=field_5f10c7212f533', 'my_upload_prefilter');
function my_upload_prefilter($errors) {
  add_filter('upload_dir', 'my_change_upload_dir');
  return $errors;
function my_change_upload_dir($uploads) {
    $uploads['path']   = $uploads['basedir'] . '/secure-files/';
    $uploads['url']    = $uploads['basedir'] . '/secure-files/';
    $uploads['subdir'] = '';
    return $uploads;

I have also followed the example found here. but the solution is not resulting in the directory being changed to plugin path. I have changed the URL to be a physical path on the server as well but the basedirectory is always /wp-content/uploads/ I assume moving the file upload outside of the normal directory should stop the media library from seeing these files, but I am wondering if there is an easier solution.

pressword 3 months 0 Answers 13 views 0

Leave an answer