Completed
Push — master ( 589d3f...c5163f )
by Zack
12:27 queued 08:09
created

GravityView_Settings::scripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 14
ccs 4
cts 4
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 11 and the first side effect is on line 4.

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
3
if( ! class_exists('GFAddOn') ) {
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...
4
	return;
5
}
6
7
/**
8
 * GravityView Settings class (get/set/license validation) using the Gravity Forms App framework
9
 * @since 1.7.4 (Before, used the Redux Framework)
10
 */
11
class GravityView_Settings extends GFAddOn {
12
13
	/**
14
	 * @var string Version number of the Add-On
15
	 */
16
	protected $_version = GravityView_Plugin::version;
17
	/**
18
	 * @var string Gravity Forms minimum version requirement
19
	 */
20
	protected $_min_gravityforms_version = GV_MIN_GF_VERSION;
21
22
	/**
23
	 * @var string Title of the plugin to be used on the settings page, form settings and plugins page. Example: 'Gravity Forms MailChimp Add-On'
24
	 */
25
	protected $_title = 'GravityView';
26
27
	/**
28
	 * @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'
29
	 */
30
	protected  $_short_title = 'GravityView';
31
32
	/**
33
	 * @var string URL-friendly identifier used for form settings, add-on settings, text domain localization...
34
	 */
35
	protected $_slug = 'gravityview';
36
37
	/**
38
	 * @var string|array A string or an array of capabilities or roles that can uninstall the plugin
39
	 */
40
	protected $_capabilities_uninstall = 'gravityview_uninstall';
41
42
	/**
43
	 * @var string|array A string or an array of capabilities or roles that have access to the settings page
44
	 */
45
	protected $_capabilities_app_settings = 'gravityview_view_settings';
46
47
	/**
48
	 * @var string|array A string or an array of capabilities or roles that have access to the settings page
49
	 */
50
	protected $_capabilities_app_menu = 'gravityview_view_settings';
51
52
	/**
53
	 * @var string The hook suffix for the app menu
54
	 */
55
	public  $app_hook_suffix = 'gravityview';
56
57
	/**
58
	 * @var GV_License_Handler Process license validation
59
	 */
60
	private $License_Handler;
61
62
	/**
63
	 * @var GravityView_Settings
64
	 */
65
	private static $instance;
66
67
	/**
68
	 * We're not able to set the __construct() method to private because we're extending the GFAddon class, so
69
	 * we fake it. When called using `new GravityView_Settings`, it will return get_instance() instead. We pass
70
	 * 'get_instance' as a test string.
71
	 *
72
	 * @see get_instance()
73
	 *
74
	 * @param string $prevent_multiple_instances
75
	 */
76
	public function __construct( $prevent_multiple_instances = '' ) {
77
78
		if( $prevent_multiple_instances === 'get_instance' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
79
			return parent::__construct();
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
80
		}
81
82
		return self::get_instance();
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
83
	}
84
85
	/**
86
	 * @return GravityView_Settings
87
	 */
88
	public static function get_instance() {
89
90
		if( empty( self::$instance ) ) {
91
			self::$instance = new self( 'get_instance' );
92
		}
93
94
		return self::$instance;
95
	}
96
97
	/**
98
	 * Prevent uninstall tab from being shown by returning false for the uninstall capability check. Otherwise:
99
	 * @inheritDoc
100
	 *
101
	 * @hack
102
	 *
103
	 * @param array|string $caps
104
	 *
105
	 * @return bool
106
	 */
107
	public function current_user_can_any( $caps ) {
108
109
		if( empty( $caps ) ) {
110
			$caps = array( 'gravityview_full_access' );
111
		}
112
113
		return GVCommon::has_cap( $caps );
114
	}
115
116
	public function uninstall_warning_message() {
117
118
		$heading = esc_html__( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' );
119
		$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' );
120
121
		return sprintf( '<h4>%s</h4><p>%s</p>', $heading, $message );
122
	}
123
124
	/**
125
     * Uninstall all traces of GravityView
126
     *
127
     * Note: method is public because parent method is public
128
     *
129
	 * @return bool
130
	 */
131 1
	public function uninstall() {
132
133 1
		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-uninstall.php' );
134
135 1
		$uninstaller = new GravityView_Uninstall();
136
137 1
		$uninstaller->fire_everything();
138
139
		/**
140
         * Set the path so that Gravity Forms can de-activate GravityView
141
         * @see GFAddOn::uninstall_addon
142
         * @uses deactivate_plugins()
143
         */
144 1
		$this->_path = GRAVITYVIEW_FILE;
145
146 1
		return true;
147
	}
148
149
	/**
150
     * Get an array of reasons why the plugin might be uninstalled
151
     *
152
     * @since 1.17.5
153
     *
154
	 * @return array Array of reasons with the label and followup questions for each uninstall reason
155
	 */
156
	private function get_uninstall_reasons() {
157
158
		$reasons = array(
159
			'will-continue' => array(
160
                'label' => esc_html__( 'I am going to continue using GravityView', 'gravityview' ),
161
            ),
162
			'no-longer-need' => array(
163
                'label' => esc_html__( 'I no longer need GravityView', 'gravityview' ),
164
            ),
165
			'doesnt-work' => array(
166
                'label' => esc_html__( 'The plugin doesn\'t work', 'gravityview' ),
167
            ),
168
			'found-other' => array(
169
                'label' => esc_html__( 'I found a better plugin', 'gravityview' ),
170
                'followup' => esc_attr__('What plugin you are using, and why?', 'gravityview'),
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...
171
            ),
172
			'other' => array(
173
                'label' => esc_html__( 'Other', 'gravityview' ),
174
            ),
175
		);
176
177
		shuffle( $reasons );
178
179
		return $reasons;
180
    }
181
182
	/**
183
     * Display a feedback form when the plugin is uninstalled
184
     *
185
     * @since 1.17.5
186
     *
187
	 * @return string HTML of the uninstallation form
188
	 */
189
	public function uninstall_form() {
190
		ob_start();
191
192
		$user = wp_get_current_user();
193
		?>
194
    <style>
195
        #gv-reason-details {
196
            min-height: 100px;
197
        }
198
        .number-scale label {
199
            border: 1px solid #cccccc;
200
            padding: .5em .75em;
201
            margin: .1em;
202
        }
203
        #gv-uninstall-thanks p {
204
            font-size: 1.2em;
205
        }
206
        .scale-description ul {
207
            margin-bottom: 0;
208
            padding-bottom: 0;
209
        }
210
        .scale-description p.description {
211
            margin-top: 0!important;
212
            padding-top: 0!important;
213
        }
214
        .gv-form-field-wrapper {
215
            margin-top: 30px;
216
        }
217
    </style>
218
219
    <div class="gv-uninstall-form-wrapper" style="font-size: 110%; padding: 15px 0;">
220
        <script>
221
            jQuery(function( $ ) {
222
                $('#gv-uninstall-feedback').on( 'change', function( e ) {
223
224
                    if( ! $( e.target ).is(':input') ) {
225
                        return;
226
                    }
227
                    var $textarea = $('.gv-followup').find('textarea');
228
                    var followup_text = $( e.target ).attr( 'data-followup' );
229
                    if( ! followup_text ) {
230
                        followup_text = $textarea.attr('data-default');
231
                    }
232
233
                    $textarea.attr( 'placeholder', followup_text );
234
235
                }).on( 'submit', function( e ) {
236
                    e.preventDefault();
237
238
                    $.post( $( this ).attr( 'action' ), $( this ).serialize() )
239
                        .done( function( data ) {
240
                            if( 'success' !== data.status ) {
241
                                gv_feedback_append_error_message();
242
                            } else {
243
                                $( '#gv-uninstall-thanks' ).fadeIn();
244
                            }
245
                        })
246
                        .fail( function( data ) {
247
                            gv_feedback_append_error_message();
248
                        })
249
                        .always( function() {
250
                            $( e.target ).remove();
251
                        });
252
253
                    return false;
254
                });
255
256
                function gv_feedback_append_error_message() {
257
                    $('#gv-uninstall-thanks').append('<div class="notice error"><?php echo esc_js( __('There was an error sharing your feedback. Sorry! Please email us at [email protected]', 'gravityview' ) ) ?></div>');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
258
                }
259
            });
260
        </script>
261
262
        <form id="gv-uninstall-feedback" method="post" action="https://hooks.zapier.com/hooks/catch/28670/6haevn/">
263
            <h2><?php esc_html_e( 'Why did you uninstall GravityView?', 'gravityview' ); ?></h2>
264
            <ul>
265
				<?php
266
                $reasons = $this->get_uninstall_reasons();
267
				foreach ( $reasons as $reason ) {
268
					printf( '<li><label><input name="reason" type="radio" value="other" data-followup="%s"> %s</label></li>', rgar( $reason, 'followup' ), rgar( $reason, 'label' ) );
269
				}
270
				?>
271
            </ul>
272
            <div class="gv-followup widefat">
273
                <p><strong><label for="gv-reason-details"><?php esc_html_e( 'Comments', 'gravityview' ); ?></label></strong></p>
274
                <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...
275
            </div>
276
            <div class="scale-description">
277
                <p><strong><?php esc_html_e('How likely are you to recommend GravityView?', 'gravityview' ); ?></strong></p>
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
278
                <ul class="inline">
279
					<?php
280
					$i = 0;
281
					while( $i < 11 ) {
282
						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...
283
						$i++;
284
					}
285
					?>
286
                </ul>
287
                <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>
288
            </div>
289
290
            <div class="gv-form-field-wrapper">
291
                <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>
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...
292
            </div>
293
294
            <div class="submit">
295
                <input type="hidden" name="siteurl" value="<?php echo esc_url( get_bloginfo( 'url' ) ); ?>" />
296
                <input type="hidden" name="email" value="<?php echo esc_attr( $user->user_email ); ?>" />
297
                <input type="hidden" name="display_name" value="<?php echo esc_attr( $user->display_name ); ?>" />
298
                <input type="submit" value="<?php esc_html_e( 'Send Us Your Feedback', 'gravityview' ); ?>" class="button button-primary button-hero" />
299
            </div>
300
        </form>
301
302
        <div id="gv-uninstall-thanks" class="notice notice-large notice-updated below-h2" style="display:none;">
303
            <h3 class="notice-title"><?php esc_html_e( 'Thank you for using GravityView!', 'gravityview' ); ?></h3>
304
            <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...
305
				<?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...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
306
            </p>
307
            <div class="wp-clearfix"></div>
308
        </div>
309
    </div>
310
		<?php
311
		$form = ob_get_clean();
312
313
		return $form;
314
	}
