Completed
Pull Request — develop (#1484)
by Zack
07:48
created

Addon_Settings::get_license_handler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
if ( ! class_exists( '\GFAddOn' ) ) {
10
	return;
11
}
12
13
/**
14
 * The Addon Settings class.
15
 *
16
 * Uses internal GFAddOn APIs.
17
 */
18
class Addon_Settings extends \GFAddOn {
19
	/**
20
	 * @var string Title of the plugin to be used on the settings page, form settings and plugins page. Example: 'Gravity Forms MailChimp Add-On'
21
	 */
22
	protected $_title = 'GravityView';
23
24
	/**
25
	 * @var string Short version of the plugin title to be used on menus and other places where a less verbose string is useful. Example: 'MailChimp'
26
	 */
27
	protected  $_short_title = 'GravityView';
28
29
	/**
30
	 * @var string URL-friendly identifier used for form settings, add-on settings, text domain localization...
31
	 */
32
	protected $_slug = 'gravityview';
33
34
	/**
35
	 * @var string|array A string or an array of capabilities or roles that can uninstall the plugin
36
	 */
37
	protected $_capabilities_uninstall = 'gravityview_uninstall';
38
39
	/**
40
	 * @var string|array A string or an array of capabilities or roles that have access to the settings page
41
	 */
42
	protected $_capabilities_app_settings = 'gravityview_view_settings';
43
44
	/**
45
	 * @var string|array A string or an array of capabilities or roles that have access to the settings page
46
	 */
47
	protected $_capabilities_app_menu = 'gravityview_view_settings';
48
49
	/**
50
	 * @var string The hook suffix for the app menu
51
	 */
52
	public $app_hook_suffix = 'gravityview';
53
54
	/**
55
	 * @var \GV\License_Handler Process license validation
56
	 */
57
	private $License_Handler;
58
59
	/**
60
	 * @var bool Whether we have initialized already or not.
61
	 */
62
	private static $initialized = false;
63
64 2
	public function __construct() {
65 2
		$this->_version = Plugin::$version;
66 2
		$this->_min_gravityforms_version = Plugin::$min_gf_version;
67
68
		/**
69
		 * Hook everywhere, but only once.
70
		 */
71 2
		if ( ! self::$initialized ) {
72
			parent::__construct();
73
			self::$initialized = true;
74
		}
75 2
	}
76
77
	/**
78
	 * Run actions when initializing admin.
79
	 *
80
	 * Triggers the license key notice, et.c
81
	 *
82
	 * @return void
83
	 */
84 1
	public function init_admin() {
85 1
		$this->_load_license_handler();
86
87 1
		add_action( 'admin_head', array( $this, 'license_key_notice' ) );
88
89 1
		add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) );
90
91
		/** @since 1.7.6 */
92 1
		add_action( 'network_admin_menu', array( $this, 'add_network_menu' ) );
93
94 1
		parent::init_admin();
95 1
	}
96
97
	/**
98
	 * Change the settings page header title to "GravityView"
99
	 *
100
	 * @param $setting_tabs
101
	 *
102
	 * @return array
103
	 */
104 1
	public function modify_app_settings_menu_title( $setting_tabs ) {
105 1
		$setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview' );
106 1
		return $setting_tabs;
107
	}
108
109
	/**
110
	 * Load license handler in admin-ajax.php
111
	 *
112
	 * @return void
113
	 */
114 1
	public function init_ajax() {
115 1
		$this->_load_license_handler();
116 1
	}
117
118
	/**
119
	 * Make sure the license handler is available
120
	 *
121
	 * @return void
122
	 */
123 1
	private function _load_license_handler() {
124 1
		if ( ! empty( $this->License_Handler ) ) {
125 1
			return;
126
		}
127 1
		$this->License_Handler = License_Handler::get( $this );
128 1
	}
129
130
	/**
131
	 * Add global Settings page for Multisite
132
	 * @since 1.7.6
133
	 * @return void
134
	 */
135 1
	public function add_network_menu() {
136
137 1
	    if ( ! gravityview()->plugin->is_network_activated() ) {
138 1
			return;
139
		}
140
141
        add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' );
142
	}
143
144
	/**
145
     * Uninstall all traces of GravityView
146
     *
147
     * Note: method is public because parent method is public
148
     *
149
	 * @return bool
150
	 */
151 1
	public function uninstall() {
152 1
		gravityview()->plugin->uninstall();
153
154
		/**
155
         * Set the path so that Gravity Forms can de-activate GravityView
156
         * @see GFAddOn::uninstall_addon
157
         * @uses deactivate_plugins()
158
         */
159 1
		$this->_path = GRAVITYVIEW_FILE;
160
161 1
		return true;
162
	}
163
164
	/**
165
	 * Prevent uninstall tab from being shown by returning false for the uninstall capability check. Otherwise:
166
	 * @inheritDoc
167
	 *
168
	 * @hack
169
	 *
170
	 * @param array|string $caps
171
	 *
172
	 * @return bool
173
	 */
174 1
	public function current_user_can_any( $caps ) {
175 1
		if ( empty( $caps ) ) {
176
			$caps = array( 'gravityview_full_access' );
177
		}
178 1
		return \GVCommon::has_cap( $caps );
179
	}
