Make WordPress Core

Changeset 43987


Ignore:
Timestamp:
12/12/2018 09:11:27 PM (8 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:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r43973 r43987  
    189189
    190190                $request->set_param( 'context', 'edit' );
     191
     192                /**
     193                 * Fires after a single attachment is completely created or updated via the REST API.
     194                 *
     195                 * @since 5.0.0
     196                 *
     197                 * @param WP_Post         $attachment Inserted or updated attachment object.
     198                 * @param WP_REST_Request $request    Request object.
     199                 * @param bool            $creating   True when creating an attachment, false when updating.
     200                 */
     201                do_action( 'rest_after_insert_attachment', $attachment, $request, true );
     202
    191203                $response = $this->prepare_item_for_response( $attachment, $request );
    192204                $response = rest_ensure_response( $response );
    … …  
    235247
    236248                $request->set_param( 'context', 'edit' );
     249
     250                /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
     251                do_action( 'rest_after_insert_attachment', $attachment, $request, false );
     252
    237253                $response = $this->prepare_item_for_response( $attachment, $request );
    238254                $response = rest_ensure_response( $response );
  • 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 );
  • 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 );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r43636 r43987  
    470470                $request->set_param( 'context', 'view' );
    471471
     472                /**
     473                 * Fires after a single term is completely created or updated via the REST API.
     474                 *
     475                 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
     476                 *
     477                 * @since 5.0.0
     478                 *
     479                 * @param WP_Term         $term     Inserted or updated term object.
     480                 * @param WP_REST_Request $request  Request object.
     481                 * @param bool            $creating True when creating a term, false when updating.
     482                 */
     483                do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, true );
     484
    472485                $response = $this->prepare_item_for_response( $term, $request );
    473486                $response = rest_ensure_response( $response );
    … …  
    558571
    559572                $request->set_param( 'context', 'view' );
     573
     574                /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
     575                do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, false );
    560576
    561577                $response = $this->prepare_item_for_response( $term, $request );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r43571 r43987  
    567567                $request->set_param( 'context', 'edit' );
    568568
     569                /**
     570                 * Fires after a user is completely created or updated via the REST API.
     571                 *
     572                 * @since 5.0.0
     573                 *
     574                 * @param WP_User         $user     Inserted or updated user object.
     575                 * @param WP_REST_Request $request  Request object.
     576                 * @param bool            $creating True when creating a user, false when updating.
     577                 */
     578                do_action( 'rest_after_insert_user', $user, $request, true );
     579
    569580                $response = $this->prepare_item_for_response( $user, $request );
    570581                $response = rest_ensure_response( $response );
    … …  
    689700
    690701                $request->set_param( 'context', 'edit' );
     702
     703                /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php */
     704                do_action( 'rest_after_insert_user', $user, $request, false );
    691705
    692706                $response = $this->prepare_item_for_response( $user, $request );
Note: See TracChangeset for help on using the changeset viewer.