Home › Forums › General Issues › Changing file upload path for acf field using upload_prefilter inside Multisite
Hi,
I run a Multisite Network with 4 sites in a sub domain config. I created a custom post type for videos.
I don’t want the video files to sit inside the wordpress folder structure, for various reasons, the main reasons being the size of my backups and the location being inside a custom CDN.
Now, what I have done works perfectly for the main site, because it uses /wp-content/uploads. So, when I upload a video into a video post, it saves that video file to /wp-content/uploads/videos, /wp-content/uploads/videos has been symlinked to my cdn – /mnt/cdn/videos (www-data has control). So the large video files goes into the cdn, away from the wordpress folder structure. All good.
https://main.site/wp-content/uploads/videos/911-trillions-follow-the-money-media.webm
But the sub sites, by default uses /wp-content/uploads/sites/x. If I use the same config for the sub sites, the video file is saved to the correct location, but wordpress then assigns an incorrect file url.
This is the function:
/** Set Video Upload Path ----------------------------------------------- **/
function video_upload_filter($errors, $file, $field) {
add_filter('upload_dir', 'video_upload_dir');
}
add_filter('acf/upload_prefilter/key=field_6075238de0b09', 'video_upload_filter', 10, 3 );
function video_upload_dir($param) {
if ((get_field('sys_site_slug', 'option') == 'main')) {
$param['path'] = '/var/www/main.site/wp-content/uploads/videos';
$param['url'] = 'https://main.site/wp-content/uploads/videos';
}
if ((get_field('sys_site_slug', 'option') == 'sub1')) {
$param['path'] = '/var/www/main.site/wp-content/uploads/videos';
$param['url'] = 'https://sub1/wp-content/uploads/videos';
}
if ((get_field('sys_site_slug', 'option') == 'sub2')) {
$param['path'] = '/var/www/main.site/wp-content/uploads/videos';
$param['url'] = 'https://sub2/wp-content/uploads/videos';
}
if ((get_field('sys_site_slug', 'option') == 'sub3')) {
$param['path'] = '/var/www/main.site/wp-content/uploads/videos';
$param['url'] = 'https://sub3/wp-content/uploads/sites/4/videos';
}
return $param;
}
I have tried many configurations, without success.
I am starting to think that the upload_prefilter is not doing it’s work when it comes to the sub sites like it does for the main site, when the upload_prefilter is called for the defined acf field.
This all sounds complicated, but if we just look at how upload_prefilter deals with multisite sub sites, we will know.
Help would be much appreciated.
You must be logged in to reply to this topic.
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.