Changeset 49172
- Timestamp:
- 10/16/2020 03:32:11 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/post.php
r49108 r49172 686 686 'post_type' => $post_type, 687 687 'post_status' => 'auto-draft', 688 ) 688 ), 689 false, 690 true 689 691 ); 690 692 $post = get_post( $post_id ); … … 692 694 set_post_format( $post, get_option( 'default_post_format' ) ); 693 695 } 696 wp_after_insert_post( $post, false ); 694 697 695 698 // Schedule auto-draft cleanup. -
trunk/src/wp-includes/class-wp-customize-manager.php
r49108 r49172 3105 3105 /** This action is documented in wp-includes/post.php */ 3106 3106 do_action( 'wp_insert_post', $post->ID, $post, true ); 3107 3108 wp_after_insert_post( $post, true ); 3107 3109 3108 3110 wp_trash_post_comments( $post_id ); -
trunk/src/wp-includes/post.php
r49141 r49172 3646 3646 * @type array $meta_input Array of post meta values keyed by their post meta key. Default empty. 3647 3647 * } 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. 3649 3650 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 3650 3651 */ 3651 function wp_insert_post( $postarr, $wp_error = false ) {3652 function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) { 3652 3653 global $wpdb; 3653 3654 … … 4311 4312 do_action( 'wp_insert_post', $post_ID, $post, $update ); 4312 4313 4314 if ( $fire_after_hooks ) { 4315 wp_after_insert_post( $post, $update ); 4316 } 4317 4313 4318 return $post_ID; 4314 4319 } … … 4322 4327 * @since 1.0.0 4323 4328 * 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. 4327 4333 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 4328 4334 */ 4329 function wp_update_post( $postarr = array(), $wp_error = false ) {4335 function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) { 4330 4336 if ( is_object( $postarr ) ) { 4331 4337 // Non-escaped post was passed. … … 4392 4398 } 4393 4399 4394 return wp_insert_post( $postarr, $wp_error );4400 return wp_insert_post( $postarr, $wp_error, $fire_after_hooks ); 4395 4401 } 4396 4402 … … 4468 4474 /** This action is documented in wp-includes/post.php */ 4469 4475 do_action( 'wp_insert_post', $post->ID, $post, true ); 4476 4477 wp_after_insert_post( $post, true ); 4470 4478 } 4471 4479 … … 4915 4923 */ 4916 4924 do_action( "{$new_status}_{$post->post_type}", $post->ID, $post ); 4925 } 4926 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 */ 4935 function 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 ); 4917 4953 } 4918 4954 … … 5790 5826 * @see wp_insert_post() 5791 5827 * 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. 5796 5833 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. 5797 5834 */ 5798 function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) {5835 function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false, $fire_after_hooks = true ) { 5799 5836 $defaults = array( 5800 5837 'file' => $file, … … 5810 5847 $data['post_type'] = 'attachment'; 5811 5848 5812 return wp_insert_post( $data, $wp_error );5849 return wp_insert_post( $data, $wp_error, $fire_after_hooks ); 5813 5850 } 5814 5851 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r49108 r49172 192 192 do_action( 'rest_after_insert_attachment', $attachment, $request, true ); 193 193 194 wp_after_insert_post( $attachment, false ); 195 194 196 if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { 195 197 // Set a custom header with the attachment_id. … … 271 273 272 274 // $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 ); 274 276 275 277 if ( is_wp_error( $id ) ) { … … 345 347 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */ 346 348 do_action( 'rest_after_insert_attachment', $attachment, $request, false ); 349 350 wp_after_insert_post( $attachment, true ); 347 351 348 352 $response = $this->prepare_item_for_response( $attachment, $request ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r49120 r49172 592 592 $prepared_post->post_type = $this->post_type; 593 593 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 ); 595 595 596 596 if ( is_wp_error( $post_id ) ) { … … 678 678 do_action( "rest_after_insert_{$this->post_type}", $post, $request, true ); 679 679 680 wp_after_insert_post( $post, false ); 681 680 682 $response = $this->prepare_item_for_response( $post, $request ); 681 683 $response = rest_ensure_response( $response ); … … 759 761 760 762 // 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 ); 762 764 763 765 if ( is_wp_error( $post_id ) ) { … … 828 830 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ 829 831 do_action( "rest_after_insert_{$this->post_type}", $post, $request, false ); 832 833 wp_after_insert_post( $post, true ); 830 834 831 835 $response = $this->prepare_item_for_response( $post, $request ); -
trunk/tests/phpunit/tests/customize/manager.php
r49117 r49172 1172 1172 'save_post' => 2, 1173 1173 'wp_insert_post' => 2, 1174 'wp_after_insert_post' => 2, 1174 1175 'trashed_post' => 1, 1175 1176 );
Note: See TracChangeset
for help on using the changeset viewer.