Skip to content

Commit 0984202

Browse files
committed
Updated gpdec-delay-for-gravity-pdf-bg-processing.php to be a class and improved support for sending multiple notifications using the same entry
1 parent 199280b commit 0984202

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed
Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Gravity Perks // Disable Entry Creation // Delay Deletion for Gravity PDF Background Processing
45
* http://gravitywiz.com/documentation/gravity-forms-disable-entry-creation/
@@ -9,20 +10,55 @@
910
*
1011
* Installation instructions:
1112
* 1. https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
12-
* 2. Update FORMID and $form_id accordingly.
13+
* 2. See usage instructions at the bottom of the file
1314
*/
14-
add_filter( 'gpdec_should_delete_entry_FORMID', '__return_false' );
15+
class GPDEC_GFPDF_Delayed_Deletion {
16+
public $deletion_queue = array();
17+
18+
function __construct( $args ) {
19+
$this->_args = wp_parse_args( $args, array(
20+
'form_id' => false,
21+
) );
22+
23+
add_action( 'plugins_loaded', array( $this, 'add_hooks' ), 16 );
24+
}
1525

16-
add_action( 'gfpdf_post_generate_and_save_pdf_notification', function ( $form, $entry, $settings, $notifications ) {
17-
$form_id = 8;
26+
public function add_hooks() {
27+
if ( ! function_exists( 'gp_disable_entry_creation' ) ) {
28+
return;
29+
}
1830

19-
if ( ! function_exists( 'gp_disable_entry_creation' ) ) {
20-
return;
31+
add_filter( 'gpdec_should_delete_entry_' . $this->_args['form_id'], '__return_false' );
32+
add_action( 'gfpdf_post_generate_and_save_pdf_notification', array( $this, 'post_generate_and_save' ), 50, 4 );
33+
add_action( 'shutdown', array( $this, 'shutdown' ) );
2134
}
2235

23-
if ( $form['id'] !== $form_id ) {
24-
return;
36+
public function post_generate_and_save( $form, $entry, $settings, $notifications ) {
37+
if ( $form['id'] != $this->_args['form_id'] ) {
38+
return;
39+
}
40+
41+
$this->deletion_queue[] = $entry;
2542
}
2643

27-
gp_disable_entry_creation()->delete_form_entry( $entry );
28-
}, 50, 4 );
44+
public function shutdown() {
45+
if ( empty( $this->deletion_queue ) ) {
46+
return;
47+
}
48+
49+
foreach ( $this->deletion_queue as $entry ) {
50+
gp_disable_entry_creation()->delete_form_entry( $entry );
51+
}
52+
}
53+
}
54+
55+
/*
56+
* Basic Usage
57+
*
58+
* Uncomment the lines below (remove the preceding // on each line) and adjust the form ID accordingly.
59+
* You may also duplicate the class instantiation if this is required for more than one form.
60+
*/
61+
62+
//new GPDEC_GFPDF_Delayed_Deletion( array(
63+
// 'form_id' => 3,
64+
//) );

0 commit comments

Comments
 (0)