180
181 1
	public function uninstall_warning_message() {
182 1
		$heading = esc_html__( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' );
183 1
		$message = esc_html__( 'Delete all Views, GravityView entry approval status, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings.', 'gravityview' );
184 1
		return sprintf( '<h4>%s</h4><p>%s</p>', $heading, $message );
185
	}
186
187
	/**
188
     * Get an array of reasons why the plugin might be uninstalled
189
     *
190
     * @since 1.17.5
191
     *
192
	 * @return array Array of reasons with the label and followup questions for each uninstall reason
193
	 */
194 1
	private function get_uninstall_reasons() {
195
		$reasons = array(
196
			'will-continue' => array(
197 1
                'label' => esc_html__( 'I am going to continue using GravityView', 'gravityview' ),
198
            ),
199
			'no-longer-need' => array(
200 1
                'label' => esc_html__( 'I no longer need GravityView', 'gravityview' ),
201
            ),
202
			'doesnt-work' => array(
203 1
                'label' => esc_html__( 'The plugin doesn\'t work', 'gravityview' ),
204
            ),
205
			'found-other' => array(
206 1
                'label' => esc_html__( 'I found a better plugin', 'gravityview' ),
207 1
                'followup' => esc_attr__( 'What plugin you are using, and why?', 'gravityview' ),
208
            ),
209
			'other' => array(
210 1
                'label' => esc_html__( 'Other', 'gravityview' ),
211
            ),
212
		);
213
214 1
		shuffle( $reasons );
215
216 1
		return $reasons;
217
    }
218
219
	/**
220
     * Display a feedback form when the plugin is uninstalled
221
     *
222
     * @since 1.17.5
223
     *
224
	 * @return string HTML of the uninstallation form
225
	 */
226 1
	public function uninstall_form() {
227 1
		ob_start();
228
229 1
		$user = wp_get_current_user();
230
		?>
231 1
    <style>
232
        #gv-reason-details {
233
            min-height: 100px;
234
        }
235
        .number-scale label {
236
            border: 1px solid #cccccc;
237
            padding: .5em .75em;
238
            margin: .1em;
239
        }
240
        #gv-uninstall-thanks p {
241
            font-size: 1.2em;
242
        }
243
        .scale-description ul {
244
            margin-bottom: 0;
245
            padding-bottom: 0;
246
        }
247
        .scale-description p.description {
248
            margin-top: 0!important;
249
            padding-top: 0!important;
250
        }
251
        .gv-form-field-wrapper {
252
            margin-top: 30px;
253
        }
254
    </style>
255
256
    <div class="gv-uninstall-form-wrapper" style="font-size: 110%; padding: 15px 0;">
257
        <script>
258
            jQuery( function( $ ) {
259
                $( '#gv-uninstall-feedback' ).on( 'change', function( e ) {
260
261
                    if ( ! $( e.target ).is( ':input' ) ) {
262
                        return;
263
                    }
264
                    var $textarea = $( '.gv-followup' ).find( 'textarea' );
265
                    var followup_text = $( e.target ).attr( 'data-followup' );
266
                    if( ! followup_text ) {
267
                        followup_text = $textarea.attr( 'data-default' );
268
                    }
269
270
                    $textarea.attr( 'placeholder', followup_text );
271
272
                } ).on( 'submit', function( e ) {
273
                    e.preventDefault();
274
275
                    $.post( $( this ).attr( 'action' ), $( this ).serialize() )
276
                        .done( function( data ) {
277
                            if ( 'success' !== data.status ) {
278
                                gv_feedback_append_error_message();
279
                            } else {
280
                                $( '#gv-uninstall-thanks' ).fadeIn();
281
                            }
282
                        })
283
                        .fail( function( data ) {
284
                            gv_feedback_append_error_message();
285
                        } )
286
                        .always( function() {
287
                            $( e.target ).remove();
288
                        } );
289
290
                    return false;
291
                });
292
293
                function gv_feedback_append_error_message() {
294
                    $( '#gv-uninstall-thanks' ).append( '<div class="notice error">' + <?php echo json_encode( esc_html( __( 'There was an error sharing your feedback. Sorry! Please email us at [email protected]', 'gravityview' ) ) ) ?> + '</div>' );
295
                }
296
            });
297
        </script>
298
299
        <form id="gv-uninstall-feedback" method="post" action="https://hooks.zapier.com/hooks/catch/28670/6haevn/">
300
            <h2><?php esc_html_e( 'Why did you uninstall GravityView?', 'gravityview' ); ?></h2>
301
            <ul>
302
				<?php
303 1
                $reasons = $this->get_uninstall_reasons();
304 1
				foreach ( $reasons as $reason ) {
305 1
					printf( '<li><label><input name="reason" type="radio" value="other" data-followup="%s"> %s</label></li>', Utils::get( $reason, 'followup' ), Utils::get( $reason, 'label' ) );
306
				}
307
				?>
308 1
            </ul>
309
            <div class="gv-followup widefat">
310
                <p><strong><label for="gv-reason-details"><?php esc_html_e( 'Comments', 'gravityview' ); ?></label></strong></p>
311
                <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>
312
            </div>
313
            <div class="scale-description">
314
                <p><strong><?php esc_html_e( 'How likely are you to recommend GravityView?', 'gravityview' ); ?></strong></p>
315
                <ul class="inline">
316
					<?php
317 1
					$i = 0;
318 1
					while( $i < 11 ) {
319 1
						echo '<li class="inline number-scale"><label><input name="likely_to_refer" id="likely_to_refer_'.$i.'" value="'.$i.'" type="radio"> '.$i.'</label></li>';
320 1
						$i++;
321
					}
322
					?>
323 1
                </ul>
324
                <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>
325
            </div>
326
327
            <div class="gv-form-field-wrapper">
328
                <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>
329
            </div>
330
331
            <div class="submit">
