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-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 );
Note: See TracChangeset for help on using the changeset viewer.