Opened 9 years ago
Closed 5 years ago
#36271 closed task (blessed) (fixed)
Trigger _doing_it_wrong if wp_send_json is used on a REST API request
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | REST API | Keywords: | has-patch |
Focuses: | Cc: |
Description
We should heavily discourage users from using wp_send_json (& co.) on REST API requests. Two changes I want to make:
- If
_doing_it_wrong
is triggered on a REST request, we should add a header ala the_deprecated_function
headers. - If
wp_send_json
is called on a REST request, we should trigger a_doing_it_wrong
and point people towardsWP_REST_Response
andWP_Error
Change History (14)
#1
@
9 years ago
- Keywords has-unit-tests added
- Milestone changed from Awaiting Review to Future Release
#2
@
5 years ago
- Keywords good-first-bug added
- Milestone set to 5.5
- Version set to 4.4
I still see this occurring in the wild. Milestoning for 5.5.
This ticket was mentioned in PR #325 on WordPress/wordpress-develop by TimothyBJacobs.
5 years ago
#4
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/36271
This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.
5 years ago
#10
@
5 years ago
I would not have used
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
here. I would have used.
if ( wp_is_json_request() ) {
CC @whyisjake @SergeyBiryukov
#11
@
5 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
@TimothyBlynJacobs Could you double-check comment:10?
At a glance, checking REST_REQUEST
seems correct to me, as the message is specific to REST API, but I'm not deeply familiar with the history here.
Note: See
TracTickets for help on using
tickets.
Moved into Future Release, needs a patch.