[wp-hackers] Plugins: Best practice for conditional loading of actions and file includes

Otto otto at ottodestruct.com
Tue Feb 9 21:14:00 UTC 2010


Basically, you want to make your javascript fire the request at
"admin_url('admin-ajax.php')". The request will need to include action
= 'some_special_action' in the POST.

Then you hook a function to wp_ajax_nopriv_some_special_action. The
function will get called for your action and it can get the stuff out
of the POST and act on it. Then it makes its own output and can call
exit or die to end the request quickly.

You *can* use the same sort of methods I describe in my earlier post,
but since there's special code for AJAX actions, you should use it


On Tue, Feb 9, 2010 at 3:01 PM, Alex Hempton-Smith
<hempsworth at googlemail.com> wrote:
> Sorry if this is a basic question, but I'm working on an Ajax driven
> plugin at the moment, and I'm using wp-load.pho and I now know I
> shouldn't be! Especially since I'd like to release the plugin!
> I'm enqueuing a js file, wherein it uses 'jQuery.post' to send data to
> my plugin file. To process that request, I have an 'if (
> isset($_POST))' which then includes wp-load.php, giving me access to
> WP functions so I can process the request and echo the result.
> Any tips on using Ajax in front-end plugins. there is a lot of
> documentation on admin-ajax but not much on Ajax in plugins...
> Many thanks,
> Alex
> --
> -- Alex  (Hempsworth)
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list