Opened 12 years ago
Last modified 3 months ago
#22589 reviewing enhancement
Network Admin + Ajax requests
Reported by: | dd32 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Networks and Sites | Keywords: | has-patch |
Focuses: | multisite, administration | Cc: |
Description
Currently there is no Network admin based ajax handler, forcing plugins which exist solely within the Network Admin to either use wp-admin/admin-ajax.php
or using the load-{$page_hook}
hook to perform any actions.
This is primarily a problem when the plugin only includes code on a conditional such as is_network_admin()
, which would be false for a /wp-admin/admin-ajax.php
request, as a result, only the load-{$page_hook}
option above is viable for those.
As a work around, plugins can include code on is_network_admin() || DOING_AJAX
to allow the usage of admin-ajax.php.
Of course, the User Admin also suffers the same issue.
I didn't see any previous tickets, and kind of want to say the existing 'workaround' is appropriate, but recording it here so we can at least close it as wontfix if appropriate.
Attachments (3)
Change History (25)
#3
@
11 years ago
+1 I have same problem.
I wrote a small workaroud:
if (defined('DOING_AJAX') && DOING_AJAX && is_multisite() && preg_match('#^'.network_admin_url().'#i',$_SERVER['HTTP_REFERER'])) { define('WP_NETWORK_ADMIN',true); }
#6
@
11 years ago
- Component changed from Network Admin to Networks and Sites
- Focuses administration added
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
#9
@
9 years ago
Any news on this? Currently my hack includes passing a salted token with request and verifying it in the normal admin ajax hook to ensure its network admin. Definitely seems there should be a better / native alternative.
#10
@
9 years ago
- Milestone changed from Awaiting Review to Future Release
If anyone wants to patch this, I'd be interested in taking a look at that patch for 4.6. :)
Some examples of plugins that are hacking together a wp-admin/admin-ajax.php
solution would be good so we know what the target audience is.
#11
@
9 years ago
- Keywords has-patch needs-testing added; needs-patch removed
22589.diff adds a wp-admin/network/admin-ajax.php
file and wp_network_ajax(_nopriv)_
actions.
#12
@
9 years ago
@thomaswm - Awesome, wonder if we can get this tested and push for it to be included in 4.6.
#14
@
8 years ago
22589.2.diff has some minor adjustments:
- if not a multisite, bail, similar like in other network areas
- do not include the
ajax-actions.php
file since it is not required at this point; if Core starts using the network AJAX functionality itself, we can either re-add the file or (what I'd prefer) create a separatenetwork-ajax-actions.php
file for this - some docs adjustments (version numbers, "network AJAX")
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
8 years ago
#17
@
8 years ago
- Owner changed from flixos90 to jeremyfelt
- Status changed from assigned to reviewing
#18
follow-up:
↓ 19
@
8 years ago
- Keywords needs-testing removed
- Fixes
require()
forwp-load.php
- Updates a few areas to match code standards.
- Adds the JS global var
networkajaxurl
onadmin-header.php
ifis_network_admin()
.
Does networkajaxurl
make sense?
#19
in reply to:
↑ 18
@
8 years ago
Replying to jeremyfelt:
Does
networkajaxurl
make sense?
It's a really long lower-case term, so not sure if it could have a better name. On the other hand it matches ajaxurl
.
What we could also do to improve the infrastructure is to add a JS function for making network AJAX requests (or adjust the existing wp.ajax.post()
. Probably a separate ticket though.
#20
@
8 years ago
Just a thought as I have been following this for a bit, could a plugin dev not just fire a request to ajaxurl with a network=true argument?
With that argument redirect the request any way you need, but leaves one endpoint to maintain, and JS can easily switch between network and single mode.
Just a thought that may simplify things.
#21
@
8 years ago
- Milestone changed from 4.6 to Future Release
I know we're close, but I'm going to punt this to a future release. There is room for more conversation here about the approach.
#22
@
3 months ago
- Owner jeremyfelt deleted
I didn't see any previous tickets, and kind of want to say the existing 'workaround' is appropriate, but recording it here so we can at least close it as wontfix if appropriate.
I kind of like this.
One question: is an admin-ajax.php
flow still desirable or is it nicer now to register REST route instead?
I don't think the workaround is appropriate; it's a hack.
We should have a dedicated /wp-admin/network/admin-ajax.php file, which contains all the network-specific ajax handlers.