0
votes

I actually create an extranet space on my website, with pages where you must to be logged-in to see the content. My problem is about media uploads. I want to make them private for a specific custom post type, and upload them in a sub directory (uploads/private). I use the upload_dir filter (add_filter('upload_dir', 'extranet_upload_directory');) with success for thumbnail for exemple, but when I upload an image in the content with a gutenberg block, this one is upload in the initial foldier (uploads), not in uploads/private.

Does anyone have an idea where to look at ?

My code below :

add_filter('upload_dir', 'extranet_upload_directory');
function extranet_upload_directory( $param ){
  $id = $_REQUEST['post_id'];

    if ( ( get_post_type( $id ) == 'test-extranet' ) ) {

      $param['subdir'] = '/private' . $param['subdir'];
      $param['path'] = $param['basedir'] . $param['subdir'];
      $param['url']  = $param['baseurl'] . $param['subdir'];


    }
    return $param;
}


1

1 Answers

0
votes

This may be a bug... I have a plugin that offers the same functionality as yours and noticed the following:

While creating a post of that new custom post type (e.g. PATHTOsite.fr/wp-admin/post-new.php?post_type=post_type_name):

When I immediately press upload after opening an new image block the uploaded image goes to default directory, uploads.

but, if I first press 'media library' after opening an new image block and then go to the upload button there and upload the image there, the image will be uploaded in the modified uploads directory.