Completed
Pull Request — master (#904)
by Zack
10:41 queued 06:56
created

GravityView_Settings   D

Complexity

Total Complexity 95

Size/Duplication

Total Lines 1050
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 4.97%

Importance

Changes 0
Metric Value
dl 0
loc 1050
ccs 16
cts 322
cp 0.0497
rs 4.4266
c 0
b 0
f 0
wmc 95
lcom 2
cbo 5

36 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A get_instance() 0 8 2
A current_user_can_any() 0 8 2
A uninstall_warning_message() 0 7 1
A uninstall() 0 17 1
B get_uninstall_reasons() 0 25 1
A init_admin() 0 13 1
A modify_app_settings_menu_title() 0 6 1
A init_ajax() 0 3 1
A _load_license_handler() 0 10 2
B uninstall_form() 0 126 3
B app_settings_uninstall_tab() 0 45 6
C license_key_notice() 0 65 12
A scripts() 0 14 1
A styles() 0 23 1
A add_network_menu() 0 5 2
B create_app_menu() 0 21 6
A app_settings_title() 0 3 1
A app_settings_icon() 0 3 1
A app_settings_tab() 0 7 2
A get_app_setting() 0 15 2
A get_app_settings() 0 3 1
A update_app_settings() 0 3 1
A set_field_error() 0 3 1
A settings_edd_license() 0 14 2
A get_license_handler() 0 3 1
D settings_submit() 0 31 8
A settings_save() 0 21 4
A single_setting_row() 0 7 1
A single_setting_label() 0 8 2
A get_default_settings() 0 16 2
A maybe_save_app_settings() 0 12 3
A get_posted_settings() 0 18 2
A get_required_indicator() 0 3 1
F app_settings_fields() 0 163 14
A getSetting() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like GravityView_Settings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GravityView_Settings, and based on these observations, apply Extract Interface, too.

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
		$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...
426
		$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...
427
		if( '' === $license_key ) {
428
			$license_status = 'inactive';
429
        }
430
		$license_id = empty( $license_key ) ? 'license' : $license_key;
431
432
		$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...
433
434
		/**
435
		 * I wanted to remove the period from after the buttons in the string,
436
		 * but didn't want to mess up the translation strings for the translators.
437
		 */
438
		$message = mb_substr( $message, 0, mb_strlen( $message ) - 1 );
439
		$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...
440
		$status = '';
441
		$update_below = false;
442
		$primary_button_link = admin_url( 'edit.php?post_type=gravityview&amp;page=gravityview_settings' );
443
444
        switch ( $license_status ) {
445
			/** @since 1.17 */
446
			case 'expired':
447
				$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...
448
				$status = 'expired';
449
				$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...
450
				break;
451
			case 'invalid':
452
				$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...
453
				$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...
454
				break;
455
			case 'deactivated':
456
				$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...
457
				$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...
458
				break;
459
			/** @noinspection PhpMissingBreakStatementInspection */
460
			case '':
461
				$license_status = 'site_inactive';
462
				// break intentionally left blank
463
			case 'inactive':
464
			case 'site_inactive':
465
				$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...
466
				$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...
467
				break;
468
		}
469
		$url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice';
470
471
		// Show a different notice on settings page for inactive licenses (hide the buttons)
472
		if( $update_below && gravityview_is_admin_page( '', 'settings' ) ) {
473
			$message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' );
474
		} else {
475
			$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>' );
476
		}
477
478
		if( !empty( $status ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
479
			GravityView_Admin_Notices::add_notice( array(
480
				'message' => $message,
481
				'class'   => 'updated',
482
				'title'   => $title,
483
				'cap'     => 'gravityview_edit_settings',
484
				'dismiss' => sha1( $license_status . '_' . $license_id . '_' . date( 'z' ) ), // Show every day, instead of every 8 weeks (which is the default)
485
			) );
486
		}
487
	}
488
489
	/**
490
     * Add tooltip script to app settings page. Not enqueued by Gravity Forms for some reason.
491
     *
492
     * @since 1.21.5
493
     *
494
     * @see GFAddOn::scripts()
495
     *
496
	 * @return array Array of scripts
497
	 */
498 3
	public function scripts() {
499 3
		$scripts = parent::scripts();
500
501 3
		$scripts[] = array(
502
			'handle'  => 'gform_tooltip_init',
503
			'enqueue' => array(
504
                array(
505
			        'admin_page' => array( 'app_settings' )
506
                )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
507
            )
508
		);
509
510 3
		return $scripts;
511
	}
512
513
	/**
514
	 * Register styles in the app admin page
515
	 * @return array
516
	 */
517 3
	public function styles() {
518
519 3
		$styles = parent::styles();
520
521 3
		$styles[] = array(
522 3
			'handle'  => 'gravityview_settings',
523 3
			'src'     => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ),
524
			'version' => GravityView_Plugin::version,
525
			"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...
526
                'gform_admin',
527
				'gaddon_form_settings_css',
528
                'gform_tooltip',
529
                'gform_font_awesome',
530
			),
531
			'enqueue' => array(
532
				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...
533
					'app_settings',
534
				) ),
