Opened 10 years ago
Closed 10 years ago
#35666 closed enhancement (fixed)
Add support for HTTP response codes to wp_send_json_error(), wp_send_json_success(), and wp_send_json
| Reported by: | johnbillion | Owned by: | johnbillion |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.7 |
| Component: | Formatting | Version: | 3.5 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
wp_send_json_error() is the JSON-encoded equivalent of wp_die(). It should therefore support the sending of an HTTP response code in a similar way so a more appropriate response code can be set for error conditions. Currently, the response code needs to be set manually, otherwise it defaults to 200.
Attachments (5)
Change History (30)
#6
@
10 years ago
- Resolution fixed
- Status closed → reopened
I've found a defect with the changes here. Namely, if status_header() was being called previously to wp_send_json(), then the default $status_header of 200 would clobber the status_header() that was first set. In other words, this breaks backwards compatibility.
On a related note, I also found that _ajax_wp_die_handler was clobbering the status_header() call if output buffering is on (since headers_sent() would be false). See 35666.3.diff.
This ticket was mentioned in Slack in #core by stevenkword. View the logs.
10 years ago
#12
@
10 years ago
@johnbillion -- Do you think you'd like to take a stab at the refresh, or would you like some fresh eyes on this?
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by desrosj. View the logs.
10 years ago
#18
@
10 years ago
- Keywords needs-refresh removed
Patch updated after 38576, but still needs testing on the output buffering.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
#20
@
10 years ago
35666.2.diff tackles this by always telling wp_die() not to set an HTTP status code header.
With output buffering on, this means a status set by wp_send_json() doesn't get clobbered. With output buffering off, the functionality doesn't change because headers_sent() in _ajax_wp_die_handler() is always true (due to the JSON echoed in wp_send_json()) so the status header doesn't get set anyway.
@westonruter Wanna give this a whirl?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
#36261 was marked as a duplicate.