Make WordPress Core


Ignore:
Timestamp:
12/01/2020 08:55:03 PM (4 years 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.

This merges [45114] into the 5.6 branch

See #45114

Location:
branches/5.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

  • branches/5.6/src/wp-includes/post.php

    r49684 r49732  
    37183718    } else {
    37193719        $previous_status = 'new';
     3720        $post_before     = null;
    37203721    }
    37213722
     
    43204321
    43214322    if ( $fire_after_hooks ) {
    4322         wp_after_insert_post( $post, $update );
     4323        wp_after_insert_post( $post, $update, $post_before );
    43234324    }
    43244325
     
    44334434    }
    44344435
     4436    $post_before = get_post( $post->ID );
     4437
    44354438    // Ensure at least one term is applied for taxonomies with a default term.
    44364439    foreach ( get_object_taxonomies( $post->post_type, 'object' ) as $taxonomy => $tax_object ) {
     
    44834486    do_action( 'wp_insert_post', $post->ID, $post, true );
    44844487
    4485     wp_after_insert_post( $post, true );
     4488    wp_after_insert_post( $post, true, $post_before );
    44864489}
    44874490
     
    49384941 * @since 5.6.0
    49394942 *
    4940  * @param int|WP_Post $post   The post ID or object that has been saved.
    4941  * @param bool        $update Whether this is an existing post being updated.
    4942  */
    4943 function wp_after_insert_post( $post, $update ) {
     4943 * @param int|WP_Post  $post        The post ID or object that has been saved.
     4944 * @param bool         $update      Whether this is an existing post being updated.
     4945 * @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
     4946 *                                  to the update for updated posts.
     4947 */
     4948function wp_after_insert_post( $post, $update, $post_before ) {
    49444949    $post = get_post( $post );
    49454950    if ( ! $post ) {
     
    49544959     * @since 5.6.0
    49554960     *
    4956      * @param int     $post_id Post ID.
    4957      * @param WP_Post $post    Post object.
    4958      * @param bool    $update  Whether this is an existing post being updated.
     4961     * @param int          $post_id     Post ID.
     4962     * @param WP_Post      $post        Post object.
     4963     * @param bool         $update      Whether this is an existing post being updated.
     4964     * @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
     4965     *                                  to the update for updated posts.
    49594966     */
    4960     do_action( 'wp_after_insert_post', $post_id, $post, $update );
     4967    do_action( 'wp_after_insert_post', $post_id, $post, $update, $post_before );
    49614968}
    49624969
Note: See TracChangeset for help on using the changeset viewer.