Make WordPress Core


Ignore:
Timestamp:
11/30/2021 01:08:05 AM (4 years ago)
Author:
peterwilsoncc
Message:

REST API: Fire wp_after_insert_post later in new post object endpoints.

In the new menu items, global items and template controllers manually call the function wp_after_insert_post() to manually fire the action of the same name after all potential data is updated.

This accounts for the use case in which a theme or plugin developer has modified the endpoints use of either taxonomy or meta data.

The new parameter $fire_after_hooks is added to wp_update_nav_menu_item() to control whether the wp_after_insert_post action is fired when it in turn calls wp_insert_post().

Props spacedmonkey, peterwilsoncc, zieladam.
Fixes #54536.

File:
1 edited

Legend:

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

    r52275 r52276  
    267267        }
    268268
     269        $post_before = get_post( $template->wp_id );
     270
    269271        if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
    270272            wp_delete_post( $template->wp_id, true );
     
    284286
    285287        if ( 'custom' === $template->source ) {
    286             $result = wp_update_post( wp_slash( (array) $changes ), true );
     288            $update = true;
     289            $result = wp_update_post( wp_slash( (array) $changes ), false );
    287290        } else {
    288             $result = wp_insert_post( wp_slash( (array) $changes ), true );
     291            $update      = false;
     292            $post_before = null;
     293            $result      = wp_insert_post( wp_slash( (array) $changes ), false );
    289294        }
    290295
     
    309314        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
    310315        do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
     316
     317        wp_after_insert_post( $post, $update, $post_before );
    311318
    312319        $response = $this->prepare_item_for_response( $template, $request );
     
    367374        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
    368375        do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
     376
     377        wp_after_insert_post( $post, false, null );
    369378
    370379        $response = $this->prepare_item_for_response( $template, $request );
Note: See TracChangeset for help on using the changeset viewer.