332
                <input type="hidden" name="siteurl" value="<?php echo esc_url( get_bloginfo( 'url' ) ); ?>" />
333
                <input type="hidden" name="email" value="<?php echo esc_attr( $user->user_email ); ?>" />
334
                <input type="hidden" name="display_name" value="<?php echo esc_attr( $user->display_name ); ?>" />
335
                <input type="submit" value="<?php esc_html_e( 'Send Us Your Feedback', 'gravityview' ); ?>" class="button button-primary button-hero" />
336
            </div>
337
        </form>
338
339
        <div id="gv-uninstall-thanks" class="notice notice-large notice-updated below-h2" style="display:none;">
340
            <h3 class="notice-title"><?php esc_html_e( 'Thank you for using GravityView!', 'gravityview' ); ?></h3>
341
            <p><?php echo gravityview_get_floaty(); ?>
342
				<?php echo make_clickable( esc_html__( 'Your feedback helps us improve GravityView. If you have any questions or comments, email us: [email protected]', 'gravityview' ) ); ?>
343 1
            </p>
344
            <div class="wp-clearfix"></div>
345
        </div>
346
    </div>
347
		<?php
348 1
		$form = ob_get_clean();
349
350 1
		return $form;
351
	}
352
353 1
	public function app_settings_uninstall_tab() {
354 1
		if ( $this->maybe_uninstall() ) {
355
			parent::app_settings_uninstall_tab();
356
			return;
357
		}
358
359 1
		if ( ! ( $this->current_user_can_any( $this->_capabilities_uninstall ) && ( ! function_exists( 'is_multisite' ) || ! is_multisite() || is_super_admin() ) ) ) {
360
			return;
361
		}
362
363
		?>
364 1
		<script>
365
			jQuery( document ).on( 'click', 'a[rel="gv-uninstall-wrapper"]', function( e ) {
366
				e.preventDefault();
367
				jQuery( '#gv-uninstall-wrapper' ).slideToggle();
368
			} );
369
		</script>
370
371
		<a rel="gv-uninstall-wrapper" href="#gv-uninstall-wrapper" class="button button-large alignright button-danger">Uninstall GravityView</a>
372
373
		<div id="gv-uninstall-wrapper">
374
			<form action="" method="post">
375
				<?php wp_nonce_field( 'uninstall', 'gf_addon_uninstall' ) ?>
376 1
				<div class="delete-alert alert_red">
377
378
					<h3>
379
						<i class="fa fa-exclamation-triangle gf_invalid"></i> <?php esc_html_e( 'Delete all GravityView content and settings', 'gravityview' ); ?>
380 1
					</h3>
381
382
					<div class="gf_delete_notice">
383
						<?php echo $this->uninstall_warning_message() ?>
384 1
					</div>
385
386
					<?php
387 1
					echo '<input type="submit" name="uninstall" value="' . sprintf( esc_attr__( 'Uninstall %s', 'gravityview' ), $this->get_short_title() ) . '" class="button button-hero" onclick="return confirm( ' . json_encode( $this->uninstall_confirm_message() ) . ' );" onkeypress="return confirm( ' . json_encode( $this->uninstall_confirm_message() ) . ' );"/>';
388
					?>
389
390
				</div>
391
			</form>
392
		</div>
393
	<?php
394 1
	}
395
396 1
	public function app_settings_tab() {
397 1
	    parent::app_settings_tab();
398
399 1
		if ( $this->maybe_uninstall() ) {
400
            echo $this->uninstall_form();
401
		}
402 1
    }
403
404
	/**
405
	 * The Settings title
406
	 *
407
	 * @return string
408
	 */
409 1
	public function app_settings_title() {
410 1
		return null;
411
	}
412
413
	/**
414
	 * Prevent displaying of any icon
415
	 *
416
	 * @return string
417
	 */
418 1
	public function app_settings_icon() {
419 1
		return '&nbsp;';
420
	}
421
422
	/**
423
	 * Retrieve a setting.
424
	 *
425
	 * @deprecated Use \GV\Addon_Settings::get
426
	 * @param string $setting_name The setting key.
427
	 *
428
	 * @return mixed The setting or null
429
	 */
430 1
	public function get_app_setting( $setting_name ) {
431 1
		return $this->get( $setting_name );
432
	}
433
434
	/**
435
	 * Retrieve a setting.
436
	 *
437
	 * @param string $key The setting key.
438
	 * @param string $default A default if not found.
439
	 *
440
	 * @return mixed The setting value.
441
	 */
442 189
	public function get( $key, $default = null ) {
443
		/**
444
		 * Backward compatibility with Redux
445
		 */
446 189
		if ( $key === 'license' ) {
447
			return array(
448 2
				'license' => $this->get( 'license_key' ),
449 2
				'status' => $this->get( 'license_key_status' ),
450 2
				'response' => $this->get( 'license_key_response' ),
451
			);
452
		}
453
454 189
		if ( 'license_key' === $key && defined( 'GRAVITYVIEW_LICENSE_KEY' ) ) {
455
			return GRAVITYVIEW_LICENSE_KEY;
456
		}
457
458 189
		return Utils::get( $this->all(), $key, $default );
459
	}
460
461
	/**
462
	 * Get the setting for GravityView by name
463
	 *
464
	 * @deprecated Use gravityview()->plugin->settings->get()
465
	 * @param  string $key     Option key to fetch
466
	 *
467
	 * @return mixed
468
	 */
469 1
	static public function getSetting( $key ) {
470 1
		if ( gravityview()->plugin->settings instanceof Addon_Settings ) {
471 1
			return gravityview()->plugin->settings->get( $key );
472
		}
473
	}
