Make WordPress Core


Ignore:
Timestamp:
12/12/2018 09:11:27 PM (7 years ago)
Author:
desrosj
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, danielbachhuber.

Merges [43737] to trunk.

Fixes #42864.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r43980 r43987  
    609609        $request->set_param( 'context', 'edit' );
    610610
     611        /**
     612         * Fires after a single post is completely created or updated via the REST API.
     613         *
     614         * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
     615         *
     616         * @since 5.0.0
     617         *
     618         * @param WP_Post         $post     Inserted or updated post object.
     619         * @param WP_REST_Request $request  Request object.
     620         * @param bool            $creating True when creating a post, false when updating.
     621         */
     622        do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
     623
    611624        $response = $this->prepare_item_for_response( $post, $request );
    612625        $response = rest_ensure_response( $response );
     
    734747
    735748        $request->set_param( 'context', 'edit' );
     749
     750        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
     751        do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
    736752
    737753        $response = $this->prepare_item_for_response( $post, $request );
Note: See TracChangeset for help on using the changeset viewer.