wp_enqueue_script registers script but does not create html tag

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.

Read More

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.

Related posts

Leave a Reply

1 comment

  1. 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.