Completed
Push — master ( 397f5b...27d97b )
by Zack
27:24 queued 14:56
created

Addon_Settings::single_setting_row_html()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 6.

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.

Loading history...
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>
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
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>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$i'
Loading history...
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(); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'gravityview_get_floaty'
Loading history...
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' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'make_clickable'
Loading history...
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() ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
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() ) . ' );"/>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
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();
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
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 '&nbsp;';
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 77
	public function get( $key, $default = null ) {
439
		/**
440
		 * Backward compatibility with Redux
441
		 */
442 77
		if ( $key === 'license' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
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 77
		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 ) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
Coding Style introduced by
The function name getSetting is in camel caps, but expected get_setting instead as per the coding standard.
Loading history...
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 77
	public function all() {
483 77
	    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 77
	private function defaults() {
503
		$defaults = array(
504
			// Set the default license in wp-config.php
505 77
			'license_key'          => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '',
506 77
			'license_key_response' => '',
507 77
			'license_key_status'   => '',
508 77
			'support-email'        => get_bloginfo( 'admin_email' ),
509 77
			'no-conflict-mode'     => '1',
510 77
			'support_port'         => '1',
511 77
			'flexbox_search'       => '1',
512 77
			'rest_api'             => '0',
513 77
			'beta'                 => '0',
514
		);
515
516
		/**
517
		 * @filter `gravityview/settings/default` Filter default global settings.
518
		 * @param[in,out] array The defaults.
519
		 */
520 77
		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';
0 ignored issues
show
introduced by
Expected 1 space between comma and "'reset'"; 0 found
Loading history...
introduced by
Expected 1 space between comma and "'button'"; 0 found
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
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;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$html'
Loading history...
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
577 1
	    if( $this->is_save_postback() ) {
578
		    $settings = $this->get_posted_settings();
579
		    $license_key = \GV\Utils::get( $settings, 'license_key' );
580
		    $license_status = \GV\Utils::get( $settings, 'license_key_status', 'inactive' );
581
        } else {
582 1
		    $license_status = $this->get( 'license_key_status', 'inactive' );
583 1
		    $license_key    = $this->get( 'license_key' );
584
	    }
585
586 1
	    $license_id = empty( $license_key ) ? 'license' : $license_key;
587
588 1
		$message = esc_html__( 'Your GravityView license %s. This means you&rsquo;re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview' );
589
590
		/**
591
		 * I wanted to remove the period from after the buttons in the string,
592
		 * but didn't want to mess up the translation strings for the translators.
593
		 */
594 1
		$message = mb_substr( $message, 0, mb_strlen( $message ) - 1 );
595 1
		$title = __ ( 'Inactive License', 'gravityview');
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
596 1
		$status = '';
597 1
		$update_below = false;
598 1
		$primary_button_link = admin_url( 'edit.php?post_type=gravityview&amp;page=gravityview_settings' );
599
600 1
        switch ( $license_status ) {
601
			/** @since 1.17 */
602 1
			case 'expired':
603
				$title = __( 'Expired License', 'gravityview' );
604
				$status = 'expired';
605
				$message = $this->get_license_handler()->strings( 'expired', $this->get( 'license_key_response' ) );
606
				break;
607 1
			case 'invalid':
608
				$title = __( 'Invalid License', 'gravityview' );
609
				$status = __( 'is invalid', 'gravityview' );
610
				break;
611 1
			case 'deactivated':
612
				$status = __( 'is inactive', 'gravityview' );
613
				$update_below = __( 'Activate your license key below.', 'gravityview' );
614
				break;
615
			/** @noinspection PhpMissingBreakStatementInspection */
616 1
			case '':
617 1
				$license_status = 'site_inactive';
618
				// break intentionally left blank
619
			case 'inactive':
620
			case 'site_inactive':
621 1
				$status = __( 'has not been activated', 'gravityview' );
622 1
				$update_below = __( 'Activate your license key below.', 'gravityview' );
623 1
				break;
624
		}
625 1
		$url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice';
626
627
		// Show a different notice on settings page for inactive licenses (hide the buttons)
628 1
		if ( $update_below && gravityview_is_admin_page( '', 'settings' ) ) {
0 ignored issues
show
Deprecated Code introduced by
The function gravityview_is_admin_page() has been deprecated with message: See `gravityview()->request->is_admin` or `\GV\Request::is_admin`

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
629
			$message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' );
630
		} else {
631 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>' );
632
		}
633
634 1
		if ( ! empty( $status ) ) {
635 1
			\GravityView_Admin_Notices::add_notice( array(
636 1
				'message' => $message,
637 1
				'class'   => 'updated',
638 1
				'title'   => $title,
639 1
				'cap'     => 'gravityview_edit_settings',
640 1
				'dismiss' => sha1( $license_status . '_' . $license_id . '_' . date( 'z' ) ), // Show every day, instead of every 8 weeks (which is the default)
641
			) );
642
		}
643 1
	}
644
645
	/**
646
	 * Allow public access to the GV\License_Handler class
647
	 * @since 1.7.4
648
	 *
649
	 * @return \GV\License_Handler
650
	 */
651 1
	public function get_license_handler() {
652 1
		return $this->License_Handler;
653
	}
654
655
	/**
656
     * Add tooltip script to app settings page. Not enqueued by Gravity Forms for some reason.
657
     *
658
     * @since 1.21.5
659
     *
660
     * @see GFAddOn::scripts()
661
     *
662
	 * @return array Array of scripts
663
	 */
664 4
	public function scripts() {
665 4
		$scripts = parent::scripts();
666
667 4
		$scripts[] = array(
668
			'handle'  => 'gform_tooltip_init',
669
			'enqueue' => array(
670
                array(
671
			        'admin_page' => array( 'app_settings' )
672
                )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
673
            )
674
		);
675
676 4
		return $scripts;
677
	}
678
679
	/**
680
	 * Register styles in the app admin page
681
	 * @return array
682
	 */
683 4
	public function styles() {
684 4
		$styles = parent::styles();
685
686 4
		$styles[] = array(
687 4
			'handle'  => 'gravityview_settings',
688 4
			'src'     => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ),
689 4
			'version' => Plugin::$version,
690
			'deps' => array(
691
                'gform_admin',
692
				'gaddon_form_settings_css',
693
                'gform_tooltip',
694
                'gform_font_awesome',
695
			),
696
			'enqueue' => array(
697
				array( 'admin_page' => array(
0 ignored issues
show
introduced by
The first index in a multi-value array must be on a new line
Loading history...
introduced by
The first value in a multi-value array must be on a new line
Loading history...
698
					'app_settings',
699
				) ),
700
			)
701
		);
702
703 4
		return $styles;
704
	}
705
706
	/**
707
	 * Add Settings link to GravityView menu
708
	 * @return void
709
	 */
710 1
	public function create_app_menu() {
711
		/**
712
		 * If not multisite, always show.
713
		 * If multisite and the plugin is network activated, show; we need to register the submenu page for the Network Admin settings to work.
714
		 * If multisite and not network admin, we don't want the settings to show.
715
		 * @since 1.7.6
716
		 */
717 1
		$show_submenu = ( ! is_multisite() ) ||  is_main_site() || ( ! gravityview()->plugin->is_network_activated() ) || ( is_network_admin() && gravityview()->plugin->is_network_activated() );
718
719
		/**
720
		 * Override whether to show the Settings menu on a per-blog basis.
721
		 * @since 1.7.6
722
		 * @param bool $hide_if_network_activated Default: true
723
		 */
724 1
		$show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu );
725
726 1
		if ( $show_submenu ) {
727 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' ) );
728
		}
729 1
	}
