WordPress.org

Make WordPress Core

Changeset 43737


Ignore:
Timestamp:
10/17/2018 11:19:02 AM (12 months 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.

Location:
branches/5.0/src/wp-includes/rest-api/endpoints
Files:
5 edited

Legend:

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

    r43691 r43737  
    186186
    187187        $request->set_param( 'context', 'edit' );
     188
     189        /**
     190         * Fires after a single attachment is completely created or updated via the REST API.
     191         *
     192         * @since 5.0.0
     193         *
     194         * @param WP_Post         $attachment Inserted or updated attachment object.
     195         * @param WP_REST_Request $request    Request object.
     196         * @param bool            $creating   True when creating an attachment, false when updating.
     197         */
     198        do_action( 'rest_after_insert_attachment', $attachment, $request, true );
     199
    188200        $response = $this->prepare_item_for_response( $attachment, $request );
    189201        $response = rest_ensure_response( $response );
     
    232244
    233245        $request->set_param( 'context', 'edit' );
     246
     247        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
     248        do_action( 'rest_after_insert_attachment', $attachment, $request, false );
     249
    234250        $response = $this->prepare_item_for_response( $attachment, $request );
    235251        $response = rest_ensure_response( $response );
  • 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 );
  • 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 );
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r43714 r43737  
    457457        $request->set_param( 'context', 'view' );
    458458
     459        /**
     460         * Fires after a single term is completely created or updated via the REST API.
     461         *
     462         * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
     463         *
     464         * @since 5.0.0
     465         *
     466         * @param WP_Term         $term     Inserted or updated term object.
     467         * @param WP_REST_Request $request  Request object.
     468         * @param bool            $creating True when creating a term, false when updating.
     469         */
     470        do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, true );
     471
    459472        $response = $this->prepare_item_for_response( $term, $request );
    460473        $response = rest_ensure_response( $response );
     
    545558
    546559        $request->set_param( 'context', 'view' );
     560
     561        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
     562        do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, false );
    547563
    548564        $response = $this->prepare_item_for_response( $term, $request );
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r43445 r43737  
    556556        $request->set_param( 'context', 'edit' );
    557557
     558        /**
     559         * Fires after a user is completely created or updated via the REST API.
     560         *
     561         * @since 5.0.0
     562         *
     563         * @param WP_User         $user     Inserted or updated user object.
     564         * @param WP_REST_Request $request  Request object.
     565         * @param bool            $creating True when creating a user, false when updating.
     566         */
     567        do_action( 'rest_after_insert_user', $user, $request, true );
     568
    558569        $response = $this->prepare_item_for_response( $user, $request );
    559570        $response = rest_ensure_response( $response );
     
    678689
    679690        $request->set_param( 'context', 'edit' );
     691
     692        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php */
     693        do_action( 'rest_after_insert_user', $user, $request, false );
    680694
    681695        $response = $this->prepare_item_for_response( $user, $request );
Note: See TracChangeset for help on using the changeset viewer.