315
316
317
	public function app_settings_uninstall_tab() {
318
319
		if ( $this->maybe_uninstall() ) {
320
321
			parent::app_settings_uninstall_tab();
322
323
			return;
324
		}
325
326
		if ( ! ( $this->current_user_can_any( $this->_capabilities_uninstall ) && ( ! function_exists( 'is_multisite' ) || ! is_multisite() || is_super_admin() ) ) ) {
327
			return;
328
		}
329
330
		?>
331
		<script>
332
			jQuery(document).on('click', 'a[rel="gv-uninstall-wrapper"]', function( e ) {
333
				e.preventDefault();
334
				jQuery( '#gv-uninstall-wrapper' ).slideToggle();
335
			});
336
		</script>
337
338
		<a rel="gv-uninstall-wrapper" href="#gv-uninstall-wrapper" class="button button-large alignright button-danger">Uninstall GravityView</a>
339
340
		<div id="gv-uninstall-wrapper">
341
			<form action="" method="post">
342
				<?php wp_nonce_field( 'uninstall', 'gf_addon_uninstall' ) ?>
343
				<div class="delete-alert alert_red">
344
345
					<h3>
346
						<i class="fa fa-exclamation-triangle gf_invalid"></i> <?php esc_html_e( 'Delete all GravityView content and settings', 'gravityview' ); ?>
347
					</h3>
348
349
					<div class="gf_delete_notice">
350
						<?php echo $this->uninstall_warning_message() ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
351
					</div>
352
353
					<?php
354
					echo '<input type="submit" name="uninstall" value="' . sprintf( esc_attr__( 'Uninstall %s', 'gravityview' ), $this->get_short_title() ) . '" class="button button-hero" onclick="return confirm(\'' . esc_js( $this->uninstall_confirm_message() ) . '\');" onkeypress="return confirm(\'' . esc_js( $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...
355
					?>
356
357
				</div>
358
			</form>
359
		</div>
360
	<?php
361
	}
362
363
	/**
364
	 * Run actions when initializing admin
365
	 *
366
	 * Triggers the license key notice
367
	 *
368
	 * @return void
369
	 */
370
	function init_admin() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
371
372
		$this->_load_license_handler();
373
374
		$this->license_key_notice();
375
376
		add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) );
