Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#9209 closed enhancement (fixed)

Ajax for public pages (à la admin-ajax.php)

Reported by: dancoulter's profile DanCoulter Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch needs-testing
Focuses: Cc:

Description

There's no way for plugins or themes to call custom Ajax actions on public parts of the blog without calling files in the plugin or theme directory directly. Some people like to restrict those directories so that they aren't world-viewable (or at least restrict access to PHP files), so it would be great if there was a public version of the admin-ajax.php file.

Attachments (1)

wp-ajax.patch (672 bytes) - added by DanCoulter 16 years ago.

Download all attachments as: .zip

Change History (5)

@DanCoulter
16 years ago

#1 @DD32
16 years ago

  • Type changed from defect (bug) to enhancement

If adding a generic Ajax handler, a Generic post handler would be appreciated, much like the current admin post handler.

#2 follow-up: @filosofo
16 years ago

Replying to DanCoulter:

There's no way for plugins or themes to call custom Ajax actions on public parts of the blog without calling files in the plugin or theme directory directly.

Actually, all you have to do is send your xhr request to something like http://example.com/?my-special-request=1

Then hook into the init action:

add_action('init', 'check_for_xhr');
function check_for_xhr() {
     if ( ! empty( $_GET['my-special-request'] ) )
          // do whatever

}

#3 in reply to: ↑ 2 @DanCoulter
16 years ago

Replying to filosofo:

Actually, all you have to do is... [snip]

Somehow that hadn't occurred to me and this is certainly the way to go with 2.7 and earlier. The downside of using the init hook is that you might not be able to let other plugins run their init actions before processing the ajax call and ending execution.

Maybe that's an edge case that doesn't warrant a change, though. Either way, I can do what I need to.

#4 @ryan
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Addressed in trunk with some new hooks.

Note: See TracTickets for help on using tickets.