Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter Appinco

    (@appinco)

    Hello,

    Let me clarify a bit more on the issue at hand, all scripts are properly enqueued in the wp_enqueue_scripts hook in the theme and activated plugins (just a couple). These have no issues with merging in the footer and are properly minified. The scripts as enqueued in the theme are enqueued into the footer as following;

    
    add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
    function enqueue_scripts() {
        wp_enqueue_script( 'theme-mobile', $base.'/resource/js/main.mobile.js', array('jquery'), null, true );
        // More enqueued scripts
    }
    

    This works without issues. However the moment I activate the plugin gravity forms all/most other scripts in the theme and plugins no longer are merged/processed on pages where gravity forms does not load/enqueue any scripts. This is very strange because on pages where there do are forms and thus make gravity forms enqueue scripts suddenly all theme and other plugin scripts do load & merge fine.

    Gravity forms only enqueues scripts on pages that use it’s forms through shortcodes. I am unable to figure out why it is that all scripts are merged fine on pages where gravity forms does load scripts, yet scripts are not merged on pages where gravity forms does not load scripts. (Forcefully deregistering all scripts enqueued by the plugin does not seem to help)

    Below is a codeblock of how the plugin enqueues it’s scripts, which seems to be properly enqueued to me.

    
    /**
     * Register needed hooks.
     *
     * @since 2.4.10
     */
    public function init() {
    
    	parent::init();
    
    	add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_form_scripts' ) );
    
    }
    
    
    /**
     * Parse current post's blocks for Gravity Forms block and enqueue required form scripts.
     *
     * @since  2.4.10
     */
    public function maybe_enqueue_form_scripts() {
    
    	global $wp_query;
    
            // Some truncated code here
    
    	foreach ( $wp_query->posts as $post ) {
    
                    // Some truncated code here
    
    		// Enqueue scripts for found forms.
    		foreach ( $form_ids as $form_id => $ajax ) {
    			$form = GFAPI::get_form( $form_id );
    			GFFormDisplay::enqueue_form_scripts( $form, $ajax );
    		}
    
    	}
    
    }
    
    
    public static function enqueue_form_scripts( $form, $ajax = false ) {
    
    	// adding pre enqueue scripts hook so that scripts can be added first if a need exists
    	/**
    	 * Fires before any scripts are enqueued (form specific using the ID as well)
    	 *
    	 * @param array $form The Form Object
    	 * @param bool  $ajax Whether AJAX is on or off (True or False)
    	 */
    	gf_do_action( array( 'gform_pre_enqueue_scripts', $form['id'] ), $form, $ajax );
    
    	if ( ! get_option( 'rg_gforms_disable_css' ) ) {
    
    		wp_enqueue_style( 'gforms_reset_css' );
    
    		if ( self::has_datepicker_field( $form ) ) {
    			wp_enqueue_style( 'gforms_datepicker_css' );
    		}
    
    		wp_enqueue_style( 'gforms_formsmain_css' );
    		wp_enqueue_style( 'gforms_ready_class_css' );
    		wp_enqueue_style( 'gforms_browsers_css' );
    
    		if ( is_rtl() ) {
    			wp_enqueue_style( 'gforms_rtl_css' );
    		}
    	}
    
    	if ( self::has_conditional_logic( $form ) ) {
    		wp_enqueue_script( 'gform_conditional_logic' );
    	}
    
    	if ( self::has_datepicker_field( $form ) ) {
    		wp_enqueue_script( 'gform_datepicker_init' );
    	}
    
    	if ( $ajax || self::has_price_field( $form ) || self::has_password_strength( $form ) || GFCommon::has_list_field( $form ) || GFCommon::has_credit_card_field( $form ) || self::has_conditional_logic( $form ) || self::has_currency_format_number_field( $form ) || self::has_calculation_field( $form ) || self::has_recaptcha_field( $form ) || self::has_checkbox_field( $form, true ) || self::has_js_merge_tag( $form ) || GFCommon::has_repeater_field( $form ) ) {
    		wp_enqueue_script( 'gform_gravityforms' );
    	}
    
    	if ( GFCommon::has_multifile_fileupload_field( $form ) ) {
    		wp_enqueue_script( 'plupload-all' );
    	}
    
    	if ( self::has_fileupload_field( $form ) ) {
    		wp_enqueue_script( 'gform_gravityforms' );
    		GFCommon::localize_gform_gravityforms_multifile();
    	}
    
    	if ( self::has_enhanced_dropdown( $form ) || self::has_pages( $form ) ) {
    		wp_enqueue_script( 'gform_json' );
    		wp_enqueue_script( 'gform_gravityforms' );
    	}
    
    	if ( self::has_character_counter( $form ) ) {
    		wp_enqueue_script( 'gform_textarea_counter' );
    	}
    
    	if ( self::has_input_mask( $form ) ) {
    		wp_enqueue_script( 'gform_masked_input' );
    	}
    
    	if ( self::has_enhanced_dropdown( $form ) && ! wp_script_is( 'chosen' ) ) {
    		wp_enqueue_script( 'gform_chosen' );
    	}
    
    	if ( self::has_enhanced_dropdown( $form ) ) {
    		if ( wp_script_is( 'chosen', 'registered' ) ) {
    			wp_enqueue_script( 'chosen' );
    		} else {
    			wp_enqueue_script( 'gform_chosen' );
    		}
    	}
    
    	if ( self::has_placeholder( $form ) ) {
    		wp_enqueue_script( 'gform_placeholder' );
    	}
    
    	/**
    	 * Fires after any scripts are enqueued (form specific using the ID as well)
    	 *
    	 * @param array $form The Form Object
    	 * @param bool  $ajax Whether AJAX is on or off (True or False)
    	 */
    	gf_do_action( array( 'gform_enqueue_scripts', $form['id'] ), $form, $ajax );
    
    	// enqueue jQuery every time form is displayed to allow 'gform_post_render' js hook
    	// to be available to users even when GF is not using it
    	wp_enqueue_script( 'jquery' );
    
    	if ( wp_script_is( 'gform_gravityforms' ) ) {
    		wp_localize_script( 'gform_gravityforms', 'gf_global', GFCommon::gf_global( false, true ) );
    	}
    
    }
    
    • This reply was modified 4 years, 9 months ago by Appinco. Reason: Corrected code blocks
Viewing 1 replies (of 1 total)