- Timestamp:
- 11/23/2016 03:32:25 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r39343 r39348 483 483 } 484 484 485 $post = $this->prepare_item_for_database( $request ); 486 487 if ( is_wp_error( $post ) ) { 488 return $post; 489 } 490 491 $post->post_type = $this->post_type; 492 $post_id = wp_insert_post( wp_slash( (array) $post ), true ); 485 $prepared_post = $this->prepare_item_for_database( $request ); 486 487 if ( is_wp_error( $prepared_post ) ) { 488 return $prepared_post; 489 } 490 491 $prepared_post->post_type = $this->post_type; 492 493 $post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true ); 493 494 494 495 if ( is_wp_error( $post_id ) ) { … … 503 504 } 504 505 505 $post->ID = $post_id; 506 $post = get_post( $post_id ); 507 508 /** 509 * Fires after a single post is created or updated via the REST API. 510 * 511 * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. 512 * 513 * @since 4.7.0 514 * 515 * @param WP_Post $post Inserted or updated post object. 516 * @param WP_REST_Request $request Request object. 517 * @param bool $creating True when creating a post, false when updating. 518 */ 519 do_action( "rest_insert_{$this->post_type}", $post, $request, true ); 506 520 507 521 $schema = $this->get_item_schema(); … … 516 530 517 531 if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) ) { 518 $this->handle_featured_media( $request['featured_media'], $post ->ID);532 $this->handle_featured_media( $request['featured_media'], $post_id ); 519 533 } 520 534 … … 524 538 525 539 if ( ! empty( $schema['properties']['template'] ) && isset( $request['template'] ) ) { 526 $this->handle_template( $request['template'], $post ->ID);527 } 528 529 $terms_update = $this->handle_terms( $post ->ID, $request );540 $this->handle_template( $request['template'], $post_id ); 541 } 542 543 $terms_update = $this->handle_terms( $post_id, $request ); 530 544 531 545 if ( is_wp_error( $terms_update ) ) { … … 533 547 } 534 548 535 $post = get_post( $post_id );536 537 549 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { 538 $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id']);550 $meta_update = $this->meta->update_value( $request['meta'], $post_id ); 539 551 540 552 if ( is_wp_error( $meta_update ) ) { … … 543 555 } 544 556 557 $post = get_post( $post_id ); 545 558 $fields_update = $this->update_additional_fields_for_object( $post, $request ); 546 559 … … 548 561 return $fields_update; 549 562 } 550 551 /**552 * Fires after a single post is created or updated via the REST API.553 *554 * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.555 *556 * @since 4.7.0557 *558 * @param object $post Inserted Post object (not a WP_Post object).559 * @param WP_REST_Request $request Request object.560 * @param bool $creating True when creating post, false when updating.561 */562 do_action( "rest_insert_{$this->post_type}", $post, $request, true );563 563 564 564 $request->set_param( 'context', 'edit' ); … … 641 641 } 642 642 643 $post = get_post( $post_id ); 644 645 /* This action is documented in lib/endpoints/class-wp-rest-controller.php */ 646 do_action( "rest_insert_{$this->post_type}", $post, $request, false ); 647 643 648 $schema = $this->get_item_schema(); 644 649 … … 669 674 } 670 675 671 $post = get_post( $post_id );672 673 676 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { 674 677 $meta_update = $this->meta->update_value( $request['meta'], $post->ID ); … … 679 682 } 680 683 684 $post = get_post( $post_id ); 681 685 $fields_update = $this->update_additional_fields_for_object( $post, $request ); 682 686 … … 684 688 return $fields_update; 685 689 } 686 687 /* This action is documented in lib/endpoints/class-wp-rest-controller.php */688 do_action( "rest_insert_{$this->post_type}", $post, $request, false );689 690 690 691 $request->set_param( 'context', 'edit' );
Note: See TracChangeset
for help on using the changeset viewer.