| @@ 680-698 (lines=19) @@ | ||
| 677 | } |
|
| 678 | ||
| 679 | // /sites/%s/posts/%d/restore -> $blog_id, $post_id |
|
| 680 | function restore_post( $path, $blog_id, $post_id ) { |
|
| 681 | $args = $this->query_args(); |
|
| 682 | $post = get_post( $post_id ); |
|
| 683 | ||
| 684 | if ( !$post || is_wp_error( $post ) ) { |
|
| 685 | return new WP_Error( 'unknown_post', 'Unknown post', 404 ); |
|
| 686 | } |
|
| 687 | ||
| 688 | if ( !current_user_can( 'delete_post', $post->ID ) ) { |
|
| 689 | return new WP_Error( 'unauthorized', 'User cannot restore trashed posts', 403 ); |
|
| 690 | } |
|
| 691 | ||
| 692 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 693 | do_action( 'wpcom_json_api_objects', 'posts' ); |
|
| 694 | ||
| 695 | wp_untrash_post( $post->ID ); |
|
| 696 | ||
| 697 | return $this->get_post_by( 'ID', $post->ID, $args['context'] ); |
|
| 698 | } |
|
| 699 | ||
| 700 | private function parse_and_set_featured_image( $post_id, $delete_featured_image, $featured_image ) { |
|
| 701 | if ( $delete_featured_image ) { |
|
| @@ 746-764 (lines=19) @@ | ||
| 743 | } |
|
| 744 | ||
| 745 | // /sites/%s/posts/%d/restore -> $blog_id, $post_id |
|
| 746 | function restore_post( $path, $blog_id, $post_id ) { |
|
| 747 | $args = $this->query_args(); |
|
| 748 | $post = get_post( $post_id ); |
|
| 749 | ||
| 750 | if ( !$post || is_wp_error( $post ) ) { |
|
| 751 | return new WP_Error( 'unknown_post', 'Unknown post', 404 ); |
|
| 752 | } |
|
| 753 | ||
| 754 | if ( !current_user_can( 'delete_post', $post->ID ) ) { |
|
| 755 | return new WP_Error( 'unauthorized', 'User cannot restore trashed posts', 403 ); |
|
| 756 | } |
|
| 757 | ||
| 758 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 759 | do_action( 'wpcom_json_api_objects', 'posts' ); |
|
| 760 | ||
| 761 | wp_untrash_post( $post->ID ); |
|
| 762 | ||
| 763 | return $this->get_post_by( 'ID', $post->ID, $args['context'] ); |
|
| 764 | } |
|
| 765 | ||
| 766 | protected function parse_and_set_featured_image( $post_id, $delete_featured_image, $featured_image ) { |
|
| 767 | if ( $delete_featured_image ) { |
|