• Resolved wedevelopthings

    (@milleniumwa)


    When I try to use autosync php for my field groups at a plugin path, ACF/ACFE does still load from DB.

    This is the code used in the plugin:

    add_action('acf/init', function(){
        acf_update_setting('acfe/php_save', plugin_dir_path( __FILE__ ) . 'includes/acfe-php/');
    
        $load_paths_php = acf_get_setting('acfe/php_load');
        $load_paths_php[] = plugin_dir_path( __FILE__ ) . 'includes/acfe-php/';
        acf_update_setting('acfe/php_load', $load_paths_php);
    });

    On saving a ACF field group, the file gets created correctly at this path, like “group_62333df612391.php”. The contents of the saved file also is correct (chmod 644, readable). But ACF still show it’s loaded from DB and the warning occurs:

    Awaiting save. <br />Save path located in plugin: /pluginname/includes/acfe-php

    When I disable the action to the default path (theme/acfe-php) it works. It gets saved to the theme folder and also loads from php and not from DB.

    I also tried a fresh installation with a fresh database and could reproduce the problem.

    Also, the path shows correctly at ACF » Settings » AutoSync » PHP Load.

    And if I replace the path, instead of adding one, the problem still exists.

    WP: 5.9.2
    ACF: 5.11.4
    ACF Pro 5.11.4
    ACFE 0.8.8.7
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The PHP/Json AutoSync settings are quite special as they are executed before the acf/init hook. This logic is also applied on the native ACF Json documentation. You should directly filter the setting using add_filter() instead of using acf_update_setting().

    You’ll find working example for the Json/PHP AutoSync with ACF Extended in the documentation here. Here is a working example in your case:

    add_filter('acfe/settings/php_save', 'my_acfe_php_save_point');
    function my_acfe_php_save_point($path){
        
        return plugin_dir_path(__FILE__) . 'includes/acfe-php';
        
    }
    
    add_filter('acfe/settings/php_load', 'my_acfe_php_load_point');
    function my_acfe_php_load_point($paths){
        
        $paths[] = plugin_dir_path(__FILE__) . 'includes/acfe-php';
        
        return $paths;
        
    }
    

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter wedevelopthings

    (@milleniumwa)

    Hello,

    thank you very much, this worked fine! I would not have thought that acfe/settings would be executed before acf/init 🙂

    To make it perfect, I still have acf_update_setting still in the code so that the changed paths continue to be displayed correctly in the settings under “AutoSync”. Without acf_update_setting the path changes are not visible.

    Best greetings!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear it now works as expected!

    You’re right, the acfe/php_save value isn’t correctly updated in the “Registered” column of the Settings UI. This is because the method used to collect those settings doesn’t pass values thru the acf/settings filters. I just added a fix for that issue for the next patch.

    You don’t need to keep that acf_update_setting() in your code, as the filter method will be correctly use in all cases behind the scene. The setting isn’t correctly displayed in the Settings UI as of now, but it’s just a visual issue. It will be fixed in the next patch.

    Thanks for the report!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘acfe/php_load does not load fields in a plugin (autosync)’ is closed to new replies.