Skip to content

Commit 65d3c65

Browse files
committed
gpnf-detach-child-entry-from-parent.php: Added snippet to display a metabox on Entry details for nested entries to detach from Parent Entry.
1 parent 26aefd9 commit 65d3c65

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Nested Forms // Metabox on Entry Details to detach child entry from parent.
4+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
5+
*
6+
* Instruction Video: https://www.loom.com/share/84a6fc86c75449baa544cd8080c3ed15
7+
*/
8+
add_filter( 'gform_entry_detail_meta_boxes', function ( $meta_boxes, $entry, $form ) {
9+
if ( class_exists( 'GP_Nested_Forms' ) ) {
10+
// Only to be displayed for Nested Entries.
11+
$parent_entry_id = rgar( $entry, 'gpnf_entry_parent' );
12+
if ( ! $parent_entry_id ) {
13+
return $meta_boxes;
14+
}
15+
16+
// Either the metabox shows when Nested entry is still attached, or the metabox is skipped when parent link is detached.
17+
$action = 'gpnf_detach_parent_entry';
18+
if ( rgpost( 'action' ) == $action ) {
19+
$entry_id = $entry['id'];
20+
gform_delete_meta( $entry_id, 'gpnf_entry_parent' );
21+
gform_delete_meta( $entry_id, 'gpnf_entry_parent_form' );
22+
} else {
23+
$meta_boxes['gpnf_metabox'] = array(
24+
'title' => 'Nested Forms',
25+
'callback' => 'detach_parent_entry_from_child',
26+
'context' => 'side',
27+
);
28+
}
29+
30+
}
31+
32+
return $meta_boxes;
33+
}, 10, 3 );
34+
35+
// Callback method
36+
function detach_parent_entry_from_child( $args ) {
37+
$action = 'gpnf_detach_parent_entry';
38+
$html = sprintf( '<input type="submit" value="%s" class="button" onclick="jQuery(\'#action\').val(\'%s\');" />', 'Detach from Parent', $action );
39+
40+
echo $html;
41+
}

0 commit comments

Comments
 (0)