1

I wrote a plugin that enqueues a script and stylesheet only on a specific admin page. It works in my dev environment and multiple production servers; however, was introduced recently to a site that is utilizing the plugin and it will not render the script or stylesheet tag to the page. Here is the code:

add_action( 'admin_enqueue_scripts', 'gf_notification_attachment_attach_script');
// actual function to enqueue
function gf_notification_attachment_attach_script(){
    global $gf_notification_attachment;
    $plugin = $gf_notification_attachment;
    if( GFForms::get_page() == 'notification_edit'){
        $script = $plugin->plugin_url . 'script';
        $script .= ( WP_DEBUG ) ? '.js' : '.min.js';
        wp_enqueue_script( $plugin->text_domain, $script, array('gform_gravityforms'), $plugin->version, true );
        wp_enqueue_style( $plugin->text_domain, $plugin->plugin_url . 'style.css', array(), $plugin->version );         
    }
}

I have inserted debug code to echo $script within the conditional in the function and it lists the path correctly. I also have dumped the global $wp_scripts var to the screen after calling the enqueue and see it listed correctly along with all the other scripts in the list.

As a bit of further testing I confirmed the only 2 plugins active were Gravity Forms and my plugin (which is dependent on GF). I also activated the default 2014 theme. I also removed the dependance on the Gravity Forms (conditional check for admin page) and tried and it still will not render the script tag.

I'm at a loss here as to what could be causing it to not show on this one site. Even wp_enqueue_script works within other plugins. Any ideas? If you wish to test the plugin and have "Gravity Forms" you can download and test the full code base yourself.

3
  • Just to clarify while this is used specifically as an addon to Gravity Forms this particular issue can be demonstrated independantly of Gravity Forms. Commented Apr 3, 2014 at 14:48
  • Why not just use the $hook parameter provided by anything hooked to admin_enqueue_scripts to check what page you're on? Commented Apr 3, 2014 at 16:45
  • Gravity Forms does specific paging within the form editor. To WordPress it looks like 1 page but is really separated by specific sub page parameters as such page=gf_edit_forms&view=settings&subview=notification Commented Apr 18, 2014 at 10:57

1 Answer 1

0

This ended up being a weird conflict with how no-conflict mode works in Gravity Forms. Finally, working with their support and trying n+1 combinations it turns out that conflict mode is causing the issue:

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

In regards to using the $hook parameter for admin_enqueue_scripts mentioned in the notes it is because of how the plugin (Gravity Forms) does specific paging within the form editor. To WordPress it looks like 1 page but is really separated by specific sub page parameters as such ?page=gf_edit_forms&view=settings&subview=notification

I hope this helps someone else, look at the plugin settings/code specific to deregistering scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.