diff --git a/class-gwiz-gf-custom-code.php b/class-gwiz-gf-custom-code.php index e0550ee..2694f65 100644 --- a/class-gwiz-gf-custom-code.php +++ b/class-gwiz-gf-custom-code.php @@ -251,6 +251,7 @@ public function init() { add_filter( 'gform_register_init_scripts', array( $this, 'register_init_scripts' ), 99, 1 ); add_filter( 'gform_register_init_scripts', array( $this, 'maybe_register_custom_js_scripts_first' ), 100, 1 ); + add_filter( 'gform_register_init_scripts', array( $this, 'maybe_remove_legacy_custom_js_scripts' ), 100, 1 ); add_filter( 'gform_get_form_filter', array( $this, 'add_custom_css' ), 10, 2 ); } @@ -341,6 +342,33 @@ public function maybe_register_custom_js_scripts_first( $form ) { GFFormDisplay::$init_scripts[ $form['id'] ] = $filtered; } + public function maybe_remove_legacy_custom_js_scripts( $form ) { + /** + * Whether or not to remove legacy Custom JS plugin scripts from the + * registration list. + * + * @param bool $should_remove_legacy_custom_js_scripts Whether to remove legacy Custom JS plugin scripts from the registration list. + * @param array $form The form object. + */ + if ( ! apply_filters( 'should_remove_legacy_custom_js_scripts', true, $form ) ) { + return; + } + + $scripts = rgar( GFFormDisplay::$init_scripts, $form['id'] ); + if ( empty( $scripts ) ) { + return; + } + + $filtered = array(); + foreach ( $scripts as $slug => $script ) { + if ( strpos( $slug, 'gf_custom_js' ) === false ) { + $filtered[ $slug ] = $script; + } + } + + GFFormDisplay::$init_scripts[ $form['id'] ] = $filtered; + } + public function add_custom_css( $form_string, $form ) { $custom_css = $this->get_custom_css( $form ); $custom_css = html_entity_decode( $custom_css ); @@ -575,7 +603,7 @@ public function maybe_display_custom_js_warning() { echo '
'; /* translators: %s: opening HTML tag, %s closing HTML tag */ echo '

' . __( sprintf( - 'Warning: %sGravity Forms Custom Javascript%s is currently active.', '', '' ), + 'Warning: %sGravity Forms Custom Javascript%s is currently active.', '', '' ), 'gf-custom-code' ) . '

'; echo '

' . __(