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