Opened 10 years ago
Closed 6 years ago
#36271 closed task (blessed) (fixed)
Trigger _doing_it_wrong if wp_send_json is used on a REST API request
| Reported by: | rmccue | Owned by: | spacedmonkey |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.5 |
| Component: | REST API | Version: | 4.4 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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_wrongis triggered on a REST request, we should add a header ala the_deprecated_functionheaders. - If
wp_send_jsonis called on a REST request, we should trigger a_doing_it_wrongand point people towardsWP_REST_ResponseandWP_Error
Change History (14)
#2
@
6 years ago
- Keywords good-first-bug added
- Milestone → 5.5
- Version → 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.
6 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.
6 years ago
#10
@
6 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
@
6 years ago
- Resolution fixed
- Status closed → 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Moved into Future Release, needs a patch.