377
378
		/** @since 1.7.6 */
379
		add_action('network_admin_menu', array( $this, 'add_network_menu' ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
380
381
		parent::init_admin();
382
	}
383
384
	/**
385
	 * Change the settings page header title to "GravityView"
386
	 *
387
	 * @param $setting_tabs
388
	 *
389
	 * @return array
390
	 */
391
	public function modify_app_settings_menu_title( $setting_tabs ) {
392
393
		$setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
394
395
		return $setting_tabs;
396
	}
397
398
	/**
399
	 * Load license handler in admin-ajax.php
400
	 */
401
	public function init_ajax() {
402
		$this->_load_license_handler();
403
	}
404
405
	/**
406
	 * Make sure the license handler is available
407
	 */
408
	private function _load_license_handler() {
409
410
		if( !empty( $this->License_Handler ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
411
			return;
412
		}
413
414
		require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
415
416
		$this->License_Handler = GV_License_Handler::get_instance( $this );
417
	}
418
419
	/**
420
	 * Display a notice if the plugin is inactive.
421
	 * @return void
422
	 */
423
	function license_key_notice() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
424
425
		// Only show on GravityView pages
426
		if( ! gravityview_is_admin_page() ) {
427
			return;
428
		}
429
430
		$license_status = self::getSetting('license_key_status');
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...
431
		$license_key = self::getSetting('license_key');
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...
432
		if( '' === $license_key ) {
433
			$license_status = 'inactive';
434
        }
435
		$license_id = empty( $license_key ) ? 'license' : $license_key;
436
437
		$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');
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...
438
439
		/**
440
		 * I wanted to remove the period from after the buttons in the string,
441
		 * but didn't want to mess up the translation strings for the translators.
442
		 */
443
		$message = mb_substr( $message, 0, mb_strlen( $message ) - 1 );
444
		$title = __('Inactive License', 'gravityview');
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...
445
		$status = '';
446
		$update_below = false;
447
		$primary_button_link = admin_url( 'edit.php?post_type=gravityview&amp;page=gravityview_settings' );
448
		switch ( $license_status ) {
449
			/** @since 1.17 */
450
			case 'expired':
451
				$title = __('Expired License', 'gravityview');
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...
452
				$status = 'expired';
453
				$message = $this->get_license_handler()->strings( 'expired', self::getSetting('license_key_response') );
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...
454
				break;
455
			case 'invalid':
456
				$title = __('Invalid License', 'gravityview');
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...
457
				$status = __('is invalid', 'gravityview');
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...
458
				break;
459
			case 'deactivated':
460
				$status = __('is inactive', 'gravityview');
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...
461
				$update_below = __('Activate your license key below.', 'gravityview');
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...
462
				break;
463
			/** @noinspection PhpMissingBreakStatementInspection */
464
			case '':
465
				$license_status = 'site_inactive';
466
				// break intentionally left blank
467
			case 'inactive':
468
			case 'site_inactive':
469
				$status = __('has not been activated', 'gravityview');
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...
470
				$update_below = __('Activate your license key below.', 'gravityview');
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...
471
				break;
472
		}
473
		$url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice';
474
475
		// Show a different notice on settings page for inactive licenses (hide the buttons)
476
		if( $update_below && gravityview_is_admin_page( '', 'settings' ) ) {
477
			$message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' );
478
		} else {
479
			$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>' );
480
		}
481
482
		if( !empty( $status ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
483
			GravityView_Admin_Notices::add_notice( array(
484
				'message' => $message,
485
				'class'	=> 'updated',
486
				'title' => $title,
487
				'cap' => 'gravityview_edit_settings',
488
				'dismiss' => sha1( $license_status.'_'.$license_id ),
489
			));
490
		}
491
	}
492
493
	/**
494
     * Add tooltip script to app settings page. Not enqueued by Gravity Forms for some reason.
495
     *
496
     * @since 1.21.5
497
     *
498
     * @see GFAddOn::scripts()
499
     *
500
	 * @return array Array of scripts
501
	 */
502 3
	public function scripts() {
503 3
		$scripts = parent::scripts();
504
505 3
		$scripts[] = array(
506
			'handle'  => 'gform_tooltip_init',
507
			'enqueue' => array(
508
                array(
509
			        'admin_page' => array( 'app_settings' )
510
                )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
511
            )
512
		);
513
514 3
		return $scripts;
515
	}
516
517
	/**
518
	 * Register styles in the app admin page
519
	 * @return array
520
	 */
521 3
	public function styles() {
522
523 3
		$styles = parent::styles();
524
525 3
		$styles[] = array(
526 3
			'handle'  => 'gravityview_settings',
527 3
			'src'     => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ),
528
			'version' => GravityView_Plugin::version,
529
			"deps" => array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal deps does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
530
				'gaddon_form_settings_css',
531
                'gform_tooltip',
532
                'gform_font_awesome',
533
			),
534
			'enqueue' => array(
535
				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...
536
					'app_settings',
537
				) ),
538
			)
