Support

Account

Home Forums General Issues Force an Image/File upload to a particular directory Reply To: Force an Image/File upload to a particular directory

  • Your code with no = typo and reverting _GET to $params seems to work…

    add_filter('plupload_default_params', function($params) {
      if (!function_exists('get_current_screen')) {
        return $params;
      }
      $current_screen = get_current_screen();
      if ($current_screen->id == 'user-edit') {
        $params['user_id'] = $_GET['user_id'];
      } elseif ($current_screen->id == 'profile') {
        $params['user_id'] = get_current_user_id();
      }
      return $params;
    });

    That is:

    a) The depopulated lists issue is gone.

    b) It still seems to successfully pass user_id to the uploader, allowing me to fetch the username with which to rename the file.

    ++

    Now, for a bonus…

    In my wp_handle_upload_prefilter function custom_upload_filter(), I should really be checking that the image upload in question is coming from the specific ACF Image field keyed field_6140a6da30a17…

    Do you happen to know if the AJAX $_POST in custom_upload_filter() already has access to any information about the instigating field in question, anything which would give away field_6140a6da30a17? (I see traces of it in the uploader’s HTML).

    Or would I somehow need, on user-edit.php, to a) check for its presence and b), if present, send it through the plupload_default_params function? (I presume I can stuff $params[] with multiple other values).