535
			)
536
		);
537
538 3
		return $styles;
539
	}
540
541
	/**
542
	 * Add global Settings page for Multisite
543
	 * @since 1.7.6
544
	 * @return void
545
	 */
546
	public function add_network_menu() {
547
		if( GravityView_Plugin::is_network_activated() ) {
548
			add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' );
549
		}
550
	}
551
552
	/**
553
	 * Add Settings link to GravityView menu
554
	 * @return void
555
	 */
556
	public function create_app_menu() {
557
558
		/**
559
		 * If not multisite, always show.
560
		 * If multisite and the plugin is network activated, show; we need to register the submenu page for the Network Admin settings to work.
561
		 * If multisite and not network admin, we don't want the settings to show.
562
		 * @since 1.7.6
563
		 */
564
		$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...
565
566
		/**
567
		 * Override whether to show the Settings menu on a per-blog basis.
568
		 * @since 1.7.6
569
		 * @param bool $hide_if_network_activated Default: true
570
		 */
571
		$show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu );
572
573
		if( $show_submenu ) {
574
			add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) );
575
		}
576
	}
577
578
	/**
579
	 * The Settings title
580
	 * @return string
581
	 */
582
	public function app_settings_title() {
583
		return null;
584
	}
585
586
	/**
587
	 * Prevent displaying of any icon
588
	 * @return string
589
	 */
590
	public function app_settings_icon() {
591
		return '&nbsp;';
592
	}
593
594
	public function app_settings_tab() {
595
	    parent::app_settings_tab();
596
597
		if ( $this->maybe_uninstall() ) {
598
            echo $this->uninstall_form();
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
599
		}
600
    }
601
602
	/**
603
	 * Make protected public
604
	 * @inheritDoc
605
	 * @access public
606
	 */
607
	public function get_app_setting( $setting_name ) {
608
609
		/**
610
		 * Backward compatibility with Redux
611
		 */
612
		if( $setting_name === 'license' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
613
			return array(
614
				'license' => parent::get_app_setting( 'license_key' ),
615
				'status' => parent::get_app_setting( 'license_key_status' ),
616
				'response' => parent::get_app_setting( 'license_key_response' ),
617
			);
618
		}
619
620
		return parent::get_app_setting( $setting_name );
621
	}
622
623
	/**
624
	 * Returns the currently saved plugin settings
625
	 *
626
	 * Different from GFAddon in two ways:
627
	 * 1. Makes protected method public
628
	 * 2. Use default settings if the original settings don't exist
629
	 *
630
	 * @access public
631
	 *
632
	 * @return array
633
	 */
634
	public function get_app_settings() {
635
		return get_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $this->get_default_settings() );
636
	}
637
638
639
	/**
640
	 * Updates app settings with the provided settings
641
	 *
642
	 * Same as the GVAddon, except it returns the value from update_option()
643
	 *
644
	 * @param array $settings - App settings to be saved
645
	 *
646
	 * @return boolean False if value was not updated and true if value was updated.
647
	 */
