Created
October 7, 2021 01:37
-
-
Save strsar/09506a4a326d436ffcb8fc6ffdecaf25 to your computer and use it in GitHub Desktop.
[WP] Gravity forms overrides
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php defined('ABSPATH') or header('Location: /'); | |
| /** | |
| * Gravity forms | |
| */ | |
| add_filter('gform_init_scripts_footer', '__return_true'); | |
| add_filter('gform_disable_print_form_scripts', '__return_true'); | |
| /** | |
| * Force Gravity forms to init scripts in the footer... | |
| * | |
| * It's crazy this needs to be here... | |
| * apparently gform_init_scripts_footer doesn't apply to ajax scripts | |
| */ | |
| add_filter('gform_cdata_open', 'wrap_gform_cdata_open', 1); | |
| add_filter('gform_cdata_close', 'wrap_gform_cdata_close', 99); | |
| function wrap_gform_cdata_open( $content = '' ) { | |
| if ( ! do_wrap_gform_cdata() ) { | |
| return $content; | |
| } | |
| $content = 'document.addEventListener( "DOMContentLoaded", function() { ' . $content; | |
| return $content; | |
| } | |
| function wrap_gform_cdata_close( $content = '' ) { | |
| if ( ! do_wrap_gform_cdata() ) { | |
| return $content; | |
| } | |
| $content .= ' }, false );'; | |
| return $content; | |
| } | |
| function do_wrap_gform_cdata() { | |
| if ( is_admin() | |
| || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) | |
| || isset( $_POST['gform_ajax'] ) | |
| || isset( $_GET['gf_page'] ) // Admin page (eg. form preview). | |
| || doing_action( 'wp_footer' ) | |
| || did_action( 'wp_footer' ) | |
| ) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| //add_filter('gform_field_css_class', function($classes, $field, $form) { | |
| // if($field->type == 'select') { | |
| // $classes .= ' custom-select'; | |
| // }else{ | |
| // $classes .= ' form-control'; | |
| // } | |
| // | |
| // return $classes; | |
| // | |
| //}, 10, 3); | |
| // @hack [form_display.php public] static function enqueue_scripts() | |
| //if ( ! function_exists( 'has_blocks' ) || ! has_blocks( $post->post_content ) ) { | |
| // return; | |
| //} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment