-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpnf-process-gpgs-feed-on-nested-after-parent-workflow-complete.php
…
…: Added snippet for GP Nested Forms to process GPGS on nested only after parent workflow is approved.
- Loading branch information
1 parent
7d2c18d
commit 4aad9de
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
gp-nested-forms/gpnf-process-gpgs-feed-on-nested-after-parent-workflow-complete.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Gravity Perks // Nested Forms // Post-specific Sessions | ||
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/ | ||
* | ||
* Make Nested Forms sessions specific to the post on which the form is rendered by appending the current post ID. | ||
*/ | ||
// Update 6 to the parent ID form and 4 to the Nested Form Field ID on the parent form | ||
add_filter( 'gpnf_should_process_gp-google-sheets_feed_6_4', 'gpgs_should_process', 10, 6 ); | ||
function gpgs_should_process( $should_process_feed, $feed, $context, $parent_form, $nested_form_field, $entry ) { | ||
// disable immediate processing of GP Google Sheets feed for parent form 6's nested field ID 4. | ||
return false; | ||
} | ||
|
||
add_action( 'gravityflow_step_complete', 'processed_nested_entries_google_sheets_feed', 10, 4 ); | ||
function processed_nested_entries_google_sheets_feed( $step_id, $entry_id, $form_id, $status ) { | ||
// Update 6 to the GP Google Sheets Workflow Step on the Parent Form | ||
if ( $step_id == '6' && $status == 'complete' ) { | ||
// When GP Google Sheets Workflow step is complete on Parent from | ||
$entry = GFAPI::get_entry( $entry_id ); | ||
$parent_form = GFAPI::get_form( $form_id ); | ||
|
||
// get all nested entries | ||
$nested_entries = array(); | ||
foreach ( $parent_form['fields'] as $field ) { | ||
if ( $field instanceof GP_Field_Nested_Form ) { | ||
$_entries = explode( ',', $entry[ $field->id ] ); | ||
$nested_entries = array_merge( $nested_entries, $_entries ); | ||
} | ||
} | ||
$nested_entries = array_unique( $nested_entries ); | ||
|
||
// process each nested entry | ||
foreach( $nested_entries as $nested_entry_id ) { | ||
Check failure on line 34 in gp-nested-forms/gpnf-process-gpgs-feed-on-nested-after-parent-workflow-complete.php GitHub Actions / PHPCS (Files Changed)
Check failure on line 34 in gp-nested-forms/gpnf-process-gpgs-feed-on-nested-after-parent-workflow-complete.php GitHub Actions / PHPCS (Files Changed)
Check failure on line 34 in gp-nested-forms/gpnf-process-gpgs-feed-on-nested-after-parent-workflow-complete.php GitHub Actions / PHPCS (Files Changed)
Check failure on line 34 in gp-nested-forms/gpnf-process-gpgs-feed-on-nested-after-parent-workflow-complete.php GitHub Actions / PHPCS (Files Changed)
|
||
$nested_entry = GFAPI::get_entry( $nested_entry_id ); | ||
if ( empty( $nested_entry_id ) || empty( $nested_entry ) || is_wp_error( $nested_entry ) ) { | ||
continue; | ||
} | ||
|
||
$feeds = gp_google_sheets()->get_active_feeds( $nested_entry['form_id'] ); | ||
if ( empty( $feeds ) ) { | ||
return; | ||
} | ||
|
||
// process feeds | ||
foreach ( $feeds as $feed ) { | ||
if ( rgar( $feed, 'addon_slug') !== 'gp-google-sheets' ) { | ||
continue; | ||
} | ||
//process the google sheets feed for the nested entry | ||
gp_google_sheets()->process_feed( $feed, $nested_entry, GFAPI::get_form( $nested_entry['form_id'] ) ); | ||
} | ||
} | ||
} | ||
} |