-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
129 lines (113 loc) · 3.66 KB
/
plugin.php
File metadata and controls
129 lines (113 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* Plugin Name: Gravity Forms Prevent Database Storing
* Plugin URI: https://github.com/devgeniem/wp-gravityforms-db-prevent
* Description: A Gravity Forms plugin to let the form creator decide if the values should be saved to database or not.
* Version: 0.0.3
* Author: Geniem
* Author URI: http://www.geniem.fi/
* License: GPL3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: geniem-db-prevent
* Domain Path: /languages
*/
namespace Geniem;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Plugin class
*/
class GF_DB_Prevent {
/**
* Plugin text domain
*/
const TEXTDOMAIN = 'geniem-db-prevent';
/**
* Constructor to initialize things
*/
public function __construct() {
add_action('init', [ $this, 'init' ], 5);
}
/**
* add filters
* @return void
*/
public function init() {
add_filter( 'gform_form_settings', [ $this, 'form_setting' ], 10, 2 );
add_filter( 'gform_tooltips', [ $this, 'add_tooltip' ], 10, 1 );
add_filter( 'gform_pre_form_settings_save', [ $this, 'save_setting' ], 10, 1 );
add_filter( 'gform_after_submission', [ $this, 'delete_entry' ], 10, 2 );
add_action( 'plugins_loaded', [ $this, 'load_textdomain' ], 10 );
}
/**
* Add the custom form setting
*
* @param array $settings Form settings.
* @param array $form The form.
* @return array
*/
public function form_setting( array $settings, array $form ) : array {
$settings[ __( 'Restrictions', 'gravityforms' ) ]['geniem_db_prevent'] = sprintf(
'<tr>
<th>%1$s %2$s</th>
<td>
<input type="checkbox" value="1" name="geniem_db_prevent" id="geniem_db_prevent"%3$s>
<label for="geniem_db_prevent">%1$s</label>
</td>
</tr>',
__( 'Prevent database storing', self::TEXTDOMAIN ),
gform_tooltip( 'geniem_db_prevent', '', true ),
rgar( $form, 'geniem_db_prevent' ) ? ' checked="checked"' : ''
);
return $settings;
}
/**
* Save the custom form setting
*
* @param array $form Form settings.
* @return array
*/
public function save_setting( array $form ) : array {
$form['geniem_db_prevent'] = rgpost( 'geniem_db_prevent' );
return $form;
}
/**
* Delete the entry in submission
*
* @param array $entry The form entry.
* @param array $form Form settings.
* @return void
*/
public function delete_entry( array $entry, array $form ) {
// Only delete if the setting is set
if ( ! empty( $form['geniem_db_prevent'] ) && $form['geniem_db_prevent'] ) {
\GFAPI::delete_entry( $entry['id'] );
}
}
/**
* Add a tooltip for the setting
*
* @param array $tooltips Tooltips.
* @return array
*/
public function add_tooltip( array $tooltips ) : array {
$tooltips['geniem_db_prevent'] = sprintf(
'<h6>%s</h6> %s',
__( 'Prevent database storing', self::TEXTDOMAIN ),
__( 'When enabled, the form entry will be deleted from the database as soon as the emails are sent.', self::TEXTDOMAIN )
);
return $tooltips;
}
/**
* Load plugin textdomain
*
* @return void
*/
public function load_textdomain() {
$data = get_plugin_data( __FILE__, false, true );
load_plugin_textdomain( $data['TextDomain'], false, $data['DomainPath'] );
}
}
// Initiate the plugin
new GF_DB_Prevent();