Opened 16 years ago
Closed 16 years ago
#9209 closed enhancement (fixed)
Ajax for public pages (à la admin-ajax.php)
Reported by: |
|
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)
Change History (5)
#2
follow-up:
↓ 3
@
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
@
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.
If adding a generic Ajax handler, a Generic post handler would be appreciated, much like the current admin post handler.