648
	public function update_app_settings( $settings ) {
649
		return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
650
	}
651
652
	/**
653
	 * Make protected public
654
	 * @inheritDoc
655
	 * @access public
656
	 */
657
	public function set_field_error( $field, $error_message = '' ) {
658
		parent::set_field_error( $field, $error_message );
659
	}
660
661
	/**
662
	 * Register the settings field for the EDD License field type
663
	 * @param array $field
664
	 * @param bool $echo Whether to echo the
665
	 *
666
	 * @return string
667
	 */
668
	protected function settings_edd_license( $field, $echo = true ) {
669
670
		$text = self::settings_text( $field, false );
671
672
		$activation = $this->License_Handler->settings_edd_license_activation( $field, false );
673
674
		$return = $text . $activation;
675
676
		if( $echo ) {
677
			echo $return;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$return'
Loading history...
678
		}
679
680
		return $return;
681
	}
682
683
	/**
684
	 * Allow public access to the GV_License_Handler class
685
	 * @since 1.7.4
686
	 *
687
	 * @return GV_License_Handler
688
	 */
689
	public function get_license_handler() {
690
		return $this->License_Handler;
691
	}
692
693
	/***
694
	 * Renders the save button for settings pages
695
	 *
696
	 * @param array $field - Field array containing the configuration options of this field
697
	 * @param bool  $echo  = true - true to echo the output to the screen, false to simply return the contents as a string
698
	 *
699
	 * @return string The HTML
700
	 */
701
	public function settings_submit( $field, $echo = true ) {
702
703
		$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...
704
705
		$attributes    = $this->get_field_attributes( $field );
706
		$default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' );
707
		$value         = $this->get_setting( $field['name'], $default_value );
708
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
709
710
		$attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton';
711
		$name    = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name'];
712
713
		if ( empty( $value ) ) {
714
			$value = __( 'Update Settings', 'gravityview' );
715
		}
716
717
		$attributes = $this->get_field_attributes( $field );
718
719
		$html = '<input
720
                    type="' . $field['type'] . '"
721
                    name="' . esc_attr( $name ) . '"
722
                    value="' . $value . '" ' .
723
		        implode( ' ', $attributes ) .
724
		        ' />';
725
726
		if ( $echo ) {
727
			echo $html;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$html'
Loading history...
728
		}
729
730
		return $html;
731
	}
732
733
	/**
734
	 * Allow customizing the Save field parameters
735
	 *
736
	 * @param array $field
737
	 * @param bool $echo
738
	 *
739
	 * @return string
740
	 */
741
	public function settings_save( $field, $echo = true ) {
742
		$field['type']  = 'submit';
743
		$field['name']  = 'gform-settings-save';
744
		$field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton';
745
746
		if ( ! rgar( $field, 'value' ) ) {
747
			$field['value'] = __( 'Update Settings', 'gravityview' );
748
		}
749
750
		$output = $this->settings_submit( $field, false );
751
752
		ob_start();
753
		$this->app_settings_uninstall_tab();
754
		$output .= ob_get_clean();
755
756
		if( $echo ) {
757
			echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
758
		}
759
760
		return $output;
761
	}
762
763
764
	/**
765
     * Keep GravityView styling for `$field['description']`, even though Gravity Forms added support for it
766
     *
767
     * Converts `$field['description']` to `$field['gv_description']`
768
     * Converts `$field['subtitle']` to `$field['description']`
769
     *
770
     * @see GravityView_Settings::single_setting_label Converts `gv_description` back to `description`
771
     * @see http://share.gravityview.co/P28uGp/2OIRKxog for image that shows subtitle vs description
772
     *
773
     * @since 1.21.5.2
774
     *
775
	 * @param array $field
776
     *
777
     * @return void
778
	 */
779
	public function single_setting_row( $field ) {
780
781
		$field['gv_description'] = rgar( $field, 'description' );
782
		$field['description']    = rgar( $field, 'subtitle' );
783
784
		parent::single_setting_row( $field );
785
	}
