My Plugins Ajax Conflict
I’ve begun creating my first Ajax plugin and I’ve just hit my first big problem. I can’t say what the plugin does at this time. My plan is to master Ajax in WordPress then apply it to Easy CSV Importer. First I need to master it without trying to add it to ECI. The plugin itself works great, I’ve already made good use of Ajax however on activating ClassiPress my plugins Ajax fails, all of it.
The Problem
When I activate ClassiPress my plugins Ajax breaks. The failure is indicated in 3 notifications/errors shown below.
I spent 4 hours trying to figure this out, whatever I do allows the plugin to work normally until ClassiPress is activated. I assume it would happen with any theme because other plugins that use Ajax work fine with ClassiPress. Here are the main functions to give you a quick idea what I’m doing and that I’m trying to do it properly…
- Using add_action(‘admin_print_scripts’, ‘wtgpt_enqueue_script’);
- Tried also using add_action(‘admin_enqueue_scripts’, ‘wtgpt_enqueue_script’,10,1);
- I use wp_deregister_script( ‘jquery’ );
- I tried registering jquery from Google but that did not help either
- I’ve also tried only loading my scripts when viewing a specific page, a plugin page but I get the same problem
- if(is_admin()){ this is used at all times, none of the Ajax is to be used on the public side
Code Dump
// load admin only scripts if user is on admin pages
if(is_admin()){
global $wtgpt_mpt_arr;
// includes (functions)
include_once(WTG_PT_PATH.'include/wtgpt_admin_functions.php');
include_once(WTG_PT_PATH.'include/wtgpt_interface.php');
// add admin menu
add_action('admin_menu', 'wtgpt_admin_menu');
// wordpress media uploader START - same media overlay as on edit post page
# you need to change the expected page slug here by changing the menu pages array key
# see variables.php for customising the menu and pages in relation to the menu pages array
if (isset($_GET['page']) && $_GET['page'] == $wtgpt_mpt_arr[1]['slug']) {
function wtgpt_mediauploader_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script('my-upload', WP_PLUGIN_URL.'/wtgplugintemplate/script/uploader.js', array('jquery','media-upload','thickbox'));
wp_enqueue_script('my-upload');
}
function wtgpt_mediauploader_styles() {
wp_enqueue_style('thickbox');
}
add_action('admin_print_scripts', 'wtgpt_mediauploader_scripts');
add_action('admin_print_styles', 'wtgpt_mediauploader_styles');
}
// wordpress media uploader FINISH
// enqueue scripts
function wtgpt_enqueue_script() {
wp_deregister_script( 'jquery' );
//wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('jquery-ui-draggable');
wp_enqueue_script('jquery-ui-droppable');
wp_enqueue_script('jquery-ui-selectable');
wp_enqueue_script('jquery-ui-resizable');
wp_enqueue_script('jquery-ui-dialog');
}
add_action('admin_print_scripts', 'wtgpt_enqueue_script');
//add_action('admin_enqueue_scripts', 'wtgpt_enqueue_script',10,1);
// register admin only styles (currently not sure if we should be unregistering a built in jquery style?)
function wtgpt_register_admin_styles() {
//wp_deregister_style('wtgpt_jquery_styles');
wp_register_style('wtgpt_jquery_styles',plugins_url('wtgplugintemplate/jquery/css/overcast/jquery-ui-1.8.13.custom.css'), array(), '1.0', 'screen');
}
add_action('init', 'wtgpt_register_admin_styles');
// print admin only styles (must be preregistered)
add_action('admin_print_styles', 'wtgpt_styles_callback');
function wtgpt_styles_callback() {
wp_enqueue_style('my_css',plugins_url('wtgplugintemplate/jquery/css/overcast/jquery-ui-1.8.13.custom.css'), array('wtgpt_jquery_styles'), '1.0.0', 'screen');
}
}

Rather than adding jquery, why not just require it for the scripts when registering.. Since it’s already included with WP..
wp_register_script( ‘ZeroClipboard’,plugins_url( ‘/js/ZeroClipboard.js’, __FILE__), array( ‘jquery’ ));
wp_enqueue_script(‘ZeroClipboard’);
Your function does that about the 3rd line, function wtgpt_mediauploader_scripts
Thank you for your quick response Brad. Must admit I’m not 100% sure what you mean. Just to be clear, I’ve tried everything, not loading jQuery myself, loading specific scripts and not the ui core or jquery on its own, I’ve tried loading jquery and jquery ui core only when visiting a specific page.
Nothing changes, my plugin always works either way, until I activate ClassiPress. Can’t find another theme that uses a lot of Ajax in admin. Have tried plugins that use Ajax in admin and not found a conflict yet.