Make WordPress Core


Ignore:
Timestamp:
10/17/2018 11:19:02 AM (8 years ago)
Author:
danielbachhuber
Message:

REST API: Fire actions after items are completely updated/inserted.

The existing rest_insert_* actions are fired before meta and additional fields are updated. These new rest_after_* actions fire after all write operations have completed.

Props timothyblynjacobs.
Fixes #42864.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r43720 r43737  
    601601                $request->set_param( 'context', 'edit' );
    602602
     603                /**
     604                 * Fires after a single post is completely created or updated via the REST API.
     605                 *
     606                 * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
     607                 *
     608                 * @since 5.0.0
     609                 *
     610                 * @param WP_Post         $post     Inserted or updated post object.
     611                 * @param WP_REST_Request $request  Request object.
     612                 * @param bool            $creating True when creating a post, false when updating.
     613                 */
     614                do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
     615
    603616                $response = $this->prepare_item_for_response( $post, $request );
    604617                $response = rest_ensure_response( $response );
     
    726739
    727740                $request->set_param( 'context', 'edit' );
     741
     742                /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
     743                do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
    728744
    729745                $response = $this->prepare_item_for_response( $post, $request );
Note: See TracChangeset for help on using the changeset viewer.