How to Auto Approve GPNF Nested Entries When The Parent Entry Is Approved

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #114
    maguirewebdesign
    Keymaster

    “Is there a way to get nested form entries approved automatically when the parent entry is approved?”

    When using Gravity Perks Nested Forms, if you have configured entry approval before a notification is sent – then, by default, sadly you’ll have to duplicate your efforts by approving both child and parent entry to send notifications for both parent and nested (child) forms.

    …Well, that was before, Saif from Gravity Wiz dropped this snippet on the GF ecosystem!

    add_action( ‘gravityview/approve_entries/approved’, function( $entry_id ) {
    $parent_entry = GFAPI::get_entry( $entry_id );
    $parent_form = GFAPI::get_form( $parent_entry[‘form_id’] );
    $nested_entries = array();

    foreach ( $parent_form[‘fields’] as $field ) {
    if ( $field instanceof GP_Field_Nested_Form ) {
    $_entries = explode( ‘,’, $parent_entry[ $field->id ] );
    $nested_entries = array_merge( $nested_entries, $_entries );
    }
    }

    foreach ( $nested_entries as $nested_entry_id ) {
    $nested_entry = GFAPI::get_entry( $nested_entry_id );
    $nested_entry[‘is_approved’] = ‘1’;
    GFAPI::update_entry( $nested_entry );
    }
    }, 10, 1 );

    Want the video walkthrough and proof in the pudding?

    Click here to watch the video tutorial

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.