539
		);
540
541 3
		return $styles;
542
	}
543
544
	/**
545
	 * Add global Settings page for Multisite
546
	 * @since 1.7.6
547
	 * @return void
548
	 */
549
	public function add_network_menu() {
550
		if( GravityView_Plugin::is_network_activated() ) {
551
			add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' );
552
		}
553
	}
554
555
	/**
556
	 * Add Settings link to GravityView menu
557
	 * @return void
558
	 */
559
	public function create_app_menu() {
560
561
		/**
562
		 * If not multisite, always show.
563
		 * If multisite and the plugin is network activated, show; we need to register the submenu page for the Network Admin settings to work.
564
		 * If multisite and not network admin, we don't want the settings to show.
565
		 * @since 1.7.6
566
		 */
567
		$show_submenu = !is_multisite() ||  is_main_site() || !GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() );
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
568
569
		/**
570
		 * Override whether to show the Settings menu on a per-blog basis.
571
		 * @since 1.7.6
572
		 * @param bool $hide_if_network_activated Default: true
573
		 */
574
		$show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu );
575
576
		if( $show_submenu ) {
577
			add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) );
578
		}
579
	}
580
581
	/**
582
	 * The Settings title
583
	 * @return string
584
	 */
585
	public function app_settings_title() {
586
		return null;
587
	}
