WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/01/2020 08:45:43 PM (11 months ago)
Author:
johnbillion
Message:

REST API: Pass the previous state of the post as a parameter to the wp_after_insert_post hook.

This enables, for example, the previous post status to be used by this hook without the need to first capture it on an earlier hook.

This also fixes the value of the $fire_after_hooks parameter in get_default_post_to_edit() so the wp_after_insert_post action correctly fires just once on the new post screen.

Props Collizo4sky, peterwilsoncc, hellofromTonya, TimothyBlynJacobs, SergeyBiryukov

Fixes #45114

File:
1 edited

Legend:

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

    r49302 r49731  
    678678        do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
    679679
    680         wp_after_insert_post( $post, false );
     680        wp_after_insert_post( $post, false, null );
    681681
    682682        $response = $this->prepare_item_for_response( $post, $request );
     
    754754        }
    755755
    756         $post = $this->prepare_item_for_database( $request );
     756        $post_before = get_post( $request['id'] );
     757        $post        = $this->prepare_item_for_database( $request );
    757758
    758759        if ( is_wp_error( $post ) ) {
     
    831832        do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
    832833
    833         wp_after_insert_post( $post, true );
     834        wp_after_insert_post( $post, true, $post_before );
    834835
    835836        $response = $this->prepare_item_for_response( $post, $request );
Note: See TracChangeset for help on using the changeset viewer.