Support

Account

Home Forums ACF PRO Local JSON in plugin not load

Solved

Local JSON in plugin not load

  • I’ve a problem with local json and i don’t know, it is a bug.

    I did everything that is on this page:
    https://www.advancedcustomfields.com/resources/local-json/
    But the own folder was used only for saving and not for loading.
    It works only in the master theme – not in my child-themes.

    So I put it in a plugin. Here is my code:

    But it is the same. ACF saves the JSON, but an other installation don’t read this file.

    Where is my mistake?

    
      // save jsonwith fields
      function bks_acf_json_save_point( $path ) {
        // update path
        $path = plugin_dir_path( __DIR__ ) . '/acf-json';
        // return
        return $path;
      }
      
      
      // load json with fields
      function bks_acf_json_load_point( $paths ) {
        // append path
        $paths[] = plugin_dir_path( __DIR__ ) . '/acf-json';
        // return
        return $paths;
      }
      
      add_filter('acf/settings/save_json', 'bks_acf_json_save_point');
      add_filter('acf/settings/load_json', 'bks_acf_json_load_point');
    

    I also tried the PHP variant. Everything is displayed correctly, but the repeat fields are not saved.

    • Beee

    • February 18, 2018 at 1:49 am

    You need to add the following line to the load function because only 1 path may exists per load/save.

    unset($paths[0]);

    That being said, I think you should look into the issue why it’s not loading from the other site, because this is the default behaviour and should work, so something is blocking it.

  • Hello @beee,

    this didn’t solve the problem.

    I have removed this line, because the json from the template is also not loaded any more.

    Thanks for the try.

    • Beee

    • February 18, 2018 at 2:45 am

    Well, according to the local json info page, it needs to be unset, so that was step 1.

    What if you dump $paths in the save function ? What does it output ?

  • I do not think so. The info page says that the folder “acf-json” is one of the load points. If you look in the code of ACF, then you see that there are many folders possible. With unset I remove one of these load points. But that is not, what i want. I want many load points.

    In the plugin i want to load the fields for all my sites. In the theme i want to load the fields for a special page.

    Please have also a look at the comment over the line with unset
    // remove original path (optional)
    I don’t want to remove this path. I will use it, too.

    And how i said: It didn’t solve the problem.

    If i use var_dump in acf_json_load_point nothing would be displayed.

    • Beee

    • February 18, 2018 at 2:59 am

    You are right, I stand corrected.

    Have you tested with a higher or lower priority ?

    Higher
    add_filter('acf/settings/load_json', 'bks_acf_json_load_point', 1);

    Lower
    add_filter('acf/settings/load_json', 'bks_acf_json_load_point', 20);

  • Actually var_dump did a job for me within my function, and in my case revealed that plugin_dir_url( __FILE__ ) was providing a url ending with / so my constructed path of:

    plugin_dir_url( __FILE__ ) . ‘/acf-json’

    (which similar to yours above skrabbel features a / in the final part) was producing an erroneous // in the URL.

    ….frustratingly though this hasn’t resolved my issue (which has similar symptoms to the above – filtering load_json within a plugin failing to then implement the field (group) ), and the above prioritizing doesn’t either.

  • I’m having issues with the synchronization feature as well. The save point works fine. The files get stored in the right place and update each time I save a group. The sync available option, however, does not appear as predicted after I pull relevant changes from my repo onto my other machine (which, in fact, has no field groups in its DB). Neither does the option appear on the original machine after I edit the files directly. I even incremented the modified property.

    These are my save and load points:

    add_filter('acf/settings/save_json', 'p2c_acf_json_save_point');
    function p2c_acf_json_save_point( $path ) {
        $path = plugin_dir_path(__FILE__) . 'fields/acf-json';
        return $path;
    }
    
    add_filter('acf/settings/load_json', 'p2c_acf_json_load_point');
    function p2c_acf_json_load_point( $paths ) {
        unset($paths[0]);
        $paths[] = plugin_dir_path(__FILE__) . 'fields/acf-json';
        return $paths;
    }

    Permissions on the directory are writeable. I use username:www-data as owner:group in my local environment with 775 permissions.

    I also tried adjusting the priority of the filters to no effect. plugin_dir_path() already provides the trailing slash and I verified that the correct directory is pushed to $paths (and the default removed).

    Any ideas?

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.