Support » Plugin: Advanced Custom Fields: Extended » Revert Back?

  • Resolved Jeffinho2016

    (@jeffinho2016)


    Hi, regarding the single meta revert back.
    On your website, it says

    “Revert Back
    It is possible to revert back to the native ACF save process. To do so, keep the feature enabled, get in the post administration you want to revert back. Disable the feature in your code, and save the post. All data will be saved back to individual meta data.”

    This does not seem to work at all.
    Is it because you’re hooking to ‘acf/init’?
    If, like you say, we disable the code (the filter) once we’re in edit mode.
    acf/init has already triggered, so deactivating the filter will not revert anything when we click on “update”.

    I tried
    1) Disabling the filter. Does not work. Does not revert back to individual meta data.
    2) Leaving the filter as is, but set acf_update_setting(‘acfe/modules/single_meta’) to false. Does not work. Does not revert back to individual meta data.
    3) Hook on pre_post_update, save_post, acf/save_post and acf/validate_save_post to also set acf_update_setting(‘acfe/modules/single_meta’) to false. Does not work. Does not revert back to individual meta data.

    What am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Jeffinho2016

    (@jeffinho2016)

    Ok so just to update that I figured a way a to do it, without deactivating the feature in the code.
    Of course this will only remain until the next time that the post is saved. It’s more for debugging purposes.
    1) Create a true/false acf field called “Revert single meta”
    2) hook onto acf/save_post at priority 1000 (important), and manually revert each meta through update_post_meta, and not update_field (the latter will mess with repeater fields);

    
    function my_custom_acf_process(){
    //FIELDID is the corresponding FIELDID of the "Revert single meta" ACF field
        if (isset($_POST['acf']['field_FIELDID'])&& $_POST['acf']['field_FIELDID']==1){
            $_POST['acf']['field_FIELDID']=0;//Revert the true/false field;
            if (acf_is_filter_enabled('acfe/single_meta')) {//Make sure plugin and feature are active
                 acf_disable_filter('acfe/single_meta');//Disable the filter
                 acfe_revert_single_meta($_POST['post_ID']);//Launch the reversal
            }
        }
    }
    add_action('acf/save_post', 'my_custom_acf_process',1000);
    
    function acfe_revert_single_meta($postID){
        if (!acf_is_filter_enabled('acfe/single_meta')) {
            $acfeData = get_post_meta($postID, 'acf', true);
            foreach ($acfeData as $acfKey => $acfValue) {
                update_post_meta($postID,$acfKey, $acfValue);
            }
            delete_post_meta($postID, 'acf');
        }else{
            die('acfe filter still active');
        }
    }
    
    Thread Starter Jeffinho2016

    (@jeffinho2016)

    Final update.
    So it turned out that everything was working from the beginning.
    The issue lays in the lack of documentation on this feature.
    After wasting an entire day trying to figure what was not working.
    I finally noticed that, in dev mode, there is an additional button that gets added in the sidebar, button that is called “Delete orphaned data” and that we’re actually supposed to click on it.
    This button and the fact that we need to click on it is NOWHERE mentioned in your documentation.
    It takes absolute luck to notice it, or hours digging in the pluging code to try to figure out why data gets merged, but not deleted. Database offloading is kind of the entire point of this feature, and it’s super weird that you don’t mention anywhere that we’re supposed to click that button.
    Also to mention somewhere in your documentation: it’s not because a field is set to “save as single meta” that it will not get merged into the “acf” field.
    I also thought the plugin was not working as expected, because it was still merging data I specifically said I wanted to keep as single meta. Not a big deal to merge it, but it should also be mentioned in your doc that this is the expected behavior. Sure it will potentially save other people lots of wasted time.
    That said, great work on the plugin!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I just tested it, and the revert-back to individual meta works as expected. Note that as explained in the documentation, it is advised to enable the Developer Mode in order to check how data are saved in the database. As described, to revert-back:

    Keep the feature enabled, get in the post administration you want to revert back. Disable the feature in your code, and save the post. All data will be saved back to individual meta data.

    Here is a video showing this process. Note that this process works because when a user click on the “Update” button, a new request is sent to the server which load again all the code, including all WP/ACF hooks, and thus, check again the if the Single Meta feature is enabled.

    Regarding your third post about the “Delete Orphan Meta” button: It is quite different from your original topic, since it’s not about reverting back to individual meta, but rather cleanup native individual meta when the Single Meta feature is enabled. Maybe you thought it wasn’t working because individual meta were still saved in the database.

    In fact, ACF Extended doesn’t take the risk to automatically delete post/user/options meta when the user doesn’t explicitly ask for it, because these data are crucial. That’s why native individual meta have to be cleanup manually (using the Developer Mode or PhpMyAdmin) or using the “Clean Orphan Meta” button.

    It’s also normal that fields using the “Save as individual meta” setting are still compressed into the Single Meta in order to keep a consistent data structure for complex fields with sub fields such as repeaters, clones etc…

    I’ll try to enhance the documentation of that feature to avoid confusion.

    Hope it’s now more clear!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.