Home › Forums › Backend Issues (wp-admin) › Change file upload path to WP Root? › Reply To: Change file upload path to WP Root?
Had this exact issue, wrote a blog post about it here: https://www.ractoon.com/2016/08/wordpress-acf-pro-files-field-custom-upload-directory/
But your code would end up looking something like:
add_filter( 'acf/upload_prefilter/name=secure_files', 'secure_upload_prefilter' );
add_filter( 'acf/prepare_field/name=secure_files', 'secure_files_field_display' );
public function secure_upload_prefilter( $errors ) {
add_filter( 'upload_dir', 'secure_upload_directory' );
return $errors;
}
function secure_upload_directory( $param ) {
$folder = '/s2member-files';
$param['path'] = WP_PLUGIN_DIR . $folder;
$param['url'] = WP_PLUGIN_URL . $folder;
$param['subdir'] = $folder;
$param['basedir'] = WP_PLUGIN_DIR;
$param['baseurl'] = WP_PLUGIN_URL;
return $param;
}
public function secure_files_field_display( $field ) {
// update paths accordingly before displaying link to file
add_filter( 'upload_dir', 'secure_upload_directory' );
return $field;
}
Where the secure_files
portion of the add_filter
would be your field name instead.
Then in the secure_upload_directory()
function you could use https://codex.wordpress.org/Function_Reference/get_home_path to grab the absolute path to the install location.
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.