[buddypress-trac] [BuddyPress] #1079: Custom AJAX action functions being called twice in /wp-admin
buddypress-trac at lists.automattic.com
buddypress-trac at lists.automattic.com
Thu Sep 24 18:29:15 UTC 2009
#1079: Custom AJAX action functions being called twice in /wp-admin
-------------------+--------------------------------------------------------
Reporter: MrMaz | Owner:
Type: defect | Status: new
Priority: minor | Milestone:
Keywords: |
-------------------+--------------------------------------------------------
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.
See: http://core.trac.wordpress.org/browser/tags/2.8.4/wp-admin/admin-
ajax.php#L1352
Since BuddyPress adds its own AJAX hook that looks for the identical
$_REQUEST variable ('action'), they BOTH execute the same action function
in succession.
See: http://trac.buddypress.org/browser/trunk/bp-core.php#L1707
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'] );
}
}}}
--
Ticket URL: <http://trac.buddypress.org/ticket/1079>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list