Opened 8 years ago
Closed 8 years ago
#38905 closed defect (bug) (fixed)
REST API: Bring consistency to the `rest_insert_*` actions
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | dev-feedback has-patch |
Focuses: | Cc: |
Description
We are inconsistent on when we fire the rest_insert_*
actions in the create_item()
and update_item()
methods.
I see three possible options here:
option A:
Immediately after the wp_insert_*()
or wp_update_*()
function - before any meta or additional fields are processed.
option B:
After the wp_insert_*()
or wp_update_*()
function and meta or additional fields are processed - before the response is prepared.
option C:
After the wp_insert_*()
or wp_update_*()
function and meta or additional fields are processed and the response is prepared - before the response is sent.
In the endpoint controllers we tend to do a mixture of B or C. Personally, I would expect option A.
Either way, we should be consistent here.
Attachments (1)
Change History (6)
#1
@
8 years ago
- Keywords has-patch added; needs-patch removed
In 38905.diff I move the rest_insert_*
actions to fire after the related object is updated or inserted. Thge patch also includes some shuffling and clean-up as well including:
- Ensure we are passing the most current
$post
and$user
objects to theupdate_additional_fields_for_object()
callbacks. - Changes the function signature of
handle_status_param()
in the comments controller to accept just the comment_id as the 2nd parameter, instead of a full WP_Comment object. Only the comment_id is needed in the method, and I wanted to avoid adding anotherget_comment()
function. (not married to this, just seemed like the most logical approach) - Renames some variables in the
create_item()
method of the Posts controller to be more explicit. - Minor fixes/clarifications to the
rest_insert_*
hook docs
#2
@
8 years ago
This all looks good to me, though I'd like to get a review from @rmccue given how late in the cycle this is - it would be then good to commit asap to make rc1.
Fire the
rest_insert_*
actions after the initial object has been inserted or updated