mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API, Posts: Add a hook to fire once a post, its terms and meta update.
Introduces the action `wp_after_insert_post` inside a wrapper function of the same name. This hook allows plugin developers to access a posts full data (including its terms and meta data) regardless of the workflow used to save it. A new parameter is introduced to `wp_insert_post()` to indicate whether the hook should be fired within the function call or will be fired afterward. Props aristath, Collizo4sky, danielbachhuber, joyously, kadamwhite, kraftbj, markparnell, mikeschroder, noisysocks, peterwilsoncc, SergeyBiryukov, talldanwp, thewebprincess, TimothyBlynJacobs. Fixes #45114. git-svn-id: https://develop.svn.wordpress.org/trunk@49172 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -591,7 +591,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
|
||||
$prepared_post->post_type = $this->post_type;
|
||||
|
||||
$post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true );
|
||||
$post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true, false );
|
||||
|
||||
if ( is_wp_error( $post_id ) ) {
|
||||
|
||||
@@ -677,6 +677,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
|
||||
|
||||
wp_after_insert_post( $post, false );
|
||||
|
||||
$response = $this->prepare_item_for_response( $post, $request );
|
||||
$response = rest_ensure_response( $response );
|
||||
|
||||
@@ -758,7 +760,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
}
|
||||
|
||||
// Convert the post object to an array, otherwise wp_update_post() will expect non-escaped input.
|
||||
$post_id = wp_update_post( wp_slash( (array) $post ), true );
|
||||
$post_id = wp_update_post( wp_slash( (array) $post ), true, false );
|
||||
|
||||
if ( is_wp_error( $post_id ) ) {
|
||||
if ( 'db_update_error' === $post_id->get_error_code() ) {
|
||||
@@ -828,6 +830,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||
/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
|
||||
do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
|
||||
|
||||
wp_after_insert_post( $post, true );
|
||||
|
||||
$response = $this->prepare_item_for_response( $post, $request );
|
||||
|
||||
return rest_ensure_response( $response );
|
||||
|
||||
Reference in New Issue
Block a user