474
475
	/**
476
	 * Get all settings.
477
	 *
478
	 * @deprecated Use \GV\Addon_Settings::all() or \GV\Addon_Settings::get()
479
	 *
480
	 * @return array The settings.
481
	 */
482 1
	public function get_app_settings() {
483 1
		return $this->all();
484
	}
485
486
	/**
487
	 * Get all the settings.
488
	 *
489
	 * @return array The settings.
490
	 */
491 189
	public function all() {
492
493 189
		$option_name = 'gravityformsaddon_' . $this->_slug . '_app_settings';
494
495 189
		if ( $this->has_site_settings() ) {
496 189
			$defaults     = $this->defaults();
497 189
			$option_value = get_option( $option_name, array() );
498
		} else {
499
			$defaults     = get_blog_option( get_main_site_id(), $option_name );
500
			$option_value = get_blog_option( get_main_site_id(), $option_name );
501
		}
502
503 189
		return wp_parse_args( $option_value, $defaults );
504
	}
505
506
	/**
507
	 * Default settings.
508
	 *
509
	 * @deprecated Use \GV\Addon_Settings::defaults()
510
	 *
511
	 * @return array The defaults.
512
	 */
513 1
	public function get_default_settings() {
514 1
		return $this->defaults();
515
	}
516
517
	/**
518
	 * Default settings.
519
	 *
520
	 * @return array The defaults.
521
	 */
522 189
	private function defaults() {
523
		$defaults = array(
524
			// Set the default license in wp-config.php
525 189
			'license_key'          => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '',
526 189
			'license_key_response' => '',
527 189
			'license_key_status'   => '',
528 189
			'support-email'        => get_bloginfo( 'admin_email' ),
529 189
			'no-conflict-mode'     => '1',
530 189
			'support_port'         => '1',
531 189
			'flexbox_search'       => '1',
532 189
			'lightbox'             => 'fancybox',
533 189
			'rest_api'             => '0',
534 189
			'beta'                 => '0',
535
		);
536
537
		/**
538
		 * @filter `gravityview/settings/default` Filter default global settings.
539
		 * @param[in,out] array The defaults.
540
		 */
541 189
		return apply_filters( 'gravityview/settings/defaults', $defaults );
542
	}
543
544
	/***
545
	 * Renders the save button for settings pages
546
	 *
547
	 * @param array $field - Field array containing the configuration options of this field
548
	 * @param bool  $echo  = true - true to echo the output to the screen, false to simply return the contents as a string
549
	 *
550
	 * @return string The HTML
551
	 */
552 2
	public function as_html( $field, $echo = true ) {
553 2
		$field['type']  = ( isset( $field['type'] ) && in_array( $field['type'], array( 'submit','reset','button' ) ) ) ? $field['type'] : 'submit';
554
555 2
		$attributes    = $this->get_field_attributes( $field );
556 2
		$default_value = Utils::get( $field, 'value', Utils::get( $field, 'default_value' ) );
557 2
		$value         = $this->get( $field['name'], $default_value );
558
559
560 2
		$attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton';
561 2
		$name    = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_' . $field['name'];
562
563 2
		if ( empty( $value ) ) {
564 2
			$value = __( 'Update Settings', 'gravityview' );
565
		}
566
567 2
		$attributes = $this->get_field_attributes( $field );
568
569
		$html = '<input
570 2
                    type="' . $field['type'] . '"
571 2
                    name="' . esc_attr( $name ) . '"
572 2
                    value="' . $value . '" ' .
573 2
		        implode( ' ', $attributes ) .
574 2
		        ' />';
575
576 2
		if ( $echo ) {
577
			echo $html;
578
		}
579
580 2
		return $html;
581
	}
582
583
	/**
584
	 * @deprecated Use \GV\Addon_Settings::as_html
585
	 */
586 1
	public function settings_submit( $field, $echo = true ) {
587 1
		gravityview()->log->warning( '\GV\Addon_Settings::settings_submit has been deprecated for \GV\Addon_Settings::as_html' );
588 1
		return $this->as_html( $field, $echo );
589
	}
590
591
	/**
592
     * Check whether GravityView is being saved
593
     *
594
     * The generic is_save_postback() is true for all addons
595
     *
596
     * @since 2.0.8
597
     *
598
	 * @return bool
599
	 */
600 1
	public function is_save_postback() {
601 1
		return isset( $_POST['gform-settings-save'] ) && isset( $_POST['_gravityview_save_settings_nonce'] );
602
	}
603
604
	/**
605
	 * Display a notice if the plugin is inactive.
606
	 *
607
	 * @return void
608
	 */
