Opened 9 months ago
Last modified 2 months ago
#4449 new enhancement
Hooking ajax actions inside of function scope in BP 1.6 causes issues with some themes
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.8 |
| Component: | Theme | Version: | 1.6 |
| Severity: | normal | Keywords: | 2nd-opinion |
| Cc: |
Description
In BP 1.6, hooks for AJAX actions were moved into the function bp_dtheme_register_actions(), which is hooked to after_setup_theme with a priority of 20. Prior to BP 1.6, these add_action() calls were in the global scope, meaning that they were fired immediately after the file was included. Some themes that directly include BP core's ajax.php, however, do it at a point *later* than after_setup_theme (such as http://wordpress.org/extend/themes/elbee-elgee, which loads ajax.php at widgets_init). As a result, the AJAX handlers are never successfully hooked, and AJAX events don't work.
I'm guessing this is affecting a very small number of themes (most either supply their own ajax.php, or load it at after_setup_theme like BP does). So it's probably something that we can fix with better documentation. A post on bpdevel would probably suffice. I thought I would first open this bug ticket, though, to see if any other dev thinks there's a better solution (such as moving the hooking event into the global scope - ugly, but it would work).
Change History (2)
comment:1
johnjamesjacoby — 5 months ago
- Milestone changed from 1.7 to 1.8
- Type changed from defect (bug) to enhancement
I'd like to see us build our own theme-side AJAX handler, without the cruft of using admin-ajax.php, which sets WP_ADMIN and calls 'admin_init' also.
Did this recently for an upcoming plugin.
However, unlike bbp_do_ajax(), I use an external file and not hooked to 'template_redirect'.
Here's a gist to look at:
https://gist.github.com/r-a-y/5209075

I'd like to see us build our own theme-side AJAX handler, without the cruft of using admin-ajax.php, which sets WP_ADMIN and calls 'admin_init' also.
Core ticket:
See: http://core.trac.wordpress.org/ticket/12400
bbPress trunk:
See: http://bbpress.trac.wordpress.org/changeset/4548/
See: http://bbpress.trac.wordpress.org/changeset/4549/
Moving to 1.8 to give us time to reimagine how to approach this, and whether or not we like the bbPress approach enough to implement it.