786
787
	/**
788
	 * The same as the parent, except added support for field descriptions
789
	 * @inheritDoc
790
	 * @param $field array
791
	 */
792
	public function single_setting_label( $field ) {
793
794
		parent::single_setting_label( $field );
795
796
		if ( $description = rgar( $field, 'gv_description' ) ) {
797
			echo '<span class="description">'. $description .'</span>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
798
		}
799
	}
800
801
	/**
802
	 * Get the default settings for the plugin
803
	 *
804
	 * Merges previous settings created when using the Redux Framework
805
	 *
806
	 * @return array Settings with defaults set
807
	 */
808
	private function get_default_settings() {
809
810
		$defaults = array(
811
			// Set the default license in wp-config.php
812
			'license_key' => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '',
813
			'license_key_response' => '',
814
			'license_key_status' => '',
815
			'support-email' => get_bloginfo( 'admin_email' ),
816
			'no-conflict-mode' => '1',
817
			'support_port' => '1',
818
			'flexbox_search' => '1',
819
			'beta' => '0',
820
		);
821
822
		return $defaults;
823
	}
824
825
	/**
826
	 * Check for the `gravityview_edit_settings` capability before saving plugin settings.
827
	 * Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions.
828
	 *
829
	 * @since 1.15
830
	 * @return void
831
	 */
832
	public function maybe_save_app_settings() {
833
834
		if ( $this->is_save_postback() ) {
835
			if ( ! GVCommon::has_cap( 'gravityview_edit_settings' ) ) {
836
				$_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't
837
				GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) );
838
				return;
839
			}
840
		}
841
842
		parent::maybe_save_app_settings();
843
	}
844
845
	/**
846
	 * When the settings are saved, make sure the license key matches the previously activated key
847
	 *
848
	 * @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset
849
	 */
850
	public function get_posted_settings() {
851
852
		$posted_settings = parent::get_posted_settings();
853
854
		$local_key = rgar( $posted_settings, 'license_key' );
855
		$response_key = rgars( $posted_settings, 'license_key_response/license_key' );
856
857
		// If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response),
858
		// then we assume it's changed. If it's changed, unset the status and the previous response.
859
		if( $local_key !== $response_key ) {
860
861
			unset( $posted_settings['license_key_response'] );
862
			unset( $posted_settings['license_key_status'] );
863
			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...
864
		}
865
866
		return $posted_settings;
867
	}
868
869
	/**
870
	 * Gets the required indicator
871
	 * Gets the markup of the required indicator symbol to highlight fields that are required
872
	 *
873
	 * @param $field - The field meta.
874
	 *
875
	 * @return string - Returns markup of the required indicator symbol
876
	 */
877
	public function get_required_indicator( $field ) {
878
		return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>';
879
	}
880
881
	/**
882
	 * Specify the settings fields to be rendered on the plugin settings page
883
	 * @return array
884
	 */