588
589
	/**
590
	 * Prevent displaying of any icon
591
	 * @return string
592
	 */
593
	public function app_settings_icon() {
594
		return '&nbsp;';
595
	}
596
597
	public function app_settings_tab() {
598
	    parent::app_settings_tab();
599
600
		if ( $this->maybe_uninstall() ) {
601
            echo $this->uninstall_form();
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
602
		}
603
    }
604
605
	/**
606
	 * Make protected public
607
	 * @inheritDoc
608
	 * @access public
609
	 */
610
	public function get_app_setting( $setting_name ) {
611
612
		/**
613
		 * Backward compatibility with Redux
614
		 */
615
		if( $setting_name === 'license' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
616
			return array(
617
				'license' => parent::get_app_setting( 'license_key' ),
618
				'status' => parent::get_app_setting( 'license_key_status' ),
619
				'response' => parent::get_app_setting( 'license_key_response' ),
620
			);
621
		}
622
623
		return parent::get_app_setting( $setting_name );
624
	}
625
626
	/**
627
	 * Returns the currently saved plugin settings
628
	 *
629
	 * Different from GFAddon in two ways:
630
	 * 1. Makes protected method public
631
	 * 2. Use default settings if the original settings don't exist
632
	 *
633
	 * @access public
634
	 *
635
	 * @return array
636
	 */