730
731
	/**
732
	 * Gets the required indicator
733
	 * Gets the markup of the required indicator symbol to highlight fields that are required
734
	 *
735
	 * @param $field - The field meta.
736
	 *
737
	 * @return string - Returns markup of the required indicator symbol
738
	 */
739 1
	public function get_required_indicator( $field ) {
740 1
		return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>';
741
	}
742
743
	/**
744
	 * Specify the settings fields to be rendered on the plugin settings page
745
	 *
746
	 * @return array
747
	 */
748 1
	public function app_settings_fields() {
749 1
		$default_settings = $this->defaults();
750
751 1
		$disabled_attribute = \GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
752
753
		$fields = array(
754
			array(
755 1
				'name' => 'gv_header',
756
				'value' => '',
757
				'type' => 'html',
758
			),
759
			array(
760 1
				'name' => 'license_key',
761
				'required' => true,
762 1
				'label' => __( 'License Key', 'gravityview' ),
763 1
				'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates &amp; support.', 'gravityview' ) . $this->get_license_handler()->license_details( $this->get_app_setting( 'license_key_response' ) ),
0 ignored issues
show
Deprecated Code introduced by
The method GV\Addon_Settings::get_app_setting() has been deprecated with message: Use \GV\Addon_Settings::get

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
764 1
				'type' => 'edd_license',
765 1
				'disabled' => ( defined( 'GRAVITYVIEW_LICENSE_KEY' )  && GRAVITYVIEW_LICENSE_KEY ),
766 1
				'data-pending-text' => __( 'Verifying license&hellip;', 'gravityview' ),
767 1
				'default_value' => $default_settings['license_key'],
768 1
				'class' => ( '' == $this->get( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key',
769
			),
770
			array(
771 1
				'name' => 'license_key_response',
772 1
				'default_value' => $default_settings['license_key_response'],
773 1
				'type' => 'hidden',
774
			),
775
			array(
776 1
				'name' => 'license_key_status',
777 1
				'default_value' => $default_settings['license_key_status'],
778 1
				'type' => 'hidden',
779
			),
780
			array(
781 1
				'name' => 'support-email',
782 1
				'type' => 'text',
783 1
				'validate' => 'email',
784 1
				'default_value' => $default_settings['support-email'],
785 1
				'label' => __( 'Support Email', 'gravityview' ),
786 1
				'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ),
787 1
				'class' => 'code regular-text',
788
			),
789
			/**
790
			 * @since 1.15 Added Support Port support
791
			 */
792
			array(
793 1
				'name' => 'support_port',
794 1
				'type' => 'radio',
795 1
				'label' => __( 'Show Support Port?', 'gravityview' ),
796 1
				'default_value' => $default_settings['support_port'],
797 1
				'horizontal' => 1,
798
				'choices' => array(
799
					array(
800 1
						'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ),
801 1
						'value' => '1',
802
					),
803
					array(
804 1
						'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ),
805 1
						'value' => '0',
806
					),
807
				),
808 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>',
809 1
				'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ),
810
			),
811
			array(
812 1
				'name' => 'no-conflict-mode',
813 1
				'type' => 'radio',
814 1
				'label' => __( 'No-Conflict Mode', 'gravityview' ),
815 1
				'default_value' => $default_settings['no-conflict-mode'],
816 1
				'horizontal' => 1,
817
				'choices' => array(
818
					array(
819 1
						'label' => _x( 'On', 'Setting: On or off', 'gravityview' ),
820 1
						'value' => '1',
821
					),
822
					array(
823 1
						'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ),
824 1
						'value' => '0',
825
					),
826
				),
827 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' ),
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
828
			),
829
			/**
830
			 * @since 2.0 Added REST API
831
			 */
832 1
			gravityview()->plugin->supports( Plugin::FEATURE_REST ) ?
833
				array(
834 1
					'name' => 'rest_api',
835 1
					'type' => 'radio',
836 1
					'label' => __( 'REST API', 'gravityview' ),
837 1
					'default_value' => $default_settings['rest_api'],
838 1
					'horizontal' => 1,
839
					'choices' => array(
840
						array(
841 1
							'label' => _x( 'Enable', 'Setting: Enable or Disable', 'gravityview' ),
842 1
							'value' => '1',
843
						),
844
						array(
845 1
							'label' => _x( 'Disable', 'Setting: Enable or Disable', 'gravityview' ),
846 1
							'value' => '0',
847
						),
848
					),
849 1
					'description' => __( 'Enable View and Entry access via the REST API? Regular per-View restrictions apply (private, password protected, etc.).', 'gravityview' ),
850 1
					'tooltip' => '<p>' . esc_html__( 'If you are unsure, choose the Disable setting.', 'gravityview' ) . '</p>',
851
				) : array(),
852
			array(
853 1
				'name' => 'beta',
854 1
				'type' => 'checkbox',
855 1
				'label' => __( 'Become a Beta Tester', 'gravityview' ),
856 1
				'default_value' => $default_settings['beta'],
857 1
				'horizontal' => 1,
858
				'choices' => array(
859
					array(
860 1
						'label' => _x( 'Show me beta versions if they are available.', 'gravityview' ),
861 1
						'value' => '1',
862 1
                        'name'  => 'beta',
863
					),
864
				),
865 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' ),
866
			),
867
		);
868
869 1
		$fields = array_filter( $fields, 'count' );
870
871
		/**
872
		 * @filter `gravityview_settings_fields` Filter the settings fields.
873
		 * @param array $fields The fields to filter.
874
		 * @deprecated Use `gravityview/settings/fields`.
875
		 */
876 1
		$fields = apply_filters( 'gravityview_settings_fields', $fields );
877
878
		/**
879
		 * @filter `gravityview/settings/fields` Filter the settings fields.
880
		 * @param array $fields The fields to filter.
881
		 */
882 1
		$fields = apply_filters( 'gravityview/settings/fields', $fields );
883
884
		/**
885
		 * Redux backward compatibility
886
		 * @since 1.7.4
887
		 */
888 1
		foreach ( $fields as &$field ) {
889 1
			$field['name']          = isset( $field['name'] ) ? $field['name'] : Utils::get( $field, 'id' );
890 1
			$field['label']         = isset( $field['label'] ) ? $field['label'] : Utils::get( $field, 'title' );
891 1
			$field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : Utils::get( $field, 'default' );
892 1
			$field['description']   = isset( $field['description'] ) ? $field['description'] : Utils::get( $field, 'subtitle' );
893
894 1
			if ( $disabled_attribute ) {
895
				$field['disabled']  = $disabled_attribute;
896
			}
897
898 1
			if ( empty( $field['disabled'] ) ) {
899 1
				unset( $field['disabled'] );
900
            }
901
		}
902
903
        $sections = array(
904
            array(
905 1
                'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), Plugin::$version ) ),
906 1
                'fields'      => $fields,
907
            )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
908
        );
909
910
        // custom 'update settings' button
911
        $button = array(
912 1
            'class' => 'button button-primary button-hero',
913
            'type' => 'save',
914
        );
915
916 1
		if ( $disabled_attribute ) {
917
			$button['disabled'] = $disabled_attribute;
918
		}
919
920
        /**
921
         * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page
922
         * Extensions can tap in here to insert their own section and settings.
923
         * <code>
924
         *   $sections[] = array(
925
         *      'title' => __( 'GravityView My Extension Settings', 'gravityview' ),
926
         *      'fields' => $settings,
927
         *   );
928
         * </code>
929
         * @param array $extension_settings Empty array, ready for extension settings!
930
         */
931 1
        $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() );
932
933
		// If there are extensions, add a section for them
934 1
		if ( ! empty( $extension_sections ) ) {
935
936
			if( $disabled_attribute ) {
937
				foreach ( $extension_sections as &$section ) {
938
					foreach ( $section['fields'] as &$field ) {
939
						$field['disabled'] = $disabled_attribute;
940
					}
941
				}
942
			}
943
944
            $k = count( $extension_sections ) - 1 ;
945
            $extension_sections[ $k ]['fields'][] = $button;
946
			$sections = array_merge( $sections, $extension_sections );
947
		} else {
948
            // add the 'update settings' button to the general section
949 1
            $sections[0]['fields'][] = $button;
950
        }
951
952 1
		return $sections;
953
	}
