Support

Account

Home Forums Backend Issues (wp-admin) Acf json will not save to a symlinked file

Solved

Acf json will not save to a symlinked file

  • Is there a reason acf json won’t save to a symlinked file?

    
    add_filter('acf/settings/save_json', [$this, 'my_acf_json_save_point']);
    add_filter('acf/settings/load_json', [$this, 'my_acf_json_load_point']);
    
    public function my_acf_json_save_point( $path ) {
            $path = get_template_directory() . '/acf-json';
    
            if (is_link($path)) {
                $path = readlink($path);
            }
            
            // return
            return $path;
        }
    
        public function my_acf_json_load_point( $paths ) {
            // remove original path (optional)
            unset($paths[0]);
    
            $path = get_template_directory();
    
            if (is_link($path)) {
                $path = readlink($path);
            }
            
            // append path
            $paths[] = $path . '/acf-json';
                
            // return
            return $paths;
            
        }
  • I’m not exactly sure why you want to do this. If acf-json is a symlink in the template directory and you add get_template_directory().'/acf-json' as a path for ACF, writing a file to the symlink will write the file to the path in the symlink. This should be handled by your server’s file system, or PHP. The only thing I can think of that would prevent this is if PHP does not have permission to write to the path that is symlinked.

  • Yeah, I guess I don’t really need the readlink thing, I wasn’t sure if I needed it or not but basically I am using bedrock, trellis (vagrant) and I symlinked my theme for multiple sites that I develop on. I did troubleshoot some stuff last night after posting and did find it was failing on the permissions for the fopen command in json.php. So it must be how it gets mounted on my server that is keeping some permissions away. I thought maybe for some reason maybe you guys only check for real directories or something but even is_dir will recognize a symlink.

  • Just a quick update, I updated my server settings on the symlink I was mounting to 777 permissions, not really sure if that is the ideal thing I want but for now that seems to work. Just posting this here just in case this resonates with someone in the future.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Acf json will not save to a symlinked file’ is closed to new replies.