1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace GV; |
3
|
|
|
|
4
|
|
|
/** If this file is called directly, abort. */ |
5
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
6
|
|
|
die(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
if ( ! class_exists( '\GFAddOn' ) ) { |
10
|
|
|
return; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The Addon Settings class. |
15
|
|
|
* |
16
|
|
|
* Uses internal GFAddOn APIs. |
17
|
|
|
*/ |
18
|
|
|
class Addon_Settings extends \GFAddOn { |
19
|
|
|
/** |
20
|
|
|
* @var string Title of the plugin to be used on the settings page, form settings and plugins page. Example: 'Gravity Forms MailChimp Add-On' |
21
|
|
|
*/ |
22
|
|
|
protected $_title = 'GravityView'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string Short version of the plugin title to be used on menus and other places where a less verbose string is useful. Example: 'MailChimp' |
26
|
|
|
*/ |
27
|
|
|
protected $_short_title = 'GravityView'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string URL-friendly identifier used for form settings, add-on settings, text domain localization... |
31
|
|
|
*/ |
32
|
|
|
protected $_slug = 'gravityview'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string|array A string or an array of capabilities or roles that can uninstall the plugin |
36
|
|
|
*/ |
37
|
|
|
protected $_capabilities_uninstall = 'gravityview_uninstall'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string|array A string or an array of capabilities or roles that have access to the settings page |
41
|
|
|
*/ |
42
|
|
|
protected $_capabilities_app_settings = 'gravityview_view_settings'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string|array A string or an array of capabilities or roles that have access to the settings page |
46
|
|
|
*/ |
47
|
|
|
protected $_capabilities_app_menu = 'gravityview_view_settings'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string The hook suffix for the app menu |
51
|
|
|
*/ |
52
|
|
|
public $app_hook_suffix = 'gravityview'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var \GV\License_Handler Process license validation |
56
|
|
|
*/ |
57
|
|
|
private $License_Handler; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var bool Whether we have initialized already or not. |
61
|
|
|
*/ |
62
|
|
|
private static $initialized = false; |
63
|
|
|
|
64
|
2 |
|
public function __construct() { |
65
|
2 |
|
$this->_version = Plugin::$version; |
66
|
2 |
|
$this->_min_gravityforms_version = Plugin::$min_gf_version; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Hook everywhere, but only once. |
70
|
|
|
*/ |
71
|
2 |
|
if ( ! self::$initialized ) { |
72
|
|
|
parent::__construct(); |
73
|
|
|
self::$initialized = true; |
74
|
|
|
} |
75
|
2 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Run actions when initializing admin. |
79
|
|
|
* |
80
|
|
|
* Triggers the license key notice, et.c |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
1 |
|
public function init_admin() { |
85
|
1 |
|
$this->_load_license_handler(); |
86
|
1 |
|
$this->license_key_notice(); |
87
|
|
|
|
88
|
1 |
|
add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) ); |
89
|
|
|
|
90
|
|
|
/** @since 1.7.6 */ |
91
|
1 |
|
add_action( 'network_admin_menu', array( $this, 'add_network_menu' ) ); |
92
|
|
|
|
93
|
1 |
|
parent::init_admin(); |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Change the settings page header title to "GravityView" |
98
|
|
|
* |
99
|
|
|
* @param $setting_tabs |
100
|
|
|
* |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
1 |
|
public function modify_app_settings_menu_title( $setting_tabs ) { |
104
|
1 |
|
$setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview' ); |
105
|
1 |
|
return $setting_tabs; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Load license handler in admin-ajax.php |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
1 |
|
public function init_ajax() { |
114
|
1 |
|
$this->_load_license_handler(); |
115
|
1 |
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Make sure the license handler is available |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
1 |
|
private function _load_license_handler() { |
123
|
1 |
|
if ( ! empty( $this->License_Handler ) ) { |
124
|
1 |
|
return; |
125
|
|
|
} |
126
|
1 |
|
$this->License_Handler = License_Handler::get( $this ); |
127
|
1 |
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Add global Settings page for Multisite |
131
|
|
|
* @since 1.7.6 |
132
|
|
|
* @return void |
133
|
|
|
*/ |
134
|
1 |
|
public function add_network_menu() { |
135
|
1 |
|
if ( gravityview()->plugin->is_network_activated() ) { |
136
|
|
|
add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' ); |
137
|
|
|
} |
138
|
1 |
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Uninstall all traces of GravityView |
142
|
|
|
* |
143
|
|
|
* Note: method is public because parent method is public |
144
|
|
|
* |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
1 |
|
public function uninstall() { |
148
|
1 |
|
gravityview()->plugin->uninstall(); |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Set the path so that Gravity Forms can de-activate GravityView |
152
|
|
|
* @see GFAddOn::uninstall_addon |
153
|
|
|
* @uses deactivate_plugins() |
154
|
|
|
*/ |
155
|
1 |
|
$this->_path = GRAVITYVIEW_FILE; |
156
|
|
|
|
157
|
1 |
|
return true; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Prevent uninstall tab from being shown by returning false for the uninstall capability check. Otherwise: |
162
|
|
|
* @inheritDoc |
163
|
|
|
* |
164
|
|
|
* @hack |
165
|
|
|
* |
166
|
|
|
* @param array|string $caps |
167
|
|
|
* |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
1 |
|
public function current_user_can_any( $caps ) { |
171
|
1 |
|
if ( empty( $caps ) ) { |
172
|
|
|
$caps = array( 'gravityview_full_access' ); |
173
|
|
|
} |
174
|
1 |
|
return \GVCommon::has_cap( $caps ); |
175
|
|
|
} |
176
|
|
|
|
177
|
1 |
|
public function uninstall_warning_message() { |
178
|
1 |
|
$heading = esc_html__( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' ); |
179
|
1 |
|
$message = esc_html__( 'Delete all Views, GravityView entry approval status, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings.', 'gravityview' ); |
180
|
1 |
|
return sprintf( '<h4>%s</h4><p>%s</p>', $heading, $message ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get an array of reasons why the plugin might be uninstalled |
185
|
|
|
* |
186
|
|
|
* @since 1.17.5 |
187
|
|
|
* |
188
|
|
|
* @return array Array of reasons with the label and followup questions for each uninstall reason |
189
|
|
|
*/ |
190
|
1 |
|
private function get_uninstall_reasons() { |
191
|
|
|
$reasons = array( |
192
|
|
|
'will-continue' => array( |
193
|
1 |
|
'label' => esc_html__( 'I am going to continue using GravityView', 'gravityview' ), |
194
|
|
|
), |
195
|
|
|
'no-longer-need' => array( |
196
|
1 |
|
'label' => esc_html__( 'I no longer need GravityView', 'gravityview' ), |
197
|
|
|
), |
198
|
|
|
'doesnt-work' => array( |
199
|
1 |
|
'label' => esc_html__( 'The plugin doesn\'t work', 'gravityview' ), |
200
|
|
|
), |
201
|
|
|
'found-other' => array( |
202
|
1 |
|
'label' => esc_html__( 'I found a better plugin', 'gravityview' ), |
203
|
1 |
|
'followup' => esc_attr__( 'What plugin you are using, and why?', 'gravityview' ), |
204
|
|
|
), |
205
|
|
|
'other' => array( |
206
|
1 |
|
'label' => esc_html__( 'Other', 'gravityview' ), |
207
|
|
|
), |
208
|
|
|
); |
209
|
|
|
|
210
|
1 |
|
shuffle( $reasons ); |
211
|
|
|
|
212
|
1 |
|
return $reasons; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Display a feedback form when the plugin is uninstalled |
217
|
|
|
* |
218
|
|
|
* @since 1.17.5 |
219
|
|
|
* |
220
|
|
|
* @return string HTML of the uninstallation form |
221
|
|
|
*/ |
222
|
1 |
|
public function uninstall_form() { |
223
|
1 |
|
ob_start(); |
224
|
|
|
|
225
|
1 |
|
$user = wp_get_current_user(); |
226
|
|
|
?> |
227
|
1 |
|
<style> |
228
|
|
|
#gv-reason-details { |
229
|
|
|
min-height: 100px; |
230
|
|
|
} |
231
|
|
|
.number-scale label { |
232
|
|
|
border: 1px solid #cccccc; |
233
|
|
|
padding: .5em .75em; |
234
|
|
|
margin: .1em; |
235
|
|
|
} |
236
|
|
|
#gv-uninstall-thanks p { |
237
|
|
|
font-size: 1.2em; |
238
|
|
|
} |
239
|
|
|
.scale-description ul { |
240
|
|
|
margin-bottom: 0; |
241
|
|
|
padding-bottom: 0; |
242
|
|
|
} |
243
|
|
|
.scale-description p.description { |
244
|
|
|
margin-top: 0!important; |
245
|
|
|
padding-top: 0!important; |
246
|
|
|
} |
247
|
|
|
.gv-form-field-wrapper { |
248
|
|
|
margin-top: 30px; |
249
|
|
|
} |
250
|
|
|
</style> |
251
|
|
|
|
252
|
|
|
<div class="gv-uninstall-form-wrapper" style="font-size: 110%; padding: 15px 0;"> |
253
|
|
|
<script> |
254
|
|
|
jQuery( function( $ ) { |
255
|
|
|
$( '#gv-uninstall-feedback' ).on( 'change', function( e ) { |
256
|
|
|
|
257
|
|
|
if ( ! $( e.target ).is( ':input' ) ) { |
258
|
|
|
return; |
259
|
|
|
} |
260
|
|
|
var $textarea = $( '.gv-followup' ).find( 'textarea' ); |
261
|
|
|
var followup_text = $( e.target ).attr( 'data-followup' ); |
262
|
|
|
if( ! followup_text ) { |
263
|
|
|
followup_text = $textarea.attr( 'data-default' ); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$textarea.attr( 'placeholder', followup_text ); |
267
|
|
|
|
268
|
|
|
} ).on( 'submit', function( e ) { |
269
|
|
|
e.preventDefault(); |
270
|
|
|
|
271
|
|
|
$.post( $( this ).attr( 'action' ), $( this ).serialize() ) |
272
|
|
|
.done( function( data ) { |
273
|
|
|
if ( 'success' !== data.status ) { |
274
|
|
|
gv_feedback_append_error_message(); |
275
|
|
|
} else { |
276
|
|
|
$( '#gv-uninstall-thanks' ).fadeIn(); |
277
|
|
|
} |
278
|
|
|
}) |
279
|
|
|
.fail( function( data ) { |
280
|
|
|
gv_feedback_append_error_message(); |
281
|
|
|
} ) |
282
|
|
|
.always( function() { |
283
|
|
|
$( e.target ).remove(); |
284
|
|
|
} ); |
285
|
|
|
|
286
|
|
|
return false; |
287
|
|
|
}); |
288
|
|
|
|
289
|
|
|
function gv_feedback_append_error_message() { |
290
|
|
|
$( '#gv-uninstall-thanks' ).append( '<div class="notice error">' + <?php echo json_encode( esc_html( __( 'There was an error sharing your feedback. Sorry! Please email us at [email protected]', 'gravityview' ) ) ) ?> + '</div>' ); |
291
|
|
|
} |
292
|
|
|
}); |
293
|
|
|
</script> |
294
|
|
|
|
295
|
|
|
<form id="gv-uninstall-feedback" method="post" action="https://hooks.zapier.com/hooks/catch/28670/6haevn/"> |
296
|
|
|
<h2><?php esc_html_e( 'Why did you uninstall GravityView?', 'gravityview' ); ?></h2> |
297
|
|
|
<ul> |
298
|
|
|
<?php |
299
|
1 |
|
$reasons = $this->get_uninstall_reasons(); |
300
|
1 |
|
foreach ( $reasons as $reason ) { |
301
|
1 |
|
printf( '<li><label><input name="reason" type="radio" value="other" data-followup="%s"> %s</label></li>', Utils::get( $reason, 'followup' ), Utils::get( $reason, 'label' ) ); |
302
|
|
|
} |
303
|
|
|
?> |
304
|
1 |
|
</ul> |
305
|
|
|
<div class="gv-followup widefat"> |
306
|
|
|
<p><strong><label for="gv-reason-details"><?php esc_html_e( 'Comments', 'gravityview' ); ?></label></strong></p> |
307
|
|
|
<textarea id="gv-reason-details" name="reason_details" data-default="<?php esc_attr_e('Please share your thoughts about GravityView', 'gravityview') ?>" placeholder="<?php esc_attr_e('Please share your thoughts about GravityView', 'gravityview'); ?>" class="large-text"></textarea> |
|
|
|
|
308
|
|
|
</div> |
309
|
|
|
<div class="scale-description"> |
310
|
|
|
<p><strong><?php esc_html_e( 'How likely are you to recommend GravityView?', 'gravityview' ); ?></strong></p> |
311
|
|
|
<ul class="inline"> |
312
|
|
|
<?php |
313
|
1 |
|
$i = 0; |
314
|
1 |
|
while( $i < 11 ) { |
315
|
1 |
|
echo '<li class="inline number-scale"><label><input name="likely_to_refer" id="likely_to_refer_'.$i.'" value="'.$i.'" type="radio"> '.$i.'</label></li>'; |
|
|
|
|
316
|
1 |
|
$i++; |
317
|
|
|
} |
318
|
|
|
?> |
319
|
1 |
|
</ul> |
320
|
|
|
<p class="description"><?php printf( esc_html_x( '%s ("Not at all likely") to %s ("Extremely likely")', 'A scale from 0 (bad) to 10 (good)', 'gravityview' ), '<label for="likely_to_refer_0"><code>0</code></label>', '<label for="likely_to_refer_10"><code>10</code></label>' ); ?></p> |
321
|
|
|
</div> |
322
|
|
|
|
323
|
|
|
<div class="gv-form-field-wrapper"> |
324
|
|
|
<label><input type="checkbox" class="checkbox" name="follow_up_with_me" value="1" /> <?php esc_html_e( 'Please follow up with me about my feedback', 'gravityview' ); ?></label> |
325
|
|
|
</div> |
326
|
|
|
|
327
|
|
|
<div class="submit"> |
328
|
|
|
<input type="hidden" name="siteurl" value="<?php echo esc_url( get_bloginfo( 'url' ) ); ?>" /> |
329
|
|
|
<input type="hidden" name="email" value="<?php echo esc_attr( $user->user_email ); ?>" /> |
330
|
|
|
<input type="hidden" name="display_name" value="<?php echo esc_attr( $user->display_name ); ?>" /> |
331
|
|
|
<input type="submit" value="<?php esc_html_e( 'Send Us Your Feedback', 'gravityview' ); ?>" class="button button-primary button-hero" /> |
332
|
|
|
</div> |
333
|
|
|
</form> |
334
|
|
|
|
335
|
|
|
<div id="gv-uninstall-thanks" class="notice notice-large notice-updated below-h2" style="display:none;"> |
336
|
|
|
<h3 class="notice-title"><?php esc_html_e( 'Thank you for using GravityView!', 'gravityview' ); ?></h3> |
337
|
|
|
<p><?php echo gravityview_get_floaty(); ?> |
|
|
|
|
338
|
|
|
<?php echo make_clickable( esc_html__( 'Your feedback helps us improve GravityView. If you have any questions or comments, email us: [email protected]', 'gravityview' ) ); ?> |
|
|
|
|
339
|
1 |
|
</p> |
340
|
|
|
<div class="wp-clearfix"></div> |
341
|
|
|
</div> |
342
|
|
|
</div> |
343
|
|
|
<?php |
344
|
1 |
|
$form = ob_get_clean(); |
345
|
|
|
|
346
|
1 |
|
return $form; |
347
|
|
|
} |
348
|
|
|
|
349
|
1 |
|
public function app_settings_uninstall_tab() { |
350
|
1 |
|
if ( $this->maybe_uninstall() ) { |
351
|
|
|
parent::app_settings_uninstall_tab(); |
352
|
|
|
return; |
353
|
|
|
} |
354
|
|
|
|
355
|
1 |
|
if ( ! ( $this->current_user_can_any( $this->_capabilities_uninstall ) && ( ! function_exists( 'is_multisite' ) || ! is_multisite() || is_super_admin() ) ) ) { |
356
|
|
|
return; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
?> |
360
|
1 |
|
<script> |
361
|
|
|
jQuery( document ).on( 'click', 'a[rel="gv-uninstall-wrapper"]', function( e ) { |
362
|
|
|
e.preventDefault(); |
363
|
|
|
jQuery( '#gv-uninstall-wrapper' ).slideToggle(); |
364
|
|
|
} ); |
365
|
|
|
</script> |
366
|
|
|
|
367
|
|
|
<a rel="gv-uninstall-wrapper" href="#gv-uninstall-wrapper" class="button button-large alignright button-danger">Uninstall GravityView</a> |
368
|
|
|
|
369
|
|
|
<div id="gv-uninstall-wrapper"> |
370
|
|
|
<form action="" method="post"> |
371
|
|
|
<?php wp_nonce_field( 'uninstall', 'gf_addon_uninstall' ) ?> |
372
|
1 |
|
<div class="delete-alert alert_red"> |
373
|
|
|
|
374
|
|
|
<h3> |
375
|
|
|
<i class="fa fa-exclamation-triangle gf_invalid"></i> <?php esc_html_e( 'Delete all GravityView content and settings', 'gravityview' ); ?> |
376
|
1 |
|
</h3> |
377
|
|
|
|
378
|
|
|
<div class="gf_delete_notice"> |
379
|
|
|
<?php echo $this->uninstall_warning_message() ?> |
|
|
|
|
380
|
1 |
|
</div> |
381
|
|
|
|
382
|
|
|
<?php |
383
|
1 |
|
echo '<input type="submit" name="uninstall" value="' . sprintf( esc_attr__( 'Uninstall %s', 'gravityview' ), $this->get_short_title() ) . '" class="button button-hero" onclick="return confirm( ' . json_encode( $this->uninstall_confirm_message() ) . ' );" onkeypress="return confirm( ' . json_encode( $this->uninstall_confirm_message() ) . ' );"/>'; |
|
|
|
|
384
|
|
|
?> |
385
|
|
|
|
386
|
|
|
</div> |
387
|
|
|
</form> |
388
|
|
|
</div> |
389
|
|
|
<?php |
390
|
1 |
|
} |
391
|
|
|
|
392
|
1 |
|
public function app_settings_tab() { |
393
|
1 |
|
parent::app_settings_tab(); |
394
|
|
|
|
395
|
1 |
|
if ( $this->maybe_uninstall() ) { |
396
|
|
|
echo $this->uninstall_form(); |
|
|
|
|
397
|
|
|
} |
398
|
1 |
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* The Settings title |
402
|
|
|
* |
403
|
|
|
* @return string |
404
|
|
|
*/ |
405
|
1 |
|
public function app_settings_title() { |
406
|
1 |
|
return null; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Prevent displaying of any icon |
411
|
|
|
* |
412
|
|
|
* @return string |
413
|
|
|
*/ |
414
|
1 |
|
public function app_settings_icon() { |
415
|
1 |
|
return ' '; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Retrieve a setting. |
420
|
|
|
* |
421
|
|
|
* @deprecated Use \GV\Addon_Settings::get |
422
|
|
|
* @param string $setting_name The setting key. |
423
|
|
|
* |
424
|
|
|
* @return mixed The setting or null |
425
|
|
|
*/ |
426
|
1 |
|
public function get_app_setting( $setting_name ) { |
427
|
1 |
|
return $this->get( $setting_name ); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* Retrieve a setting. |
432
|
|
|
* |
433
|
|
|
* @param string $key The setting key. |
434
|
|
|
* @param string $default A default if not found. |
435
|
|
|
* |
436
|
|
|
* @return mixed The setting value. |
437
|
|
|
*/ |
438
|
76 |
|
public function get( $key, $default = null ) { |
439
|
|
|
/** |
440
|
|
|
* Backward compatibility with Redux |
441
|
|
|
*/ |
442
|
76 |
|
if ( $key === 'license' ) { |
|
|
|
|
443
|
|
|
return array( |
444
|
2 |
|
'license' => $this->get( 'license_key' ), |
445
|
2 |
|
'status' => $this->get( 'license_key_status' ), |
446
|
2 |
|
'response' => $this->get( 'license_key_response' ), |
447
|
|
|
); |
448
|
|
|
} |
449
|
76 |
|
return Utils::get( $this->all(), $key, $default ); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Get the setting for GravityView by name |
454
|
|
|
* |
455
|
|
|
* @deprecated Use gravityview()->plugin->settings->get() |
456
|
|
|
* @param string $key Option key to fetch |
457
|
|
|
* |
458
|
|
|
* @return mixed |
459
|
|
|
*/ |
460
|
1 |
|
static public function getSetting( $key ) { |
|
|
|
|
461
|
1 |
|
if ( gravityview()->plugin->settings instanceof Addon_Settings ) { |
462
|
1 |
|
return gravityview()->plugin->settings->get( $key ); |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Get all settings. |
468
|
|
|
* |
469
|
|
|
* @deprecated Use \GV\Addon_Settings::all() or \GV\Addon_Settings::get() |
470
|
|
|
* |
471
|
|
|
* @return array The settings. |
472
|
|
|
*/ |
473
|
1 |
|
public function get_app_settings() { |
474
|
1 |
|
return $this->all(); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Get all the settings. |
479
|
|
|
* |
480
|
|
|
* @return array The settings. |
481
|
|
|
*/ |
482
|
76 |
|
public function all() { |
483
|
76 |
|
return wp_parse_args( get_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', array() ), $this->defaults() ); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Default settings. |
488
|
|
|
* |
489
|
|
|
* @deprecated Use \GV\Addon_Settings::defaults() |
490
|
|
|
* |
491
|
|
|
* @return array The defaults. |
492
|
|
|
*/ |
493
|
1 |
|
public function get_default_settings() { |
494
|
1 |
|
return $this->defaults(); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Default settings. |
499
|
|
|
* |
500
|
|
|
* @return array The defaults. |
501
|
|
|
*/ |
502
|
76 |
|
private function defaults() { |
503
|
|
|
$defaults = array( |
504
|
|
|
// Set the default license in wp-config.php |
505
|
76 |
|
'license_key' => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '', |
506
|
76 |
|
'license_key_response' => '', |
507
|
76 |
|
'license_key_status' => '', |
508
|
76 |
|
'support-email' => get_bloginfo( 'admin_email' ), |
509
|
76 |
|
'no-conflict-mode' => '1', |
510
|
76 |
|
'support_port' => '1', |
511
|
76 |
|
'flexbox_search' => '1', |
512
|
76 |
|
'rest_api' => '0', |
513
|
76 |
|
'beta' => '0', |
514
|
|
|
); |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* @filter `gravityview/settings/default` Filter default global settings. |
518
|
|
|
* @param[in,out] array The defaults. |
519
|
|
|
*/ |
520
|
76 |
|
return apply_filters( 'gravityview/settings/defaults', $defaults ); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/*** |
524
|
|
|
* Renders the save button for settings pages |
525
|
|
|
* |
526
|
|
|
* @param array $field - Field array containing the configuration options of this field |
527
|
|
|
* @param bool $echo = true - true to echo the output to the screen, false to simply return the contents as a string |
528
|
|
|
* |
529
|
|
|
* @return string The HTML |
530
|
|
|
*/ |
531
|
2 |
|
public function as_html( $field, $echo = true ) { |
532
|
2 |
|
$field['type'] = ( isset( $field['type'] ) && in_array( $field['type'], array( 'submit','reset','button' ) ) ) ? $field['type'] : 'submit'; |
|
|
|
|
533
|
|
|
|
534
|
2 |
|
$attributes = $this->get_field_attributes( $field ); |
535
|
2 |
|
$default_value = Utils::get( $field, 'value', Utils::get( $field, 'default_value' ) ); |
536
|
2 |
|
$value = $this->get( $field['name'], $default_value ); |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
539
|
2 |
|
$attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton'; |
540
|
2 |
|
$name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_' . $field['name']; |
541
|
|
|
|
542
|
2 |
|
if ( empty( $value ) ) { |
543
|
2 |
|
$value = __( 'Update Settings', 'gravityview' ); |
544
|
|
|
} |
545
|
|
|
|
546
|
2 |
|
$attributes = $this->get_field_attributes( $field ); |
547
|
|
|
|
548
|
|
|
$html = '<input |
549
|
2 |
|
type="' . $field['type'] . '" |
550
|
2 |
|
name="' . esc_attr( $name ) . '" |
551
|
2 |
|
value="' . $value . '" ' . |
552
|
2 |
|
implode( ' ', $attributes ) . |
553
|
2 |
|
' />'; |
554
|
|
|
|
555
|
2 |
|
if ( $echo ) { |
556
|
|
|
echo $html; |
|
|
|
|
557
|
|
|
} |
558
|
|
|
|
559
|
2 |
|
return $html; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* @deprecated Use \GV\Addon_Settings::as_html |
564
|
|
|
*/ |
565
|
1 |
|
public function settings_submit( $field, $echo = true ) { |
566
|
1 |
|
gravityview()->log->warning( '\GV\Addon_Settings::settings_submit has been deprecated for \GV\Addon_Settings::as_html' ); |
567
|
1 |
|
return $this->as_html( $field, $echo ); |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* Display a notice if the plugin is inactive. |
572
|
|
|
* |
573
|
|
|
* @return void |
574
|
|
|
*/ |
575
|
1 |
|
public function license_key_notice() { |
576
|
1 |
|
$license_status = $this->get( 'license_key_status' ); |
577
|
1 |
|
$license_key = $this->get( 'license_key' ); |
578
|
1 |
|
if( '' === $license_key ) { |
579
|
1 |
|
$license_status = 'inactive'; |
580
|
|
|
} |
581
|
1 |
|
$license_id = empty( $license_key ) ? 'license' : $license_key; |
582
|
|
|
|
583
|
1 |
|
$message = esc_html__( 'Your GravityView license %s. This means you’re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview' ); |
584
|
|
|
|
585
|
|
|
/** |
586
|
|
|
* I wanted to remove the period from after the buttons in the string, |
587
|
|
|
* but didn't want to mess up the translation strings for the translators. |
588
|
|
|
*/ |
589
|
1 |
|
$message = mb_substr( $message, 0, mb_strlen( $message ) - 1 ); |
590
|
1 |
|
$title = __ ( 'Inactive License', 'gravityview'); |
|
|
|
|
591
|
1 |
|
$status = ''; |
592
|
1 |
|
$update_below = false; |
593
|
1 |
|
$primary_button_link = admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ); |
594
|
|
|
|
595
|
1 |
|
switch ( $license_status ) { |
596
|
|
|
/** @since 1.17 */ |
597
|
1 |
|
case 'expired': |
598
|
|
|
$title = __( 'Expired License', 'gravityview' ); |
599
|
|
|
$status = 'expired'; |
600
|
|
|
$message = $this->get_license_handler()->strings( 'expired', $this->get( 'license_key_response' ) ); |
601
|
|
|
break; |
602
|
1 |
|
case 'invalid': |
603
|
|
|
$title = __( 'Invalid License', 'gravityview' ); |
604
|
|
|
$status = __( 'is invalid', 'gravityview' ); |
605
|
|
|
break; |
606
|
1 |
|
case 'deactivated': |
607
|
|
|
$status = __( 'is inactive', 'gravityview' ); |
608
|
|
|
$update_below = __( 'Activate your license key below.', 'gravityview' ); |
609
|
|
|
break; |
610
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */ |
611
|
1 |
|
case '': |
612
|
|
|
$license_status = 'site_inactive'; |
613
|
|
|
// break intentionally left blank |
614
|
1 |
|
case 'inactive': |
615
|
|
|
case 'site_inactive': |
616
|
1 |
|
$status = __( 'has not been activated', 'gravityview' ); |
617
|
1 |
|
$update_below = __( 'Activate your license key below.', 'gravityview' ); |
618
|
1 |
|
break; |
619
|
|
|
} |
620
|
1 |
|
$url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice'; |
621
|
|
|
|
622
|
|
|
// Show a different notice on settings page for inactive licenses (hide the buttons) |
623
|
1 |
|
if ( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
|
|
|
624
|
|
|
$message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' ); |
625
|
|
|
} else { |
626
|
1 |
|
$message = sprintf( $message, $status, "\n\n" . '<a href="' . esc_url( $primary_button_link ) . '" class="button button-primary">', '</a>', '<a href="' . esc_url( $url ) . '" class="button button-secondary">', '</a>' ); |
627
|
|
|
} |
628
|
|
|
|
629
|
1 |
|
if ( ! empty( $status ) ) { |
630
|
1 |
|
\GravityView_Admin_Notices::add_notice( array( |
631
|
1 |
|
'message' => $message, |
632
|
1 |
|
'class' => 'updated', |
633
|
1 |
|
'title' => $title, |
634
|
1 |
|
'cap' => 'gravityview_edit_settings', |
635
|
1 |
|
'dismiss' => sha1( $license_status . '_' . $license_id . '_' . date( 'z' ) ), // Show every day, instead of every 8 weeks (which is the default) |
636
|
|
|
) ); |
637
|
|
|
} |
638
|
1 |
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* Allow public access to the GV\License_Handler class |
642
|
|
|
* @since 1.7.4 |
643
|
|
|
* |
644
|
|
|
* @return \GV\License_Handler |
645
|
|
|
*/ |
646
|
1 |
|
public function get_license_handler() { |
647
|
1 |
|
return $this->License_Handler; |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Add tooltip script to app settings page. Not enqueued by Gravity Forms for some reason. |
652
|
|
|
* |
653
|
|
|
* @since 1.21.5 |
654
|
|
|
* |
655
|
|
|
* @see GFAddOn::scripts() |
656
|
|
|
* |
657
|
|
|
* @return array Array of scripts |
658
|
|
|
*/ |
659
|
4 |
|
public function scripts() { |
660
|
4 |
|
$scripts = parent::scripts(); |
661
|
|
|
|
662
|
4 |
|
$scripts[] = array( |
663
|
|
|
'handle' => 'gform_tooltip_init', |
664
|
|
|
'enqueue' => array( |
665
|
|
|
array( |
666
|
|
|
'admin_page' => array( 'app_settings' ) |
667
|
|
|
) |
|
|
|
|
668
|
|
|
) |
669
|
|
|
); |
670
|
|
|
|
671
|
4 |
|
return $scripts; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
/** |
675
|
|
|
* Register styles in the app admin page |
676
|
|
|
* @return array |
677
|
|
|
*/ |
678
|
4 |
|
public function styles() { |
679
|
4 |
|
$styles = parent::styles(); |
680
|
|
|
|
681
|
4 |
|
$styles[] = array( |
682
|
4 |
|
'handle' => 'gravityview_settings', |
683
|
4 |
|
'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ), |
684
|
4 |
|
'version' => Plugin::$version, |
685
|
|
|
'deps' => array( |
686
|
|
|
'gform_admin', |
687
|
|
|
'gaddon_form_settings_css', |
688
|
|
|
'gform_tooltip', |
689
|
|
|
'gform_font_awesome', |
690
|
|
|
), |
691
|
|
|
'enqueue' => array( |
692
|
|
|
array( 'admin_page' => array( |
|
|
|
|
693
|
|
|
'app_settings', |
694
|
|
|
) ), |
695
|
|
|
) |
696
|
|
|
); |
697
|
|
|
|
698
|
4 |
|
return $styles; |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* Add Settings link to GravityView menu |
703
|
|
|
* @return void |
704
|
|
|
*/ |
705
|
1 |
|
public function create_app_menu() { |
706
|
|
|
/** |
707
|
|
|
* If not multisite, always show. |
708
|
|
|
* If multisite and the plugin is network activated, show; we need to register the submenu page for the Network Admin settings to work. |
709
|
|
|
* If multisite and not network admin, we don't want the settings to show. |
710
|
|
|
* @since 1.7.6 |
711
|
|
|
*/ |
712
|
1 |
|
$show_submenu = ( ! is_multisite() ) || is_main_site() || ( ! gravityview()->plugin->is_network_activated() ) || ( is_network_admin() && gravityview()->plugin->is_network_activated() ); |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* Override whether to show the Settings menu on a per-blog basis. |
716
|
|
|
* @since 1.7.6 |
717
|
|
|
* @param bool $hide_if_network_activated Default: true |
718
|
|
|
*/ |
719
|
1 |
|
$show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu ); |
720
|
|
|
|
721
|
1 |
|
if ( $show_submenu ) { |
722
|
1 |
|
add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) ); |
723
|
|
|
} |
724
|
1 |
|
} |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* Gets the required indicator |
728
|
|
|
* Gets the markup of the required indicator symbol to highlight fields that are required |
729
|
|
|
* |
730
|
|
|
* @param $field - The field meta. |
731
|
|
|
* |
732
|
|
|
* @return string - Returns markup of the required indicator symbol |
733
|
|
|
*/ |
734
|
1 |
|
public function get_required_indicator( $field ) { |
735
|
1 |
|
return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>'; |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* Specify the settings fields to be rendered on the plugin settings page |
740
|
|
|
* |
741
|
|
|
* @return array |
742
|
|
|
*/ |
743
|
1 |
|
public function app_settings_fields() { |
744
|
1 |
|
$default_settings = $this->defaults(); |
745
|
|
|
|
746
|
1 |
|
$disabled_attribute = \GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled'; |
747
|
|
|
|
748
|
|
|
$fields = array( |
749
|
|
|
array( |
750
|
1 |
|
'name' => 'gv_header', |
751
|
|
|
'value' => '', |
752
|
|
|
'type' => 'html', |
753
|
|
|
), |
754
|
|
|
array( |
755
|
1 |
|
'name' => 'license_key', |
756
|
|
|
'required' => true, |
757
|
1 |
|
'label' => __( 'License Key', 'gravityview' ), |
758
|
1 |
|
'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview' ) . $this->get_license_handler()->license_details( $this->get_app_setting( 'license_key_response' ) ), |
|
|
|
|
759
|
1 |
|
'type' => 'edd_license', |
760
|
1 |
|
'disabled' => ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ), |
761
|
1 |
|
'data-pending-text' => __( 'Verifying license…', 'gravityview' ), |
762
|
1 |
|
'default_value' => $default_settings['license_key'], |
763
|
1 |
|
'class' => ( '' == $this->get( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', |
764
|
|
|
), |
765
|
|
|
array( |
766
|
1 |
|
'name' => 'license_key_response', |
767
|
1 |
|
'default_value' => $default_settings['license_key_response'], |
768
|
1 |
|
'type' => 'hidden', |
769
|
|
|
), |
770
|
|
|
array( |
771
|
1 |
|
'name' => 'license_key_status', |
772
|
1 |
|
'default_value' => $default_settings['license_key_status'], |
773
|
1 |
|
'type' => 'hidden', |
774
|
|
|
), |
775
|
|
|
array( |
776
|
1 |
|
'name' => 'support-email', |
777
|
1 |
|
'type' => 'text', |
778
|
1 |
|
'validate' => 'email', |
779
|
1 |
|
'default_value' => $default_settings['support-email'], |
780
|
1 |
|
'label' => __( 'Support Email', 'gravityview' ), |
781
|
1 |
|
'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ), |
782
|
1 |
|
'class' => 'code regular-text', |
783
|
|
|
), |
784
|
|
|
/** |
785
|
|
|
* @since 1.15 Added Support Port support |
786
|
|
|
*/ |
787
|
|
|
array( |
788
|
1 |
|
'name' => 'support_port', |
789
|
1 |
|
'type' => 'radio', |
790
|
1 |
|
'label' => __( 'Show Support Port?', 'gravityview' ), |
791
|
1 |
|
'default_value' => $default_settings['support_port'], |
792
|
1 |
|
'horizontal' => 1, |
793
|
|
|
'choices' => array( |
794
|
|
|
array( |
795
|
1 |
|
'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ), |
796
|
1 |
|
'value' => '1', |
797
|
|
|
), |
798
|
|
|
array( |
799
|
1 |
|
'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ), |
800
|
1 |
|
'value' => '0', |
801
|
|
|
), |
802
|
|
|
), |
803
|
1 |
|
'tooltip' => '<p><img src="' . esc_url_raw( plugins_url( 'assets/images/beacon.png', GRAVITYVIEW_FILE ) ) . '" alt="' . esc_attr__( 'The Support Port looks like this.', 'gravityview' ) . '" class="alignright" style="max-width:40px; margin:.5em;" />' . esc_html__( 'The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.', 'gravityview' ) . '</p>', |
804
|
1 |
|
'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ), |
805
|
|
|
), |
806
|
|
|
array( |
807
|
1 |
|
'name' => 'no-conflict-mode', |
808
|
1 |
|
'type' => 'radio', |
809
|
1 |
|
'label' => __( 'No-Conflict Mode', 'gravityview' ), |
810
|
1 |
|
'default_value' => $default_settings['no-conflict-mode'], |
811
|
1 |
|
'horizontal' => 1, |
812
|
|
|
'choices' => array( |
813
|
|
|
array( |
814
|
1 |
|
'label' => _x( 'On', 'Setting: On or off', 'gravityview' ), |
815
|
1 |
|
'value' => '1', |
816
|
|
|
), |
817
|
|
|
array( |
818
|
1 |
|
'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ), |
819
|
1 |
|
'value' => '0', |
820
|
|
|
), |
821
|
|
|
), |
822
|
1 |
|
'description' => __( 'Set this to ON to prevent extraneous scripts and styles from being printed on GravityView admin pages, reducing conflicts with other plugins and themes.', 'gravityview' ) . ' ' . __( 'If your Edit View tabs are ugly, enable this setting.', 'gravityview' ), |
|
|
|
|
823
|
|
|
), |
824
|
|
|
/** |
825
|
|
|
* @since 2.0 Added REST API |
826
|
|
|
*/ |
827
|
1 |
|
gravityview()->plugin->supports( Plugin::FEATURE_REST ) ? |
828
|
|
|
array( |
829
|
1 |
|
'name' => 'rest_api', |
830
|
1 |
|
'type' => 'radio', |
831
|
1 |
|
'label' => __( 'REST API', 'gravityview' ), |
832
|
1 |
|
'default_value' => $default_settings['rest_api'], |
833
|
1 |
|
'horizontal' => 1, |
834
|
|
|
'choices' => array( |
835
|
|
|
array( |
836
|
1 |
|
'label' => _x( 'Enable', 'Setting: Enable or Disable', 'gravityview' ), |
837
|
1 |
|
'value' => '1', |
838
|
|
|
), |
839
|
|
|
array( |
840
|
1 |
|
'label' => _x( 'Disable', 'Setting: Enable or Disable', 'gravityview' ), |
841
|
1 |
|
'value' => '0', |
842
|
|
|
), |
843
|
|
|
), |
844
|
1 |
|
'description' => __( 'Enable View and Entry access via the REST API? Regular per-View restrictions apply (private, password protected, etc.).', 'gravityview' ), |
845
|
1 |
|
'tooltip' => '<p>' . esc_html__( 'If you are unsure, choose the Disable setting.', 'gravityview' ) . '</p>', |
846
|
|
|
) : array(), |
847
|
|
|
array( |
848
|
1 |
|
'name' => 'beta', |
849
|
1 |
|
'type' => 'checkbox', |
850
|
1 |
|
'label' => __( 'Become a Beta Tester', 'gravityview' ), |
851
|
1 |
|
'default_value' => $default_settings['beta'], |
852
|
1 |
|
'horizontal' => 1, |
853
|
|
|
'choices' => array( |
854
|
|
|
array( |
855
|
1 |
|
'label' => _x( 'Show me beta versions if they are available.', 'gravityview' ), |
856
|
1 |
|
'value' => '1', |
857
|
1 |
|
'name' => 'beta', |
858
|
|
|
), |
859
|
|
|
), |
860
|
1 |
|
'description' => __( 'You will have early access to the latest GravityView features and improvements. There may be bugs! If you encounter an issue, help make GravityView better by reporting it!', 'gravityview' ), |
861
|
|
|
), |
862
|
|
|
); |
863
|
|
|
|
864
|
1 |
|
$fields = array_filter( $fields, 'count' ); |
865
|
|
|
|
866
|
|
|
/** |
867
|
|
|
* @filter `gravityview_settings_fields` Filter the settings fields. |
868
|
|
|
* @param array $fields The fields to filter. |
869
|
|
|
* @deprecated Use `gravityview/settings/fields`. |
870
|
|
|
*/ |
871
|
1 |
|
$fields = apply_filters( 'gravityview_settings_fields', $fields ); |
872
|
|
|
|
873
|
|
|
/** |
874
|
|
|
* @filter `gravityview/settings/fields` Filter the settings fields. |
875
|
|
|
* @param array $fields The fields to filter. |
876
|
|
|
*/ |
877
|
1 |
|
$fields = apply_filters( 'gravityview/settings/fields', $fields ); |
878
|
|
|
|
879
|
|
|
/** |
880
|
|
|
* Redux backward compatibility |
881
|
|
|
* @since 1.7.4 |
882
|
|
|
*/ |
883
|
1 |
|
foreach ( $fields as &$field ) { |
884
|
1 |
|
$field['name'] = isset( $field['name'] ) ? $field['name'] : Utils::get( $field, 'id' ); |
885
|
1 |
|
$field['label'] = isset( $field['label'] ) ? $field['label'] : Utils::get( $field, 'title' ); |
886
|
1 |
|
$field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : Utils::get( $field, 'default' ); |
887
|
1 |
|
$field['description'] = isset( $field['description'] ) ? $field['description'] : Utils::get( $field, 'subtitle' ); |
888
|
|
|
|
889
|
1 |
|
if ( $disabled_attribute ) { |
890
|
|
|
$field['disabled'] = $disabled_attribute; |
891
|
|
|
} |
892
|
|
|
|
893
|
1 |
|
if ( empty( $field['disabled'] ) ) { |
894
|
1 |
|
unset( $field['disabled'] ); |
895
|
|
|
} |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
$sections = array( |
899
|
|
|
array( |
900
|
1 |
|
'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), Plugin::$version ) ), |
901
|
1 |
|
'fields' => $fields, |
902
|
|
|
) |
|
|
|
|
903
|
|
|
); |
904
|
|
|
|
905
|
|
|
// custom 'update settings' button |
906
|
|
|
$button = array( |
907
|
1 |
|
'class' => 'button button-primary button-hero', |
908
|
|
|
'type' => 'save', |
909
|
|
|
); |
910
|
|
|
|
911
|
1 |
|
if ( $disabled_attribute ) { |
912
|
|
|
$button['disabled'] = $disabled_attribute; |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
/** |
916
|
|
|
* @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
917
|
|
|
* Extensions can tap in here to insert their own section and settings. |
918
|
|
|
* <code> |
919
|
|
|
* $sections[] = array( |
920
|
|
|
* 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
921
|
|
|
* 'fields' => $settings, |
922
|
|
|
* ); |
923
|
|
|
* </code> |
924
|
|
|
* @param array $extension_settings Empty array, ready for extension settings! |
925
|
|
|
*/ |
926
|
1 |
|
$extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
927
|
|
|
|
928
|
|
|
// If there are extensions, add a section for them |
929
|
1 |
|
if ( ! empty( $extension_sections ) ) { |
930
|
|
|
|
931
|
|
|
if( $disabled_attribute ) { |
932
|
|
|
foreach ( $extension_sections as &$section ) { |
933
|
|
|
foreach ( $section['fields'] as &$field ) { |
934
|
|
|
$field['disabled'] = $disabled_attribute; |
935
|
|
|
} |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
$k = count( $extension_sections ) - 1 ; |
940
|
|
|
$extension_sections[ $k ]['fields'][] = $button; |
941
|
|
|
$sections = array_merge( $sections, $extension_sections ); |
942
|
|
|
} else { |
943
|
|
|
// add the 'update settings' button to the general section |
944
|
1 |
|
$sections[0]['fields'][] = $button; |
945
|
|
|
} |
946
|
|
|
|
947
|
1 |
|
return $sections; |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
/** |
951
|
|
|
* Updates app settings with the provided settings |
952
|
|
|
* |
953
|
|
|
* Same as the GFAddon, except it returns the value from update_option() |
954
|
|
|
* |
955
|
|
|
* @param array $settings - App settings to be saved |
956
|
|
|
* |
957
|
|
|
* @deprecated Use \GV\Addon_Settings::set or \GV\Addon_Settings::update |
958
|
|
|
* |
959
|
|
|
* @return boolean False if value was not updated and true if value was updated. |
960
|
|
|
*/ |
961
|
|
|
public function update_app_settings( $settings ) { |
962
|
|
|
return $this->update( $settings ); |
963
|
|
|
} |
964
|
|
|
|
965
|
|
|
/** |
966
|
|
|
* Sets a subset of settings. |
967
|
|
|
* |
968
|
|
|
* @param array|string An array of settings to update, or string (key) and $value to update one setting. |
969
|
|
|
* @param mixed $value A value if $settings is string (key). Default: null. |
970
|
|
|
*/ |
971
|
3 |
|
public function set( $settings, $value = null ) { |
972
|
3 |
|
if ( is_string( $settings ) ) { |
973
|
2 |
|
$settings = array( $settings => $value ); |
974
|
|
|
} |
975
|
3 |
|
$settings = wp_parse_args( $settings, $this->all() ); |
976
|
3 |
|
return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings ); |
977
|
|
|
} |
978
|
|
|
|
979
|
|
|
/** |
980
|
|
|
* Updates settings. |
981
|
|
|
* |
982
|
|
|
* @param array $settings The settings array. |
983
|
|
|
* |
984
|
|
|
* @return boolean False if value was not updated and true if value was updated. |
985
|
|
|
*/ |
986
|
1 |
|
public function update( $settings ) { |
987
|
1 |
|
return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings ); |
988
|
|
|
} |
989
|
|
|
|
990
|
|
|
/** |
991
|
|
|
* Register the settings field for the EDD License field type |
992
|
|
|
* @param array $field |
993
|
|
|
* @param bool $echo Whether to echo the |
994
|
|
|
* |
995
|
|
|
* @return string |
996
|
|
|
*/ |
997
|
1 |
|
protected function settings_edd_license( $field, $echo = true ) { |
998
|
|
|
|
999
|
1 |
|
if ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ) { |
1000
|
|
|
$field['input_type'] = 'password'; |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
1 |
|
$text = $this->settings_text( $field, false ); |
1004
|
|
|
|
1005
|
1 |
|
$activation = $this->License_Handler->settings_edd_license_activation( $field, false ); |
1006
|
|
|
|
1007
|
1 |
|
$return = $text . $activation; |
1008
|
|
|
|
1009
|
1 |
|
if ( $echo ) { |
1010
|
1 |
|
echo $return; |
|
|
|
|
1011
|
|
|
} |
1012
|
|
|
|
1013
|
1 |
|
return $return; |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
/** |
1017
|
|
|
* Allow pure HTML settings row |
1018
|
|
|
* |
1019
|
|
|
* @since 2.0.6 |
1020
|
|
|
* |
1021
|
|
|
* @param array $field |
1022
|
|
|
* @param bool $echo Whether to echo the |
1023
|
|
|
* |
1024
|
|
|
* @return string |
1025
|
|
|
*/ |
1026
|
1 |
|
protected function settings_html( $field, $echo = true ) { |
1027
|
|
|
|
1028
|
1 |
|
$return = \GV\Utils::get( $field, 'value', '' ); |
1029
|
|
|
|
1030
|
1 |
|
if ( $echo ) { |
1031
|
1 |
|
echo $return; |
|
|
|
|
1032
|
|
|
} |
1033
|
|
|
|
1034
|
1 |
|
return $return; |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
/** |
1038
|
|
|
* No <th> needed for pure HTML settings row |
1039
|
|
|
* |
1040
|
|
|
* @since 2.0.6 |
1041
|
|
|
* |
1042
|
|
|
* @param array $field |
1043
|
|
|
* |
1044
|
|
|
* @return void |
1045
|
|
|
*/ |
1046
|
1 |
|
public function single_setting_row_html( $field ) { |
1047
|
|
|
?> |
1048
|
|
|
|
1049
|
|
|
<tr id="gaddon-setting-row-<?php echo esc_attr( $field['name'] ); ?>"> |
1050
|
|
|
<td colspan="2"> |
1051
|
|
|
<?php $this->single_setting( $field ); ?> |
1052
|
1 |
|
</td> |
1053
|
|
|
</tr> |
1054
|
|
|
|
1055
|
|
|
<?php |
1056
|
1 |
|
} |
1057
|
|
|
|
1058
|
|
|
/** |
1059
|
|
|
* Allow customizing the Save field parameters |
1060
|
|
|
* |
1061
|
|
|
* @param array $field |
1062
|
|
|
* @param bool $echo |
1063
|
|
|
* |
1064
|
|
|
* @return string |
1065
|
|
|
*/ |
1066
|
1 |
|
public function settings_save( $field, $echo = true ) { |
1067
|
1 |
|
$field['type'] = 'submit'; |
1068
|
1 |
|
$field['name'] = 'gform-settings-save'; |
1069
|
1 |
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; |
1070
|
1 |
|
$field['value'] = Utils::get( $field, 'value', __( 'Update Settings', 'gravityview' ) ); |
1071
|
|
|
|
1072
|
1 |
|
$output = $this->settings_submit( $field, false ); |
|
|
|
|
1073
|
|
|
|
1074
|
1 |
|
ob_start(); |
1075
|
1 |
|
$this->app_settings_uninstall_tab(); |
1076
|
1 |
|
$output .= ob_get_clean(); |
1077
|
|
|
|
1078
|
1 |
|
if ( $echo ) { |
1079
|
1 |
|
echo $output; |
|
|
|
|
1080
|
|
|
} |
1081
|
|
|
|
1082
|
1 |
|
return $output; |
1083
|
|
|
} |
1084
|
|
|
|
1085
|
|
|
/** |
1086
|
|
|
* Keep GravityView styling for `$field['description']`, even though Gravity Forms added support for it |
1087
|
|
|
* |
1088
|
|
|
* Converts `$field['description']` to `$field['gv_description']` |
1089
|
|
|
* Converts `$field['subtitle']` to `$field['description']` |
1090
|
|
|
* |
1091
|
|
|
* @see \GV\Addon_Settings::single_setting_label Converts `gv_description` back to `description` |
1092
|
|
|
* @see http://share.gravityview.co/P28uGp/2OIRKxog for image that shows subtitle vs description |
1093
|
|
|
* |
1094
|
|
|
* @since 1.21.5.2 |
1095
|
|
|
* |
1096
|
|
|
* @param array $field |
1097
|
|
|
* |
1098
|
|
|
* @return void |
1099
|
|
|
*/ |
1100
|
1 |
|
public function single_setting_row( $field ) { |
1101
|
1 |
|
$field['gv_description'] = Utils::get( $field, 'description' ); |
1102
|
1 |
|
$field['description'] = Utils::get( $field, 'subtitle' ); |
1103
|
1 |
|
parent::single_setting_row( $field ); |
1104
|
1 |
|
} |
1105
|
|
|
|
1106
|
|
|
/** |
1107
|
|
|
* The same as the parent, except added support for field descriptions |
1108
|
|
|
* @inheritDoc |
1109
|
|
|
* @param $field array |
1110
|
|
|
*/ |
1111
|
1 |
|
public function single_setting_label( $field ) { |
1112
|
1 |
|
parent::single_setting_label( $field ); |
1113
|
1 |
|
if ( $description = Utils::get( $field, 'gv_description' ) ) { |
1114
|
1 |
|
echo '<span class="description">'. $description .'</span>'; |
|
|
|
|
1115
|
|
|
} |
1116
|
1 |
|
} |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* Check for the `gravityview_edit_settings` capability before saving plugin settings. |
1120
|
|
|
* Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions. |
1121
|
|
|
* |
1122
|
|
|
* @since 1.15 |
1123
|
|
|
* @return void |
1124
|
|
|
*/ |
1125
|
1 |
|
public function maybe_save_app_settings() { |
1126
|
|
|
|
1127
|
1 |
|
if ( $this->is_save_postback() ) { |
1128
|
|
|
if ( ! \GVCommon::has_cap( 'gravityview_edit_settings' ) ) { |
1129
|
|
|
$_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't |
1130
|
|
|
\GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) ); |
1131
|
|
|
return; |
1132
|
|
|
} |
1133
|
|
|
} |
1134
|
1 |
|
parent::maybe_save_app_settings(); |
1135
|
1 |
|
} |
1136
|
|
|
|
1137
|
|
|
/** |
1138
|
|
|
* When the settings are saved, make sure the license key matches the previously activated key |
1139
|
|
|
* |
1140
|
|
|
* @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset |
1141
|
|
|
*/ |
1142
|
1 |
|
public function get_posted_settings() { |
1143
|
1 |
|
$posted_settings = parent::get_posted_settings(); |
1144
|
|
|
|
1145
|
1 |
|
$local_key = Utils::get( $posted_settings, 'license_key' ); |
1146
|
1 |
|
$response_key = Utils::get( $posted_settings, 'license_key_response/license_key' ); |
1147
|
|
|
|
1148
|
|
|
// If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response), |
1149
|
|
|
// then we assume it's changed. If it's changed, unset the status and the previous response. |
1150
|
1 |
|
if ( $local_key !== $response_key ) { |
1151
|
|
|
unset( $posted_settings['license_key_response'] ); |
1152
|
|
|
unset( $posted_settings['license_key_status'] ); |
1153
|
|
|
\GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
|
|
|
1154
|
|
|
} |
1155
|
1 |
|
return $posted_settings; |
1156
|
|
|
} |
1157
|
|
|
} |
1158
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.