954
955
	/**
956
	 * Updates app settings with the provided settings
957
	 *
958
	 * Same as the GFAddon, except it returns the value from update_option()
959
	 *
960
	 * @param array $settings - App settings to be saved
961
	 *
962
	 * @deprecated Use \GV\Addon_Settings::set or \GV\Addon_Settings::update
963
	 *
964
	 * @return boolean False if value was not updated and true if value was updated.
965
	 */
966
	public function update_app_settings( $settings ) {
967
		return $this->update( $settings );
968
	}
969
970
	/**
971
	 * Sets a subset of settings.
972
	 *
973
	 * @param array|string An array of settings to update, or string (key) and $value to update one setting.
974
	 * @param mixed $value A value if $settings is string (key). Default: null.
975
	 */
976 4
	public function set( $settings, $value = null ) {
977 4
		if ( is_string( $settings ) ) {
978 2
			$settings = array( $settings => $value );
979
		}
980 4
		$settings = wp_parse_args( $settings, $this->all() );
981 4
		return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
982
	}
983
984
	/**
985
	 * Updates settings.
986
	 *
987
	 * @param array $settings The settings array.
988
	 *
989
	 * @return boolean False if value was not updated and true if value was updated.
990
	 */
991 1
	public function update( $settings ) {
992 1
		return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
993
	}
