This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
/
gravityforms.php
6022 lines (5149 loc) · 187 KB
/
gravityforms.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
/*
Plugin Name: Gravity Forms
Plugin URI: https://gravityforms.com
Description: Easily create web forms and manage form entries within the WordPress admin.
Version: 2.4.20
Author: Gravity Forms
Author URI: https://gravityforms.com
License: GPL-2.0+
Text Domain: gravityforms
Domain Path: /languages
------------------------------------------------------------------------
Copyright 2009-2020 Rocketgenius, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses.
*/
//------------------------------------------------------------------------------------------------------------------
//---------- Gravity Forms License Key -----------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
// If you hardcode a Gravity Forms License Key here, it will automatically populate on activation.
$gf_license_key = '';
//-- OR ---//
// You can also add the Gravity Forms license key to your wp-config.php file to automatically populate on activation
// Add the code in the comment below to your wp-config.php to do so:
// define('GF_LICENSE_KEY','YOUR_KEY_GOES_HERE');
//------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
//---------- reCAPTCHA Keys -----------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
// If you hardcode your reCAPTCHA Keys here, it will automatically populate on activation.
$gf_recaptcha_private_key = '';
$gf_recaptcha_public_key = '';
//-- OR ---//
// You can also add the reCAPTCHA keys to your wp-config.php file to automatically populate on activation
// Add the two lines of code in the comment below to your wp-config.php to do so:
// define('GF_RECAPTCHA_PRIVATE_KEY','YOUR_PRIVATE_KEY_GOES_HERE');
// define('GF_RECAPTCHA_PUBLIC_KEY','YOUR_PUBLIC_KEY_GOES_HERE');
//------------------------------------------------------------------------------------------------------------------
if ( ! defined( 'ABSPATH' ) ) {
die();
}
if ( ! defined( 'RG_CURRENT_PAGE' ) ) {
/**
* Defines the current page.
*
* @since Unknown
*
* @used-by GFForms::init()
* @used-by GFCommon::ensure_wp_version()
*
* @var string RG_CURRENT_PAGE The current page.
*/
define( 'RG_CURRENT_PAGE', basename( $_SERVER['PHP_SELF'] ) );
}
if ( ! defined( 'IS_ADMIN' ) ) {
/**
* Checks if an admin page is being viewed.
*
* @since Unknown
*
* @used-by GFForms::init()
* @used-by GFFormsModel::get_default_value()
* @used-by GFFormsModel::get_label()
*
* @var boolean IS_ADMIN True if admin page. False otherwise.
*/
define( 'IS_ADMIN', is_admin() );
}
/**
* Defines the current view within Gravity Forms.
*
* Defined from URL parameters.
*
* @since Unknown
* @deprecated 2.1.3.6
*
* @uses GFForms::get()
*
* @var string|boolean RG_CURRENT_VIEW The view if available. False otherwise.
*/
define( 'RG_CURRENT_VIEW', GFForms::get( 'view' ) );
/**
* Defines the minimum version of WordPress required for Gravity Forms.
*
* @since Unknown
*
* @used-by GFCommon::ensure_wp_version()
* @used-by GF_SUPPORTED_WP_VERSION
* @used-by GFSettings::gravityforms_settings_page()
*
* @var string GF_MIN_WP_VERSION Minimum version number.
*/
define( 'GF_MIN_WP_VERSION', '3.7' );
/**
* Checks if the current WordPress version is supported.
*
* @since Unknown
*
* @used-by GFForms::init()
* @used-by GFCommon::ensure_wp_version()
* @uses GF_MIN_WP_VERSION
*
* @var boolean GF_SUPPORTED_VERSION True if supported. False otherwise.
*/
define( 'GF_SUPPORTED_WP_VERSION', version_compare( get_bloginfo( 'version' ), GF_MIN_WP_VERSION, '>=' ) );
/**
* Defines the minimum version of WordPress that will be officially supported.
*
* @var string GF_MIN_WP_VERSION_SUPPORT_TERMS The version number
*/
define( 'GF_MIN_WP_VERSION_SUPPORT_TERMS', '5.3' );
if ( ! defined( 'GRAVITY_MANAGER_URL' ) ) {
/**
* Defines the Gravity Manager URL.
*
* @var string GRAVITY_MANAGER_URL The full URL to the Gravity Manager.
*/
define( 'GRAVITY_MANAGER_URL', 'https://gravityapi.com/wp-content/plugins/gravitymanager' );
}
require_once( plugin_dir_path( __FILE__ ) . 'currency.php' );
require_once( plugin_dir_path( __FILE__ ) . 'common.php' );
require_once( plugin_dir_path( __FILE__ ) . 'forms_model.php' );
require_once( plugin_dir_path( __FILE__ ) . 'widget.php' );
require_once( plugin_dir_path( __FILE__ ) . 'includes/api.php' );
require_once( plugin_dir_path( __FILE__ ) . 'includes/webapi/webapi.php' );
require_once( plugin_dir_path( __FILE__ ) . 'includes/fields/class-gf-fields.php' );
require_once( plugin_dir_path( __FILE__ ) . 'includes/class-gf-download.php' );
require_once( plugin_dir_path( __FILE__ ) . 'includes/query/class-gf-query.php' );
// Load Logging if Logging Add-On is not active.
if ( ! GFCommon::is_logging_plugin_active() ) {
require_once( plugin_dir_path( __FILE__ ) . 'includes/logging/logging.php' );
}
// GFCommon::$version is deprecated, set it to current version for backwards compatibility
GFCommon::$version = GFForms::$version;
add_action( 'init', array( 'GFForms', 'init' ) );
add_action( 'wp', array( 'GFForms', 'maybe_process_form' ), 9 );
add_action( 'admin_init', array( 'GFForms', 'maybe_process_form' ), 9 );
add_action( 'wp', array( 'GFForms', 'process_exterior_pages' ) );
add_action( 'admin_init', array( 'GFForms', 'process_exterior_pages' ) );
add_filter( 'upgrader_pre_install', array( 'GFForms', 'validate_upgrade' ), 10, 2 );
add_filter( 'tiny_mce_before_init', array( 'GFForms', 'modify_tiny_mce_4' ), 20 );
add_filter( 'user_has_cap', array( 'RGForms', 'user_has_cap' ), 10, 3 );
add_filter( 'query', array( 'GFForms', 'filter_query' ) );
//Hooks for no-conflict functionality
if ( is_admin() && ( GFForms::is_gravity_page() || GFForms::is_gravity_ajax_action() ) ) {
add_action( 'wp_print_scripts', array( 'GFForms', 'no_conflict_mode_script' ), 1000 );
add_action( 'admin_print_footer_scripts', array( 'GFForms', 'no_conflict_mode_script' ), 9 );
add_action( 'wp_print_styles', array( 'GFForms', 'no_conflict_mode_style' ), 1000 );
add_action( 'admin_print_styles', array( 'GFForms', 'no_conflict_mode_style' ), 1 );
add_action( 'admin_print_footer_scripts', array( 'GFForms', 'no_conflict_mode_style' ), 1 );
add_action( 'admin_footer', array( 'GFForms', 'no_conflict_mode_style' ), 1 );
}
add_action( 'plugins_loaded', array( 'GFForms', 'loaded' ) );
register_activation_hook( __FILE__, array( 'GFForms', 'activation_hook' ) );
register_deactivation_hook( __FILE__, array( 'GFForms', 'deactivation_hook' ) );
gf_upgrade();
/**
* Class GFForms
*
* Handles the loading of Gravity Forms and other core functionality
*/
class GFForms {
/**
* Defines this version of Gravity Forms.
*
* @since Unknown
* @access public
*
* @var string $version The version number.
*/
public static $version = '2.4.20';
/**
* Handles background upgrade tasks.
*
* @var GF_Background_Upgrader
*/
public static $background_upgrader = null;
/**
* Runs after Gravity Forms is loaded.
*
* Initializes add-ons.
*
* @since Unknown
* @access public
*
* @uses GFAddOn::init_addons()
*
* @return void
*/
public static function loaded() {
/**
* Fires when Gravity Forms has loaded.
*
* When developing Add-Ons, use this hook to initialize any functionality that depends on Gravity Forms functionality.
*/
do_action( 'gform_loaded' );
//initializing Add-Ons if necessary
if ( class_exists( 'GFAddOn' ) ) {
GFAddOn::init_addons();
}
if ( defined( 'OSDXP_DASHBOARD_VER' ) ) {
// Integration with osDXP.
require_once plugin_dir_path( __FILE__ ) . 'includes/class-gf-osdxp.php';
}
}
/**
* Determines if the 3rd party Members plugin is active.
*
* @since 2.4.13 Removed Members v1 support.
* @since Unknown
*
* @param null $deprecated No longer used. Previously the minimum version number of Members plugin to check for.
*
* @return boolean True if the Members plugin is active. False otherwise.
*/
public static function has_members_plugin( $deprecated = null ) {
return function_exists( 'members_register_cap_group' ) && function_exists( 'members_register_cap' );
}
/**
* Initializes Gravity Forms.
*
* @since Unknown
* @access public
*
* @return void
*/
public static function init() {
if ( ! wp_next_scheduled( 'gravityforms_cron' ) ) {
wp_schedule_event( time(), 'daily', 'gravityforms_cron' );
}
add_action( 'gravityforms_cron', array( 'GFForms', 'cron' ) );
GF_Download::maybe_process();
//load text domains
GFCommon::load_gf_text_domain( 'gravityforms' );
add_filter( 'gform_logging_supported', array( 'GFForms', 'set_logging_supported' ) );
add_action( 'admin_head', array( 'GFCommon', 'maybe_output_gf_vars' ) );
add_action( 'admin_head', array( 'GFForms', 'load_admin_bar_styles' ) );
add_action( 'wp_head', array( 'GFForms', 'load_admin_bar_styles' ) );
self::register_scripts();
self::init_background_upgrader();
// Run background feed processing.
require_once( plugin_dir_path( __FILE__ ) . 'includes/addon/class-gf-feed-processor.php' );
gf_feed_processor();
// Maybe set up Gravity Forms
if ( ( false === ( defined( 'DOING_AJAX' ) && true === DOING_AJAX ) ) ) {
gf_upgrade()->maybe_upgrade();
}
// Load Editor Blocks if WordPress is 5.0+.
if ( function_exists( 'register_block_type' ) ) {
// Load block framework.
if ( ! class_exists( 'GF_Blocks' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/blocks/class-gf-blocks.php';
}
// Load included Blocks.
GFCommon::glob_require_once( '/includes/blocks/class-gf-block-*.php' );
}
// Plugin update actions
add_filter( 'transient_update_plugins', array( 'GFForms', 'check_update' ) );
add_filter( 'site_transient_update_plugins', array( 'GFForms', 'check_update' ) );
add_filter( 'auto_update_plugin', array( 'GFForms', 'maybe_auto_update' ), 10, 2 );
if ( IS_ADMIN ) {
global $current_user;
//Members plugin integration. Adding Gravity Forms roles to the checkbox list
if ( self::has_members_plugin() ) {
add_action( 'members_register_cap_groups', array( 'GFForms', 'members_register_cap_group' ) );
add_action( 'members_register_caps', array( 'GFForms', 'members_register_caps' ) );
}
// User Role Editor integration.
add_filter( 'ure_capabilities_groups_tree', array( 'GFForms', 'filter_ure_capabilities_groups_tree' ) );
add_filter( 'ure_custom_capability_groups', array( 'GFForms', 'filter_ure_custom_capability_groups' ), 10, 2 );
if ( is_multisite() ) {
add_filter( 'wpmu_drop_tables', array( 'GFFormsModel', 'mu_drop_tables' ) );
}
add_action( 'admin_enqueue_scripts', array( 'GFForms', 'enqueue_admin_scripts' ) );
add_action( 'print_media_templates', array( 'GFForms', 'action_print_media_templates' ) );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
add_action( 'admin_footer', array( 'GFForms', 'deprecate_add_on_methods' ) );
}
//Loading Gravity Forms if user has access to any functionality
if ( GFCommon::current_user_can_any( GFCommon::all_caps() ) ) {
require_once( GFCommon::get_base_path() . '/export.php' );
GFExport::maybe_export();
//Imports theme forms if configured to be automatic imported
gf_upgrade()->maybe_import_theme_forms();
//creates the "Forms" left menu
add_action( 'admin_menu', array( 'GFForms', 'create_menu' ) );
// Add site-wide admin notices
add_action( 'admin_notices', array( 'GFForms', 'action_admin_notices' ) );
if ( GF_SUPPORTED_WP_VERSION ) {
add_action( 'admin_footer', array( 'GFForms', 'check_upload_folder' ) );
add_action( 'wp_dashboard_setup', array( 'GFForms', 'dashboard_setup' ) );
// Support modifying the admin page title for settings
add_filter( 'admin_title', array( __class__, 'modify_admin_title' ), 10, 2 );
// Display admin notice if logging is enabled.
add_action( 'admin_notices', array( 'GFForms', 'maybe_display_logging_notice' ) );
require_once( GFCommon::get_base_path() . '/includes/locking/locking.php' );
if ( self::is_gravity_page() ) {
require_once( GFCommon::get_base_path() . '/tooltips.php' );
} elseif ( RG_CURRENT_PAGE == 'media-upload.php' ) {
require_once( GFCommon::get_base_path() . '/entry_list.php' );
} elseif ( in_array( RG_CURRENT_PAGE, array( 'admin.php', 'admin-ajax.php' ) ) ) {
add_action( 'wp_ajax_rg_save_form', array( 'GFForms', 'save_form' ) );
add_action( 'wp_ajax_rg_change_input_type', array( 'GFForms', 'change_input_type' ) );
add_action( 'wp_ajax_rg_refresh_field_preview', array( 'GFForms', 'refresh_field_preview' ) );
add_action( 'wp_ajax_rg_add_field', array( 'GFForms', 'add_field' ) );
add_action( 'wp_ajax_rg_duplicate_field', array( 'GFForms', 'duplicate_field' ) );
add_action( 'wp_ajax_rg_delete_field', array( 'GFForms', 'delete_field' ) );
add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file' ) );
add_action( 'wp_ajax_rg_select_export_form', array( 'GFForms', 'select_export_form' ) );
add_action( 'wp_ajax_rg_start_export', array( 'GFForms', 'start_export' ) );
add_action( 'wp_ajax_gf_upgrade_license', array( 'GFForms', 'upgrade_license' ) );
add_action( 'wp_ajax_gf_delete_custom_choice', array( 'GFForms', 'delete_custom_choice' ) );
add_action( 'wp_ajax_gf_save_custom_choice', array( 'GFForms', 'save_custom_choice' ) );
add_action( 'wp_ajax_gf_get_post_categories', array( 'GFForms', 'get_post_category_values' ) );
add_action( 'wp_ajax_gf_get_address_rule_values_select', array(
'GFForms',
'get_address_rule_values_select'
) );
add_action( 'wp_ajax_gf_get_notification_post_categories', array(
'GFForms',
'get_notification_post_category_values'
) );
//add_action( 'wp_ajax_gf_save_confirmation', array( 'GFForms', 'save_confirmation' ) );
add_action( 'wp_ajax_gf_delete_confirmation', array( 'GFForms', 'delete_confirmation' ) );
add_action( 'wp_ajax_gf_save_new_form', array( 'GFForms', 'save_new_form' ) );
add_action( 'wp_ajax_gf_save_title', array( 'GFForms', 'save_form_title' ) );
//entry list ajax operations
add_action( 'wp_ajax_rg_update_lead_property', array( 'GFForms', 'update_lead_property' ) );
add_action( 'wp_ajax_delete-gf_entry', array( 'GFForms', 'update_lead_status' ) );
//form list ajax operations
add_action( 'wp_ajax_rg_update_form_active', array( 'GFForms', 'update_form_active' ) );
//notification list ajax operations
add_action( 'wp_ajax_rg_update_notification_active', array(
'GFForms',
'update_notification_active'
) );
//confirmation list ajax operations
add_action( 'wp_ajax_rg_update_confirmation_active', array(
'GFForms',
'update_confirmation_active'
) );
//dynamic captcha image
add_action( 'wp_ajax_rg_captcha_image', array( 'GFForms', 'captcha_image' ) );
//dashboard message "dismiss upgrade" link
add_action( 'wp_ajax_rg_dismiss_upgrade', array( 'GFForms', 'dashboard_dismiss_upgrade' ) );
// entry detail: resend notifications
add_action( 'wp_ajax_gf_resend_notifications', array( 'GFForms', 'resend_notifications' ) );
// Shortcode UI
add_action( 'wp_ajax_gf_do_shortcode', array( 'GFForms', 'handle_ajax_do_shortcode' ) );
// Export
add_filter( 'wp_ajax_gf_process_export', array( 'GFForms', 'ajax_process_export' ) );
add_filter( 'wp_ajax_gf_download_export', array( 'GFForms', 'ajax_download_export' ) );
// Dismiss message
add_action( 'wp_ajax_gf_dismiss_message', array( 'GFForms', 'ajax_dismiss_message' ) );
// Check background tasks for the system report
add_action( 'wp_ajax_gf_check_background_tasks', array( 'GFForms', 'check_background_tasks' ) );
// Check status of upgrade
add_action( 'wp_ajax_gf_force_upgrade', array( 'GFForms', 'ajax_force_upgrade' ) );
// Disable logging.
add_action( 'wp_ajax_gf_disable_logging', array( 'GFForms', 'ajax_disable_logging' ) );
// Get change log.
add_action( 'wp_ajax_gf_get_changelog', array( 'GFForms', 'ajax_display_changelog' ) );
}
add_filter( 'plugins_api', array( 'GFForms', 'get_addon_info' ), 100, 3 );
add_action( 'after_plugin_row', array( 'GFForms', 'plugin_row' ), 10, 2 );
add_action( 'in_plugin_update_message-gravityforms/gravityforms.php', array( 'GFForms', 'in_plugin_update_message' ), 10, 2 );
add_action( 'install_plugins_pre_plugin-information', array( 'GFForms', 'display_changelog' ), 9 );
add_filter( 'plugin_action_links', array( 'GFForms', 'plugin_settings_link' ), 10, 2 );
}
}
add_action( 'admin_init', array( 'GFForms', 'ajax_parse_request' ), 10 );
$gf_page = self::get_page();
if ( $gf_page == 'entry_list' && ! isset( $_GET['filter'] ) ) {
require_once( GFCommon::get_base_path() . '/entry_list.php' );
$default_filter = GFEntryList::get_default_filter();
if ( $default_filter !== 'all' ) {
$url = add_query_arg( array( 'filter' => $default_filter ) );
$url = esc_url_raw( $url );
wp_safe_redirect( $url );
}
}
if ( $gf_page == 'entry_list' ) {
add_filter( 'screen_settings', array( 'GFForms', 'show_screen_options' ), 10, 2 );
// For WP 5.4.1 and older.
add_filter( 'set-screen-option', array( 'GFForms', 'set_screen_options' ), 10, 3 );
// For WP 5.4.2+.
add_filter( 'set_screen_option_gform_entries_screen_options', array( 'GFForms', 'set_screen_options', ), 10, 3 );
}
if ( $gf_page == 'form_list' ) {
// For WP 5.4.1 and older.
add_filter( 'set-screen-option', array( 'GFForms', 'set_screen_options' ), 10, 3 );
// For WP 5.4.2+.
add_filter( 'set_screen_option_gform_forms_per_page', array( 'GFForms', 'set_screen_options' ), 10, 3 );
}
add_filter( 'wp_privacy_personal_data_exporters', array( 'GFForms', 'register_data_exporter' ), 10 );
add_filter( 'wp_privacy_personal_data_erasers', array( 'GFForms', 'register_data_eraser' ), 10 );
} else {
add_action( 'wp_enqueue_scripts', array( 'GFForms', 'enqueue_scripts' ), 11 );
add_action( 'wp', array( 'GFForms', 'ajax_parse_request' ), 10 );
}
// Add admin bar items
add_action( 'wp_before_admin_bar_render', array( 'GFForms', 'admin_bar' ) );
add_shortcode( 'gravityform', array( 'GFForms', 'parse_shortcode' ) );
add_shortcode( 'gravityforms', array( 'GFForms', 'parse_shortcode' ) );
// ManageWP premium update filters
add_filter( 'mwp_premium_update_notification', array( 'GFForms', 'premium_update_push' ) );
add_filter( 'mwp_premium_perform_update', array( 'GFForms', 'premium_update' ) );
// Push Gravity Forms to the top of the list of plugins to make sure it's loaded before any add-ons
add_action( 'activated_plugin', array( 'GFForms', 'load_first' ) );
// Add the "Add Form" button to the editor. The customizer doesn't run in the admin context.
if ( GFForms::page_supports_add_form_button() ) {
require_once( GFCommon::get_base_path() . '/tooltips.php' );
// Adding "embed form" button to the editor
add_action( 'media_buttons', array( 'GFForms', 'add_form_button' ), 20 );
// Adding the modal
add_action( 'admin_print_footer_scripts', array( 'GFForms', 'add_mce_popup' ) );
}
}
/**
* Ensures that Gravity Forms is loaded first.
*
* @since Unknown
* @access public
*
* @return void
*/
public static function load_first() {
$plugin_path = basename( dirname( __FILE__ ) ) . '/gravityforms.php';
$active_plugins = array_values( maybe_unserialize( self::get_wp_option( 'active_plugins' ) ) );
$key = array_search( $plugin_path, $active_plugins );
if ( $key > 0 ) {
array_splice( $active_plugins, $key, 1 );
array_unshift( $active_plugins, $plugin_path );
update_option( 'active_plugins', $active_plugins );
}
}
/**
* Performs Gravity Forms deactivation tasks.
*
* @since Unknown
* @access public
*
* @uses GFCache::flush()
*
* @return void
*/
public static function deactivation_hook() {
GFCache::flush( true );
flush_rewrite_rules();
}
/**
* Performs Gravity Forms activation tasks.
*
* @since 2.3
* @access public
*/
public static function activation_hook() {
self::init_background_upgrader();
gf_upgrade()->maybe_upgrade();
}
/**
* Add Gravity Forms to the plugins that support logging.
*
* @since Unknown
* @access public
*
* @param array $plugins Existing plugins that support logging.
*
* @return array $plugins Supported plugins.
*/
public static function set_logging_supported( $plugins ) {
$plugins['gravityformsapi'] = 'Gravity Forms API';
$plugins['gravityforms'] = 'Gravity Forms Core';
return $plugins;
}
/**
* Gets the value of an option from the wp_options table.
*
* @since Unknown
* @access public
* @global $wpdb
*
* @param string $option_name The option to find.
*
* @return string The option value, if found.
*/
public static function get_wp_option( $option_name ) {
global $wpdb;
return $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->prefix}options WHERE option_name=%s", $option_name ) );
}
/**
* Determines if a form should be processed, and passes it off to processing.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::get_form()
* @uses GFCommon::get_base_path()
* @uses GFFormDisplay::process_form()
* @uses GFFormDisplay::process_send_resume_link()
*
* @return void
*/
public static function maybe_process_form() {
if ( isset( $_POST['gform_send_resume_link'] ) ) {
require_once( GFCommon::get_base_path() . '/form_display.php' );
GFFormDisplay::process_send_resume_link();
} elseif ( isset( $_POST['gform_submit'] ) ) {
require_once( GFCommon::get_base_path() . '/form_display.php' );
$form_id = GFFormDisplay::is_submit_form_id_valid();
if ( $form_id ) {
GFFormDisplay::process_form( $form_id );
}
}
}
/**
* Processes pages that are not loaded directly within WordPress
*
* @since Unknown
* @access public
*
* @uses GFCommon::get_upload_page_slug()
* @uses GFCommon::get_base_path()
*
* @return void
*/
public static function process_exterior_pages() {
if ( rgempty( 'gf_page', $_GET ) ) {
return;
}
$page = rgget( 'gf_page' );
$is_legacy_upload_page = $_SERVER['REQUEST_METHOD'] == 'POST' && $page == 'upload';
if ( $is_legacy_upload_page && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
_doing_it_wrong( 'gf_page=upload', 'gf_page=upload is now deprecated. Use GFCommon::get_upload_page_slug() instead', '1.9.6.13' );
}
$is_upload_page = $_SERVER['REQUEST_METHOD'] == 'POST' && $page == GFCommon::get_upload_page_slug();
if ( $is_upload_page || $is_legacy_upload_page ) {
require_once( GFCommon::get_base_path() . '/includes/upload.php' );
exit();
}
// Ensure users are logged in
if ( ! is_user_logged_in() ) {
auth_redirect();
}
switch ( $page ) {
case 'preview':
require_once( GFCommon::get_base_path() . '/preview.php' );
break;
case 'print-entry' :
require_once( GFCommon::get_base_path() . '/print-entry.php' );
break;
case 'select_columns' :
require_once( GFCommon::get_base_path() . '/select_columns.php' );
break;
}
exit();
}
/**
* Checks for Gravity Forms updates.
*
* @since Unknown
* @access public
*
* @uses GFCommon::check_update()
*
* @param GFAutoUpgrade $update_plugins_option The GFAutoUpgrade object.
*
* @return GFAutoUpgrade The GFAutoUpgrade object.
*/
public static function check_update( $update_plugins_option ) {
if ( ! class_exists( 'GFCommon' ) ) {
require_once( 'common.php' );
}
return GFCommon::check_update( $update_plugins_option, true );
}
/**
* Adds index and htaccess files to the upload root for security.
*
* @since Unknown
* @access public
*
* @return void
*/
public static function add_security_files() {
GFCommon::log_debug( __METHOD__ . '(): Start adding security files' );
$upload_root = GFFormsModel::get_upload_root();
if ( ! is_dir( $upload_root ) ) {
return;
}
GFCommon::recursive_add_index_file( $upload_root );
GFCommon::add_htaccess_file();
}
/**
* Self-heals suspicious files.
*
* @since Unknown
*/
private static function do_self_healing() {
GFCommon::log_debug( __METHOD__ . '(): Start self healing' );
$gf_upload_root = GFFormsModel::get_upload_root();
if ( ! is_dir( $gf_upload_root ) || is_link( $gf_upload_root ) ) {
return;
}
self::rename_suspicious_files_recursive( $gf_upload_root );
}
/**
* Renames files with a .bak extension if they have a file extension that is not allowed in the Gravity Forms uploads folder.
*
* @since Unknown
* @access private
*
* @used-by GFForms::do_self_healing()
*
* @param string $dir The path to process.
*/
private static function rename_suspicious_files_recursive( $dir ) {
if ( ! is_dir( $dir ) || is_link( $dir ) ) {
return;
}
if ( ! ( $dir_handle = opendir( $dir ) ) ) {
return;
}
// Ignores all errors
set_error_handler( '__return_false', E_ALL );
while ( false !== ( $file = readdir( $dir_handle ) ) ) {
if ( is_dir( $dir . DIRECTORY_SEPARATOR . $file ) && $file != '.' && $file != '..' ) {
self::rename_suspicious_files_recursive( $dir . DIRECTORY_SEPARATOR . $file );
} elseif ( GFCommon::file_name_has_disallowed_extension( $file )
&& ! GFCommon::match_file_extension( $file, array( 'htaccess', 'bak', 'html' ) )
) {
$mini_hash = substr( wp_hash( $file ), 0, 6 );
$newName = sprintf( '%s/%s.%s.bak', $dir, $file, $mini_hash );
rename( $dir . '/' . $file, $newName );
}
}
// Restores error handler
restore_error_handler();
closedir( $dir_handle );
return;
}
/**
* Renames suspicious content within the wp_upload directory.
*
* @deprecated 2.4.11
*
* @since Unknown
*/
private static function heal_wp_upload_dir() {
_deprecated_function( 'heal_wp_upload_dir', '2.4.11' );
$wp_upload_dir = wp_upload_dir();
$wp_upload_path = $wp_upload_dir['basedir'];
if ( ! is_dir( $wp_upload_path ) || is_link( $wp_upload_path ) ) {
return;
}
// ignores all errors
set_error_handler( '__return_false', E_ALL );
foreach ( glob( $wp_upload_path . DIRECTORY_SEPARATOR . '*_input_*.php' ) as $filename ) {
$mini_hash = substr( wp_hash( $filename ), 0, 6 );
$newName = sprintf( '%s.%s.bak', $filename, $mini_hash );
rename( $filename, $newName );
}
// restores error handler
restore_error_handler();
return;
}
/**
* Defines styles needed for "no conflict mode"
*
* @since Unknown
* @access public
* @global $wp_styles
*
* @uses GFForms::no_conflict_mode()
*/
public static function no_conflict_mode_style() {
if ( ! get_option( 'gform_enable_noconflict' ) ) {
return;
}
global $wp_styles;
$wp_required_styles = array( 'admin-bar', 'colors', 'ie', 'wp-admin', 'editor-style' );
$gf_required_styles = array(
'common' => array( 'gform_tooltip', 'gform_font_awesome', 'gform_admin' ),
'gf_edit_forms' => array(
'thickbox',
'editor-buttons',
'wp-jquery-ui-dialog',
'media-views',
'buttons',
'wp-pointer',
'gform_chosen',
),
'gf_edit_forms_settings' => array(
'thickbox',
'editor-buttons',
'wp-jquery-ui-dialog',
'media-views',
'buttons',
),
'gf_new_form' => array( 'thickbox' ),
'gf_entries' => array( 'thickbox', 'gform_chosen' ),
'gf_settings' => array(),
'gf_export' => array(),
'gf_help' => array(),
'gf_system_status' => array( 'thickbox' ),
);
self::no_conflict_mode( $wp_styles, $wp_required_styles, $gf_required_styles, 'styles' );
}
/**
* Defines scripts needed for "no conflict mode".
*
* @since Unknown
* @access public
* @global $wp_scripts
*
* @uses GFForms::no_conflict_mode()
*/
public static function no_conflict_mode_script() {
if ( ! get_option( 'gform_enable_noconflict' ) ) {
return;
}
global $wp_scripts;
$wp_required_scripts = array( 'admin-bar', 'common', 'jquery-color', 'utils', 'svg-painter' );
$gf_required_scripts = array(
'common' => array( 'gform_tooltip_init', 'sack' ),
'gf_edit_forms' => array(
'backbone',
'editor',
'gform_floatmenu',
'gform_forms',
'gform_form_admin',
'gform_form_editor',
'gform_gravityforms',
'gform_json',
'gform_menu',
'gform_placeholder',
'jquery-ui-autocomplete',
'jquery-ui-core',
'jquery-ui-datepicker',
'jquery-ui-sortable',
'jquery-ui-draggable',
'jquery-ui-droppable',
'jquery-ui-tabs',
'json2',
'media-editor',
'media-models',
'media-upload',
'media-views',
'plupload',
'plupload-flash',
'plupload-html4',
'plupload-html5',
'quicktags',
'rg_currency',
'thickbox',
'word-count',
'wp-plupload',
'wpdialogs-popup',
'wplink',
'wp-pointer',
'gform_chosen',
),
'gf_edit_forms_settings' => array(
'editor',
'word-count',
'quicktags',
'wpdialogs-popup',
'media-upload',
'wplink',
'backbone',
'jquery-ui-sortable',
'json2',
'media-editor',
'media-models',
'media-views',
'plupload',
'plupload-flash',
'plupload-html4',
'plupload-html5',
'plupload-silverlight',
'wp-plupload',
'gform_placeholder',
'gform_json',
'gform_gravityforms',
'gform_forms',
'gform_form_admin',
'jquery-ui-datepicker',
'gform_masked_input',
'sack',
'jquery-ui-autocomplete',
'wp-tinymce',
'wp-tinymce-root',
'wp-tinymce-lists',
),
'gf_new_form' => array(
'thickbox',
'jquery-ui-core',
'jquery-ui-sortable',
'jquery-ui-tabs',
'rg_currency',
'gform_gravityforms',
'gform_json',
'gform_form_admin',
),
'gf_entries' => array(
'thickbox',
'gform_gravityforms',
'wp-lists',
'gform_json',
'gform_field_filter',
'plupload-all',
'postbox',
'gform_chosen',
),
'gf_settings' => array(),
'gf_export' => array( 'gform_form_admin', 'jquery-ui-datepicker', 'gform_field_filter' ),
'gf_help' => array(),
'gf_system_status' => array(
'gform_system_report_clipboard',
'thickbox',
'gform_placeholder'),
);
self::no_conflict_mode( $wp_scripts, $wp_required_scripts, $gf_required_scripts, 'scripts' );
}
/**
* Runs "no conflict mode".
*
* @since Unknown
* @access private
*
* @used-by GFForms::no_conflict_mode_style()
* @used-by GFForms::no_conflict_mode_script()
*
* @param WP_Scripts $wp_objects WP_Scripts object.
* @param array $wp_required_objects Scripts required by WordPress Core.
* @param array $gf_required_objects Scripts required by Gravity Forms.
* @param string $type Determines if scripts or styles are being run through the function.
*/