[wp-hackers] AJAX for the frontend

Expert IT Dude expert.it.dude at gmail.com
Thu Sep 17 16:27:09 UTC 2009


"Implementing Ajax on the viewer-facing side of a WordPress site is
slightly more ad-hoc than doing Ajax on the administration side,
because WordPress itself doesn't have viewer-facing Ajax built in"
(http://codex.wordpress.org/AJAX_in_Plugins)

'Slightly' is a gross understatement. Let's call this what it actually
is: A hack. Spent half a day hunting for an AJAX interface in the WP
front-end and discovered it doesn't exist.

It would literally only be about 50 lines or so of code to write a
wp-ajax.php file for the root WP directory that has a singular hook
that plugins could utilize for a callback. Even if the WP frontend
doesn't ever use it, plugins could cleanly and consistently leverage
the hooking interface for whatever AJAX they want on the frontend. It
would pretty much be a copy-and-paste from the admin-ajax.php script
(with maybe a couple changes to wp-settings.php), is something a core
WP developer could crank out in an evening, and would save us plugin
developers a major headache. We could then just simply use
jQuery.load('wp-ajax.php', {...}); (or similar) from wherever and,
bam!, instant AJAX support for our plugins on the frontend complete
with a clean hooking interface similar to what admin-side AJAX plugins
already have.


More information about the wp-hackers mailing list