Make WordPress Core


Ignore:
Timestamp:
10/17/2018 11:19:02 AM (6 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-comments-controller.php

    r43445 r43737  
    623623
    624624        $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view';
    625 
    626625        $request->set_param( 'context', $context );
     626
     627        /**
     628         * Fires completely after a comment is created or updated via the REST API.
     629         *
     630         * @since 5.0.0
     631         *
     632         * @param WP_Comment      $comment  Inserted or updated comment object.
     633         * @param WP_REST_Request $request  Request object.
     634         * @param bool            $creating True when creating a comment, false
     635         *                                  when updating.
     636         */
     637        do_action( 'rest_after_insert_comment', $comment, $request, true );
    627638
    628639        $response = $this->prepare_item_for_response( $comment, $request );
     
    747758
    748759        $request->set_param( 'context', 'edit' );
     760
     761        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */
     762        do_action( 'rest_after_insert_comment', $comment, $request, false );
    749763
    750764        $response = $this->prepare_item_for_response( $comment, $request );
Note: See TracChangeset for help on using the changeset viewer.