Opened 9 years ago
Closed 8 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 |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Formatting | Keywords: | has-patch commit |
Focuses: | Cc: |
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)
#4
@
8 years ago
- Owner set to johnbillion
- Resolution set to fixed
- Status changed from new to closed
In 38422:
#6
@
8 years ago
- Resolution fixed deleted
- Status changed from closed to 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.
8 years ago
#12
@
8 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.
8 years ago
#14
@
8 years ago
- Owner changed from johnbillion to stevenkword
- Status changed from reopened to reviewing
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by desrosj. View the logs.
8 years ago
#18
@
8 years ago
- Keywords needs-refresh removed
Patch 35666.4.diff updated after 38576, but still needs testing on the output buffering.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#20
@
8 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?
#36261 was marked as a duplicate.