609
	public function license_key_notice() {
610
611
	    if( $this->is_save_postback() ) {
612
		    $settings = $this->get_posted_settings();
613
		    $license_key = defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : \GV\Utils::get( $settings, 'license_key' );
614
		    $license_status = \GV\Utils::get( $settings, 'license_key_status', 'inactive' );
615
        } else {
616
		    $license_status = $this->get( 'license_key_status', 'inactive' );
617
		    $license_key    = $this->get( 'license_key' );
618
	    }
619
620
	    $license_id = empty( $license_key ) ? 'license' : $license_key;
621
622
		$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' );
623
624
		/** @internal Do not use! Will change without notice (pun slightly intended). */
625
		$message = apply_filters( 'gravityview/settings/license-key-notice', $message );
626
627
		/**
628
		 * I wanted to remove the period from after the buttons in the string,
629
		 * but didn't want to mess up the translation strings for the translators.
630
		 */
631
		$message = mb_substr( $message, 0, mb_strlen( $message ) - 1 );
632
		$title = __( 'Inactive License', 'gravityview');
633
		$status = '';
634
		$update_below = false;
635
		$primary_button_link = admin_url( 'edit.php?post_type=gravityview&amp;page=gravityview_settings' );
636
637
        switch ( $license_status ) {
638
			/** @since 1.17 */
639
			case 'expired':
640
				$title = __( 'Expired License', 'gravityview' );
641
				$status = 'expired';
642
				$message = $this->get_license_handler()->strings( 'expired', $this->get( 'license_key_response' ) );
643
				break;
644
			case 'invalid':
645
				$title = __( 'Invalid License', 'gravityview' );
646
				$status = __( 'is invalid', 'gravityview' );
647
				break;
648
			case 'deactivated':
649
				$status = __( 'is inactive', 'gravityview' );
650
				$update_below = __( 'Activate your license key below.', 'gravityview' );
651
				break;
652
			/** @noinspection PhpMissingBreakStatementInspection */
653
			case '':
654
				$license_status = 'site_inactive';
655
				// break intentionally left blank
656
			case 'inactive':
657
			case 'site_inactive':
658
				$status = __( 'has not been activated', 'gravityview' );
659
				$update_below = __( 'Activate your license key below.', 'gravityview' );
660
				break;
661
		}
662
		$url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice';
663
664
		// Show a different notice on settings page for inactive licenses (hide the buttons)
665
		if ( $update_below && gravityview()->request->is_admin( '', 'settings' ) ) {
0 ignored issues
show
Unused Code introduced by
The call to Frontend_Request::is_admin() has too many arguments starting with ''.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to Request::is_admin() has too many arguments starting with ''.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug Best Practice introduced by
The expression $update_below of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
666
			$message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' );
667
		} else {
668
			$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>' );
669
		}
670
671
		if ( empty( $status ) ) {
672
			return;
673
		}
674
675
        \GravityView_Admin_Notices::add_notice( array(
676
            'message' => $message,
677
            'class'   => 'notice notice-warning',
678
            'title'   => $title,
679
            'cap'     => 'gravityview_edit_settings',
680
            'dismiss' => sha1( $license_status . '_' . $license_id . '_' . date( 'z' ) ), // Show every day, instead of every 8 weeks (which is the default)
681
        ) );
682
	}
683
684
	/**
685
	 * Allow public access to the GV\License_Handler class
686
	 * @since 1.7.4
687
	 *
688
	 * @return \GV\License_Handler
689
	 */
690 1
	public function get_license_handler() {
691 1
		return $this->License_Handler;
692
	}
693
694
	/**
695
     * Add tooltip script to app settings page. Not enqueued by Gravity Forms for some reason.
696
     *
697
     * @since 1.21.5
698
     *
699
     * @see GFAddOn::scripts()
700
     *
701
	 * @return array Array of scripts
702
	 */
703 23
	public function scripts() {
704 23
		$scripts = parent::scripts();
705
706 23
		$scripts[] = array(
707
			'handle'  => 'gform_tooltip_init',
708
			'enqueue' => array(
709
                array(
710
			        'admin_page' => array( 'app_settings' )
711
                )
712
            )
713
		);
714
715 23
		return $scripts;
716
	}
717
718
	/**
719
	 * Register styles in the app admin page
720
	 * @return array
721
	 */
722 23
	public function styles() {
723 23
		$styles = parent::styles();
724
725 23
		$styles[] = array(
726 23
			'handle'  => 'gravityview_settings',
727 23
			'src'     => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ),
728 23
			'version' => Plugin::$version,
729
			'deps' => array(
730
                'gform_admin',
731
				'gaddon_form_settings_css',
732
                'gform_tooltip',
733
                'gform_font_awesome',
734
			),
735
			'enqueue' => array(
736
				array( 'admin_page' => array(
737
					'app_settings',
738
				) ),
739
			)
740
		);
741
742 23
		return $styles;
743
	}
744
745
	/**
746
	 * Does the current site have its own settings?
747
	 *
748
	 * - If not multisite, returns true.
749
	 * - If multisite and the plugin is network activated, returns true; we need to register the submenu page for the Network Admin settings to work.
750
	 * - If multisite and not network admin, return false.
751
	 *
752
	 * @since 2.8.2
753
	 *
754
	 * @return bool
755
	 */
756 189
	private function has_site_settings() {
757 189
		return ( ! is_multisite() ) || is_main_site() || ( ! gravityview()->plugin->is_network_activated() ) || ( is_network_admin() && gravityview()->plugin->is_network_activated() );
758
	}
759
760
	/**
761
	 * Add Settings link to GravityView menu
762
	 * @return void
763
	 */
764 1
	public function create_app_menu() {
765
766
		/**
767
		 * Override whether to show the Settings menu on a per-blog basis.
768
		 * @since 1.7.6
769
		 * @param bool $hide_if_network_activated Default: true
770
		 */
771 1
		$show_submenu = apply_filters( 'gravityview/show-settings-menu', $this->has_site_settings() );
772
773 1
		if ( ! $show_submenu ) {
774
			return;
775
		}
776
777 1
		add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) );
778 1
	}
779
780
	/**
781
	 * Gets the required indicator
782
	 * Gets the markup of the required indicator symbol to highlight fields that are required
783
	 *
784
	 * @param $field - The field meta.
785
	 *
786
	 * @return string - Returns markup of the required indicator symbol
787
	 */
788 1
	public function get_required_indicator( $field ) {
789 1
		return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>';
790
	}
791
792
	/**
793
	 * Specify the settings fields to be rendered on the plugin settings page
794
	 *
795
	 * @return array
796
	 */
797 1
	public function app_settings_fields() {
798 1
		$default_settings = $this->defaults();
799
800 1
		$disabled_attribute = \GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
801
802
		$fields = array(
803
			array(
804 1
				'name' => 'gv_header',
805
				'value' => '',
806
				'type' => 'html',
807
			),
808
			array(
809 1
				'name' => 'license_key',
810 1
				'required' => ! defined( 'GRAVITYVIEW_LICENSE_KEY' ) || ! GRAVITYVIEW_LICENSE_KEY,
811 1
				'label' => __( 'License Key', 'gravityview' ),
812 1
				'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates &amp; support.', 'gravityview' ) . $this->get_license_handler()->license_details( $this->get_app_setting( 'license_key_response' ) ),
0 ignored issues
show
Deprecated Code introduced by
The method GV\Addon_Settings::get_app_setting() has been deprecated with message: Use \GV\Addon_Settings::get

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

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

Loading history...
813 1
				'type' => 'edd_license',
814 1
				'disabled' => ( defined( 'GRAVITYVIEW_LICENSE_KEY' )  && GRAVITYVIEW_LICENSE_KEY ),
815 1
				'data-pending-text' => __( 'Verifying license&hellip;', 'gravityview' ),
816 1
				'default_value' => $default_settings['license_key'],
817 1
				'class' => ( '' == $this->get( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key',
818
			),
819
			array(
820 1
				'name' => 'license_key_response',
821 1
				'default_value' => $default_settings['license_key_response'],
822 1
				'type' => 'hidden',
823
			),
824
			array(
825 1
				'name' => 'license_key_status',
826 1
				'default_value' => $default_settings['license_key_status'],
827 1
				'type' => 'hidden',
828
			),
829
			array(
830 1
				'name' => 'support-email',
831 1
				'type' => 'text',
832 1
				'validate' => 'email',
833 1
				'default_value' => $default_settings['support-email'],
834 1
				'label' => __( 'Support Email', 'gravityview' ),
835 1
				'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ),
836 1
				'class' => 'code regular-text',
837
			),
838
			/**
839
			 * @since 1.15 Added Support Port support
840
			 */
841
			array(
842 1
				'name' => 'support_port',
843 1
				'type' => 'radio',
844 1
				'label' => __( 'Show Support Port?', 'gravityview' ),
845 1
				'default_value' => $default_settings['support_port'],
846 1
				'horizontal' => 1,
847
				'choices' => array(
848
					array(
849 1
						'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ),
850 1
						'value' => '1',
851
					),
852
					array(
853 1
						'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ),
854 1
						'value' => '0',
855
					),
856
				),
857 1
				'tooltip' => '<p><img src="' . esc_url_raw( plugins_url( 'assets/images/beacon.png', GRAVITYVIEW_FILE ) ) . '" alt="' . esc_attr__( 'The Support Port looks like this.', 'gravityview' ) . '" class="alignright" style="max-width:40px; margin:.5em;" />' . esc_html__( 'The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.', 'gravityview' ) . '</p>',
858 1
				'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ),
859
			),
860
			array(
861 1
				'name' => 'no-conflict-mode',
862 1
				'type' => 'radio',
863 1
				'label' => __( 'No-Conflict Mode', 'gravityview' ),
864 1
				'default_value' => $default_settings['no-conflict-mode'],
865 1
				'horizontal' => 1,
866
				'choices' => array(
867
					array(
868 1
						'label' => _x( 'On', 'Setting: On or off', 'gravityview' ),
869 1
						'value' => '1',
870
					),
871
					array(
872 1
						'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ),
873 1
						'value' => '0',
874
					),
875
				),
876 1
				'description'   => __( 'Set this to ON to prevent extraneous scripts and styles from being printed on GravityView admin pages, reducing conflicts with other plugins and themes.', 'gravityview' ) . ' ' . __( 'If your Edit View tabs are ugly, enable this setting.', 'gravityview' ),
877
			),
878
			/**
879
			 * @since 2.0 Added REST API
880
			 */
881 1
			gravityview()->plugin->supports( Plugin::FEATURE_REST ) ?
882
				array(
883 1
					'name' => 'rest_api',
884 1
					'type' => 'radio',
885 1
					'label' => __( 'REST API', 'gravityview' ),
886 1
					'default_value' => $default_settings['rest_api'],
887 1
					'horizontal' => 1,
888
					'choices' => array(
889
						array(
890 1
							'label' => _x( 'Enable', 'Setting: Enable or Disable', 'gravityview' ),
891 1
							'value' => '1',
892
						),
893
						array(
894 1
							'label' => _x( 'Disable', 'Setting: Enable or Disable', 'gravityview' ),
895 1
							'value' => '0',
896
						),
897
					),
898 1
					'description' => __( 'Enable View and Entry access via the REST API? Regular per-View restrictions apply (private, password protected, etc.).', 'gravityview' ),
899 1
					'tooltip' => '<p>' . esc_html__( 'If you are unsure, choose the Disable setting.', 'gravityview' ) . '</p>',
900
				) : array(),
901
			array(
902 1
				'name' => 'beta',
903 1
				'type' => 'checkbox',
904 1
				'label' => __( 'Become a Beta Tester', 'gravityview' ),
905 1
				'default_value' => $default_settings['beta'],
906 1
				'horizontal' => 1,
907
				'choices' => array(
908
					array(
909 1
						'label' => esc_html__( 'Show me beta versions if they are available.', 'gravityview' ),
910 1
						'value' => '1',
911 1
                        'name'  => 'beta',
912
					),
913
				),
914 1
				'description'   => __( 'You will have early access to the latest GravityView features and improvements. There may be bugs! If you encounter an issue, help make GravityView better by reporting it!', 'gravityview' ),
915
			),
916
		);
917
918 1
		$fields = array_filter( $fields, 'count' );
919
920
		/**
921
		 * @filter `gravityview_settings_fields` Filter the settings fields.
922
		 * @param array $fields The fields to filter.
923
		 * @deprecated Use `gravityview/settings/fields`.
924
		 */
925 1
		$fields = apply_filters( 'gravityview_settings_fields', $fields );
926
927
		/**
928
		 * @filter `gravityview/settings/fields` Filter the settings fields.
929
		 * @param array $fields The fields to filter.
930
		 */
931 1
		$fields = apply_filters( 'gravityview/settings/fields', $fields );
932
933
		/**
934
		 * Redux backward compatibility
935
		 * @since 1.7.4
936
		 */
937 1
		foreach ( $fields as &$field ) {
938 1
			$field['name']          = isset( $field['name'] ) ? $field['name'] : Utils::get( $field, 'id' );
939 1
			$field['label']         = isset( $field['label'] ) ? $field['label'] : Utils::get( $field, 'title' );
940 1
			$field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : Utils::get( $field, 'default' );
941 1
			$field['description']   = isset( $field['description'] ) ? $field['description'] : Utils::get( $field, 'subtitle' );
942
943 1
			if ( $disabled_attribute ) {
944
				$field['disabled']  = $disabled_attribute;
945
			}
946
947 1
			if ( empty( $field['disabled'] ) ) {
948 1
				unset( $field['disabled'] );
949
            }
950
		}
951
952
        $sections = array(
953
            array(
954 1
                'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), Plugin::$version ) ),
955 1
                'fields'      => $fields,
956
            )
957
        );
958
959
        // custom 'update settings' button
960
        $button = array(
961 1
            'class' => 'button button-primary button-hero',
962
            'type' => 'save',
963
        );
964
965 1
		if ( $disabled_attribute ) {
966
			$button['disabled'] = $disabled_attribute;
967
		}
968
969
        /**
970
         * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page
971
         * Extensions can tap in here to insert their own section and settings.
972
         * <code>
973
         *   $sections[] = array(
974
         *      'title' => __( 'GravityView My Extension Settings', 'gravityview' ),
975
         *      'fields' => $settings,
976
         *   );
977
         * </code>
978
         * @param array $extension_settings Empty array, ready for extension settings!
979
         */
980 1
        $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() );
981
982
		// If there are extensions, add a section for them
983 1
		if ( ! empty( $extension_sections ) ) {
984
985
			if( $disabled_attribute ) {
986
				foreach ( $extension_sections as &$section ) {
987
					foreach ( $section['fields'] as &$field ) {
988
						$field['disabled'] = $disabled_attribute;
989
					}
990
				}
991
			}
992
993
            $k = count( $extension_sections ) - 1 ;
994
            $extension_sections[ $k ]['fields'][] = $button;
995
			$sections = array_merge( $sections, $extension_sections );
996
		} else {
997
            // add the 'update settings' button to the general section
998 1
            $sections[0]['fields'][] = $button;
999
        }
1000
1001 1
		return $sections;
1002
	}
1003
1004
	/**
1005
	 * Updates app settings with the provided settings
1006
	 *
1007
	 * Same as the GFAddon, except it returns the value from update_option()
1008
	 *
1009
	 * @param array $settings - App settings to be saved
1010
	 *
1011
	 * @deprecated Use \GV\Addon_Settings::set or \GV\Addon_Settings::update
1012
	 *
1013
	 * @return boolean False if value was not updated and true if value was updated.
1014
	 */
1015
	public function update_app_settings( $settings ) {
1016
		return $this->update( $settings );
1017
	}
1018
1019
	/**
1020
	 * Sets a subset of settings.
1021
	 *
1022
	 * @param array|string An array of settings to update, or string (key) and $value to update one setting.
1023
	 * @param mixed $value A value if $settings is string (key). Default: null.
1024
	 */
1025 4
	public function set( $settings, $value = null ) {
1026 4
		if ( is_string( $settings ) ) {
1027 2
			$settings = array( $settings => $value );
1028
		}
1029 4
		$settings = wp_parse_args( $settings, $this->all() );
1030 4
		return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
1031
	}
1032
1033
	/**
1034
	 * Updates settings.
1035
	 *
1036
	 * @param array $settings The settings array.
1037
	 *
1038
	 * @return boolean False if value was not updated and true if value was updated.
1039
	 */
1040 1
	public function update( $settings ) {
1041 1
		return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
1042
	}
1043
1044
	/**
1045
	 * Register the settings field for the EDD License field type
1046
	 * @param array $field
1047
	 * @param bool $echo Whether to echo the
1048
	 *
1049
	 * @return string
1050
	 */
1051 1
	protected function settings_edd_license( $field, $echo = true ) {
1052
1053 1
	    if ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ) {
1054
		    $field['input_type'] = 'password';
1055
        }
1056
1057 1
		$text = $this->settings_text( $field, false );
1058
1059 1
		$activation = $this->License_Handler->settings_edd_license_activation( $field, false );
1060
1061 1
		$return = $text . $activation;
1062
1063 1
		if ( $echo ) {
1064 1
			echo $return;
1065
		}
