Home › Forums › General Issues › Problems with Local JSON › Reply To: Problems with Local JSON
If anyone else comes across a similar issue, the problem was that ACF now runs the WordPress sanitize_file_name()
function on the JSON file names before saving them. That being said, I was using a different function that uses sanitize_file_name()
to rename image files.
The fix was to write a condition into my existing function:
function image_hash_rename( $filename ) {
$info = pathinfo( $filename );
$ext = empty( $info['extension'] ) ? '' : '.' . $info['extension'];
if ( '.json' === $ext ) { // output ACF JSON files in correct format
return $filename;
}
$name = basename( $filename, $ext );
$hash = md5( $name );
return date('m_d_y') . '_' . $hash . $ext;
}
add_filter( 'sanitize_file_name', 'image_hash_rename', 10 );
After doing so, the JSON files are now being saved in the correct format and I was able to sync with them again.
Thanks to Matt Shaw (WP Engine Support) for working through this with me and create a solution that worked.
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.