Recently I’ve been working a lot with Gravity Forms and some of the add-ons available to extend Gravity Forms features.

Today I’d the opportunity to spend time debugging some odd behaviours at Gravity Forms’ form editor screen, where some of the features related with one extension in particular weren’t working properly.

Turned out those odd behaviours were caused by a missing javascript file which was supposed to be enqueued with the Form Editor screen, but in the end it wasn’t. Funny that on my local WordPress installation I wasn’t able to reproduce the issue, but at the production installation it was happening consistently.

(No-)Conflict mode

The Gravity Forms plugin has a general setting to turn on/off the no-conflict mode:

Set this to ON to prevent extraneous scripts and styles from being printed on Gravity Forms admin pages, reducing conflicts with other plugins and themes.

Pretty cool feature, hum?!

Gravity Forms settings screen
Gravity Forms settings screen

When this mode is turned on, all the scripts and styles not allowed by the plugin itself, won’t load in the Gravity Forms admin pages, including the ones that are part of other Gravity Forms add-ons plugins that are not prepared to work in the no-Conflict mode.

The anti- no-conflict mode

In case you’re developing or debugging a Gravity Forms extension it is then recommended that in case you need to enqueue some style or script file on the Gravity Forms admin pages, you need to take into consideration that some users will use the no-conflict mode. In this case, the extension must “tell” Gravity Forms core that there are some extra scripts to be allowed when no-conflict mode is turned on.

Luckily, there’s a special filter to register “safe” scripts and styles – gform_noconflict_scripts. Here’s an example:

<?php
add_action( 'admin_enqueue_scripts', 'enqueue_scripts' );

function enqueue_scripts(){
    //enqueing my script on gravity form pages
    wp_enqueue_script( "my_addon_script", plugins_url("my-script.js", "my-plugin") );
}

add_filter('gform_noconflict_scripts', 'register_safe_script' );

function register_safe_script( $scripts ){
    //registering my script with Gravity Forms so that it gets enqueued when running on no-conflict mode
    $scripts[] = "my_addon_script";
    return $scripts;
}
?>

More information at Gravity Forms developer docs and WordPress Codex.