#42600 closed defect (bug) (duplicate)
Adding term with duplicate name via REST API no longer returning existing term ID
Reported by: | shooper | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9 |
Component: | REST API | Keywords: | has-patch has-unit-tests dev-feedback |
Focuses: | rest-api | Cc: |
Description
Reported by @coleh in the ticket that caused this change, #41370.
In WordPress 4.9, if you add a term with a duplicate name using the REST API, the 'data' element used to contain the ID of the existing term. It now just an array that only includes the HTTP status code.
Here's the output of the REST API calls in both 4.8 and 4.9:
In WordPress 4.8, returns HTTP status code 500 and this body:
{ "code": "term_exists", "message": "A term with the name provided already exists with this parent.", "data": 2 }
In WordPress 4.9, returns HTTP status code 409 and this body:
{ "code": "term_exists", "message": "A term with the name provided already exists with this parent.", "data": { "status": 409 } }
Note that this was my original patch. I'm happy to provide the fix for it here.
Attachments (1)
Change History (4)
Note: See
TracTickets for help on using
tickets.
I don't believe it's possible to have 100% backward compatibility with 4.8.x as by changing the HTTP status code to 409, the data element in the response became an array instead of an integer. What I suggest is adding 'term_id' to the data array.
Is there a way to change the status code without using the add_data() function?