forked from aubreypwd-old/gravityforms-firstdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gffd-gfadmin.php
260 lines (224 loc) · 5.52 KB
/
gffd-gfadmin.php
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
// Include Gravity Forms admin CSS
// so we can use cool things like tabs, etc.
function gffd_admin_enqueue_css(){
wp_enqueue_style(
'gf_css',
gffd_plugin_url(),
array(),
'',
false
);
wp_enqueue_style(
'gffd_admin_css',
plugins_url('gffd-gfadmin.css', ___GFFDFILE___),
array(),
'',
false
);
}
// Check if a request var matches, if so, express $classes.
// Used when trying to see if &subpage=x
function gffd_request_match_class_active($request_var, $var_value, $classes, $echo){
if(isset($_REQUEST[$request_var])){
if($_REQUEST[$request_var]==$var_value){
if($echo==true){
echo $classes;
}else{
return $classes;
}
}else{
if($echo==true){
echo '';
}else{
return '';
}
}
}else{
if($var_value!=''){
if($echo==true){
echo '';
}else{
return '';
}
// If the var_value is blank, they
// must be asking if the request_var
// is unset.
//
// If it's unset, and we're asking if
// it is by sending '', then express
// the classes.
}else{
if($echo==true){
echo $classes;
}else{
return $classes;
}
}
}
}
// Hyper testing if a request var is set and matches.
//
// Use like:
//
// func('subpage','this-subpage')
//
// or
//
// func('subpage',array(
// 'subpage1',
// 'subpage2'
// ))
//
// ... which will test if either is being requested via subpage
// request var in OR mode.
function gffd_admin_request_match($request_var,$request_strings){
if(is_array($request_strings)){
foreach($request_strings as $request_string){
if(isset($_REQUEST[$request_var])){
if($_REQUEST[$request_var]==$request_string){
return true; // one matched
}
}else{
//do nothing
}
}
return false; //none matched.
}else{
if(isset($_REQUEST[$request_var])){
if($_REQUEST[$request_var]==$request_strings){
return true;
}else{
return false;
}
}else{
return false;
}
}
}
// Test if request variables are set.
//
// To test, use:
//
// func('form'), which will test if $_REQUEST[form]
// is set.
//
// func(array('form','subpage')), which will test
// if $_REQUEST[form] and $_REQUEST[subpage] are set.
function gffd_admin_is_requested($requested_vars, $match_value=false){
if(!is_array($requested_vars)){
if(isset($_REQUEST[$requested_vars])){
return true;
}else{
return false;
}
}else{
$requests_all_present=true;
foreach($requested_vars as $var_request){
if(!isset($_REQUEST[$var_request])){
$requests_all_present = false;
}
}
return $requests_all_present;
}
}
// Include our WP Admin scripts
// for the plugin.
function gffd_admin_scripts(){
wp_enqueue_script(
'gffd-gf-admin-js',
plugins_url('gffd-gfadmin.js', ___GFFDFILE___),
array(),
'',
false
);
}
add_action('admin_init','gffd_admin_scripts');
// Add a settings panel to the Gravity Forms Menu.
function gffd_admin_init(){
RGForms::add_settings_page(
__(gffd_glossary('settings_name')),
'gffd_admin_page',
''
);
}
add_action( 'admin_init', 'gffd_admin_init' );
// Setup the actual settings pages in
// wp-admin.
function gffd_admin_page(){
include "gffd-gfadmin.html.php";
}
// Get a particular setting.
function gffd_admin_get_setting($setting_key){
return get_option($setting_key);
}
// Set a particular setting.
function gffd_admin_set_setting($setting_key, $value){
return update_option($setting_key,$value);
}
// Save the settings.
function gffd_save_admin_settings(){
// Check if our submit button was clicked,
// if so, keep saving!
if(!isset($_REQUEST['gffd_admin_submit'])) return;
$gffd_admin_settings = gffd_admin_settings();
foreach($gffd_admin_settings as $setting_key => $setting){
if(isset($_REQUEST[$setting_key])){
// Make sure checks get value
if($_REQUEST[$setting_key]=="" && $setting['html_type']=='checkbox'){
$_REQUEST[$setting_key]="checked";
}
// I like to store each option as it's own
// separate key in the DB so one can
// manually hack in and change things.
gffd_admin_set_setting(
$setting_key,
$_REQUEST[$setting_key]
);
}else{
delete_option($setting_key);
}
}
// Go back to the referer page, so we
// don't get that re-post stuff on refresh.
wp_redirect($_SERVER['HTTP_REFERER']);
}
add_action('admin_init','gffd_save_admin_settings');
// The settings for gravity forms.
function gffd_admin_settings(){
return array(
'gffd_gateway_id'=>array(
'label'=>'Gateway ID',
'description'=>'You can find the Gateway ID at <strong>Administration → Terminals → Details → Gateway ID</strong>.',
// Could be textarea, chekcbox, etc.
'html_tag'=>'input',
// Could be password, date, strongail, etc.
'html_type'=>'text',
// <input>'s should = false.
// <textarea>'s should = true for </textarea>.
'html_close'=>false
),
'gffd_gateway_password'=>array(
'label'=>'Generated Password',
'description'=>'You can get the Gateway Password at <strong>Administration → Terminals → Details → Password</strong>. You may have to generate a new password to put here.',
'html_tag'=>'input',
'html_type'=>'text',
//Don't have to set (see below).
'html_close'=>false
),
'gffd_test_mode'=>array(
'label'=>'Enable Test Mode',
// Used with checkboxes, if true will show
// label next to the box [x] Label.
'checkbox_label'=>true,
'description'=>"Use this option to enable test mode when performing transactions.",
'html_tag'=>'input',
'html_type'=>'checkbox',
)
);
}
function gffd_get_gf_admin_setting($setting_id){
$settings = gffd_admin_settings();
return $settings[$setting_id];
}
?>