994
995
	/**
996
	 * Register the settings field for the EDD License field type
997
	 * @param array $field
998
	 * @param bool $echo Whether to echo the
999
	 *
1000
	 * @return string
1001
	 */
1002 1
	protected function settings_edd_license( $field, $echo = true ) {
1003
1004 1
	    if ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ) {
1005
		    $field['input_type'] = 'password';
1006
        }
1007
1008 1
		$text = $this->settings_text( $field, false );
1009
1010 1
		$activation = $this->License_Handler->settings_edd_license_activation( $field, false );
1011
1012 1
		$return = $text . $activation;
1013
1014 1
		if ( $echo ) {
1015 1
			echo $return;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$return'
Loading history...
1016
		}
1017
1018 1
		return $return;
1019
	}
1020
1021
	/**
1022
	 * Allow pure HTML settings row
1023
     *
1024
     * @since 2.0.6
1025
     *
1026
	 * @param array $field
1027
	 * @param bool $echo Whether to echo the
1028
	 *
1029
	 * @return string
1030
	 */
1031 1
	protected function settings_html( $field, $echo = true ) {
1032
1033 1
		$return = \GV\Utils::get( $field, 'value', '' );
1034
1035 1
		if ( $echo ) {
1036 1
			echo $return;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$return'
Loading history...
1037
		}
1038
1039 1
		return $return;
1040
	}
