Skip to:

Opened 15 years ago

Closed 15 years ago

#1079 closed defect (bug) (fixed)

Custom AJAX action functions being called twice in /wp-admin

Reported by: mrmaz's profile MrMaz Owned by:
Milestone: 1.1 Priority: minor
Severity: Version:
Component: Keywords: Ajax, core function, duplicate calls
Cc: Jason_JM


If you use WordPress admin interface hooks to introduce custom AJAX functionality, the actions functions are being called twice.

The reason is because if you call the default ajaxurl (which is "http://[your-site]/wp-admin/admin-ajax.php") it provides a default switch case that calls your action function for you.


Since BuddyPress adds its own AJAX hook that looks for the identical $_REQUEST variable ('action'), they BOTH execute the same action function in succession.


The only safe workaround is to set your own ajaxurl inside your custom jQuery function to something other than "/wp-admin/admin-ajax.php" You must take care to not override the JS var "ajaxurl" that is set near the top of the document. Its probably a good idea to just avoid creating a JS variable named "ajaxurl" altogether.

A possible fix to the core is to do something like below, but I am not sure if this will have any side-effects or break other code.

function bp_core_add_ajax_hook() {
    if ( !defined('WP_ADMIN') )
        do_action( 'wp_ajax_' . $_REQUEST['action'] );

Change History (3)

#1 @Jason_JM
15 years ago

  • Keywords Ajax core function duplicate calls added
  • Milestone set to 1.1

Andy said he's bored, so Milestone 1.1


#2 @Jason_JM
15 years ago

  • Cc Jason_JM added

#3 @apeatling
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [1959]) Fixes #1079

Note: See TracTickets for help on using tickets.