Skip to content

Instantly share code, notes, and snippets.

@hmowais
Created December 18, 2019 11:37
Show Gist options
  • Save hmowais/85514b14b452d7a8d79f6964a08cb31b to your computer and use it in GitHub Desktop.
Save hmowais/85514b14b452d7a8d79f6964a08cb31b to your computer and use it in GitHub Desktop.
ACF file Upload to Seperate Folder
<?php
// ACF upload prefilter
function acf_upload_dir_prefilter($errors, $file, $field) {
$upload_dir = wp_upload_dir();
// only allow admin
if( !current_user_can('manage_options') ) {
$errors[] = 'Only administrators may upload attachments';
}
$_filter = false;
// This filter changes directory just for item being uploaded
add_filter( 'upload_dir', 'my_custom_upload_directory' );
// return
return $errors;
}
// ACF hook, set to field key of your file upload field
add_filter('acf/upload_prefilter/name=specs_sheet_file', 'acf_upload_dir_prefilter');
// acf custom file upload directory
function my_custom_upload_directory( $param ) {
$folder = '/acf_attached_file';
$param['path'] = $param['basedir'] . $folder;
$param['url'] = $param['baseurl'] . $folder;
$param['subdir'] = '/';
return $param;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment