GravityView  1.22.6
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-settings.php
Go to the documentation of this file.
1 <?php
2 
3 if( ! class_exists('GFAddOn') ) {
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  */
17  /**
18  * @var string Gravity Forms minimum version requirement
19  */
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  */
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' ) {
79  return parent::__construct();
80  }
81 
82  return self::get_instance();
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  public function uninstall() {
132 
133  include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-uninstall.php' );
134 
135  $uninstaller = new GravityView_Uninstall();
136 
137  $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  $this->_path = GRAVITYVIEW_FILE;
145 
146  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'),
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 support@gravityview.co', 'gravityview' ) ) ?></div>');
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
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>
275  </div>
276  <div class="scale-description">
277  <p><strong><?php esc_html_e('How likely are you to recommend GravityView?', 'gravityview' ); ?></strong></p>
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>';
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>
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(); ?>
305  <?php echo make_clickable( esc_html__('Your feedback helps us improve GravityView. If you have any questions or comments, email us: support@gravityview.co', 'gravityview' ) ); ?>
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 
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() ?>
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() ) . '\');"/>';
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() {
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' ) );
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');
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 ) ) {
411  return;
412  }
413 
414  require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php');
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() {
424 
425  $license_status = self::getSetting('license_key_status');
426  $license_key = self::getSetting('license_key');
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');
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');
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');
448  $status = 'expired';
449  $message = $this->get_license_handler()->strings( 'expired', self::getSetting('license_key_response') );
450  break;
451  case 'invalid':
452  $title = __('Invalid License', 'gravityview');
453  $status = __('is invalid', 'gravityview');
454  break;
455  case 'deactivated':
456  $status = __('is inactive', 'gravityview');
457  $update_below = __('Activate your license key below.', 'gravityview');
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');
466  $update_below = __('Activate your license key below.', 'gravityview');
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 ) ) {
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  public function scripts() {
499  $scripts = parent::scripts();
500 
501  $scripts[] = array(
502  'handle' => 'gform_tooltip_init',
503  'enqueue' => array(
504  array(
505  'admin_page' => array( 'app_settings' )
506  )
507  )
508  );
509 
510  return $scripts;
511  }
512 
513  /**
514  * Register styles in the app admin page
515  * @return array
516  */
517  public function styles() {
518 
519  $styles = parent::styles();
520 
521  $styles[] = array(
522  'handle' => 'gravityview_settings',
523  'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ),
524  'version' => GravityView_Plugin::version,
525  "deps" => array(
526  'gform_admin',
527  'gaddon_form_settings_css',
528  'gform_tooltip',
529  'gform_font_awesome',
530  ),
531  'enqueue' => array(
532  array( 'admin_page' => array(
533  'app_settings',
534  ) ),
535  )
536  );
537 
538  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() {
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() );
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() {
596 
597  if ( $this->maybe_uninstall() ) {
598  echo $this->uninstall_form();
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' ) {
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 
636  $settings = get_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $this->get_default_settings() );
637 
638  if( defined( 'GRAVITYVIEW_LICENSE_KEY' ) ) {
639  $settings['license_key'] = GRAVITYVIEW_LICENSE_KEY;
640  }
641 
642  return $settings;
643  }
644 
645 
646  /**
647  * Updates app settings with the provided settings
648  *
649  * Same as the GVAddon, except it returns the value from update_option()
650  *
651  * @param array $settings - App settings to be saved
652  *
653  * @return boolean False if value was not updated and true if value was updated.
654  */
655  public function update_app_settings( $settings ) {
656  return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
657  }
658 
659  /**
660  * Make protected public
661  * @inheritDoc
662  * @access public
663  */
664  public function set_field_error( $field, $error_message = '' ) {
665  parent::set_field_error( $field, $error_message );
666  }
667 
668  /**
669  * Register the settings field for the EDD License field type
670  * @param array $field
671  * @param bool $echo Whether to echo the
672  *
673  * @return string
674  */
675  protected function settings_edd_license( $field, $echo = true ) {
676 
677  if ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ) {
678  $field['input_type'] = 'password';
679  }
680 
681  $text = $this->settings_text( $field, false );
682 
683  $activation = $this->License_Handler->settings_edd_license_activation( $field, false );
684 
685  $return = $text . $activation;
686 
687  if( $echo ) {
688  echo $return;
689  }
690 
691  return $return;
692  }
693 
694  /**
695  * Allow public access to the GV_License_Handler class
696  * @since 1.7.4
697  *
698  * @return GV_License_Handler
699  */
700  public function get_license_handler() {
701  return $this->License_Handler;
702  }
703 
704  /***
705  * Renders the save button for settings pages
706  *
707  * @param array $field - Field array containing the configuration options of this field
708  * @param bool $echo = true - true to echo the output to the screen, false to simply return the contents as a string
709  *
710  * @return string The HTML
711  */
712  public function settings_submit( $field, $echo = true ) {
713 
714  $field['type'] = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit';
715 
716  $attributes = $this->get_field_attributes( $field );
717  $default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' );
718  $value = $this->get_setting( $field['name'], $default_value );
719 
720 
721  $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton';
722  $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name'];
723 
724  if ( empty( $value ) ) {
725  $value = __( 'Update Settings', 'gravityview' );
726  }
727 
728  $attributes = $this->get_field_attributes( $field );
729 
730  $html = '<input
731  type="' . $field['type'] . '"
732  name="' . esc_attr( $name ) . '"
733  value="' . $value . '" ' .
734  implode( ' ', $attributes ) .
735  ' />';
736 
737  if ( $echo ) {
738  echo $html;
739  }
740 
741  return $html;
742  }
743 
744  /**
745  * Allow customizing the Save field parameters
746  *
747  * @param array $field
748  * @param bool $echo
749  *
750  * @return string
751  */
752  public function settings_save( $field, $echo = true ) {
753  $field['type'] = 'submit';
754  $field['name'] = 'gform-settings-save';
755  $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton';
756 
757  if ( ! rgar( $field, 'value' ) ) {
758  $field['value'] = __( 'Update Settings', 'gravityview' );
759  }
760 
761  $output = $this->settings_submit( $field, false );
762 
763  ob_start();
765  $output .= ob_get_clean();
766 
767  if( $echo ) {
768  echo $output;
769  }
770 
771  return $output;
772  }
773 
774 
775  /**
776  * Keep GravityView styling for `$field['description']`, even though Gravity Forms added support for it
777  *
778  * Converts `$field['description']` to `$field['gv_description']`
779  * Converts `$field['subtitle']` to `$field['description']`
780  *
781  * @see GravityView_Settings::single_setting_label Converts `gv_description` back to `description`
782  * @see http://share.gravityview.co/P28uGp/2OIRKxog for image that shows subtitle vs description
783  *
784  * @since 1.21.5.2
785  *
786  * @param array $field
787  *
788  * @return void
789  */
790  public function single_setting_row( $field ) {
791 
792  $field['gv_description'] = rgar( $field, 'description' );
793  $field['description'] = rgar( $field, 'subtitle' );
794 
796  }
797 
798  /**
799  * The same as the parent, except added support for field descriptions
800  * @inheritDoc
801  * @param $field array
802  */
803  public function single_setting_label( $field ) {
804 
806 
807  if ( $description = rgar( $field, 'gv_description' ) ) {
808  echo '<span class="description">'. $description .'</span>';
809  }
810  }
811 
812  /**
813  * Get the default settings for the plugin
814  *
815  * Merges previous settings created when using the Redux Framework
816  *
817  * @return array Settings with defaults set
818  */
819  private function get_default_settings() {
820 
821  $defaults = array(
822  // Set the default license in wp-config.php
823  'license_key' => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '',
824  'license_key_response' => '',
825  'license_key_status' => '',
826  'support-email' => get_bloginfo( 'admin_email' ),
827  'no-conflict-mode' => '1',
828  'support_port' => '1',
829  'flexbox_search' => '1',
830  'beta' => '0',
831  );
832 
833  return $defaults;
834  }
835 
836  /**
837  * Check for the `gravityview_edit_settings` capability before saving plugin settings.
838  * Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions.
839  *
840  * @since 1.15
841  * @return void
842  */
843  public function maybe_save_app_settings() {
844 
845  if ( $this->is_save_postback() ) {
846  if ( ! GVCommon::has_cap( 'gravityview_edit_settings' ) ) {
847  $_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't
848  GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) );
849  return;
850  }
851  }
852 
854  }
855 
856  /**
857  * When the settings are saved, make sure the license key matches the previously activated key
858  *
859  * @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset
860  */
861  public function get_posted_settings() {
862 
863  $posted_settings = parent::get_posted_settings();
864 
865  $local_key = rgar( $posted_settings, 'license_key' );
866  $response_key = rgars( $posted_settings, 'license_key_response/license_key' );
867 
868  // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response),
869  // then we assume it's changed. If it's changed, unset the status and the previous response.
870  if( $local_key !== $response_key ) {
871 
872  unset( $posted_settings['license_key_response'] );
873  unset( $posted_settings['license_key_status'] );
874  GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) );
875  }
876 
877  return $posted_settings;
878  }
879 
880  /**
881  * Gets the required indicator
882  * Gets the markup of the required indicator symbol to highlight fields that are required
883  *
884  * @param $field - The field meta.
885  *
886  * @return string - Returns markup of the required indicator symbol
887  */
888  public function get_required_indicator( $field ) {
889  return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>';
890  }
891 
892  /**
893  * Specify the settings fields to be rendered on the plugin settings page
894  * @return array
895  */
896  public function app_settings_fields() {
897 
898  $default_settings = $this->get_default_settings();
899 
900  $disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
901 
902  $fields = apply_filters( 'gravityview_settings_fields', array(
903  array(
904  'name' => 'license_key',
905  'required' => true,
906  'label' => __( 'License Key', 'gravityview' ),
907  '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' ) ),
908  'type' => 'edd_license',
909  'disabled' => ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ),
910  'data-pending-text' => __('Verifying license&hellip;', 'gravityview'),
911  'default_value' => $default_settings['license_key'],
912  'class' => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key',
913  ),
914  array(
915  'name' => 'license_key_response',
916  'default_value' => $default_settings['license_key_response'],
917  'type' => 'hidden',
918  ),
919  array(
920  'name' => 'license_key_status',
921  'default_value' => $default_settings['license_key_status'],
922  'type' => 'hidden',
923  ),
924  array(
925  'name' => 'support-email',
926  'type' => 'text',
927  'validate' => 'email',
928  'default_value' => $default_settings['support-email'],
929  'label' => __( 'Support Email', 'gravityview' ),
930  'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ),
931  'class' => 'code regular-text',
932  ),
933  /**
934  * @since 1.15 Added Support Port support
935  */
936  array(
937  'name' => 'support_port',
938  'type' => 'radio',
939  'label' => __( 'Show Support Port?', 'gravityview' ),
940  'default_value' => $default_settings['support_port'],
941  'horizontal' => 1,
942  'choices' => array(
943  array(
944  'label' => _x('Show', 'Setting: Show or Hide', 'gravityview'),
945  'value' => '1',
946  ),
947  array(
948  'label' => _x('Hide', 'Setting: Show or Hide', 'gravityview'),
949  'value' => '0',
950  ),
951  ),
952  '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>',
953  'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ),
954  ),
955  array(
956  'name' => 'no-conflict-mode',
957  'type' => 'radio',
958  'label' => __( 'No-Conflict Mode', 'gravityview' ),
959  'default_value' => $default_settings['no-conflict-mode'],
960  'horizontal' => 1,
961  'choices' => array(
962  array(
963  'label' => _x('On', 'Setting: On or off', 'gravityview'),
964  'value' => '1',
965  ),
966  array(
967  'label' => _x('Off', 'Setting: On or off', 'gravityview'),
968  'value' => '0',
969  ),
970  ),
971  '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'),
972  ),
973  array(
974  'name' => 'beta',
975  'type' => 'checkbox',
976  'label' => __( 'Become a Beta Tester', 'gravityview' ),
977  'default_value' => $default_settings['beta'],
978  'horizontal' => 1,
979  'choices' => array(
980  array(
981  'label' => _x('Show me beta versions if they are available.', 'gravityview'),
982  'value' => '1',
983  'name' => 'beta',
984  ),
985  ),
986  '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'),
987  ),
988  ) );
989 
990 
991 
992  /**
993  * Redux backward compatibility
994  * @since 1.7.4
995  */
996  foreach ( $fields as &$field ) {
997  $field['name'] = isset( $field['name'] ) ? $field['name'] : rgget('id', $field );
998  $field['label'] = isset( $field['label'] ) ? $field['label'] : rgget('title', $field );
999  $field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field );
1000  $field['description'] = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field );
1001 
1002  if( $disabled_attribute ) {
1003  $field['disabled'] = $disabled_attribute;
1004  }
1005 
1006  if( empty( $field['disabled'] ) ) {
1007  unset( $field['disabled'] );
1008  }
1009  }
1010 
1011  $sections = array(
1012  array(
1013  'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ),
1014  'fields' => $fields,
1015  )
1016  );
1017 
1018  // custom 'update settings' button
1019  $button = array(
1020  'class' => 'button button-primary button-hero',
1021  'type' => 'save',
1022  );
1023 
1024  if( $disabled_attribute ) {
1025  $button['disabled'] = $disabled_attribute;
1026  }
1027 
1028 
1029  /**
1030  * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page
1031  * Extensions can tap in here to insert their own section and settings.
1032  * <code>
1033  * $sections[] = array(
1034  * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ),
1035  * 'fields' => $settings,
1036  * );
1037  * </code>
1038  * @param array $extension_settings Empty array, ready for extension settings!
1039  */
1040  $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() );
1041 
1042  // If there are extensions, add a section for them
1043  if ( ! empty( $extension_sections ) ) {
1044 
1045  if( $disabled_attribute ) {
1046  foreach ( $extension_sections as &$section ) {
1047  foreach ( $section['fields'] as &$field ) {
1048  $field['disabled'] = $disabled_attribute;
1049  }
1050  }
1051  }
1052 
1053  $k = count( $extension_sections ) - 1 ;
1054  $extension_sections[ $k ]['fields'][] = $button;
1055  $sections = array_merge( $sections, $extension_sections );
1056  } else {
1057  // add the 'update settings' button to the general section
1058  $sections[0]['fields'][] = $button;
1059  }
1060 
1061  return $sections;
1062  }
1063 
1064  /**
1065  * Get the setting for GravityView by name
1066  *
1067  * @param string $key Option key to fetch
1068  *
1069  * @return mixed
1070  */
1071  static public function getSetting( $key ) {
1072  return self::get_instance()->get_app_setting( $key );
1073  }
1074 
1075 }
1076 
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:35
$url
Definition: post_image.php:25
app_settings_icon()
Prevent displaying of any icon.
current_user_can_any( $caps)
Prevent uninstall tab from being shown by returning false for the uninstall capability check...
update_app_settings( $settings)
Updates app settings with the provided settings.
app_settings_uninstall_tab()
includes
add_network_menu()
Add global Settings page for Multisite.
settings_save( $field, $echo=true)
Allow customizing the Save field parameters.
maybe_save_app_settings()
Check for the gravityview_edit_settings capability before saving plugin settings. ...
app_settings_fields()
Specify the settings fields to be rendered on the plugin settings page.
get_app_setting( $setting_name)
Make protected public public.
get_uninstall_reasons()
Get an array of reasons why the plugin might be uninstalled.
scale description ul
single_setting_row( $field)
Keep GravityView styling for `$field[&#39;description&#39;]`, even though Gravity Forms added support for it...
static getSetting( $key)
Get the setting for GravityView by name.
scale description p description
scripts()
Add tooltip script to app settings page.
__construct( $prevent_multiple_instances='')
We&#39;re not able to set the __construct() method to private because we&#39;re extending the GFAddon class...
settings_edd_license( $field, $echo=true)
Register the settings field for the EDD License field type.
get_license_handler()
Allow public access to the GV_License_Handler class.
GravityView Settings class (get/set/license validation) using the Gravity Forms App framework...
set_field_error( $field, $error_message='')
Make protected public public.
gravityview_get_floaty( $height=87)
Get an image of our intrepid explorer friend.
get_posted_settings()
When the settings are saved, make sure the license key matches the previously activated key...
get_default_settings()
Get the default settings for the plugin.
settings_submit( $field, $echo=true)
styles()
Register styles in the app admin page.
static add_notice( $notice=array())
Add a notice to be displayed in the admin.
static is_network_activated()
Check whether GravityView is network activated.
uninstall_form()
Display a feedback form when the plugin is uninstalled.
uninstall()
Uninstall all traces of GravityView.
create_app_menu()
Add Settings link to GravityView menu.
Delete GravityView content when GravityView is uninstalled, if the setting is set to "Delete on Unins...
gravityview()
The main GravityView wrapper function.
get_app_settings()
Returns the currently saved plugin settings.
single_setting_label( $field)
The same as the parent, except added support for field descriptions .
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
get_required_indicator( $field)
Gets the required indicator Gets the markup of the required indicator symbol to highlight fields that...
const GRAVITYVIEW_FILE(! defined( 'ABSPATH'))
Plugin Name: GravityView Plugin URI: https://gravityview.co Description: The best, easiest way to display Gravity Forms entries on your website.
Definition: gravityview.php:26
const GV_MIN_GF_VERSION
GravityView requires at least this version of Gravity Forms to function properly. ...
Definition: gravityview.php:40
gv form field wrapper
app_settings_title()
The Settings title.
$field
Definition: gquiz_grade.php:11
$description
Definition: post_image.php:28
$title