Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#30143 closed enhancement (duplicate)

Using admin-ajax from the frontend

Reported by: lukecarbis's profile lukecarbis Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: javascript, template, performance Cc:


WP Ajax should not be used from the frontend because responses from admin-ajax.php are not cached (including nocache_headers()). Also, it has admin and .php in the URL.

Instead, we should add a query var, and then do the template_include routine to select a template that returns JSON. This would also makes sites more RESTful.

I've put together a bit of an idea of how this should work here:

This routine is something that we could put in the docs, however, if parts of this were implemented in core it would make things a lot simpler for everyone.

My suggestion is to add wp_ajax_action to the default query vars, and ajax callbacks inside the template loader (see the gist above for an example).

(props @westonruter for some help putting this together)

Change History (2)

This ticket was mentioned in Slack in #core by lukecarbis. View the logs.

10 years ago

#2 @westi
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

We have an older ticket where we have already been working on this issue and trying to come up with a secure solution - #12400

Note: See TracTickets for help on using tickets.