Make WordPress Core


Ignore:
Timestamp:
12/12/2018 09:11:27 PM (5 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-comments-controller.php

    r43571 r43987  
    634634
    635635        $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view';
    636 
    637636        $request->set_param( 'context', $context );
     637
     638        /**
     639         * Fires completely after a comment is created or updated via the REST API.
     640         *
     641         * @since 5.0.0
     642         *
     643         * @param WP_Comment      $comment  Inserted or updated comment object.
     644         * @param WP_REST_Request $request  Request object.
     645         * @param bool            $creating True when creating a comment, false
     646         *                                  when updating.
     647         */
     648        do_action( 'rest_after_insert_comment', $comment, $request, true );
    638649
    639650        $response = $this->prepare_item_for_response( $comment, $request );
     
    757768
    758769        $request->set_param( 'context', 'edit' );
     770
     771        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */
     772        do_action( 'rest_after_insert_comment', $comment, $request, false );
    759773
    760774        $response = $this->prepare_item_for_response( $comment, $request );
Note: See TracChangeset for help on using the changeset viewer.