1041
1042
	/**
1043
	 * No <th> needed for pure HTML settings row
1044
	 *
1045
	 * @since 2.0.6
1046
	 *
1047
	 * @param array $field
1048
	 *
1049
	 * @return void
1050
	 */
1051 1
	public function single_setting_row_html( $field ) {
1052
		?>
1053
1054
        <tr id="gaddon-setting-row-<?php echo esc_attr( $field['name'] ); ?>">
1055
            <td colspan="2">
1056
				<?php $this->single_setting( $field ); ?>
1057 1
            </td>
1058
        </tr>
1059
1060
		<?php
1061 1
	}
1062
1063
	/**
1064
	 * Allow customizing the Save field parameters
1065
	 *
1066
	 * @param array $field
1067
	 * @param bool $echo
1068
	 *
1069
	 * @return string
1070
	 */
1071 1
	public function settings_save( $field, $echo = true ) {
1072 1
		$field['type']  = 'submit';
1073 1
		$field['name']  = 'gform-settings-save';
1074 1
		$field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton';
1075 1
		$field['value'] = Utils::get( $field, 'value', __( 'Update Settings', 'gravityview' ) );
1076
1077 1
		$output = $this->settings_submit( $field, false );
0 ignored issues
show
Deprecated Code introduced by
The method GV\Addon_Settings::settings_submit() has been deprecated with message: Use \GV\Addon_Settings::as_html

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1078
1079 1
		ob_start();
1080 1
		$this->app_settings_uninstall_tab();
1081 1
		$output .= ob_get_clean();
1082
1083 1
		if ( $echo ) {
1084 1
			echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
1085
		}
1086
1087 1
		return $output;
1088
	}
