Support

Account

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.