AJAX changes in BuddyPress 1.6

In a recent change, we’ve updated where the Default Theme’s ajaxurl variable points to; it now points to admin-ajax.php instead of wp-load.php. If you are a BuddyPress plugin author who uses this, update your plugin now to ensure compatibility with BuddyPress 1.6.

Since the early days, the Default Theme has output a javascript variable called “ajaxurl” into the page, and it contained the URL to wp-load.php, which is used early in the WordPress loading bootstrap. Likewise, in WordPress itself, when you’re at a page inside the /wp-admin/ part of the site, it also sets a variable called ajaxurl; rather than pointing to the same place as BuddyPress, the URL it contained was to admin-ajax.php.

Why the difference? BuddyPress was doing it wrong; admin-ajax.php works just fine from the front of your site. We’ve figured out a way to guarantee backwards compatibility for any combination and version of BP Default that you might be using, so nothing will break when you upgrade to BuddyPress 1.6.

However, in situations where a site uses 1.6’s Default Theme as the active theme, or as a parent theme, or when _inc/ajax.php is copied into another theme, if a third-party BuddyPress plugin makes use of BuddyPress’ ajaxurl, your plugin’s AJAX may break. In a nutshell, unless you terminate script output through exit() after your AJAX handler does its stuff, WordPress will suffix your output with a zero (details on the WP Codex), and this may have undesired results.

Plugin authors should implement this change in their plugins now. It’s a backwards compatible change, and will work on all current versions of BuddyPress, and help you avoid bug reports after 1.6 is released.