637
	public function get_app_settings() {
638
		return get_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $this->get_default_settings() );
639
	}
640
641
642
	/**
643
	 * Updates app settings with the provided settings
644
	 *
645
	 * Same as the GVAddon, except it returns the value from update_option()
646
	 *
647
	 * @param array $settings - App settings to be saved
648
	 *
649
	 * @return boolean False if value was not updated and true if value was updated.
650
	 */
651
	public function update_app_settings( $settings ) {
652
		return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
653
	}
654
655
	/**
656
	 * Make protected public
657
	 * @inheritDoc
658
	 * @access public
659
	 */
660
	public function set_field_error( $field, $error_message = '' ) {
661
		parent::set_field_error( $field, $error_message );
662
	}
663
664
	/**
665
	 * Register the settings field for the EDD License field type
666
	 * @param array $field
667
	 * @param bool $echo Whether to echo the
668
	 *
669
	 * @return string
670
	 */
671
	protected function settings_edd_license( $field, $echo = true ) {
672
673
		$text = self::settings_text( $field, false );
674
675
		$activation = $this->License_Handler->settings_edd_license_activation( $field, false );
676
677
		$return = $text . $activation;
678
679
		if( $echo ) {
680
			echo $return;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$return'
Loading history...
681
		}
682
683
		return $return;
684
	}
685
686
	/**
687
	 * Allow public access to the GV_License_Handler class
688
	 * @since 1.7.4
689
	 *
690
	 * @return GV_License_Handler
691
	 */
692
	public function get_license_handler() {
693
		return $this->License_Handler;
694
	}
695
696
	/***
697
	 * Renders the save button for settings pages
698
	 *
699
	 * @param array $field - Field array containing the configuration options of this field
700
	 * @param bool  $echo  = true - true to echo the output to the screen, false to simply return the contents as a string
701
	 *
702
	 * @return string The HTML
703
	 */
704
	public function settings_submit( $field, $echo = true ) {
705
706
		$field['type']  = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit';
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...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
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...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
707
708
		$attributes    = $this->get_field_attributes( $field );
709
		$default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' );
710
		$value         = $this->get_setting( $field['name'], $default_value );
711
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
712
713
		$attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton';
714
		$name    = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name'];
715
716
		if ( empty( $value ) ) {
717
			$value = __( 'Update Settings', 'gravityview' );
718
		}
719
720
		$attributes = $this->get_field_attributes( $field );
721
722
		$html = '<input
723
                    type="' . $field['type'] . '"
724
                    name="' . esc_attr( $name ) . '"
725
                    value="' . $value . '" ' .
726
		        implode( ' ', $attributes ) .
727
		        ' />';
728
729
		if ( $echo ) {
730
			echo $html;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$html'
Loading history...
731
		}
732
733
		return $html;
734
	}
735
736
	/**
737
	 * Allow customizing the Save field parameters
738
	 *
739
	 * @param array $field
740
	 * @param bool $echo
741
	 *
742
	 * @return string
743
	 */
744
	public function settings_save( $field, $echo = true ) {
745
		$field['type']  = 'submit';
746
		$field['name']  = 'gform-settings-save';
747
		$field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton';
748
749
		if ( ! rgar( $field, 'value' ) ) {
750
			$field['value'] = __( 'Update Settings', 'gravityview' );
751
		}
752
753
		$output = $this->settings_submit( $field, false );
754
755
		ob_start();
756
		$this->app_settings_uninstall_tab();
757
		$output .= ob_get_clean();
758
759
		if( $echo ) {
760
			echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
761
		}
762
763
		return $output;
764
	}
765
766
767
	/**
768
	 * The same as the parent, except added support for field descriptions
769
	 * @inheritDoc
770
	 * @param $field array
771
	 */
772
	public function single_setting_label( $field ) {
773
774
		parent::single_setting_label( $field );
775
776
		// Added by GravityView
777
		if ( isset( $field['description'] ) ) {
778
			echo '<span class="description">'. $field['description'] .'</span>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field'
Loading history...
779
		}
780
781
	}
