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-posts-controller.php

    r49120 r49172  
    592592        $prepared_post->post_type = $this->post_type;
    593593
    594         $post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true );
     594        $post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true, false );
    595595
    596596        if ( is_wp_error( $post_id ) ) {
     
    678678        do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
    679679
     680        wp_after_insert_post( $post, false );
     681
    680682        $response = $this->prepare_item_for_response( $post, $request );
    681683        $response = rest_ensure_response( $response );
     
    759761
    760762        // Convert the post object to an array, otherwise wp_update_post() will expect non-escaped input.
    761         $post_id = wp_update_post( wp_slash( (array) $post ), true );
     763        $post_id = wp_update_post( wp_slash( (array) $post ), true, false );
    762764
    763765        if ( is_wp_error( $post_id ) ) {
     
    828830        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
    829831        do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
     832
     833        wp_after_insert_post( $post, true );
    830834
    831835        $response = $this->prepare_item_for_response( $post, $request );
Note: See TracChangeset for help on using the changeset viewer.