GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gv-settings-addon.php
Go to the documentation of this file.
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  */
58 
59  /**
60  * @var bool Whether we have initialized already or not.
61  */
62  private static $initialized = false;
63 
64  public function __construct() {
65  $this->_version = Plugin::$version;
66  $this->_min_gravityforms_version = Plugin::$min_gf_version;
67 
68  /**
69  * Hook everywhere, but only once.
70  */
71  if ( ! self::$initialized ) {
72  parent::__construct();
73  self::$initialized = true;
74  }
75  }
76 
77  /**
78  * Run actions when initializing admin.
79  *
80  * Triggers the license key notice, et.c
81  *
82  * @return void
83  */
84  public function init_admin() {
85  $this->_load_license_handler();
86 
87  add_action( 'admin_head', array( $this, 'license_key_notice' ) );
88 
89  add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) );
90 
91  /** @since 1.7.6 */
92  add_action( 'network_admin_menu', array( $this, 'add_network_menu' ) );
93 
94  parent::init_admin();
95  }
96 
97  /**
98  * Change the settings page header title to "GravityView"
99  *
100  * @param $setting_tabs
101  *
102  * @return array
103  */
104  public function modify_app_settings_menu_title( $setting_tabs ) {
105  $setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview' );
106  return $setting_tabs;
107  }
108 
109  /**
110  * Load license handler in admin-ajax.php
111  *
112  * @return void
113  */
114  public function init_ajax() {
115  $this->_load_license_handler();
116  }
117 
118  /**
119  * Make sure the license handler is available
120  *
121  * @return void
122  */
123  private function _load_license_handler() {
124  if ( ! empty( $this->License_Handler ) ) {
125  return;
126  }
127  $this->License_Handler = License_Handler::get( $this );
128  }
129 
130  /**
131  * Add global Settings page for Multisite
132  * @since 1.7.6
133  * @return void
134  */
135  public function add_network_menu() {
136 
137  if ( ! gravityview()->plugin->is_network_activated() ) {
138  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  public function uninstall() {
152  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  $this->_path = GRAVITYVIEW_FILE;
160 
161  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  public function current_user_can_any( $caps ) {
175  if ( empty( $caps ) ) {
176  $caps = array( 'gravityview_full_access' );
177  }
178  return \GVCommon::has_cap( $caps );
179  }
180 
181  public function uninstall_warning_message() {
182  $heading = esc_html__( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' );
183  $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  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  private function get_uninstall_reasons() {
195  $reasons = array(
196  'will-continue' => array(
197  'label' => esc_html__( 'I am going to continue using GravityView', 'gravityview' ),
198  ),
199  'no-longer-need' => array(
200  'label' => esc_html__( 'I no longer need GravityView', 'gravityview' ),
201  ),
202  'doesnt-work' => array(
203  'label' => esc_html__( 'The plugin doesn\'t work', 'gravityview' ),
204  ),
205  'found-other' => array(
206  'label' => esc_html__( 'I found a better plugin', 'gravityview' ),
207  'followup' => esc_attr__( 'What plugin you are using, and why?', 'gravityview' ),
208  ),
209  'other' => array(
210  'label' => esc_html__( 'Other', 'gravityview' ),
211  ),
212  );
213 
214  shuffle( $reasons );
215 
216  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  public function uninstall_form() {
227  ob_start();
228 
229  $user = wp_get_current_user();
230  ?>
231  <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 support@gravityview.co', '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  $reasons = $this->get_uninstall_reasons();
304  foreach ( $reasons as $reason ) {
305  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  </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  $i = 0;
318  while( $i < 11 ) {
319  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  $i++;
321  }
322  ?>
323  </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: support@gravityview.co', 'gravityview' ) ); ?>
343  </p>
344  <div class="wp-clearfix"></div>
345  </div>
346  </div>
347  <?php
348  $form = ob_get_clean();
349 
350  return $form;
351  }
352 
353  public function app_settings_uninstall_tab() {
354  if ( $this->maybe_uninstall() ) {
356  return;
357  }
358 
359  if ( ! ( $this->current_user_can_any( $this->_capabilities_uninstall ) && ( ! function_exists( 'is_multisite' ) || ! is_multisite() || is_super_admin() ) ) ) {
360  return;
361  }
362 
363  ?>
364  <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  <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  </h3>
381 
382  <div class="gf_delete_notice">
383  <?php echo $this->uninstall_warning_message() ?>
384  </div>
385 
386  <?php
387  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  }
395 
396  public function app_settings_tab() {
398 
399  if ( $this->maybe_uninstall() ) {
400  echo $this->uninstall_form();
401  }
402  }
403 
404  /**
405  * The Settings title
406  *
407  * @return string
408  */
409  public function app_settings_title() {
410  return null;
411  }
412 
413  /**
414  * Prevent displaying of any icon
415  *
416  * @return string
417  */
418  public function app_settings_icon() {
419  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  public function get_app_setting( $setting_name ) {
431  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  public function get( $key, $default = null ) {
443  /**
444  * Backward compatibility with Redux
445  */
446  if ( $key === 'license' ) {
447  return array(
448  'license' => $this->get( 'license_key' ),
449  'status' => $this->get( 'license_key_status' ),
450  'response' => $this->get( 'license_key_response' ),
451  );
452  }
453  return Utils::get( $this->all(), $key, $default );
454  }
455 
456  /**
457  * Get the setting for GravityView by name
458  *
459  * @deprecated Use gravityview()->plugin->settings->get()
460  * @param string $key Option key to fetch
461  *
462  * @return mixed
463  */
464  static public function getSetting( $key ) {
465  if ( gravityview()->plugin->settings instanceof Addon_Settings ) {
466  return gravityview()->plugin->settings->get( $key );
467  }
468  }
469 
470  /**
471  * Get all settings.
472  *
473  * @deprecated Use \GV\Addon_Settings::all() or \GV\Addon_Settings::get()
474  *
475  * @return array The settings.
476  */
477  public function get_app_settings() {
478  return $this->all();
479  }
480 
481  /**
482  * Get all the settings.
483  *
484  * @return array The settings.
485  */
486  public function all() {
487  return wp_parse_args( get_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', array() ), $this->defaults() );
488  }
489 
490  /**
491  * Default settings.
492  *
493  * @deprecated Use \GV\Addon_Settings::defaults()
494  *
495  * @return array The defaults.
496  */
497  public function get_default_settings() {
498  return $this->defaults();
499  }
500 
501  /**
502  * Default settings.
503  *
504  * @return array The defaults.
505  */
506  private function defaults() {
507  $defaults = array(
508  // Set the default license in wp-config.php
509  'license_key' => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '',
510  'license_key_response' => '',
511  'license_key_status' => '',
512  'support-email' => get_bloginfo( 'admin_email' ),
513  'no-conflict-mode' => '1',
514  'support_port' => '1',
515  'flexbox_search' => '1',
516  'rest_api' => '0',
517  'beta' => '0',
518  );
519 
520  /**
521  * @filter `gravityview/settings/default` Filter default global settings.
522  * @param[in,out] array The defaults.
523  */
524  return apply_filters( 'gravityview/settings/defaults', $defaults );
525  }
526 
527  /***
528  * Renders the save button for settings pages
529  *
530  * @param array $field - Field array containing the configuration options of this field
531  * @param bool $echo = true - true to echo the output to the screen, false to simply return the contents as a string
532  *
533  * @return string The HTML
534  */
535  public function as_html( $field, $echo = true ) {
536  $field['type'] = ( isset( $field['type'] ) && in_array( $field['type'], array( 'submit','reset','button' ) ) ) ? $field['type'] : 'submit';
537 
538  $attributes = $this->get_field_attributes( $field );
539  $default_value = Utils::get( $field, 'value', Utils::get( $field, 'default_value' ) );
540  $value = $this->get( $field['name'], $default_value );
541 
542 
543  $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton';
544  $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_' . $field['name'];
545 
546  if ( empty( $value ) ) {
547  $value = __( 'Update Settings', 'gravityview' );
548  }
549 
550  $attributes = $this->get_field_attributes( $field );
551 
552  $html = '<input
553  type="' . $field['type'] . '"
554  name="' . esc_attr( $name ) . '"
555  value="' . $value . '" ' .
556  implode( ' ', $attributes ) .
557  ' />';
558 
559  if ( $echo ) {
560  echo $html;
561  }
562 
563  return $html;
564  }
565 
566  /**
567  * @deprecated Use \GV\Addon_Settings::as_html
568  */
569  public function settings_submit( $field, $echo = true ) {
570  gravityview()->log->warning( '\GV\Addon_Settings::settings_submit has been deprecated for \GV\Addon_Settings::as_html' );
571  return $this->as_html( $field, $echo );
572  }
573 
574  /**
575  * Check whether GravityView is being saved
576  *
577  * The generic is_save_postback() is true for all addons
578  *
579  * @since 2.0.8
580  *
581  * @return bool
582  */
583  public function is_save_postback() {
584  return isset( $_POST['gform-settings-save'] ) && isset( $_POST['_gravityview_save_settings_nonce'] );
585  }
586 
587  /**
588  * Display a notice if the plugin is inactive.
589  *
590  * @return void
591  */
592  public function license_key_notice() {
593 
594  if( $this->is_save_postback() ) {
595  $settings = $this->get_posted_settings();
596  $license_key = \GV\Utils::get( $settings, 'license_key' );
597  $license_status = \GV\Utils::get( $settings, 'license_key_status', 'inactive' );
598  } else {
599  $license_status = $this->get( 'license_key_status', 'inactive' );
600  $license_key = $this->get( 'license_key' );
601  }
602 
603  $license_id = empty( $license_key ) ? 'license' : $license_key;
604 
605  $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' );
606 
607  /** @internal Do not use! Will change without notice (pun slightly intended). */
608  $message = apply_filters( 'gravityview/settings/license-key-notice', $message );
609 
610  /**
611  * I wanted to remove the period from after the buttons in the string,
612  * but didn't want to mess up the translation strings for the translators.
613  */
614  $message = mb_substr( $message, 0, mb_strlen( $message ) - 1 );
615  $title = __( 'Inactive License', 'gravityview');
616  $status = '';
617  $update_below = false;
618  $primary_button_link = admin_url( 'edit.php?post_type=gravityview&amp;page=gravityview_settings' );
619 
620  switch ( $license_status ) {
621  /** @since 1.17 */
622  case 'expired':
623  $title = __( 'Expired License', 'gravityview' );
624  $status = 'expired';
625  $message = $this->get_license_handler()->strings( 'expired', $this->get( 'license_key_response' ) );
626  break;
627  case 'invalid':
628  $title = __( 'Invalid License', 'gravityview' );
629  $status = __( 'is invalid', 'gravityview' );
630  break;
631  case 'deactivated':
632  $status = __( 'is inactive', 'gravityview' );
633  $update_below = __( 'Activate your license key below.', 'gravityview' );
634  break;
635  /** @noinspection PhpMissingBreakStatementInspection */
636  case '':
637  $license_status = 'site_inactive';
638  // break intentionally left blank
639  case 'inactive':
640  case 'site_inactive':
641  $status = __( 'has not been activated', 'gravityview' );
642  $update_below = __( 'Activate your license key below.', 'gravityview' );
643  break;
644  }
645  $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice';
646 
647  // Show a different notice on settings page for inactive licenses (hide the buttons)
648  if ( $update_below && gravityview()->request->is_admin( '', 'settings' ) ) {
649  $message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' );
650  } else {
651  $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>' );
652  }
653 
654  if ( empty( $status ) ) {
655  return;
656  }
657 
659  'message' => $message,
660  'class' => 'notice notice-warning',
661  'title' => $title,
662  'cap' => 'gravityview_edit_settings',
663  'dismiss' => sha1( $license_status . '_' . $license_id . '_' . date( 'z' ) ), // Show every day, instead of every 8 weeks (which is the default)
664  ) );
665  }
666 
667  /**
668  * Allow public access to the GV\License_Handler class
669  * @since 1.7.4
670  *
671  * @return \GV\License_Handler
672  */
673  public function get_license_handler() {
674  return $this->License_Handler;
675  }
676 
677  /**
678  * Add tooltip script to app settings page. Not enqueued by Gravity Forms for some reason.
679  *
680  * @since 1.21.5
681  *
682  * @see GFAddOn::scripts()
683  *
684  * @return array Array of scripts
685  */
686  public function scripts() {
687  $scripts = parent::scripts();
688 
689  $scripts[] = array(
690  'handle' => 'gform_tooltip_init',
691  'enqueue' => array(
692  array(
693  'admin_page' => array( 'app_settings' )
694  )
695  )
696  );
697 
698  return $scripts;
699  }
700 
701  /**
702  * Register styles in the app admin page
703  * @return array
704  */
705  public function styles() {
706  $styles = parent::styles();
707 
708  $styles[] = array(
709  'handle' => 'gravityview_settings',
710  'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ),
711  'version' => Plugin::$version,
712  'deps' => array(
713  'gform_admin',
714  'gaddon_form_settings_css',
715  'gform_tooltip',
716  'gform_font_awesome',
717  ),
718  'enqueue' => array(
719  array( 'admin_page' => array(
720  'app_settings',
721  ) ),
722  )
723  );
724 
725  return $styles;
726  }
727 
728  /**
729  * Add Settings link to GravityView menu
730  * @return void
731  */
732  public function create_app_menu() {
733  /**
734  * If not multisite, always show.
735  * If multisite and the plugin is network activated, show; we need to register the submenu page for the Network Admin settings to work.
736  * If multisite and not network admin, we don't want the settings to show.
737  * @since 1.7.6
738  */
739  $show_submenu = ( ! is_multisite() ) || is_main_site() || ( ! gravityview()->plugin->is_network_activated() ) || ( is_network_admin() && gravityview()->plugin->is_network_activated() );
740 
741  /**
742  * Override whether to show the Settings menu on a per-blog basis.
743  * @since 1.7.6
744  * @param bool $hide_if_network_activated Default: true
745  */
746  $show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu );
747 
748  if ( $show_submenu ) {
749  add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) );
750  }
751  }
752 
753  /**
754  * Gets the required indicator
755  * Gets the markup of the required indicator symbol to highlight fields that are required
756  *
757  * @param $field - The field meta.
758  *
759  * @return string - Returns markup of the required indicator symbol
760  */
761  public function get_required_indicator( $field ) {
762  return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>';
763  }
764 
765  /**
766  * Specify the settings fields to be rendered on the plugin settings page
767  *
768  * @return array
769  */
770  public function app_settings_fields() {
771  $default_settings = $this->defaults();
772 
773  $disabled_attribute = \GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
774 
775  $fields = array(
776  array(
777  'name' => 'gv_header',
778  'value' => '',
779  'type' => 'html',
780  ),
781  array(
782  'name' => 'license_key',
783  'required' => true,
784  'label' => __( 'License Key', 'gravityview' ),
785  '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' ) ),
786  'type' => 'edd_license',
787  'disabled' => ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ),
788  'data-pending-text' => __( 'Verifying license&hellip;', 'gravityview' ),
789  'default_value' => $default_settings['license_key'],
790  'class' => ( '' == $this->get( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key',
791  ),
792  array(
793  'name' => 'license_key_response',
794  'default_value' => $default_settings['license_key_response'],
795  'type' => 'hidden',
796  ),
797  array(
798  'name' => 'license_key_status',
799  'default_value' => $default_settings['license_key_status'],
800  'type' => 'hidden',
801  ),
802  array(
803  'name' => 'support-email',
804  'type' => 'text',
805  'validate' => 'email',
806  'default_value' => $default_settings['support-email'],
807  'label' => __( 'Support Email', 'gravityview' ),
808  'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ),
809  'class' => 'code regular-text',
810  ),
811  /**
812  * @since 1.15 Added Support Port support
813  */
814  array(
815  'name' => 'support_port',
816  'type' => 'radio',
817  'label' => __( 'Show Support Port?', 'gravityview' ),
818  'default_value' => $default_settings['support_port'],
819  'horizontal' => 1,
820  'choices' => array(
821  array(
822  'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ),
823  'value' => '1',
824  ),
825  array(
826  'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ),
827  'value' => '0',
828  ),
829  ),
830  '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>',
831  'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ),
832  ),
833  array(
834  'name' => 'no-conflict-mode',
835  'type' => 'radio',
836  'label' => __( 'No-Conflict Mode', 'gravityview' ),
837  'default_value' => $default_settings['no-conflict-mode'],
838  'horizontal' => 1,
839  'choices' => array(
840  array(
841  'label' => _x( 'On', 'Setting: On or off', 'gravityview' ),
842  'value' => '1',
843  ),
844  array(
845  'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ),
846  'value' => '0',
847  ),
848  ),
849  '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' ),
850  ),
851  /**
852  * @since 2.0 Added REST API
853  */
854  gravityview()->plugin->supports( Plugin::FEATURE_REST ) ?
855  array(
856  'name' => 'rest_api',
857  'type' => 'radio',
858  'label' => __( 'REST API', 'gravityview' ),
859  'default_value' => $default_settings['rest_api'],
860  'horizontal' => 1,
861  'choices' => array(
862  array(
863  'label' => _x( 'Enable', 'Setting: Enable or Disable', 'gravityview' ),
864  'value' => '1',
865  ),
866  array(
867  'label' => _x( 'Disable', 'Setting: Enable or Disable', 'gravityview' ),
868  'value' => '0',
869  ),
870  ),
871  'description' => __( 'Enable View and Entry access via the REST API? Regular per-View restrictions apply (private, password protected, etc.).', 'gravityview' ),
872  'tooltip' => '<p>' . esc_html__( 'If you are unsure, choose the Disable setting.', 'gravityview' ) . '</p>',
873  ) : array(),
874  array(
875  'name' => 'beta',
876  'type' => 'checkbox',
877  'label' => __( 'Become a Beta Tester', 'gravityview' ),
878  'default_value' => $default_settings['beta'],
879  'horizontal' => 1,
880  'choices' => array(
881  array(
882  'label' => _x( 'Show me beta versions if they are available.', 'gravityview' ),
883  'value' => '1',
884  'name' => 'beta',
885  ),
886  ),
887  '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' ),
888  ),
889  );
890 
891  $fields = array_filter( $fields, 'count' );
892 
893  /**
894  * @filter `gravityview_settings_fields` Filter the settings fields.
895  * @param array $fields The fields to filter.
896  * @deprecated Use `gravityview/settings/fields`.
897  */
898  $fields = apply_filters( 'gravityview_settings_fields', $fields );
899 
900  /**
901  * @filter `gravityview/settings/fields` Filter the settings fields.
902  * @param array $fields The fields to filter.
903  */
904  $fields = apply_filters( 'gravityview/settings/fields', $fields );
905 
906  /**
907  * Redux backward compatibility
908  * @since 1.7.4
909  */
910  foreach ( $fields as &$field ) {
911  $field['name'] = isset( $field['name'] ) ? $field['name'] : Utils::get( $field, 'id' );
912  $field['label'] = isset( $field['label'] ) ? $field['label'] : Utils::get( $field, 'title' );
913  $field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : Utils::get( $field, 'default' );
914  $field['description'] = isset( $field['description'] ) ? $field['description'] : Utils::get( $field, 'subtitle' );
915 
916  if ( $disabled_attribute ) {
917  $field['disabled'] = $disabled_attribute;
918  }
919 
920  if ( empty( $field['disabled'] ) ) {
921  unset( $field['disabled'] );
922  }
923  }
924 
925  $sections = array(
926  array(
927  'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), Plugin::$version ) ),
928  'fields' => $fields,
929  )
930  );
931 
932  // custom 'update settings' button
933  $button = array(
934  'class' => 'button button-primary button-hero',
935  'type' => 'save',
936  );
937 
938  if ( $disabled_attribute ) {
939  $button['disabled'] = $disabled_attribute;
940  }
941 
942  /**
943  * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page
944  * Extensions can tap in here to insert their own section and settings.
945  * <code>
946  * $sections[] = array(
947  * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ),
948  * 'fields' => $settings,
949  * );
950  * </code>
951  * @param array $extension_settings Empty array, ready for extension settings!
952  */
953  $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() );
954 
955  // If there are extensions, add a section for them
956  if ( ! empty( $extension_sections ) ) {
957 
958  if( $disabled_attribute ) {
959  foreach ( $extension_sections as &$section ) {
960  foreach ( $section['fields'] as &$field ) {
961  $field['disabled'] = $disabled_attribute;
962  }
963  }
964  }
965 
966  $k = count( $extension_sections ) - 1 ;
967  $extension_sections[ $k ]['fields'][] = $button;
968  $sections = array_merge( $sections, $extension_sections );
969  } else {
970  // add the 'update settings' button to the general section
971  $sections[0]['fields'][] = $button;
972  }
973 
974  return $sections;
975  }
976 
977  /**
978  * Updates app settings with the provided settings
979  *
980  * Same as the GFAddon, except it returns the value from update_option()
981  *
982  * @param array $settings - App settings to be saved
983  *
984  * @deprecated Use \GV\Addon_Settings::set or \GV\Addon_Settings::update
985  *
986  * @return boolean False if value was not updated and true if value was updated.
987  */
988  public function update_app_settings( $settings ) {
989  return $this->update( $settings );
990  }
991 
992  /**
993  * Sets a subset of settings.
994  *
995  * @param array|string An array of settings to update, or string (key) and $value to update one setting.
996  * @param mixed $value A value if $settings is string (key). Default: null.
997  */
998  public function set( $settings, $value = null ) {
999  if ( is_string( $settings ) ) {
1000  $settings = array( $settings => $value );
1001  }
1002  $settings = wp_parse_args( $settings, $this->all() );
1003  return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
1004  }
1005 
1006  /**
1007  * Updates settings.
1008  *
1009  * @param array $settings The settings array.
1010  *
1011  * @return boolean False if value was not updated and true if value was updated.
1012  */
1013  public function update( $settings ) {
1014  return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings );
1015  }
1016 
1017  /**
1018  * Register the settings field for the EDD License field type
1019  * @param array $field
1020  * @param bool $echo Whether to echo the
1021  *
1022  * @return string
1023  */
1024  protected function settings_edd_license( $field, $echo = true ) {
1025 
1026  if ( defined( 'GRAVITYVIEW_LICENSE_KEY' ) && GRAVITYVIEW_LICENSE_KEY ) {
1027  $field['input_type'] = 'password';
1028  }
1029 
1030  $text = $this->settings_text( $field, false );
1031 
1032  $activation = $this->License_Handler->settings_edd_license_activation( $field, false );
1033 
1034  $return = $text . $activation;
1035 
1036  if ( $echo ) {
1037  echo $return;
1038  }
1039 
1040  return $return;
1041  }
1042 
1043  /**
1044  * Allow pure HTML settings row
1045  *
1046  * @since 2.0.6
1047  *
1048  * @param array $field
1049  * @param bool $echo Whether to echo the
1050  *
1051  * @return string
1052  */
1053  protected function settings_html( $field, $echo = true ) {
1054 
1055  $return = \GV\Utils::get( $field, 'value', '' );
1056 
1057  if ( $echo ) {
1058  echo $return;
1059  }
1060 
1061  return $return;
1062  }
1063 
1064  /**
1065  * No <th> needed for pure HTML settings row
1066  *
1067  * @since 2.0.6
1068  *
1069  * @param array $field
1070  *
1071  * @return void
1072  */
1073  public function single_setting_row_html( $field ) {
1074  ?>
1075 
1076  <tr id="gaddon-setting-row-<?php echo esc_attr( $field['name'] ); ?>">
1077  <td colspan="2">
1078  <?php $this->single_setting( $field ); ?>
1079  </td>
1080  </tr>
1081 
1082  <?php
1083  }
1084 
1085  /**
1086  * Allow customizing the Save field parameters
1087  *
1088  * @param array $field
1089  * @param bool $echo
1090  *
1091  * @return string
1092  */
1093  public function settings_save( $field, $echo = true ) {
1094  $field['type'] = 'submit';
1095  $field['name'] = 'gform-settings-save';
1096  $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton';
1097  $field['value'] = Utils::get( $field, 'value', __( 'Update Settings', 'gravityview' ) );
1098 
1099  $output = $this->settings_submit( $field, false );
1100 
1101  ob_start();
1102  $this->app_settings_uninstall_tab();
1103  $output .= ob_get_clean();
1104 
1105  if ( $echo ) {
1106  echo $output;
1107  }
1108 
1109  return $output;
1110  }
1111 
1112  /**
1113  * Keep GravityView styling for `$field['description']`, even though Gravity Forms added support for it
1114  *
1115  * Converts `$field['description']` to `$field['gv_description']`
1116  * Converts `$field['subtitle']` to `$field['description']`
1117  *
1118  * @see \GV\Addon_Settings::single_setting_label Converts `gv_description` back to `description`
1119  * @see http://share.gravityview.co/P28uGp/2OIRKxog for image that shows subtitle vs description
1120  *
1121  * @since 1.21.5.2
1122  *
1123  * @param array $field
1124  *
1125  * @return void
1126  */
1127  public function single_setting_row( $field ) {
1128  $field['gv_description'] = Utils::get( $field, 'description' );
1129  $field['description'] = Utils::get( $field, 'subtitle' );
1131  }
1132 
1133  /**
1134  * The same as the parent, except added support for field descriptions
1135  * @inheritDoc
1136  * @param $field array
1137  */
1138  public function single_setting_label( $field ) {
1140  if ( $description = Utils::get( $field, 'gv_description' ) ) {
1141  echo '<span class="description">'. $description .'</span>';
1142  }
1143  }
1144 
1145  /**
1146  * Check for the `gravityview_edit_settings` capability before saving plugin settings.
1147  * Gravity Forms says you're able to edit if you're able to view settings. GravityView allows two different permissions.
1148  *
1149  * @since 1.15
1150  * @return void
1151  */
1152  public function maybe_save_app_settings() {
1153 
1154  if ( $this->is_save_postback() ) {
1155  if ( ! \GVCommon::has_cap( 'gravityview_edit_settings' ) ) {
1156  $_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't
1157  \GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) );
1158  return;
1159  }
1160  }
1162  }
1163 
1164  /**
1165  * When the settings are saved, make sure the license key matches the previously activated key
1166  *
1167  * @return array settings from parent::get_posted_settings(), with `license_key_response` and `license_key_status` potentially unset
1168  */
1169  public function get_posted_settings() {
1170  $posted_settings = parent::get_posted_settings();
1171 
1172  $local_key = Utils::get( $posted_settings, 'license_key' );
1173  $response_key = Utils::get( $posted_settings, 'license_key_response/license_key' );
1174 
1175  // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response),
1176  // then we assume it's changed. If it's changed, unset the status and the previous response.
1177  if ( $local_key !== $response_key ) {
1178  unset( $posted_settings['license_key_response'] );
1179  unset( $posted_settings['license_key_status'] );
1180  \GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) );
1181  }
1182  return $posted_settings;
1183  }
1184 }
get_uninstall_reasons()
Get an array of reasons why the plugin might be uninstalled.
$url
Definition: post_image.php:25
all()
Get all the settings.
If this file is called directly, abort.
gravityview_get_floaty( $height=87, $css_class=null)
Get an image of our intrepid explorer friend.
app_settings_uninstall_tab()
if(empty( $value)) $user
uninstall()
Uninstall all traces of GravityView.
single_setting_row_html( $field)
No needed for pure HTML settings row.
settings_html( $field, $echo=true)
Allow pure HTML settings row.
is_save_postback()
Check whether GravityView is being saved.
app_settings_icon()
Prevent displaying of any icon.
settings_save( $field, $echo=true)
Allow customizing the Save field parameters.
settings_edd_license( $field, $echo=true)
Register the settings field for the EDD License field type.
modify_app_settings_menu_title( $setting_tabs)
Change the settings page header title to "GravityView".
create_app_menu()
Add Settings link to GravityView menu.
gravityview()
Definition: _stubs.php:26
uninstall_form()
Display a feedback form when the plugin is uninstalled.
get( $key, $default=null)
Retrieve a setting.
get_app_settings()
Get all settings.
styles()
Register styles in the app admin page.
current_user_can_any( $caps)
Prevent uninstall tab from being shown by returning false for the uninstall capability check...
scale description p description
single_setting_label( $field)
The same as the parent, except added support for field descriptions .
app_settings_fields()
Specify the settings fields to be rendered on the plugin settings page.
single_setting_row( $field)
Keep GravityView styling for `$field[&#39;description&#39;]`, even though Gravity Forms added support for it...
defaults()
Default settings.
const GRAVITYVIEW_FILE
Full path to the GravityView file "GRAVITYVIEW_FILE" "./gravityview.php".
Definition: gravityview.php:31
get_required_indicator( $field)
Gets the required indicator Gets the markup of the required indicator symbol to highlight fields that...
add_network_menu()
Add global Settings page for Multisite.
scripts()
Add tooltip script to app settings page.
get_app_setting( $setting_name)
Retrieve a setting.
app_settings_title()
The Settings title.
static add_notice( $notice=array())
Add a notice to be displayed in the admin.
init_admin()
Run actions when initializing admin.
update( $settings)
Updates settings.
If this file is called directly, abort.
scale description ul
as_html( $field, $echo=true)
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gv form field wrapper
update_app_settings( $settings)
Updates app settings with the provided settings.
maybe_save_app_settings()
Check for the gravityview_edit_settings capability before saving plugin settings. ...
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
static getSetting( $key)
Get the setting for GravityView by name.
init_ajax()
Load license handler in admin-ajax.php.
_load_license_handler()
Make sure the license handler is available.
license_key_notice()
Display a notice if the plugin is inactive.
get_posted_settings()
When the settings are saved, make sure the license key matches the previously activated key...
get_license_handler()
Allow public access to the GV class.
get_default_settings()
Default settings.
settings_submit( $field, $echo=true)
$field
Definition: gquiz_grade.php:11
$description
Definition: post_image.php:28
$title