782
783
	/**
784
	 * Get the default settings for the plugin
785
	 *
786
	 * Merges previous settings created when using the Redux Framework
787
	 *
788
	 * @return array Settings with defaults set
789
	 */
790
	private function get_default_settings() {
791
792
		$defaults = array(
793
			// Set the default license in wp-config.php
794
			'license_key' => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '',
795
			'license_key_response' => '',
796
			'license_key_status' => '',
797
			'support-email' => get_bloginfo( 'admin_email' ),
798
			'no-conflict-mode' => '1',
799
			'support_port' => '1',
800
			'flexbox_search' => '1',
801
			'beta' => '0',
802
		);
803
804
		return $defaults;
805
	}
806
807
	/**
808
	 * Check for the `gravityview_edit_settings` capability before saving plugin settings.
809
	 * Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions.
810
	 *
811
	 * @since 1.15
812
	 * @return void
813
	 */
814
	public function maybe_save_app_settings() {
815
816
		if ( $this->is_save_postback() ) {
817
			if ( ! GVCommon::has_cap( 'gravityview_edit_settings' ) ) {
818
				$_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't
819
				GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) );
820
				return;
821
			}
822
		}
823
824
		parent::maybe_save_app_settings();
825
	}
826
827
	/**
828
	 * When the settings are saved, make sure the license key matches the previously activated key
829
	 *
830
	 * @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset
831
	 */
832
	public function get_posted_settings() {
833
834
		$posted_settings = parent::get_posted_settings();
835
836
		$local_key = rgar( $posted_settings, 'license_key' );
837
		$response_key = rgars( $posted_settings, 'license_key_response/license_key' );
838
839
		// If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response),
840
		// then we assume it's changed. If it's changed, unset the status and the previous response.
841
		if( $local_key !== $response_key ) {
842
843
			unset( $posted_settings['license_key_response'] );
844
			unset( $posted_settings['license_key_status'] );
845
			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...
846
		}
847
848
		return $posted_settings;
849
	}
850
851
	/**
852
	 * Gets the required indicator
853
	 * Gets the markup of the required indicator symbol to highlight fields that are required
854
	 *
855
	 * @param $field - The field meta.
856
	 *
857
	 * @return string - Returns markup of the required indicator symbol
858
	 */
859
	public function get_required_indicator( $field ) {
860
		return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>';
861
	}
862
863
	/**
864
	 * Specify the settings fields to be rendered on the plugin settings page
865
	 * @return array
866
	 */