885
	public function app_settings_fields() {
886
887
		$default_settings = $this->get_default_settings();
888
889
		$disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
890
891
		$fields = apply_filters( 'gravityview_settings_fields', array(
892
			array(
893
				'name'                => 'license_key',
894
				'required'               => true,
895
				'label'             => __( 'License Key', 'gravityview' ),
896
				'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...
897
				'type'              => 'edd_license',
898
				'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...
899
				'default_value'           => $default_settings['license_key'],
900
				'class'             => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key',
901
			),
902
			array(
903
				'name'       => 'license_key_response',
904
				'default_value'  => $default_settings['license_key_response'],
905
				'type'     => 'hidden',
906
			),
907
			array(
908
				'name'       => 'license_key_status',
909
				'default_value'  => $default_settings['license_key_status'],
910
				'type'     => 'hidden',
911
			),
912
			array(
913
				'name'       => 'support-email',
914
				'type'     => 'text',
915
				'validate' => 'email',
916
				'default_value'  => $default_settings['support-email'],
917
				'label'    => __( 'Support Email', 'gravityview' ),
918
				'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ),
919
				'class'    => 'code regular-text',
920
			),
921
			/**
922
			 * @since 1.15 Added Support Port support
923
			 */
924
			array(
925
				'name'         => 'support_port',
926
				'type'       => 'radio',
927
				'label'      => __( 'Show Support Port?', 'gravityview' ),
928
				'default_value'    => $default_settings['support_port'],
929
				'horizontal' => 1,
930
				'choices'    => array(
931
					array(
932
						'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...
933
						'value' => '1',
934
					),
935
					array(
936
						'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...
937
						'value' => '0',
938
					),
939
				),
940
				'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...
941
				'description'   => __( 'Show the Support Port on GravityView pages?', 'gravityview' ),
942
			),
943
			array(
944
				'name'         => 'no-conflict-mode',
945
				'type'       => 'radio',
946
				'label'      => __( 'No-Conflict Mode', 'gravityview' ),
947
				'default_value'    => $default_settings['no-conflict-mode'],
948
				'horizontal' => 1,
949
				'choices'    => array(
950
					array(
951
						'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...
952
						'value' => '1',
953
					),
954
					array(
955
						'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...
956
						'value' => '0',
957
					),
958
				),
959
				'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...
960
			),
961
			array(
962
				'name'       => 'beta',
963
				'type'       => 'checkbox',
964
				'label'      => __( 'Become a Beta Tester', 'gravityview' ),
965
				'default_value'    => $default_settings['beta'],
966
				'horizontal' => 1,
967
				'choices'    => array(
968
					array(
969
						'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...
970
						'value' => '1',
971
                        'name'  => 'beta',
972
					),
973
				),
974
				'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...
975
			),
976
		) );
977
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 3 empty lines
Loading history...
978
979
980
		/**
981
		 * Redux backward compatibility
982
		 * @since 1.7.4
983
		 */
984
		foreach ( $fields as &$field ) {
985
			$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...
986
			$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...
987
			$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...
988
			$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...
989
990
			if( $disabled_attribute ) {
991
				$field['disabled']  = $disabled_attribute;
992
			}
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
        $sections = array(
997
            array(
998
                '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...
999
                'fields'      => $fields,
1000
            )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
1001
        );
1002
1003
        // custom 'update settings' button
1004
        $button = array(
1005
            'class' => 'button button-primary button-hero',
1006
            'type'     => 'save',
1007
        );
1008
1009
		if( $disabled_attribute ) {
1010
			$button['disabled'] = $disabled_attribute;
1011
		}
1012
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1013
1014
        /**
1015
         * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page
1016
         * Extensions can tap in here to insert their own section and settings.
1017
         * <code>
1018
         *   $sections[] = array(
1019
         *      'title' => __( 'GravityView My Extension Settings', 'gravityview' ),
1020
         *      'fields' => $settings,
1021
         *   );
1022
         * </code>
1023
         * @param array $extension_settings Empty array, ready for extension settings!
1024
         */
1025
        $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() );
1026
1027
		// If there are extensions, add a section for them
1028
		if ( ! empty( $extension_sections ) ) {
1029
1030
			if( $disabled_attribute ) {
1031
				foreach ( $extension_sections as &$section ) {
1032
					foreach ( $section['fields'] as &$field ) {
1033
						$field['disabled'] = $disabled_attribute;
1034
					}
1035
				}
1036
			}
1037
1038
            $k = count( $extension_sections ) - 1 ;
1039
            $extension_sections[ $k ]['fields'][] = $button;
1040
			$sections = array_merge( $sections, $extension_sections );
1041
		} else {
1042
            // add the 'update settings' button to the general section
1043
            $sections[0]['fields'][] = $button;
1044
        }
1045
1046
		return $sections;
1047
	}
1048
1049
	/**
1050
	 * Get the setting for GravityView by name
1051
	 *
1052
	 * @param  string $key     Option key to fetch
1053
	 *
1054
	 * @return mixed
1055
	 */
1056
	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...
1057
		return self::get_instance()->get_app_setting( $key );
1058
	}
1059
1060
}
1061
1062
GravityView_Settings::get_instance();