WordPress.org

Make WordPress Core

Ticket #45114: 45114.2.diff

File 45114.2.diff, 10.4 KB (added by peterwilsoncc, 12 months ago)
  • src/wp-admin/includes/post.php

    diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
    index 0faf51d412..78029fd456 100644
    a b function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) 
    685685                                'post_title'  => __( 'Auto Draft' ),
    686686                                'post_type'   => $post_type,
    687687                                'post_status' => 'auto-draft',
    688                         )
     688                        ),
     689                        false,
     690                        true
    689691                );
    690692                $post    = get_post( $post_id );
    691693                if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
    692694                        set_post_format( $post, get_option( 'default_post_format' ) );
    693695                }
     696                wp_after_insert_post( $post, false );
    694697
    695698                // Schedule auto-draft cleanup.
    696699                if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
  • src/wp-includes/class-wp-customize-manager.php

    diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php
    index 832cf2f6fd..88a8128acd 100644
    a b public function trash_changeset_post( $post ) { 
    31053105                /** This action is documented in wp-includes/post.php */
    31063106                do_action( 'wp_insert_post', $post->ID, $post, true );
    31073107
     3108                wp_after_insert_post( $post, true );
     3109
    31083110                wp_trash_post_comments( $post_id );
    31093111
    31103112                /** This action is documented in wp-includes/post.php */
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index ee1c9caea9..2042342eea 100644
    a b function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 
    36453645 *     @type array  $tax_input             Array of taxonomy terms keyed by their taxonomy name. Default empty.
    36463646 *     @type array  $meta_input            Array of post meta values keyed by their post meta key. Default empty.
    36473647 * }
    3648  * @param bool  $wp_error Optional. Whether to return a WP_Error on failure. Default false.
     3648 * @param bool  $wp_error         Optional. Whether to return a WP_Error on failure. Default false.
     3649 * @param bool  $fire_after_hooks Whether to fire the after insert hooks. Default true.
    36493650 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
    36503651 */
    3651 function wp_insert_post( $postarr, $wp_error = false ) {
     3652function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) {
    36523653        global $wpdb;
    36533654
    36543655        // Capture original pre-sanitized array for passing into filters.
    function wp_insert_post( $postarr, $wp_error = false ) { 
    43104311         */
    43114312        do_action( 'wp_insert_post', $post_ID, $post, $update );
    43124313
     4314        if ( $fire_after_hooks ) {
     4315                wp_after_insert_post( $post, $update );
     4316        }
     4317
    43134318        return $post_ID;
    43144319}
    43154320
    function wp_insert_post( $postarr, $wp_error = false ) { 
    43214326 *
    43224327 * @since 1.0.0
    43234328 *
    4324  * @param array|object $postarr  Optional. Post data. Arrays are expected to be escaped,
    4325  *                               objects are not. Default array.
    4326  * @param bool         $wp_error Optional. Allow return of WP_Error on failure. Default false.
     4329 * @param array|object $postarr          Optional. Post data. Arrays are expected to be escaped,
     4330 *                                       objects are not. Default array.
     4331 * @param bool         $wp_error         Optional. Allow return of WP_Error on failure. Default false.
     4332 * @param bool         $fire_after_hooks Whether to fire the after insert hooks. Default true.
    43274333 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
    43284334 */
    4329 function wp_update_post( $postarr = array(), $wp_error = false ) {
     4335function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) {
    43304336        if ( is_object( $postarr ) ) {
    43314337                // Non-escaped post was passed.
    43324338                $postarr = get_object_vars( $postarr );
    function wp_update_post( $postarr = array(), $wp_error = false ) { 
    43914397                }
    43924398        }
    43934399
    4394         return wp_insert_post( $postarr, $wp_error );
     4400        return wp_insert_post( $postarr, $wp_error, $fire_after_hooks );
    43954401}
    43964402
    43974403/**
    function wp_publish_post( $post ) { 
    44674473
    44684474        /** This action is documented in wp-includes/post.php */
    44694475        do_action( 'wp_insert_post', $post->ID, $post, true );
     4476
     4477        wp_after_insert_post( $post, true );
    44704478}
    44714479
    44724480/**
    function wp_transition_post_status( $new_status, $old_status, $post ) { 
    49164924        do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
    49174925}
    49184926
     4927/**
     4928 * Fires actions after a post, its terms and meta data has been saved.
     4929 *
     4930 * @since 5.6.0
     4931 *
     4932 * @param int|WP_Post $post   The post ID or object that has been saved.
     4933 * @param bool        $update Whether this is an existing post being updated.
     4934 */
     4935function wp_after_insert_post( $post, $update ) {
     4936        $post = get_post( $post );
     4937        if ( ! $post ) {
     4938                return;
     4939        }
     4940
     4941        $post_id = $post->ID;
     4942
     4943        /**
     4944         * Fires once a post, its terms and meta data has been saved.
     4945         *
     4946         * @since 5.6.0
     4947         *
     4948         * @param int     $post_id Post ID.
     4949         * @param WP_Post $post    Post object.
     4950         * @param bool    $update  Whether this is an existing post being updated.
     4951         */
     4952        do_action( 'wp_after_insert_post', $post_id, $post, $update );
     4953}
     4954
    49194955//
    49204956// Comment, trackback, and pingback functions.
    49214957//
    function is_local_attachment( $url ) { 
    57895825 *
    57905826 * @see wp_insert_post()
    57915827 *
    5792  * @param string|array $args     Arguments for inserting an attachment.
    5793  * @param string       $file     Optional. Filename.
    5794  * @param int          $parent   Optional. Parent post ID.
    5795  * @param bool         $wp_error Optional. Whether to return a WP_Error on failure. Default false.
     5828 * @param string|array $args             Arguments for inserting an attachment.
     5829 * @param string       $file             Optional. Filename.
     5830 * @param int          $parent           Optional. Parent post ID.
     5831 * @param bool         $wp_error         Optional. Whether to return a WP_Error on failure. Default false.
     5832 * @param bool         $fire_after_hooks Whether to fire the after insert hooks. Default true.
    57965833 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    57975834 */
    5798 function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) {
     5835function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false, $fire_after_hooks = true ) {
    57995836        $defaults = array(
    58005837                'file'        => $file,
    58015838                'post_parent' => 0,
    function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = fa 
    58095846
    58105847        $data['post_type'] = 'attachment';
    58115848
    5812         return wp_insert_post( $data, $wp_error );
     5849        return wp_insert_post( $data, $wp_error, $fire_after_hooks );
    58135850}
    58145851
    58155852/**
  • src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
    index 58aaa37a81..fcbf70f501 100644
    a b public function create_item( $request ) { 
    191191                 */
    192192                do_action( 'rest_after_insert_attachment', $attachment, $request, true );
    193193
     194                wp_after_insert_post( $attachment, false );
     195
    194196                if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    195197                        // Set a custom header with the attachment_id.
    196198                        // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
    protected function insert_attachment( $request ) { 
    270272                }
    271273
    272274                // $post_parent is inherited from $attachment['post_parent'].
    273                 $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true );
     275                $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true, false );
    274276
    275277                if ( is_wp_error( $id ) ) {
    276278                        if ( 'db_update_error' === $id->get_error_code() ) {
    public function update_item( $request ) { 
    345347                /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
    346348                do_action( 'rest_after_insert_attachment', $attachment, $request, false );
    347349
     350                wp_after_insert_post( $attachment, true );
     351
    348352                $response = $this->prepare_item_for_response( $attachment, $request );
    349353                $response = rest_ensure_response( $response );
    350354
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index 76a924cf96..06db540af2 100644
    a b public function create_item( $request ) { 
    591591
    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 ) ) {
    597597
    public function create_item( $request ) { 
    677677                 */
    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 );
    682684
    public function update_item( $request ) { 
    758760                }
    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 ) ) {
    764766                        if ( 'db_update_error' === $post_id->get_error_code() ) {
    public function update_item( $request ) { 
    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 );
    830832
     833                wp_after_insert_post( $post, true );
     834
    831835                $response = $this->prepare_item_for_response( $post, $request );
    832836
    833837                return rest_ensure_response( $response );
  • tests/phpunit/tests/customize/manager.php

    diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php
    index 4316fb3a92..015037012f 100644
    a b function test_save_changeset_post_without_theme_activation() { 
    11711171                        'save_post_customize_changeset' => 2,
    11721172                        'save_post'                     => 2,
    11731173                        'wp_insert_post'                => 2,
     1174                        'wp_after_insert_post'          => 2,
    11741175                        'trashed_post'                  => 1,
    11751176                );
    11761177                $action_counts    = array();