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).
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.