-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_settings.php
More file actions
1654 lines (1462 loc) · 53.4 KB
/
form_settings.php
File metadata and controls
1654 lines (1462 loc) · 53.4 KB
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
if ( ! class_exists( 'GFForms' ) ) {
die();
}
use Gravity_Forms\Gravity_Forms\Settings\Settings;
/**
* Class GFFormSettings
*
* Handles the form settings page.
*
* @since Unknown
*/
class GFFormSettings {
/**
* Stores the current instance of the Settings renderer.
*
* @since 2.5
*
* @var false|Gravity_Forms\Gravity_Forms\Settings\Settings
*/
private static $_settings_renderer = false;
/**
* Determines which form settings page to display.
*
* @since Unknown
*
* @return void
*/
public static function form_settings_page() {
$subview = rgget( 'subview' ) ? rgget( 'subview' ) : 'settings';
switch ( $subview ) {
case 'settings':
self::form_settings_ui();
break;
case 'confirmation':
require_once( 'includes/class-confirmation.php' );
self::page_header( __( 'Confirmations', 'gravityforms' ) );
GF_Confirmation::render_page();
self::page_footer();
break;
case 'notification':
self::notification_page();
break;
case 'personal-data':
self::personal_data_page();
break;
default:
/**
* Fires when the settings page view is determined
*
* Used to add additional pages to the form settings
*
* @since Unknown
*
* @param string $subview Used to complete the action name, allowing an additional subview to be detected
*/
do_action( "gform_form_settings_page_{$subview}" );
}
}
/**
* Displays the form settings UI.
*
* @since Unknown
*
* @return void
*/
public static function form_settings_ui() {
$form_id = rgget( 'id' );
// Form ID isn't valid (it's either deleted or just not an existing form ID)
if ( ! GFAPI::form_id_exists( $form_id ) ) {
GFCommon::log_error( __METHOD__ . '(): Invalid Form ID: ' . $form_id );
wp_die( 'Invalid Form ID' );
}
self::page_header();
if ( ! self::get_settings_renderer() ) {
self::initialize_settings_renderer();
}
self::get_settings_renderer()->render();
self::page_footer();
}
/**
* Prepare form settings fields.
*
* @since 2.5
* @since 2.9.8 Updated honeypotAction default to spam.
* @since 2.9.21 Moved the honeypot fields to a new spam section and added submission speed check fields.
*
* @param array $form Form being edited.
*
* @return array
*/
public static function form_settings_fields( $form ) {
// Handles the deprecation notice for the confirmation ready classes in the CSS class field of form settings.
$deprecated_confirmation_classes_field_notice = function ( $value, $field ) use ( $form ) {
if ( GFCommon::is_legacy_markup_enabled_og( $form ) ) {
return false;
}
$deprecated_confirmation_classes = [
'gf_confirmation_simple_yellow',
'gf_confirmation_simple_gray',
'gf_confirmation_yellow_gradient',
'gf_confirmation_green_gradient',
];
if ( in_array( $value, $deprecated_confirmation_classes ) ) {
return '<div id="gfield-warning-deprecated" class="gform-alert gform-alert--notice gform-alert--inline" role="alert" style="margin-block-start: 1rem;">
<span class="gform-alert__icon gform-icon gform-icon--circle-notice-fine" aria-hidden="true"></span>
<div class="gform-alert__message-wrap">
<p class="gform-alert__message">' . esc_html__( 'This form uses the "' . $value . '" Ready Class, which will be removed in Gravity Forms 4.0. You can use a CSS code snippet instead.', 'gravityforms' ) .
' <a href="https://docs.gravityforms.com/migrating-your-forms-from-ready-classes/" target="_blank" title="' .
esc_attr__( 'Deprecation of Ready Classes in Gravity Forms 4.0', 'gravityforms' ) . '">' .
esc_html__( 'Learn more', 'gravityforms' ) .
'<span class="screen-reader-text">' . esc_html__( '(opens in a new tab)', 'gravityforms' ) . '</span> ' .
'<span class="gform-icon gform-icon--external-link" aria-hidden="true"></span></a></p>
</div>
</div>';
}
return '';
};
$fields = array(
'form_basics' => array(
'title' => esc_html__( 'Form Basics', 'gravityforms' ),
'fields' => array(
array(
'name' => 'title',
'type' => 'text',
'label' => esc_html__( 'Form Title', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_title', '', true ),
'required' => true,
'validation_callback' => function ( $field, $value ) use ( $form ) {
// If value is empty, set error.
if ( rgblank( $value ) ) {
$field->set_error( rgobj( $field, 'error_message' ) );
return;
}
// Get forms.
$forms = GFFormsModel::get_forms();
// Loop through forms, look for duplicate title.
foreach ( $forms as $f ) {
// If form does not have a duplicate title, skip.
if ( strtolower( $f->title ) !== strtolower( $value ) ) {
continue;
}
// If form ID matches, skip.
if ( (int) $form['id'] === (int) $f->id ) {
continue;
}
// Set field error.
$field->set_error( esc_html__( 'The form title you have entered has already been used. Please enter a unique form title.', 'gravityforms' ) );
return;
}
$field->do_validation( $value );
},
),
array(
'name' => 'description',
'type' => 'textarea',
'label' => esc_html__( 'Form Description', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_description', '', true ),
'allow_html' => true,
),
),
),
'form_layout' => array(
'title' => esc_html__( 'Form Layout', 'gravityforms' ),
'fields' => array(
array(
'name' => 'labelPlacement',
'type' => 'select',
'label' => esc_html__( 'Label Placement', 'gravityforms' ),
'default_value' => 'top_label',
'tooltip' => gform_tooltip( 'form_label_placement', '', true ),
'choices' => array(
array(
'label' => __( 'Top aligned', 'gravityforms' ),
'value' => 'top_label',
),
array(
'label' => __( 'Left aligned', 'gravityforms' ),
'value' => 'left_label',
),
array(
'label' => __( 'Right aligned', 'gravityforms' ),
'value' => 'right_label',
),
),
),
array(
'name' => 'descriptionPlacement',
'type' => 'select',
'label' => esc_html__( 'Description Placement', 'gravityforms' ),
'default_value' => 'below',
'tooltip' => gform_tooltip( 'form_description_placement', '', true ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'labelPlacement',
'values' => array( 'top_label' ),
),
),
),
'choices' => array(
array(
'label' => __( 'Below inputs', 'gravityforms' ),
'value' => 'below',
),
array(
'label' => __( 'Above inputs', 'gravityforms' ),
'value' => 'above',
),
),
),
array(
'name' => 'validationPlacement',
'type' => 'select',
'label' => esc_html__( 'Validation Message Placement', 'gravityforms' ),
'default_value' => 'below',
'tooltip' => gform_tooltip( 'form_validation_placement', '', true ),
'choices' => array(
array(
'label' => __( 'Below inputs', 'gravityforms' ),
'value' => 'below',
),
array(
'label' => __( 'Above inputs', 'gravityforms' ),
'value' => 'above',
),
),
),
array(
'name' => 'subLabelPlacement',
'type' => 'select',
'label' => esc_html__( 'Sub-Label Placement', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_sub_label_placement', '', true ),
'choices' => array(
array(
'label' => __( 'Below inputs', 'gravityforms' ),
'value' => 'below',
),
array(
'label' => __( 'Above inputs', 'gravityforms' ),
'value' => 'above',
),
),
),
array(
'name' => 'validationSummary',
'type' => 'toggle',
'label' => esc_html__( 'Validation Summary', 'gravityforms' ),
'default_value' => false,
'tooltip' => gform_tooltip( 'validation_summary', '', true ),
),
array(
'name' => 'requiredIndicator',
'label' => esc_html__( 'Required Field Indicator', 'gravityforms' ),
'type' => 'radio',
'default_value' => ( GFCommon::is_legacy_markup_enabled( $form ) ) ? 'asterisk' : 'text',
'horizontal' => true,
'tooltip' => gform_tooltip( 'form_required_indicator', '', true ),
'choices' => array(
array(
'label' => esc_html__( 'Text: (Required)', 'gravityforms' ),
'value' => 'text',
),
array(
'label' => esc_html__( 'Asterisk: *', 'gravityforms' ),
'value' => 'asterisk',
),
array(
'label' => esc_html__( 'Custom:', 'gravityforms' ),
'value' => 'custom',
),
),
),
array(
'name' => 'customRequiredIndicator',
'type' => 'text',
'label' => esc_html__( 'Custom Required Indicator', 'gravityforms' ),
'default_value' => esc_html__( '(Required)', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'requiredIndicator',
'values' => array( 'custom' ),
),
),
),
),
array(
'name' => 'cssClass',
'type' => 'text',
'after_input' => $deprecated_confirmation_classes_field_notice,
'label' => esc_html__( 'CSS Class Name', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_css_class', '', true ),
),
),
),
'form_button' => array(
'title' => esc_html__( 'Form Button', 'gravityforms' ),
'fields' => array(
array(
'name' => 'deprecated',
'type' => 'html',
'html' => esc_html__( 'Form button settings are now located in the form editor! To edit the button settings, go to the form editor and click on the submit button.', 'gravityforms' ),
),
),
),
'save_and_continue' => array(
'title' => esc_html__( 'Save and Continue', 'gravityforms' ),
'fields' => array(
array(
'name' => 'saveEnabled',
'type' => 'toggle',
'label' => __( 'Enable Save and Continue', 'gravityforms' ),
),
array(
'name' => 'saveButtonText',
'type' => 'text',
'label' => esc_html__( 'Link Text', 'gravityforms' ),
'default_value' => __( 'Save & Continue', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'saveEnabled',
),
),
),
'description' => sprintf(
'<div class="alert warning"><p>%s</p><p>%s</p></div>',
esc_html( 'This feature stores potentially private and sensitive data on this server and protects it with a unique link which is displayed to the user on the page in plain, unencrypted text. The link is similar to a password so it\'s strongly advisable to ensure that the page enforces a secure connection (HTTPS) before activating this setting.', 'gravityforms' ),
esc_html( 'When this setting is activated two confirmations and one notification are automatically generated and can be modified in their respective editors. When this setting is deactivated the confirmations and the notification will be deleted automatically and any modifications will be lost.', 'gravityforms' )
),
),
),
),
'restrictions' => array(
'title' => esc_html__( 'Restrictions', 'gravityforms' ),
'fields' => array(
array(
'name' => 'limitEntries',
'type' => 'checkbox',
'label' => __( 'Limit number of entries', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_limit_entries', '', true ),
'choices' => array(
array(
'name' => 'limitEntries',
'label' => __( 'Enable entry limit', 'gravityforms' ),
),
),
'fields' => array(
array(
'name' => 'limitEntriesNumber',
'type' => 'text_and_select',
'label' => __( 'Number of Entries', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'limitEntries',
),
),
),
'inputs' => array(
'text' => array(
'name' => 'limitEntriesCount',
'input_type' => 'number',
),
'select' => array(
'name' => 'limitEntriesPeriod',
'choices' => array(
array(
'label' => __( 'total entries', 'gravityforms' ),
'value' => '',
),
array(
'label' => __( 'per day', 'gravityforms' ),
'value' => 'day',
),
array(
'label' => __( 'per week', 'gravityforms' ),
'value' => 'week',
),
array(
'label' => __( 'per month', 'gravityforms' ),
'value' => 'month',
),
array(
'label' => __( 'per year', 'gravityforms' ),
'value' => 'year',
),
),
),
),
),
array(
'name' => 'limitEntriesMessage',
'type' => 'textarea',
'label' => esc_html__( 'Entry Limit Reached Message', 'gravityforms' ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'limitEntries',
),
),
),
),
),
),
array(
'name' => 'scheduleForm',
'type' => 'checkbox',
'label' => __( 'Schedule Form', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_schedule_form', '', true ),
'choices' => array(
array(
'name' => 'scheduleForm',
'label' => __( 'Schedule Form', 'gravityforms' ),
),
),
'fields' => array(
array(
'name' => 'scheduleStart',
'type' => 'date_time',
'label' => esc_html__( 'Schedule Start Date/Time', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
array(
'name' => 'scheduleEnd',
'type' => 'date_time',
'label' => esc_html__( 'Schedule Form End Date/Time', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
array(
'name' => 'schedulePendingMessage',
'type' => 'textarea',
'label' => esc_html__( 'Form Pending Message', 'gravityforms' ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
array(
'name' => 'scheduleMessage',
'type' => 'textarea',
'label' => esc_html__( 'Form Expired Message', 'gravityforms' ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
),
),
array(
'name' => 'requireLogin',
'type' => 'checkbox',
'label' => __( 'Require user to be logged in', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_require_login', '', true ),
'choices' => array(
array(
'name' => 'requireLogin',
'label' => __( 'Require user to be logged in', 'gravityforms' ),
),
),
'fields' => array(
array(
'name' => 'requireLoginMessage',
'type' => 'textarea',
'label' => esc_html__( 'Require Login Message', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_require_login_message', '', true ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'requireLogin',
),
),
),
),
),
),
),
),
'spam' => array(
'title' => esc_html__( 'Spam Detection', 'gravityforms' ),
'fields' => array(
array(
'name' => 'enableHoneypot',
'type' => 'toggle',
'label' => esc_html__( 'Honeypot', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_honeypot', '', true ),
),
array(
'name' => 'honeypotAction',
'type' => 'radio',
'default_value' => 'spam',
'horizontal' => true,
'label' => esc_html__( 'If the honeypot flags a submission as spam:', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'enableHoneypot',
),
),
),
'choices' => array(
array(
'label' => esc_html__( 'Do not create an entry', 'gravityforms' ),
'value' => 'abort',
),
array(
'label' => esc_html__( 'Create an entry and mark it as spam', 'gravityforms' ),
'value' => 'spam',
),
),
),
array(
'name' => 'enableSubmitSpeedCheck',
'type' => 'toggle',
'label' => esc_html__( 'Submission Speed Check', 'gravityforms' ),
'description' => esc_html__( 'Flags the submission as spam if the elapsed time between page load and form submission is less than the threshold.', 'gravityforms' ),
'default_value' => false,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'enableHoneypot',
),
),
),
),
array(
'name' => 'submitSpeedCheckThreshold',
'type' => 'text',
'input_type' => 'number',
'min' => 1,
'default_value' => 2000,
'label' => esc_html__( 'Submission Speed Check: Threshold (milliseconds)', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'enableHoneypot',
),
array(
'field' => 'enableSubmitSpeedCheck',
),
),
),
'validation_callback' => function ( $field, $value ) {
if ( ! ctype_digit( $value ) || (int) $value < 1 ) {
$field->set_error( esc_html__( 'Please enter a valid number greater than zero.', 'gravityforms' ) );
}
},
),
array(
'name' => 'submitSpeedCheckMode',
'type' => 'radio',
'default_value' => 'normal',
'label' => esc_html__( 'Submission Speed Check: Mode', 'gravityforms' ),
'description' => esc_html__( 'Submission speed is captured for each page of a multi-page form and for each submission attempt after a validation error. If there are multiple submission speeds for one submission, which mode should be used to evaluate the submission?', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'enableHoneypot',
),
array(
'field' => 'enableSubmitSpeedCheck',
),
),
),
'choices' => array(
array(
'label' => esc_html__( 'Normal: at least one speed must be above the threshold.', 'gravityforms' ),
'value' => 'normal',
),
array(
'label' => esc_html__( 'Strict: all speeds must be above the threshold.', 'gravityforms' ),
'value' => 'strict',
),
),
),
),
),
'form_options' => array(
'title' => esc_html__( 'Form Options', 'gravityforms' ),
'fields' => array(
array(
'name' => 'enableAnimation',
'type' => 'toggle',
'label' => __( 'Animated transitions', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_animation', '', true ),
),
),
),
);
if ( self::legacy_markup_enabled_or_posted( $form ) ) {
$fields['form_options']['fields'][] = array(
'name' => 'markupVersion',
'type' => 'toggle',
'label' => __( 'Enable legacy markup', 'gravityforms' ),
'description' => self::legacy_markup_warning(),
'default_value' => rgar( $form, 'markupVersion' ) ? $form['markupVersion'] : 1,
'tooltip' => gform_tooltip( 'form_legacy_markup', '', true ),
);
}
/**
* Filters the form settings before they are displayed.
*
* @deprecated
* @remove-in 3.0
* @since 1.7
*
* @param array $form_settings The form settings.
* @param array $form The Form Object.
*/
if ( has_filter( 'gform_form_settings' ) ) {
trigger_error( 'gform_form_settings is deprecated and will be removed in version 3.0.', E_USER_DEPRECATED ); // phpcs:ignore QITStandard.PHP.DebugCode.DebugFunctionFound
}
$legacy_settings = apply_filters( 'gform_form_settings', array(), $form );
// If legacy settings exist, add to fields.
if ( ! empty( $legacy_settings ) ) {
// Add section.
$fields['legacy_settings'] = array(
'title' => esc_html__( 'Legacy Settings', 'gravityforms' ),
'fields' => array(
array(
'name' => 'legacy',
'type' => 'html',
'html' => function() {
$form_id = rgget( 'id' );
$form = GFFormsModel::get_form_meta( $form_id );
$legacy_settings = apply_filters( 'gform_form_settings', array(), $form );
$html = '<table class="gforms_form_settings" cellspacing="0" cellpadding="0" width="100%">';
foreach ( $legacy_settings as $title => $legacy_fields ) {
$html .= sprintf( '<tr><td colspan="2"><h4 class="gf_settings_subgroup_title">%s</h4></td>', esc_html( $title ) );
if ( is_array( $legacy_fields ) ) {
foreach ( $legacy_fields as $field ) {
$html .= $field;
}
}
}
$html .= '</table>';
return $html;
},
),
),
);
}
/**
* Filters the form settings fields before they are displayed.
*
* @since 2.5
*
* @param array $fields Form settings fields.
* @param array $form Form Object.
*/
$fields = gf_apply_filters( array( 'gform_form_settings_fields', rgar( $form, 'id' ) ), $fields, $form );
return $fields;
}
/**
* The Settings API runs the settings field method before processing the postback,
* so we have to run this hack to ensure we're respecting the posted value on initial load.
*
* @todo - Remove this and fix the Settings API order-of-operations.
*
* @since 3.0.0
*
* @param array $form The form to check.
*
* @return bool
*/
public static function legacy_markup_enabled_or_posted( $form ) {
if ( $_POST && empty( $_POST['_gform_setting_markupVersion'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing,
return apply_filters( 'gform_show_legacy_markup_setting', false );
}
return apply_filters( 'gform_show_legacy_markup_setting', GFCommon::is_legacy_markup_enabled( $form ) );
}
/**
* Determine whether to show the legacy markup setting.
*
* @since 2.7.15
*
* @return bool
*/
public static function show_legacy_markup_setting() {
$show_legacy_setting = true;
if ( version_compare( get_option( 'rg_form_original_version', '1.0' ), '2.7.14.2', '>=' ) && ! self::legacy_is_in_use() ) {
$show_legacy_setting = false;
}
// if this is a new install, and if there are no forms with legacy markup enabled, do not show the legacy markup setting
return apply_filters( 'gform_show_legacy_markup_setting', $show_legacy_setting );
}
/**
* Check whether any forms on this site use legacy markup.
*
* @since 2.7.15
*
* @return bool
*/
public static function legacy_is_in_use() {
$legacy_is_in_use = GFCache::get( 'legacy_is_in_use', $found_in_cache );
if ( ! $found_in_cache ) {
$legacy_is_in_use = GFFormsModel::has_legacy_markup();
GFCache::set( 'legacy_is_in_use', $legacy_is_in_use, true, DAY_IN_SECONDS );
}
return $legacy_is_in_use;
}
/**
* Get the warning for the legacy markup field.
*
* @since 2.7.15
*
* @return string
*/
public static function legacy_markup_warning() {
return '<div class="gform-alert" data-js="gform-alert" role="status">
<span
class="gform-alert__icon gform-icon gform-icon--campaign"
aria-hidden="true"
></span>
<div class="gform-alert__message-wrap">
<p class="gform-alert__message">' . esc_html__( 'Legacy markup is incompatible with many new features, including the Orbital Theme.', 'gravityforms' ) . '</p>
<p class="gform-alert__message">' . esc_html__( 'Legacy markup will be removed in Gravity Forms 4.0, and then all forms will use modern markup. We recommend using modern markup on all forms.', 'gravityforms' ) . '</p>
<a
class="gform-alert__cta gform-button gform-button--white gform-button--size-xs"
href="https://docs.gravityforms.com/about-legacy-markup"
target="_blank"
>'
. esc_html__( 'Learn More', 'gravityforms' ) .
'<span class="screen-reader-text">' . esc_html__('about form legacy markup', 'gravityforms') . '</span>
<span class="screen-reader-text">' . esc_html__('(opens in a new tab)', 'gravityforms') . '</span>
<span class="gform-icon gform-icon--external-link" aria-hidden="true"></span>
</a>
</div>
</div>';
}
/**
* Displays a warning if confirmation deprecated CSS Ready Classes are used in the form settings.
*
* This method checks if the form uses any deprecated CSS Ready Classes and displays
* a warning message. It also ensures the warning is not shown if the user has dismissed it.
*
* @since 2.9.15
*
* @param array $form The form object being checked for deprecated classes.
*
* @return string|false The HTML for the warning message or false if no warning is needed.
*/
public static function deprecated_classes_warning( $form ) {
if ( GFCommon::is_legacy_markup_enabled_og( $form ) ){
return false;
}
$deprecated_confirmation_classes = [
'gf_confirmation_simple_yellow',
'gf_confirmation_simple_gray',
'gf_confirmation_yellow_gradient',
'gf_confirmation_green_gradient',
];
if ( isset( $form['cssClass'] ) ) {
$field_classes = explode( ' ', $form['cssClass'] );
foreach ( $field_classes as $class ) {
if ( in_array( $class, $deprecated_confirmation_classes ) ) {
return '<div class="gform-alert" data-js="gform-alert" style="grid-column: 1/-1;">
<span class="gform-alert__icon gform-icon gform-icon--campaign" aria-hidden="true"></span>
<div class="gform-alert__message-wrap">
<p class="gform-alert__message">' . esc_html__( 'This form uses a deprecated CSS Ready Class, which will be removed in Gravity Forms 4.0.', 'gravityforms' ) . '</p>
<a class="gform-alert__cta gform-button gform-button--white gform-button--size-xs" href="https://docs.gravityforms.com/migrating-your-forms-from-ready-classes/" target="_blank">'
. esc_html__( 'Learn More', 'gravityforms' ) .
'<span class="screen-reader-text">' . esc_html__('about deprecated ready classes', 'gravityforms') . '</span>
<span class="screen-reader-text">' . esc_html__('(opens in a new tab)', 'gravityforms') . '</span>
<span class="gform-icon gform-icon--external-link" aria-hidden="true"></span>
</a>
</div>
</div>';
}
}
}
return '';
}
// # SETTINGS RENDERER ---------------------------------------------------------------------------------------------
/**
* Initialize Plugin Settings fields renderer.
*
* @since 2.5
* @since 2.9.8 Updated honeypotAction default to spam.
* @since 2.9.21 Updated to save the submission speed check fields.
*/
public static function initialize_settings_renderer() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
$form_id = rgget( 'id' );
$form = GFCommon::gform_admin_pre_render( GFFormsModel::get_form_meta( $form_id ) );
// Initialize new settings renderer.
$renderer = new Settings(
array(
'fields' => array_values( self::form_settings_fields( $form ) ),
'initial_values' => self::get_initial_values( $form ),
'save_callback' => function( $values ) use ( &$form, $form_id ) {
// Set form version.
$form['version'] = GFForms::$version;
// Save custom settings fields to the form object if they don't already exist there.
$form = self::save_changed_form_settings_fields( $form, $values );
// Form Basics
$form['title'] = rgar( $values, 'title' );
$form['description'] = rgar( $values, 'description' );
// Form Layout
$form['labelPlacement'] = GFCommon::whitelist( rgar( $values, 'labelPlacement' ), array( 'top_label', 'left_label', 'right_label' ) );
$form['descriptionPlacement'] = GFCommon::whitelist( rgar( $values, 'descriptionPlacement' ), array( 'below', 'above' ) );
$form['validationPlacement'] = GFCommon::whitelist( rgar( $values, 'validationPlacement' ), array( 'below', 'above' ) );
$form['subLabelPlacement'] = GFCommon::whitelist( rgar( $values, 'subLabelPlacement' ), array( 'below', 'above' ) );
$form['validationSummary'] = rgar( $values, 'validationSummary', false );
$form['requiredIndicator'] = GFCommon::whitelist( rgar( $values, 'requiredIndicator' ), array( 'text', 'asterisk', 'custom' ) );
$form['customRequiredIndicator'] = rgar( $values, 'customRequiredIndicator' );
$form['cssClass'] = rgar( $values, 'cssClass' );
// Save and Continue
$form['save']['enabled'] = (bool) rgar( $values, 'saveEnabled' );
$form['save']['button']['type'] = 'link';
$form['save']['button']['text'] = rgar( $values, 'saveButtonText' );
// Limit Entries
$form['limitEntries'] = (bool) rgar( $values, 'limitEntries' );
$form['limitEntriesCount'] = absint( rgar( $values, 'limitEntriesCount' ) );
$form['limitEntriesPeriod'] = rgar( $values, 'limitEntriesPeriod' ) ? GFCommon::whitelist( $values['limitEntriesPeriod'], array( '', 'day', 'week', 'month', 'year' ) ) : '';
$form['limitEntriesMessage'] = rgar( $values, 'limitEntriesMessage' );
// Require Login
$form['requireLogin'] = (bool) rgar( $values, 'requireLogin' );
$form['requireLoginMessage'] = rgar( $values, 'requireLoginMessage' );
// Scheduling
$form['scheduleForm'] = rgar( $values, 'scheduleForm' );
$form['scheduleStart'] = rgars( $values, 'scheduleStart/date' );
$form['scheduleStartHour'] = rgars( $values, 'scheduleStart/hour' );
$form['scheduleStartMinute'] = rgars( $values, 'scheduleStart/minute' );
$form['scheduleStartAmpm'] = rgars( $values, 'scheduleStart/ampm' );
$form['scheduleEnd'] = rgars( $values, 'scheduleEnd/date' );
$form['scheduleEndHour'] = rgars( $values, 'scheduleEnd/hour' );
$form['scheduleEndMinute'] = rgars( $values, 'scheduleEnd/minute' );
$form['scheduleEndAmpm'] = rgars( $values, 'scheduleEnd/ampm' );
$form['schedulePendingMessage'] = rgar( $values, 'schedulePendingMessage' );
$form['scheduleMessage'] = rgar( $values, 'scheduleMessage' );
// Spam Detection.
$form['enableHoneypot'] = (bool) rgar( $values, 'enableHoneypot' );
$form['honeypotAction'] = GFCommon::whitelist(
rgar( $values, 'honeypotAction' ),
array(
'spam',
'abort',
)
);
$form['enableSubmitSpeedCheck'] = (bool) rgar( $values, 'enableSubmitSpeedCheck' );
$form['submitSpeedCheckThreshold'] = absint( rgar( $values, 'submitSpeedCheckThreshold' ) );
$form['submitSpeedCheckMode'] = GFCommon::whitelist(
rgar( $values, 'submitSpeedCheckMode' ),
array(
'normal',
'strict',
)
);
// Form Options.
$form['enableAnimation'] = (bool) rgar( $values, 'enableAnimation' );
$form['markupVersion'] = rgar( $values, 'markupVersion' ) ? 1 : 2;
// Enable/Disable Save & Continue.
if ( $form['save']['enabled'] ) {
$form = GFFormSettings::activate_save( $form );
} else {
$form = GFFormSettings::deactivate_save( $form );
}
/**
* Filters the updated form settings before being saved.
*
* @since 1.7
*
* @param array $form The form settings.
*/
$form = apply_filters( 'gform_pre_form_settings_save', $form );
// Save form.
GFFormDetail::save_form_info( $form_id, addslashes( json_encode( $form ) ) );
},
'before_fields' => function() use ( &$form ) {
// Ensure form is not empty and display form settings warning accordingly.
$notice = self::deprecated_classes_warning( $form );
if ( ! empty( $notice ) ) {
echo $notice; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
<script type="text/javascript">
<?php GFCommon::gf_global(); ?>
var form = <?php echo json_encode( $form ); ?>;
var fieldSettings = [];
jQuery( document ).ready( function() {
ToggleConditionalLogic( true, 'form_button' );
jQuery( document ).trigger( 'gform_load_form_settings', [ form ] );