WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/01/2020 08:45:43 PM (12 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-attachments-controller.php

    r49172 r49731  
    192192        do_action( 'rest_after_insert_attachment', $attachment, $request, true );
    193193
    194         wp_after_insert_post( $attachment, false );
     194        wp_after_insert_post( $attachment, false, null );
    195195
    196196        if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     
    322322        }
    323323
    324         $response = parent::update_item( $request );
     324        $attachment_before = get_post( $request['id'] );
     325        $response          = parent::update_item( $request );
    325326
    326327        if ( is_wp_error( $response ) ) {
     
    348349        do_action( 'rest_after_insert_attachment', $attachment, $request, false );
    349350
    350         wp_after_insert_post( $attachment, true );
     351        wp_after_insert_post( $attachment, true, $attachment_before );
    351352
    352353        $response = $this->prepare_item_for_response( $attachment, $request );
Note: See TracChangeset for help on using the changeset viewer.