867
	public function app_settings_fields() {
868
869
		$default_settings = $this->get_default_settings();
870
871
		$disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
872
873
		$fields = apply_filters( 'gravityview_settings_fields', array(
874
			array(
875
				'name'                => 'license_key',
876
				'required'               => true,
877
				'label'             => __( 'License Key', 'gravityview' ),
878
				'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
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
879
				'type'              => 'edd_license',
880
				'data-pending-text' => __('Verifying license&hellip;', 'gravityview'),
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...
881
				'default_value'           => $default_settings['license_key'],
882
				'class'             => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key',
883
			),
884
			array(
885
				'name'       => 'license_key_response',
886
				'default_value'  => $default_settings['license_key_response'],
887
				'type'     => 'hidden',
888
			),
889
			array(
890
				'name'       => 'license_key_status',
891
				'default_value'  => $default_settings['license_key_status'],
892
				'type'     => 'hidden',
893
			),
894
			array(
895
				'name'       => 'support-email',
896
				'type'     => 'text',
897
				'validate' => 'email',
898
				'default_value'  => $default_settings['support-email'],
899
				'label'    => __( 'Support Email', 'gravityview' ),
900
				'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ),
901
				'class'    => 'code regular-text',
902
			),
903
			/**
904
			 * @since 1.15 Added Support Port support
905
			 */
906
			array(
907
				'name'         => 'support_port',
908
				'type'       => 'radio',
909
				'label'      => __( 'Show Support Port?', 'gravityview' ),
910
				'default_value'    => $default_settings['support_port'],
911
				'horizontal' => 1,
912
				'choices'    => array(
913
					array(
914
						'label' => _x('Show', 'Setting: Show or Hide', 'gravityview'),
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...
915
						'value' => '1',
916
					),
917
					array(
918
						'label' => _x('Hide', 'Setting: Show or Hide', 'gravityview'),
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...
919
						'value' => '0',
920
					),
921
				),
922
				'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>',
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...
923
				'description'   => __( 'Show the Support Port on GravityView pages?', 'gravityview' ),
924
			),
925
			array(
926
				'name'         => 'no-conflict-mode',
927
				'type'       => 'radio',
928
				'label'      => __( 'No-Conflict Mode', 'gravityview' ),
929
				'default_value'    => $default_settings['no-conflict-mode'],
930
				'horizontal' => 1,
931
				'choices'    => array(
932
					array(
933
						'label' => _x('On', 'Setting: On or off', 'gravityview'),
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...
934
						'value' => '1',
935
					),
936
					array(
937
						'label' => _x('Off', 'Setting: On or off', 'gravityview'),
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...
938
						'value' => '0',
939
					),
940
				),
941
				'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...
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...
942
			),
943
			array(
944
				'name'       => 'beta',
945
				'type'       => 'checkbox',
946
				'label'      => __( 'Become a Beta Tester', 'gravityview' ),
947
				'default_value'    => $default_settings['beta'],
948
				'horizontal' => 1,
949
				'choices'    => array(
950
					array(
951
						'label' => _x('Show me beta versions if they are available.', 'gravityview'),
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...
952
						'value' => '1',
953
                        'name'  => 'beta',
954
					),
955
				),
956
				'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'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
957
			),
958
		) );
959
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 3 empty lines
Loading history...
960
961
962
		/**
963
		 * Redux backward compatibility
964
		 * @since 1.7.4
965
		 */
966
		foreach ( $fields as &$field ) {
967
			$field['name']          = isset( $field['name'] ) ? $field['name'] : rgget('id', $field );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
968
			$field['label']         = isset( $field['label'] ) ? $field['label'] : rgget('title', $field );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
969
			$field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
970
			$field['description']   = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
971
972
			if( $disabled_attribute ) {
973
				$field['disabled']  = $disabled_attribute;
974
			}
975
		}
976
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
977
978
        $sections = array(
979
            array(
980
                'description' =>      sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ),
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 6 found
Loading history...
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...
981
                'fields'      => $fields,
982
            )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
983
        );
984
985
        // custom 'update settings' button
986
        $button = array(
987
            'class' => 'button button-primary button-hero',
988
            'type'     => 'save',
989
        );
990
991
		if( $disabled_attribute ) {
992
			$button['disabled'] = $disabled_attribute;
993
		}
994
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
995
996
        /**
997
         * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page
998
         * Extensions can tap in here to insert their own section and settings.
999
         * <code>
1000
         *   $sections[] = array(
1001
         *      'title' => __( 'GravityView My Extension Settings', 'gravityview' ),
1002
         *      'fields' => $settings,
1003
         *   );
1004
         * </code>
1005
         * @param array $extension_settings Empty array, ready for extension settings!
1006
         */
1007
        $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() );
1008
1009
		// If there are extensions, add a section for them
1010
		if ( ! empty( $extension_sections ) ) {
1011
1012
			if( $disabled_attribute ) {
1013
				foreach ( $extension_sections as &$section ) {
1014
					foreach ( $section['fields'] as &$field ) {
1015
						$field['disabled'] = $disabled_attribute;
1016
					}
1017
				}
1018
			}
1019
1020
            $k = count( $extension_sections ) - 1 ;
1021
            $extension_sections[ $k ]['fields'][] = $button;
1022
			$sections = array_merge( $sections, $extension_sections );
1023
		} else {
1024
            // add the 'update settings' button to the general section
1025
            $sections[0]['fields'][] = $button;
1026
        }
1027
1028
		return $sections;
1029
	}
1030
1031
	/**
1032
	 * Get the setting for GravityView by name
1033
	 *
1034
	 * @param  string $key     Option key to fetch
1035
	 *
1036
	 * @return mixed
1037
	 */
1038
	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...
1039
		return self::get_instance()->get_app_setting( $key );
1040
	}
1041
1042
}
1043
1044
GravityView_Settings::get_instance();