Home › Forums › General Issues › acf/upload_prefilter – for every field on options page › Reply To: acf/upload_prefilter – for every field on options page
Hi John,
Thanks for your input. Using your method for logging the $_POST data, this is the result:
Array
(
[name] => test.png
[action] => upload-attachment
[_wpnonce] => dee97d17e2
[_acfuploader] => field_5a856f0eb49d7
)
So, there’s nothing being sent about the origin page, just the ACF field’s key.
I guess the only and easiest way is just to create an array of all the fields (potentially only about 10, not that many in my use case). This is how I’ve solved it:
$fields = array('field_1', 'field_2', 'field_3');
foreach ($fields as $field) {
add_filter("acf/upload_prefilter/name=$field", function($errors) {
add_filter('upload_dir', function($uploads) {
$dir = '/options';
$uploads['url'] = $uploads['baseurl'] . $dir;
$uploads['path'] = $uploads['basedir'] . $dir;
return $uploads;
});
return $errors;
});
}
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.