Make WordPress Core


Ignore:
Timestamp:
12/12/2018 09:11:27 PM (6 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-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 );
Note: See TracChangeset for help on using the changeset viewer.