1089
1090
	/**
1091
     * Keep GravityView styling for `$field['description']`, even though Gravity Forms added support for it
1092
     *
1093
     * Converts `$field['description']` to `$field['gv_description']`
1094
     * Converts `$field['subtitle']` to `$field['description']`
1095
     *
1096
     * @see \GV\Addon_Settings::single_setting_label Converts `gv_description` back to `description`
1097
     * @see http://share.gravityview.co/P28uGp/2OIRKxog for image that shows subtitle vs description
1098
     *
1099
     * @since 1.21.5.2
1100
     *
1101
	 * @param array $field
1102
     *
1103
     * @return void
1104
	 */
1105 1
	public function single_setting_row( $field ) {
1106 1
		$field['gv_description'] = Utils::get( $field, 'description' );
1107 1
		$field['description']    = Utils::get( $field, 'subtitle' );
1108 1
		parent::single_setting_row( $field );
1109 1
	}
1110
1111
	/**
1112
	 * The same as the parent, except added support for field descriptions
1113
	 * @inheritDoc
1114
	 * @param $field array
1115
	 */
1116 1
	public function single_setting_label( $field ) {
1117 1
		parent::single_setting_label( $field );
1118 1
		if ( $description = Utils::get( $field, 'gv_description' ) ) {
1119 1
			echo '<span class="description">'. $description .'</span>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
1120
		}
1121 1
	}
1122
1123
	/**
1124
	 * Check for the `gravityview_edit_settings` capability before saving plugin settings.
1125
	 * Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions.
1126
	 *
1127
	 * @since 1.15
1128
	 * @return void
1129
	 */
1130 1
	public function maybe_save_app_settings() {
1131
1132 1
		if ( $this->is_save_postback() ) {
1133
			if ( ! \GVCommon::has_cap( 'gravityview_edit_settings' ) ) {
1134
				$_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't
1135
				\GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) );
1136
				return;
1137
			}
1138
		}
1139 1
		parent::maybe_save_app_settings();
1140 1
	}
1141
1142
	/**
1143
	 * When the settings are saved, make sure the license key matches the previously activated key
1144
	 *
1145
	 * @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset
1146
	 */
1147 1
	public function get_posted_settings() {
1148 1
		$posted_settings = parent::get_posted_settings();
1149
1150 1
		$local_key = Utils::get( $posted_settings, 'license_key' );
1151 1
		$response_key = Utils::get( $posted_settings, 'license_key_response/license_key' );
1152
1153
		// If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response),
1154
		// then we assume it's changed. If it's changed, unset the status and the previous response.
1155 1
		if ( $local_key !== $response_key ) {
1156
			unset( $posted_settings['license_key_response'] );
1157
			unset( $posted_settings['license_key_status'] );
1158
			\GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
1159
		}
1160 1
		return $posted_settings;
1161
	}
1162
}
1163