Changeset 39348
- Timestamp:
- 11/23/2016 03:32:25 PM (8 years ago)
- Location:
- trunk/src/wp-includes/rest-api/endpoints
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r39342 r39348 156 156 $attachment = get_post( $id ); 157 157 158 /** 159 * Fires after a single attachment is created or updated via the REST API. 160 * 161 * @since 4.7.0 162 * 163 * @param WP_Post $attachment Inserted or updated attachment 164 * object. 165 * @param WP_REST_Request $request The request sent to the API. 166 * @param bool $creating True when creating an attachment, false when updating. 167 */ 168 do_action( 'rest_insert_attachment', $attachment, $request, true ); 169 158 170 // Include admin functions to get access to wp_generate_attachment_metadata(). 159 171 require_once ABSPATH . 'wp-admin/includes/admin.php'; … … 177 189 $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ) ); 178 190 179 /**180 * Fires after a single attachment is created or updated via the REST API.181 *182 * @since 4.7.0183 *184 * @param object $attachment Inserted attachment.185 * @param WP_REST_Request $request The request sent to the API.186 * @param bool $creating True when creating an attachment, false when updating.187 */188 do_action( 'rest_insert_attachment', $attachment, $request, true );189 190 191 return $response; 191 192 } … … 220 221 $attachment = get_post( $request['id'] ); 221 222 223 /* This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */ 224 do_action( 'rest_insert_attachment', $data, $request, false ); 225 222 226 $fields_update = $this->update_additional_fields_for_object( $attachment, $request ); 223 227 … … 229 233 $response = $this->prepare_item_for_response( $attachment, $request ); 230 234 $response = rest_ensure_response( $response ); 231 232 /* This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */233 do_action( 'rest_insert_attachment', $data, $request, false );234 235 235 236 return $response; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39342 r39348 568 568 569 569 if ( isset( $request['status'] ) ) { 570 $comment = get_comment( $comment_id ); 571 572 $this->handle_status_param( $request['status'], $comment ); 573 } 570 $this->handle_status_param( $request['status'], $comment_id ); 571 } 572 573 $comment = get_comment( $comment_id ); 574 575 /** 576 * Fires after a comment is created or updated via the REST API. 577 * 578 * @since 4.7.0 579 * 580 * @param WP_Comment $comment Inserted or updated comment object. 581 * @param WP_REST_Request $request Request object. 582 * @param bool $creating True when creating a comment, false 583 * when updating. 584 */ 585 do_action( 'rest_insert_comment', $comment, $request, true ); 574 586 575 587 $schema = $this->get_item_schema(); … … 583 595 } 584 596 585 $comment = get_comment( $comment_id );586 587 597 $fields_update = $this->update_additional_fields_for_object( $comment, $request ); 588 598 … … 601 611 $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) ); 602 612 603 /**604 * Fires after a comment is created or updated via the REST API.605 *606 * @since 4.7.0607 *608 * @param array $comment Comment as it exists in the database.609 * @param WP_REST_Request $request The request sent to the API.610 * @param bool $creating True when creating a comment, false when updating.611 */612 do_action( 'rest_insert_comment', $comment, $request, true );613 613 614 614 return $response; … … 667 667 if ( empty( $prepared_args ) && isset( $request['status'] ) ) { 668 668 // Only the comment status is being changed. 669 $change = $this->handle_status_param( $request['status'], $ comment);669 $change = $this->handle_status_param( $request['status'], $id ); 670 670 671 671 if ( ! $change ) { … … 696 696 697 697 if ( isset( $request['status'] ) ) { 698 $this->handle_status_param( $request['status'], $comment ); 699 } 700 } 698 $this->handle_status_param( $request['status'], $id ); 699 } 700 } 701 702 $comment = get_comment( $id ); 703 704 /* This action is documented in lib/endpoints/class-wp-rest-comments-controller.php */ 705 do_action( 'rest_insert_comment', $comment, $request, false ); 701 706 702 707 $schema = $this->get_item_schema(); … … 710 715 } 711 716 712 $comment = get_comment( $id );713 714 717 $fields_update = $this->update_additional_fields_for_object( $comment, $request ); 715 718 … … 721 724 722 725 $response = $this->prepare_item_for_response( $comment, $request ); 723 724 /* This action is documented in lib/endpoints/class-wp-rest-comments-controller.php */725 do_action( 'rest_insert_comment', $comment, $request, false );726 726 727 727 return rest_ensure_response( $response ); … … 1434 1434 * 1435 1435 * @param string|int $new_status New comment status. 1436 * @param WP_Comment $comment Comment data.1436 * @param int $comment_id Comment ID. 1437 1437 * @return bool Whether the status was changed. 1438 1438 */ 1439 protected function handle_status_param( $new_status, $comment ) {1440 $old_status = wp_get_comment_status( $comment ->comment_ID);1439 protected function handle_status_param( $new_status, $comment_id ) { 1440 $old_status = wp_get_comment_status( $comment_id ); 1441 1441 1442 1442 if ( $new_status === $old_status ) { … … 1448 1448 case 'approve': 1449 1449 case '1': 1450 $changed = wp_set_comment_status( $comment ->comment_ID, 'approve' );1450 $changed = wp_set_comment_status( $comment_id, 'approve' ); 1451 1451 break; 1452 1452 case 'hold': 1453 1453 case '0': 1454 $changed = wp_set_comment_status( $comment ->comment_ID, 'hold' );1454 $changed = wp_set_comment_status( $comment_id, 'hold' ); 1455 1455 break; 1456 1456 case 'spam' : 1457 $changed = wp_spam_comment( $comment ->comment_ID);1457 $changed = wp_spam_comment( $comment_id ); 1458 1458 break; 1459 1459 case 'unspam' : 1460 $changed = wp_unspam_comment( $comment ->comment_ID);1460 $changed = wp_unspam_comment( $comment_id ); 1461 1461 break; 1462 1462 case 'trash' : 1463 $changed = wp_trash_comment( $comment ->comment_ID);1463 $changed = wp_trash_comment( $comment_id ); 1464 1464 break; 1465 1465 case 'untrash' : 1466 $changed = wp_untrash_comment( $comment ->comment_ID);1466 $changed = wp_untrash_comment( $comment_id ); 1467 1467 break; 1468 1468 default : -
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' ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r39342 r39348 404 404 * @since 4.7.0 405 405 * 406 * @param WP_Term $term Inserted Term object.406 * @param WP_Term $term Inserted or updated term object. 407 407 * @param WP_REST_Request $request Request object. 408 * @param bool $creating True when creating term, false when updating.408 * @param bool $creating True when creating a term, false when updating. 409 409 */ 410 410 do_action( "rest_insert_{$this->taxonomy}", $term, $request, true ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r39342 r39348 462 462 $user = get_user_by( 'id', $user_id ); 463 463 464 if ( ! empty( $request['roles'] ) && ! empty( $schema['properties']['roles'] ) ) {465 array_map( array( $user, 'add_role' ), $request['roles'] );466 }467 468 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {469 $meta_update = $this->meta->update_value( $request['meta'], $user_id );470 471 if ( is_wp_error( $meta_update ) ) {472 return $meta_update;473 }474 }475 476 $fields_update = $this->update_additional_fields_for_object( $user, $request );477 478 if ( is_wp_error( $fields_update ) ) {479 return $fields_update;480 }481 482 464 /** 483 465 * Fires immediately after a user is created or updated via the REST API. … … 485 467 * @since 4.7.0 486 468 * 487 * @param WP_User $user Data used to create the user.469 * @param WP_User $user Inserted or updated user object. 488 470 * @param WP_REST_Request $request Request object. 489 * @param bool $creating True when creating user, false when updating user.471 * @param bool $creating True when creating a user, false when updating. 490 472 */ 491 473 do_action( 'rest_insert_user', $user, $request, true ); 474 475 if ( ! empty( $request['roles'] ) && ! empty( $schema['properties']['roles'] ) ) { 476 array_map( array( $user, 'add_role' ), $request['roles'] ); 477 } 478 479 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { 480 $meta_update = $this->meta->update_value( $request['meta'], $user_id ); 481 482 if ( is_wp_error( $meta_update ) ) { 483 return $meta_update; 484 } 485 } 486 487 $user = get_user_by( 'id', $user_id ); 488 $fields_update = $this->update_additional_fields_for_object( $user, $request ); 489 490 if ( is_wp_error( $fields_update ) ) { 491 return $fields_update; 492 } 492 493 493 494 $request->set_param( 'context', 'edit' ); … … 574 575 } 575 576 576 $user = get_user_by( 'id', $id ); 577 $user = get_user_by( 'id', $user_id ); 578 579 /* This action is documented in lib/endpoints/class-wp-rest-users-controller.php */ 580 do_action( 'rest_insert_user', $user, $request, false ); 577 581 578 582 if ( is_multisite() && ! is_user_member_of_blog( $id ) ) { … … 594 598 } 595 599 600 $user = get_user_by( 'id', $user_id ); 596 601 $fields_update = $this->update_additional_fields_for_object( $user, $request ); 597 602 … … 599 604 return $fields_update; 600 605 } 601 602 /* This action is documented in lib/endpoints/class-wp-rest-users-controller.php */603 do_action( 'rest_insert_user', $user, $request, false );604 606 605 607 $request->set_param( 'context', 'edit' );
Note: See TracChangeset
for help on using the changeset viewer.