Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There is a plugin that's conflicting with mine when the user loads the admin pages of my plugin, therefore I want to deregister and remove the conflicting script on these pages.

Here is the code for the conflicting script:-

add_action( 'admin_head', 'function_name' );

function function_name() {
if ( is_admin() ) {
    wp_enqueue_script(
        'script_name',
        plugins_url('/js/some_javascript_file.js', __FILE__ )
    );
}
}   

So In my code I check to see if the user is in our admin pages and if so I try to deregister the script as follows:-

function admin_hc_deregister_conflicts() {
 wp_deregister_script('script_name');
}

add_action('admin_head', array($this,'admin_hc_deregister_conflicts'),11);

The problem is that the script is still being loaded in my admin area causing a lot of problems!

Please can someone advise:-

i) Is it possible to remove a script that has been enqueued but not registered? ii) What can I add to my plugin to remove this script from being loaded in our admin pages so that there are no conflicts?

Thanks in advance!

share|improve this question
    
Is it not possible to code around the conflict, i.e., since you know there's a conflict, make your code take it into account and work around it. I ask because it's not obvious if your plugin is for public consumption or just for you. –  akTed Jan 7 '13 at 17:24
    
That is likely not a good solution in this case. The conflicting plugin is being a bad citizen by enqueueing scripts admin-wide rather than directly where they need to be. If those scripts are used admin-wide, then It's up to Paul here to code around the conflicts. –  chrisguitarguy Jan 7 '13 at 17:31
2  
a registered script is... registered, an enqueued script is registered and then enqueued, technically either dequeueing or deregistering should work, and does in fact work when I test it. it's also worth noting that admin_head is the wrong action to enqueue a script, but there's nothing you can do about that! –  Milo Jan 7 '13 at 17:35
    
I missed in the Question "our" admin pages. So if by that you mean option pages for your plugin, I stand corrected. Dequeue-ing should work. –  akTed Jan 7 '13 at 17:43
add comment

2 Answers 2

up vote 2 down vote accepted

Yep, it's possible, but you want to use wp_dequeue_script.

Try this:

<?php
function admin_hc_deregister_conflicts()
{
    wp_dequeue_script('script_name');
}
share|improve this answer
    
Thanks! Strangely, the script is still being loaded in my admin pages. Perhaps it's something to do with the order in which the scripts are being loaded? UPDATE: I was being a muppet: my hooked pages weren't working correctly - this works fine now! –  Paul McCarthy Jan 7 '13 at 17:59
add comment

See wp_dequeue_script. Keep in mind that you might be breaking functionality of the offending plugin, which is bad form (even if said plugin is poorly written).

It's up to the end user to decide if a (possibly) badly coded plugin is worth using, and you (however well-intentioned) "fixing" another's plugin through yours might only make yours look bad in the end. Most users don't care why something works or doesn't.

share|improve this answer
    
Thanks, yes I wouldn't usually attempt to deregister another author's script - but this particular script is loaded admin wide when it should only be loaded on its own admin pages and thus causing conflicts in my admin area –  Paul McCarthy Jan 7 '13 at 18:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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