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.

I used the Custom Category Post Order plugin in my Wordpress site. But this plugin load 4 times jquery ui code in. This jQuery ui code generate errors in my own javascript code. Is it posible to load only the jquery ui script in the admin page in wordpress. Of is that not possible.?

share|improve this question
    
add_action( 'admin_enqueue_scripts', 'my_function_to_enqueue_scripts' ); –  Tom Auger Aug 15 '12 at 15:39
add comment

2 Answers

This is a very poorly coded plugin, and a good writer should know better.

I've grepped through the code and found the process_post method which is hooked into init (why?!) and enqueues jquery-ui-sortable which is probably the code which breaks your code:

function process_post(){
    global $wp_query;
    wp_enqueue_script( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.8.20', 1 );
}

and

add_action('init', array($this,'process_post'));

in the constructor.

However the class isn't actually assigned to a variable when defined:

new customcategorypostorder();

And so unfortunately none of the actions can be accessed so you have no option but to modify their code. (Out of interest does anyone know how PHP handles such an instance?) To keep things simple, I'd recommend assigning the class to a variable, and then removing the hook and then re-adding it to just the admin area. To be brutally honest it shouldn't be added to any 'init' hook whatsoever, but it's probably best for compatibility reasons.

Modify last line of plugin into something like this,

$customcategorypostorderinstance = new customcategorypostorder();

And the add this to functions.php,

remove_action('init', array($customcategorypostorderinstance, 'process_post'));
add_action('admin_init', array($customcategorypostorderinstance, 'process_post'));

Hope this helps, and remember to complain to the developer!

share|improve this answer
add comment

It's very possible, and a good plugin writer should know better. The solution is not a simple one, and unless you're comfortable editing the plugin, you'll probably want to contact the author of the offending code.

Scribu has a great little tutorial on the proper ways to load javascript located here: http://scribu.net/wordpress/optimal-script-loading.html

And Justin Tadlock does a good admin specific writeup here: http://justintadlock.com/archives/2011/07/12/how-to-load-javascript-in-the-wordpress-admin

share|improve this answer
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.