[wp-trac] [WordPress Trac] #45114: Publish posts and fire related hooks on `rest_after_insert_{$this->post_type}` for rest requests.
WordPress Trac
noreply at wordpress.org
Wed Oct 17 21:51:06 UTC 2018
#45114: Publish posts and fire related hooks on
`rest_after_insert_{$this->post_type}` for rest requests.
---------------------------+------------------------------
Reporter: peterwilsoncc | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
---------------------------+------------------------------
Comment (by kadamwhite):
While discussing this in Slack, @peterwilsoncc proposed the pseudocode
{{{#!php
function is_rest_request() {
return apply_filters ('is_rest_request', false);
}
add_filter( 'rest_pre_dispatch', function(){
add_filter( 'is_rest_request', '__return_true' );
} )
add_filter( 'rest_request_after_callbacks', function(){
remove_filter( 'is_rest_request', '__return_true' );
} )
}}}
I wonder (without having done any actual research into this) when else
we'd need to remove that filter so that is_rest_request returns false
again: possibly situations where we encounter an error while fulfilling
the request (in case the request is being dispatched from within the PHP
layer and that error is handled somehow); or if there are permissions
failures or other changes of state during a request lifecycle.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45114#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list