WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/16/2020 03:32:11 AM (13 months ago)
Author:
peterwilsoncc
Message:

REST API, Posts: Add a hook to fire once a post, its terms and meta update.

Introduces the action wp_after_insert_post inside a wrapper function of the same name. This hook allows plugin developers to access a posts full data (including its terms and meta data) regardless of the workflow used to save it.

A new parameter is introduced to wp_insert_post() to indicate whether the hook should be fired within the function call or will be fired afterward.

Props aristath, Collizo4sky, danielbachhuber, joyously, kadamwhite, kraftbj, markparnell, mikeschroder, noisysocks, peterwilsoncc, SergeyBiryukov, talldanwp, thewebprincess, TimothyBlynJacobs.
Fixes #45114.

File:
1 edited

Legend:

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

    r49108 r49172  
    192192        do_action( 'rest_after_insert_attachment', $attachment, $request, true );
    193193
     194        wp_after_insert_post( $attachment, false );
     195
    194196        if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    195197            // Set a custom header with the attachment_id.
     
    271273
    272274        // $post_parent is inherited from $attachment['post_parent'].
    273         $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true );
     275        $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true, false );
    274276
    275277        if ( is_wp_error( $id ) ) {
     
    345347        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
    346348        do_action( 'rest_after_insert_attachment', $attachment, $request, false );
     349
     350        wp_after_insert_post( $attachment, true );
    347351
    348352        $response = $this->prepare_item_for_response( $attachment, $request );
Note: See TracChangeset for help on using the changeset viewer.