1066
1067 1
		return $return;
1068
	}
1069
1070
	/**
1071
	 * Allow pure HTML settings row
1072
     *
1073
     * @since 2.0.6
1074
     *
1075
	 * @param array $field
1076
	 * @param bool $echo Whether to echo the
1077
	 *
1078
	 * @return string
1079
	 */
1080 1
	protected function settings_html( $field, $echo = true ) {
1081
1082 1
		$return = \GV\Utils::get( $field, 'value', '' );
1083
1084 1
		if ( $echo ) {
1085 1
			echo $return;
1086
		}
1087
1088 1
		return $return;
1089
	}
1090
1091
	/**
1092
	 * No <th> needed for pure HTML settings row
1093
	 *
1094
	 * @since 2.0.6
1095
	 *
1096
	 * @param array $field
1097
	 *
1098
	 * @return void
1099
	 */
1100 1
	public function single_setting_row_html( $field ) {
1101
		?>
1102
1103
        <tr id="gaddon-setting-row-<?php echo esc_attr( $field['name'] ); ?>">
1104
            <td colspan="2">
1105
				<?php $this->single_setting( $field ); ?>
1106 1
            </td>
1107
        </tr>
1108
1109
		<?php
1110 1
	}
1111
1112
	/**
1113
	 * Allow customizing the Save field parameters
1114
	 *
1115
	 * @param array $field
1116
	 * @param bool $echo
1117
	 *
1118
	 * @return string
1119
	 */
1120 1
	public function settings_save( $field, $echo = true ) {
1121 1
		$field['type']  = 'submit';
1122 1
		$field['name']  = 'gform-settings-save';
1123 1
		$field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton';
1124 1
		$field['value'] = Utils::get( $field, 'value', __( 'Update Settings', 'gravityview' ) );
1125
1126 1
		$output = $this->settings_submit( $field, false );
0 ignored issues
show
Deprecated Code introduced by
The method GV\Addon_Settings::settings_submit() has been deprecated with message: Use \GV\Addon_Settings::as_html

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

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

Loading history...
1127
1128 1
		ob_start();
1129 1
		$this->app_settings_uninstall_tab();
1130 1
		$output .= ob_get_clean();
1131
1132 1
		if ( $echo ) {
1133 1
			echo $output;
1134
		}
1135
1136 1
		return $output;
1137
	}
1138
1139
	/**
1140
     * Keep GravityView styling for `$field['description']`, even though Gravity Forms added support for it
1141
     *
1142
     * Converts `$field['description']` to `$field['gv_description']`
1143
     * Converts `$field['subtitle']` to `$field['description']`
1144
     *
1145
     * @see \GV\Addon_Settings::single_setting_label Converts `gv_description` back to `description`
1146
     * @see http://share.gravityview.co/P28uGp/2OIRKxog for image that shows subtitle vs description
1147
     *
1148
     * @since 1.21.5.2
1149
     *
1150
	 * @param array $field
1151
     *
1152
     * @return void
1153
	 */
1154 1
	public function single_setting_row( $field ) {
1155 1
		$field['gv_description'] = Utils::get( $field, 'description' );
1156 1
		$field['description']    = Utils::get( $field, 'subtitle' );
1157 1
		parent::single_setting_row( $field );
1158 1
	}
1159
1160
	/**
1161
	 * The same as the parent, except added support for field descriptions
1162
	 * @inheritDoc
1163
	 * @param $field array
1164
	 */
1165 1
	public function single_setting_label( $field ) {
1166 1
		parent::single_setting_label( $field );
1167 1
		if ( $description = Utils::get( $field, 'gv_description' ) ) {
1168 1
			echo '<span class="description">'. $description .'</span>';
1169
		}
1170 1
	}
1171
1172
	/**
1173
	 * Check for the `gravityview_edit_settings` capability before saving plugin settings.
1174
	 * Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions.
1175
	 *
1176
	 * @since 1.15
1177
	 * @return void
1178
	 */
1179 1
	public function maybe_save_app_settings() {
1180
1181 1
		if ( $this->is_save_postback() ) {
1182
			if ( ! \GVCommon::has_cap( 'gravityview_edit_settings' ) ) {
1183
				$_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't
1184
				\GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) );
1185
				return;
1186
			}
1187
		}
1188 1
		parent::maybe_save_app_settings();
1189 1
	}
1190
1191
	/**
1192
	 * When the settings are saved, make sure the license key matches the previously activated key
1193
	 *
1194
	 * @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset
1195
	 */
1196 1
	public function get_posted_settings() {
1197 1
		$posted_settings = parent::get_posted_settings();
1198
1199 1
		$local_key = Utils::get( $posted_settings, 'license_key' );
1200
1201 1
		if ( ! $local_key && defined( 'GRAVITYVIEW_LICENSE_KEY' ) ) {
1202
			$local_key = GRAVITYVIEW_LICENSE_KEY;
1203
		}
1204
1205 1
		$response_key = Utils::get( $posted_settings, 'license_key_response/license_key' );
1206
1207 1
		static $added_message = false;
1208
1209
		// If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response),
1210
		// then we assume it's changed. If it's changed, unset the status and the previous response.
1211 1
		if ( ! $added_message && ( $local_key !== $response_key ) ) {
1212
1213
			unset( $posted_settings['license_key_response'] );
1214
			unset( $posted_settings['license_key_status'] );
1215
1216
			\GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) );
1217
1218
			$added_message = true;
1219
		}
1220 1
		return $posted_settings;
1221
	}
1222
}
1223