-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
1505 lines (1265 loc) · 47.1 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use Gravity_Forms\Gravity_Forms\Settings\Settings;
use \Gravity_Forms\Gravity_Forms\License;
use \Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints\GF_Setup_Wizard_Endpoint_Save_Prefs;
class_exists( 'GFForms' ) || die();
/**
* Class GFSettings
*
* Generates the Gravity Forms settings page
*/
class GFSettings {
/**
* Stores the current instance of the Settings renderer.
*
* @since 2.5
*
* @var false|Settings
*/
private static $_settings_renderer = false;
/**
* Settings pages associated with add-ons
*
* @since Unknown
* @access public
*
* @var array $addon_pages
*/
public static $addon_pages = array();
/**
* Used to hold the addon that has been uninstalled.
*
* @since 2.5
*
* @var string $uninstalled_addon
*/
private static $uninstalled_addon;
/**
* Adds a settings page to the Gravity Forms settings.
*
* @since Unknown
* @access public
*
* @uses GFSettings::$addon_pages
*
* @param string|array $name The settings page slug.
* @param string|array $handler The callback function to run for this settings page.
* @param string $icon_path The path to the icon for the settings tab. @deprecated.
*/
public static function add_settings_page( $name, $handler, $icon_path = '' ) {
if ( ! empty( $icon_path ) ) {
_deprecated_argument( __METHOD__, '2.5', '$icon_path has been deprecated in favor of passing a dashicons string via $name[\'icon\']' );
}
$title = '';
$icon = 'gform-icon--cog';
// if name is an array, assume that an array of args is passed.
if ( is_array( $name ) ) {
/**
* Extracting args.
*
* @var string $name
* @var string $title
* @var string $tab_label
* @var string|array $handler
* @var string $icon
*/
extract(
wp_parse_args(
$name, array(
'name' => '',
'title' => '',
'tab_label' => '',
'handler' => false,
'icon' => 'gform-icon--cog',
)
)
);
}
if ( ! isset( $tab_label ) || ! $tab_label ) {
$tab_label = $name;
}
/**
* Adds additional actions after settings pages are registered.
*
* @since Unknown
*
* @param string|array $handler The callback function being run.
*/
add_action( 'gform_settings_' . str_replace( ' ', '_', $name ), $handler );
self::$addon_pages[ $name ] = array( 'name' => $name, 'title' => $title, 'tab_label' => $tab_label, 'icon' => $icon );
}
/**
* Determines the content displayed on the Gravity Forms settings page.
*
* @since Unknown
* @access public
*
* @uses GFSettings::get_subview()
* @uses GFSettings::gravityforms_settings_page()
* @uses GFSettings::settings_uninstall_page()
* @uses GFSettings::page_header()
* @uses GFSettings::page_footer()
*
* @return void
*/
public static function settings_page() {
$subview = self::get_subview();
switch ( $subview ) {
case 'settings':
self::gravityforms_settings_page();
break;
case 'recaptcha':
self::recaptcha_page();
break;
case 'uninstall':
self::settings_uninstall_page();
break;
default:
self::page_header();
/**
* Fires in the settings page depending on which page of the settings page you are in (the Subview).
*
* @since Unknown
*
* @param mixed $subview The sub-section of the main Form's settings
*/
do_action( 'gform_settings_' . str_replace( ' ', '_', $subview ) );
self::page_footer();
}
}
/**
* Displays the Gravity Forms uninstall page.
*
* @since Unknown
* @access public
*
* @used-by GFSettings::settings_page()
* @uses GFSettings::page_header()
* @uses GFCommon::current_user_can_any()
* @uses GFFormsModel::drop_tables()
* @uses GFCommon::delete_directory()
* @uses GFFormsModel::get_upload_root()
* @uses GFCommon::current_user_can_any()
* @uses GFSettings::page_footer()
*/
public static function settings_uninstall_page() {
self::page_header( __( 'Uninstall Gravity Forms', 'gravityforms' ), '' );
if ( isset( $_POST['uninstall'] ) ) {
check_admin_referer( 'gform_uninstall', 'gform_uninstall_nonce' );
if ( ! GFCommon::current_user_can_uninstall() ) {
die( esc_html__( "You don't have adequate permission to uninstall Gravity Forms.", 'gravityforms' ) );
}
/**
* Used to perform any cleanup tasks when the uninstall button has been clicked on the Forms > Settings > Uninstall page.
*
* @since 2.6.9
*/
do_action( 'gform_uninstalling' );
// Background tasks cleanup moved to \Gravity_Forms\Gravity_Forms\Async\GF_Background_Process_Service_Provider().
// Removing cron task
wp_clear_scheduled_hook( 'gravityforms_cron' );
// Dropping all tables
RGFormsModel::drop_tables();
// Removing options
delete_option( 'rg_form_version' );
delete_option( 'rg_gforms_disable_css' );
delete_option( 'rg_gforms_enable_html5' );
delete_option( 'rg_gforms_captcha_public_key' );
delete_option( 'rg_gforms_captcha_private_key' );
delete_option( 'rg_gforms_captcha_type' );
delete_option( 'rg_gforms_message' );
delete_option( 'rg_gforms_currency' );
delete_option( 'rg_gforms_enable_akismet' );
delete_option( 'gf_dismissed_upgrades' );
delete_option( 'gf_db_version' );
delete_option( 'gf_previous_db_version' );
delete_option( 'gf_upgrade_lock' );
delete_option( 'gf_submissions_block' );
delete_option( 'gf_imported_file' );
delete_option( 'gf_imported_theme_file' );
delete_option( 'gf_rest_api_db_version' );
delete_option( 'gform_api_count' );
delete_option( 'gform_email_count' );
delete_option( 'gform_enable_toolbar_menu' );
delete_option( 'gform_enable_logging' );
delete_option( 'gform_pending_installation' );
delete_option( 'gform_version_info' );
delete_option( 'gform_enable_noconflict' );
delete_option( 'gform_enable_background_updates' );
delete_option( 'gform_sticky_admin_messages' );
delete_option( 'gform_upgrade_status' );
delete_option( 'gform_custom_choices' );
delete_option( 'gform_recaptcha_keys_status' );
delete_option( 'gform_upload_page_slug' );
delete_option( 'gravityformsaddon_gravityformswebapi_version' );
delete_option( 'gravityformsaddon_gravityformswebapi_settings' );
// Remove setup wizard data.
GFForms::get_service_container()->get( \Gravity_Forms\Gravity_Forms\Setup_Wizard\GF_Setup_Wizard_Service_Provider::SAVE_PREFS_ENDPOINT )->remove_setup_data();
// Removes license key
GFFormsModel::save_key( '' );
// Removing gravity forms upload folder
GFCommon::delete_directory( RGFormsModel::get_upload_root() );
// Delete Logging settings and logging files
gf_logging()->delete_settings();
gf_logging()->delete_log_files();
// Deactivating plugin
$plugin = 'gravityforms/gravityforms.php';
deactivate_plugins( $plugin );
update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
?>
<div class="updated fade gf-notice notice-success" role="alert"><?php echo sprintf( esc_html__( 'Gravity Forms has been successfully uninstalled. It can be re-activated from the %splugins page%s.', 'gravityforms' ), "<a href='plugins.php'>", '</a>' ) ?></div>
<?php
return;
}
self::uninstall_addon_message();
?>
<div class="gform-settings-panel">
<header class="gform-settings-panel__header">
<h4 class="gform-settings-panel__title"><?php esc_html_e( 'Uninstall Gravity Forms', 'gravityforms' ); ?></h4>
</header>
<div class="gform-settings-panel__content">
<p class="alert error">
<?php esc_html_e('This operation deletes ALL Gravity Forms settings. If you continue, you will NOT be able to retrieve these settings.', 'gravityforms'); ?>
</p>
<form action="" method="post">
<?php
if ( GFCommon::current_user_can_uninstall() ) {
wp_nonce_field( 'gform_uninstall', 'gform_uninstall_nonce' );
$uninstall_button = sprintf(
'<input type="submit" name="uninstall" class="button red" value="%1$s" onclick="return confirm( \'%2$s\' );" onkeypress="return confirm( \'%2$s\' );" />',
esc_attr__( 'Uninstall Gravity Forms', 'gravityforms' ),
esc_js( __( "Warning! ALL Gravity Forms data, including form entries will be deleted. This cannot be undone. 'OK' to delete, 'Cancel' to stop", 'gravityforms' ) )
);
/**
* Allows for the modification of the Gravity Forms uninstall button.
*
* @since Unknown
*
* @param string $uninstall_button The HTML of the uninstall button.
*/
echo apply_filters( 'gform_uninstall_button', $uninstall_button );
}
?>
</form>
</div>
</div>
<?php
self::uninstall_addons();
self::page_footer();
}
/**
* Handles the uninstallation process for addons from the settings page.
*
* @since 2.5
*/
private static function uninstall_addons() {
$uninstallable_addons = GFAddOn::get_registered_addons( true );
// Display the complete list of addons to install.
if ( ! rgpost( 'uninstall_addon' ) ) {
GFAddOn::addons_for_uninstall( $uninstallable_addons );
return;
}
// Uninstall the addon and remove it from the list of installed addons on page reload.
check_admin_referer( 'uninstall', 'gf_addon_uninstall' );
foreach ( $uninstallable_addons as $key => $addon ) {
if ( rgpost( 'addon' ) !== $addon->get_short_title() ) {
continue;
}
unset( $uninstallable_addons[ $key ] );
$addon->uninstall_addon();
break;
}
GFAddOn::addons_for_uninstall( array_values( $uninstallable_addons ) );
}
/**
* Renders the uninstall message when an addon is uninstalled.
*
* @since 2.5
*
*/
private static function uninstall_addon_message() {
if ( isset( self::$uninstalled_addon ) ) {
?>
<div class="alert success"><?php echo sprintf( esc_html__( '%s uninstalled. It can be re-activated from the %splugins page%s.', 'gravityforms' ), self::$uninstalled_addon ,"<a href='plugins.php'>", '</a>' ) ?></div>
<?php
}
}
// # PLUGIN SETTINGS -----------------------------------------------------------------------------------------------
/**
* Displays the main Gravity Forms settings page.
*
* @since Unknown
* @access public
* @global $wpdb
*/
public static function gravityforms_settings_page() {
if ( ! GFCommon::ensure_wp_version() ) {
return;
}
self::page_header();
wp_enqueue_style( 'gform_admin' );
// Initialize Settings renderer.
if ( ! self::get_settings_renderer() ) {
self::initialize_plugin_settings();
}
self::get_settings_renderer()->render();
self::page_footer();
}
/**
* Determine whether Orbital should be the default theme.
*
* @since 2.7.15
*
* @return bool
*/
public static function is_orbital_default() {
if ( 'orbital' == get_option( 'rg_gforms_default_theme' ) ) {
return true;
}
// If there is no default theme saved, and if this is an old installation, Gravity Theme should be the default.
if ( version_compare( get_option( 'rg_form_original_version', '1.0.0' ), '2.7.14.2', '<' ) ) {
return false;
}
return true;
}
/**
* Prepare Plugin Settings fields.
*
* @since 2.5
*
* @return array
*/
private static function plugin_settings_fields() {
$license_section_description = esc_html__( 'A valid license key is required for access to automatic plugin upgrades and product support.', 'gravityforms' );
$is_hidden = false;
if ( ! is_main_site() && GFCommon::is_network_active() ) {
$is_hidden = true;
$license_section_description = esc_html__( 'License key is managed by the administrator of this network', 'gravityforms' );
}
$fields = array(
'license_key' => array(
'title' => esc_html__( 'Support License Key', 'gravityforms' ),
'class' => 'gform-settings-panel--full',
'description' => $license_section_description,
'fields' => array(
array(
'name' => 'license_key',
'label' => esc_html__( 'Paste Your License Key Here', 'gravityforms' ),
'type' => 'text',
'input_type' => 'password',
'callback' => array( 'GFSettings', 'license_key_render_callback' ),
'class' => 'gform-admin-input',
'validation_callback' => array( 'GFSettings', 'license_key_validation_callback' ),
'hidden' => $is_hidden,
'after_input' => function () {
/**
* @var License\GF_License_API_Connector $license_connector
*/
$license_connector = GFForms::get_service_container()->get( License\GF_License_Service_Provider::LICENSE_API_CONNECTOR );
$is_save_postback = self::get_settings_renderer()->is_save_postback();
$license_key = $is_save_postback ? rgpost( '_gform_setting_license_key' ) : GFCommon::get_key();
if ( empty( $license_key ) ) {
delete_transient( 'rg_gforms_registration_error' );
return '';
}
$license_info = $license_connector->check_license( trim( $license_key ), ! $is_save_postback );
$usability = $license_info->get_usability();
$license_key_alert = sprintf(
'<div class="alert gforms_note_%s">%s %s</div>',
$usability,
$is_save_postback && ! $license_info->can_be_used() ? __( 'Your license key was not updated. ', 'gravityforms' ) : null,
License\GF_License_Statuses::get_message_for_code( $license_info->get_status() )
);
delete_transient( 'rg_gforms_registration_error' );
return $license_key_alert;
},
'feedback_callback' => function () {
$license_key = GFCommon::get_key();
if ( empty( $license_key ) ) {
return License\GF_License_Statuses::USABILITY_ALLOWED;
}
/**
* @var License\GF_License_API_Connector $license_connector
*/
$license_connector = GFForms::get_service_container()->get( License\GF_License_Service_Provider::LICENSE_API_CONNECTOR );
$license_info = $license_connector->check_license();
return $license_info->get_usability();
},
'save_callback' => function( $field, $value ) {
// Remove non-alphanumeric characters.
$value = preg_replace( '/[^a-zA-Z0-9]/', '', $value );
if ( isset( $_POST['_gform_setting_license_key'] ) ) {
GFFormsModel::save_key( $value );
}
return $value;
},
),
),
),
'license_key_details' => array(
'id' => 'section_license_key_details',
'title' => __( 'Your License Details', 'gravityforms' ),
'class' => 'gform-settings-panel--no-padding gform-settings-panel--license-details',
'fields' => array(
array(
'name' => 'license_key_details',
'type' => 'html',
'html' => array( 'GFSettings', 'license_key_details_callback' ),
),
),
),
'currency' => array(
'id' => 'section_currency',
'title' => esc_html__( 'Default Currency', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'currency',
'description' => esc_html__( 'Select the default currency for your forms. This is used for product fields, credit card fields and others.', 'gravityforms' ),
'type' => 'select',
'choices' => RGCurrency::get_grouped_currency_options(),
'enhanced_ui' => true,
'after_select' => self::currency_message_callback(),
'save_callback' => function( $field, $value ) {
update_option( 'rg_gforms_currency', $value );
return $value;
},
),
),
),
'logging' => array(
'id' => 'section_enable_logging',
'title' => esc_html__( 'Logging', 'gravityforms' ),
'description' => esc_html__( 'Enable if you would like logging within Gravity Forms. Logging allows you to easily debug the inner workings of Gravity Forms to solve any possible issues. ', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'enable_logging',
'type' => 'toggle',
'toggle_label' => esc_html__( 'Enable Logging', 'gravityforms' ),
'save_callback' => function( $field, $value ) {
if ( (bool) $value ) {
GFSettings::enable_logging();
} else {
GFSettings::disable_logging();
}
return $value;
},
),
),
),
);
$fields['default_theme'] = array(
'id' => 'section_default_theme',
'title' => esc_html__( 'Default Form Theme', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'default_theme',
'type' => 'select',
'choices' => array(
array(
'label' => esc_html__( 'Gravity Forms 2.5 Theme', 'gravityforms' ),
'value' => 'gravity-theme',
'default' => ! self::is_orbital_default(),
),
array(
'label' => esc_html__( 'Orbital Theme (Recommended)', 'gravityforms' ),
'value' => 'orbital',
'default' => self::is_orbital_default(),
),
),
'description' => esc_html__( 'This theme will be used by default everywhere forms are embedded on your site.', 'gravityforms' ) . ' <a href="https://docs.gravityforms.com/block-themes-and-style-settings/" target="_blank" aria-label="' . esc_html__( 'Learn more about form theme and style settings', 'gravityforms' ) . '">' . esc_html__( 'Learn more about form theme and style settings.', 'gravityforms' ) . '</a>',
'save_callback' => function( $field, $value ) {
update_option( 'rg_gforms_default_theme', $value );
return $value;
},
),
),
);
$fields['toolbar'] = array(
'id' => 'section_enable_toolbar',
'title' => esc_html__( 'Toolbar Menu', 'gravityforms' ),
'description' => esc_html__( 'Enable to display the forms menu in the WordPress top toolbar. The forms menu will display the ten forms recently opened in the form editor.', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'enable_toolbar',
'type' => 'toggle',
'toggle_label' => esc_html__( 'Enable Toolbar Menu', 'gravityforms' ),
'save_callback' => function( $field, $value ) {
update_option( 'gform_enable_toolbar_menu', (bool) $value );
return $value;
},
),
),
);
$fields['background_updates'] = array(
'id' => 'section_enable_background_updates',
'title' => esc_html__( 'Automatic Background Updates', 'gravityforms' ),
'description' => esc_html__( 'Enable to allow Gravity Forms to download and install bug fixes and security updates automatically in the background. Requires a valid license key.', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'enable_background_updates',
'type' => 'toggle',
'toggle_label' => esc_html__( 'Enable Automatic Background Updates', 'gravityforms' ),
'save_callback' => function( $field, $value ) {
update_option( 'gform_enable_background_updates', (bool) $value );
return $value;
},
),
),
);
$fields['no_conflict_mode'] = array(
'id' => 'section_conflict_mode',
'title' => esc_html__( 'No Conflict Mode', 'gravityforms' ),
'description' => esc_html__( 'Enable to prevent extraneous scripts and styles from being printed on a Gravity Forms admin pages, reducing conflicts with other plugins and themes.', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'enable_noconflict',
'type' => 'toggle',
'toggle_label' => esc_html__( 'No Conflict Mode', 'gravityforms' ),
'save_callback' => function( $field, $value ) {
update_option( 'gform_enable_noconflict', (bool) $value );
return $value;
},
),
),
);
$fields['akismet'] = array(
'id' => 'section_enable_akismet',
'title' => esc_html__( 'Akismet Integration', 'gravityforms' ),
'description' => esc_html__( 'Protect your form entries from spam using Akismet.', 'gravityforms' ),
'class' => 'gform-settings-panel--half',
'dependency' => array( 'GFCommon', 'has_akismet' ),
'fields' => array(
array(
'name' => 'enable_akismet',
'type' => 'toggle',
'toggle_label' => esc_html__( 'Enable Akismet Integration', 'gravityforms' ),
'default_value' => true,
'save_callback' => function( $field, $value ) {
update_option( 'rg_gforms_enable_akismet', (bool) $value );
return $value;
},
),
),
);
$fields['telemetry'] = array(
'id' => 'section_enable_telemetry_collection',
'title' => esc_html__( 'Data Collection', 'gravityforms' ),
'description' => sprintf( __( 'We love improving the form building experience for everyone in our community. By enabling data collection, you can help us learn more about how our customers use Gravity Forms. %1$sLearn more...%2$s', 'gravityforms' ), '<a target="_blank" href="https://docs.gravityforms.com/about-additional-data-collection/">', '</a>' ),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'rg_gforms_dataCollection',
'type' => 'toggle',
'default_value' => get_option( 'rg_gforms_dataCollection', 0 ),
'toggle_label' => esc_html__( 'Enable Data Collection', 'gravityforms' ),
'save_callback' => function( $field, $value ) {
update_option( 'rg_gforms_dataCollection', (bool) $value ? 1 : 0 );
return $value;
},
),
),
);
/**
* Allows forcing the display of the disable CSS setting.
*
* @since 2.8
*
* @param bool $gform_display_disable_css_setting Indicates if the disable CSS setting should be displayed or not.
*/
$gform_display_disable_css_setting = apply_filters( 'gform_display_disable_css_setting', (bool) get_option( 'rg_gforms_disable_css' ) );
if ( $gform_display_disable_css_setting ) {
$fields['css'] = array(
'id' => 'section_default_css',
'title' => esc_html__( 'Output Default CSS', 'gravityforms' ),
'description' => sprintf(
esc_html__( 'Enable this option to output the default form CSS. Disable it if you plan to create your own CSS in a child theme. Note: after Gravity Forms 2.8, this setting will no longer appear on the settings page. If you previously had it enabled, you will need to use the %sgform_disable_css%s filter to disable it.', 'gravityforms' ),
'<a href="https://docs.gravityforms.com/gform_disable_css/" target="_blank">',
'</a>'
),
'class' => 'gform-settings-panel--half',
'fields' => array(
array(
'name' => 'disable_css',
'type' => 'toggle',
'toggle_label' => esc_html__( 'Disable CSS', 'gravityforms' ),
'save_callback' => function( $field, $value ) {
update_option( 'rg_gforms_disable_css', ! (bool) $value );
return $value;
},
),
),
);
}
// Check if user has hidden license details in the installation wizard.
$hide_license_option = get_option( 'rg_gforms_' . GF_Setup_Wizard_Endpoint_Save_Prefs::PARAM_HIDE_LICENSE, false );
// Cast license option to bool.
if ( $hide_license_option === 'true' ) {
$hide_license_option = true;
}
if ( $hide_license_option === 'false' ) {
$hide_license_option = false;
}
$display_license_details = ! $hide_license_option;
/**
* Allows display of the license details panel to be disabled.
*
* @since 2.5.17
*
* @param bool $display_license_details Indicates if the license details panel should be displayed.
*/
if ( ! apply_filters( 'gform_settings_display_license_details', $display_license_details ) ) {
unset( $fields['license_key_details'] );
}
/**
* Allows the plugin settings fields to be overridden before they are displayed.
*
* @since 2.5.17
*
* @param array $fields The plugin settings fields.
*/
return array_values( apply_filters( 'gform_plugin_settings_fields', $fields ) );
}
public static function license_key_details_callback() {
$key = GFCommon::get_key();
$empty_string = '<div class="gform-p-16">' . __( 'Please enter a valid license key to see details.', 'gravityforms' ) . '</div>';
if ( empty( $key ) ) {
return $empty_string;
}
/**
* @var License\GF_License_API_Connector $license_connector
*/
$license_connector = GFForms::get_service_container()->get( License\GF_License_Service_Provider::LICENSE_API_CONNECTOR );
$license_info = $license_connector->check_license( $key );
if ( ! $license_info->can_be_used() ) {
return $empty_string;
}
$cta = $license_info->get_cta();
$days_left_header = $cta['type'] === 'text' ? __( 'Days Left', 'gravityforms' ) : '';
ob_start();
?>
<table class="gform-table gform-table--responsive gform-table--no-outer-border gform-table--license-ui">
<thead>
<tr>
<th scope="col"><?php esc_html_e( 'License Type', 'gravityforms' ); ?></th>
<th scope="col"><?php esc_html_e( 'License Status', 'gravityforms' ); ?></th>
<th scope="col"><?php esc_html_e( 'Purchase Date', 'gravityforms' ); ?></th>
<th scope="col"><?php esc_html_e( 'License Activations', 'gravityforms' ); ?></th>
<th scope="col"><?php echo esc_html( $license_info->renewal_text() ); ?></th>
<th scope="col"><?php echo esc_html( $days_left_header ); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td data-header="<?php esc_html_e( 'License Type', 'gravityforms' ); ?>">
<p><?php echo esc_html( trim( str_replace( 'Gravity Forms', '', $license_info->get_data_value( 'product_name' ) ) ) ); ?></p>
</td>
<td data-header="<?php esc_html_e( 'License Status', 'gravityforms' ); ?>">
<p>
<?php
$status_class = $license_info->display_as_valid() ? 'active' : 'error';
$status_label = $license_info->get_display_status();
?>
<span class="gform-status-indicator gform-status-indicator--size-sm gform-status-indicator--theme-cosmos gform-status--no-hover gform-status--static gform-status--no-icon gform-status--<?php echo esc_html( $status_class ); ?>">
<span class="gform-status-indicator-status gform-typography--weight-medium gform-typography--size-text-xs">
<?php echo esc_html( $status_label ); ?>
</span>
</span>
</p>
</td>
<td data-header="<?php esc_attr_e( 'Purchase Date', 'gravityforms' ); ?>">
<p><?php echo esc_html( gmdate( 'M d, Y', strtotime( $license_info->get_data_value( 'date_created' ) ) ) ); ?></p>
</td>
<td data-header="<?php esc_attr_e( 'License Activations', 'gravityforms' ); ?>">
<p>
<?php $activation_class = $license_info->max_seats_exceeded() ? 'gform-c-error-text' : ''; ?>
<span class="<?php echo esc_attr( $activation_class ); ?>">
<?php echo esc_html( sprintf( '%s of %s', $license_info->get_data_value( 'active_sites' ), $license_info->get_data_value( 'max_sites' ) ) ); ?>
</span>
</p>
</td>
<td data-header="<?php echo esc_attr( $license_info->renewal_text() ); ?>">
<p><?php echo esc_html( $license_info->renewal_date() ); ?></p>
</td>
<td data-header="<?php echo esc_attr( $days_left_header ); ?>">
<p>
<?php if ( $cta['type'] === 'button' ) : ?>
<a
class="gform-button gform-button--white gform-button--icon-leading gform-button--size-xs"
href="<?php echo esc_url( $cta['link'] ); ?>"
target="_blank"
rel="noopener"
>
<i class="gform-button__icon gform-icon gform-icon--<?php echo esc_attr( $cta['class'] ); ?>"></i>
<?php echo esc_html( $cta['label'] ); ?>
</a>
<?php elseif ( $cta['type'] === 'text' ) : ?>
<?php echo esc_html( $cta['content'] ); ?>
<?php endif; ?>
</p>
</td>
</tr>
</tbody>
</table>
<?php
return ob_get_clean();
}
/**
* Callback to output any additional markup after the currency select markup.
*
* @since 2.5
*
* @return false|string
*/
public static function currency_message_callback() {
// Start output buffer to capture any echoed output.
ob_start();
/**
* Allows third-party code to add a message after the Currency setting markup.
*
* @since Unknown
* @since 2.5 - Moved to currency message callback.
*
* @param string The default message.
*/
do_action( 'gform_currency_setting_message', '' );
$output = ob_get_clean();
// Message was echoed, return it.
if ( ! empty( $output ) ) {
return $output;
}
return '';
}
/**
* Render the License Key Field as a callback.
*
* Callback is used so that the gform_settings_key_field filter can be retained.
*
* @since 2.5
*
* @param object $field The Field Object for the rendered input.
*
* @return string
*/
public static function license_key_render_callback( $field ) {
$html = apply_filters( 'gform_settings_key_field', $field->markup() );
return $html;
}
/**
* Custom validation callback for the License Key Field.
*
* Callback is used so that we can skip validation if the License Key field is null.
*
* @since 2.5
*
* @param object $field The Field Object for the rendered input.
* @param mixed $value The current posted field value.
*
* @return void
*/
public static function license_key_validation_callback( $field, $value ) {
if ( is_null( $value ) ) {
return;
}
$field->do_validation( $value );
}
/**
* Initialize Plugin Settings fields renderer.
*
* @since 2.5
*/
public static function initialize_plugin_settings() {
require_once( GFCommon::get_base_path() . '/tooltips.php' );
$initial_values = array(
'license_key' => GFCommon::get_key(),
'default_theme' => get_option( 'rg_gforms_default_theme', 'gravity-theme' ),
'currency' => GFCommon::get_currency(),
'disable_css' => ! (bool) get_option( 'rg_gforms_disable_css' ),
'enable_noconflict' => (bool) get_option( 'gform_enable_noconflict' ),
'enable_akismet' => (bool) get_option( 'rg_gforms_enable_akismet', true ),
'enable_background_updates' => (bool) get_option( 'gform_enable_background_updates' ),
'enable_toolbar' => (bool) get_option( 'gform_enable_toolbar_menu' ),
'enable_logging' => (bool) get_option( 'gform_enable_logging' ),
);
$renderer = new Settings(
array(
'fields' => self::plugin_settings_fields(),
'header' => array(
'icon' => 'fa fa-gear',
'title' => esc_html__( 'Settings: General', 'gravityforms' ),
),
'input_name_prefix' => '_gform_setting',
'capability' => 'gravityforms_edit_settings',
'initial_values' => $initial_values,
'save_callback' => function( $values ) {
GFCommon::cache_remote_message();
},
)
);
self::set_settings_renderer( $renderer );
// Process save callback.
if ( self::get_settings_renderer()->is_save_postback() ) {
self::get_settings_renderer()->process_postback();
}
}
// # reCAPTCHA SETTINGS --------------------------------------------------------------------------------------------
/**
* Display reCAPTCHA Settings page.
*
* @since 2.5
*/
private static function recaptcha_page() {
if ( ! GFCommon::ensure_wp_version() ) {
return;
}
self::page_header();
wp_enqueue_style( 'gform_admin' );
// Initialize Settings renderer.
if ( ! self::get_settings_renderer() ) {
self::initialize_recaptcha_settings();
}
self::get_settings_renderer()->render();
self::page_footer();
}
/**
* Initialize reCAPTCHA Settings renderer.
*
* @since 2.5
*/
public static function initialize_recaptcha_settings() {
require_once( GFCommon::get_base_path() . '/tooltips.php' );
$renderer = new Settings(
array(
'fields' => array(
array(
'id' => 'recpatcha',
'title' => esc_html__( 'reCAPTCHA Settings', 'gravityforms' ),
'description' => sprintf(
'%s <strong>%s</strong> %s <a href="https://www.google.com/recaptcha/admin/create" target="_blank">%s</a>',
esc_html__( 'Gravity Forms integrates with reCAPTCHA, a free CAPTCHA service that uses an advanced risk analysis engine and adaptive challenges to keep automated software from engaging in abusive activities on your site. ', 'gravityforms' ),
esc_html__( 'Please note, only v2 keys are supported and checkbox keys are not compatible with invisible reCAPTCHA.', 'gravityforms' ),
esc_html__( 'These settings are required only if you decide to use the reCAPTCHA field.', 'gravityforms' ),
esc_html__( 'Get your reCAPTCHA Keys.', 'gravityforms' )
),
'class' => 'gform-settings-panel--full',
'fields' => array(
array(
'name' => 'public_key',
'label' => esc_html__( 'Site Key', 'gravityforms' ),
'tooltip' => gform_tooltip( 'settings_recaptcha_public', null, true ),
'type' => 'text',
'feedback_callback' => function( $value ) {