• Resolved Koen

    (@drhnews)


    I have the impression add_action(‘frontend_admin/save_post’, ‘save_my_post’, 10, 2); in my snippet is no longer being executed.

    Has it been removed from the free version?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Koen

    (@drhnews)

    Upon submitting my form, frontend_admin/save_post no longer kicks in if post data in the form has not changed.

    However, I need it to run as I need to update fields in my post that are not part of the form.

    This worked up to version 3.18.6

    Thread Starter Koen

    (@drhnews)

    Correction. Probaly worked up to 3.18.4 as per changelog of 3.18.6: “Tweeked submission records to only hold updated or new data.”

    Reinstalled 3.18.4.

    Plugin Author Shabti Kaplan

    (@shabti)

    Hi Koen,

    I apologize that the new version has affected your code snippet. If you need help with your code snippet for the new version, paste it here and I will show you what needs to be changed

    Thread Starter Koen

    (@drhnews)

    Shabti,

    Thank you for helping out.

    Here is my (redacted) snippet:

    function my_acf_save_post( $form, $post_id ) {
    
    $user = wp_get_current_user();
    $values = get_field('my_status', $post_id);
    
    remove_action('frontend_admin/save_post','my_acf_save_post', 10);
    
    if ($values == 'New') {
        update_field('my_status', 'Processed', $post_id);
        update_field('my_processed_user', $user, $post_id);
        wp_update_post( array( 'ID' => $post_id,'post_status' => 'draft' ) );
    } elseif ($values == 'Processed') {
        update_field('my_status', 'Completed', $post_id);
        update_field('my_completed_user', $user, $post_id);
        wp_update_post( array( 'ID' => $post_id,'post_status' => 'private' ) ); 
    }   
    
    add_action('frontend_admin/save_post','my_acf_save_post', 10, 2);    
    
    }
    
    add_action('frontend_admin/save_post','my_acf_save_post', 10, 2);
    Plugin Author Shabti Kaplan

    (@shabti)

    the beautiful thing about this hook is that yiu don’t need to call the remove action and add action functions in order to avoid an endless loop. Thats just a side note.

    Now for your issue: are you using data that is stored in the form record?

    Thread Starter Koen

    (@drhnews)

    I’m updating ACF fields that are not in the form, but are part of the same custom post type as the fields in the form.

    But if they should be, but hidden, that can be changed.

    Plugin Author Shabti Kaplan

    (@shabti)

    you really should replace

    wp_get_current_user() with get_current_user_id()

    its really not healthy for the database to have replicated data multiple times.

    Regarding the snippet not working, it could be that there is a bug with this in the latest version. I’ll triple check and let you know what I find

    Thread Starter Koen

    (@drhnews)

    Maybe I should explain the process in which the form is used.
    I have a custom post type with a number of fields that need to be verified and some fields that should be updated behind the scenes after form submission.

    The form is part of a verification process in which one logged in user checks visible fields and updates them if required.
    Next, the same post is presented to a second user with the same purpose, i.e. verifying data is correct.
    Kind of the four eyes principal.

    So even if data in the form, hence nothing in any field of the post, changed, I want to set some fields for tracking purposes using above snippet upon submission of the form.

    PS. Thank you for the tips.

    Thread Starter Koen

    (@drhnews)

    Shabti,

    Just upgraded to 3.18.8 and my snippets seem to be working fine.

    Thak you for the effort.

    Much appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘What happened to frontend_admin/save_post?’ is closed to new replies.