Changeset 39161
- Timestamp:
- 11/08/2016 01:08:49 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r39155 r39161 73 73 // Attaching media to a post requires ability to edit said post. 74 74 if ( ! empty( $request['post'] ) ) { 75 $parent = $this->get_post( (int) $request['post'] );75 $parent = get_post( (int) $request['post'] ); 76 76 $post_parent_type = get_post_type_object( $parent->post_type ); 77 77 … … 154 154 } 155 155 156 $attachment = $this->get_post( $id );156 $attachment = get_post( $id ); 157 157 158 158 // Include admin functions to get access to wp_generate_attachment_metadata(). … … 218 218 } 219 219 220 $attachment = $this->get_post( $request['id'] );220 $attachment = get_post( $request['id'] ); 221 221 222 222 $fields_update = $this->update_additional_fields_for_object( $attachment, $request ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39157 r39161 107 107 if ( ! empty( $request['post'] ) ) { 108 108 foreach ( (array) $request['post'] as $post_id ) { 109 $post = $this->get_post( $post_id );109 $post = get_post( $post_id ); 110 110 111 111 if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post ) ) { … … 315 315 } 316 316 317 $post = $this->get_post( $comment->comment_post_ID );317 $post = get_post( $comment->comment_post_ID ); 318 318 319 319 if ( $post && ! $this->check_read_post_permission( $post ) ) { … … 346 346 347 347 if ( ! empty( $comment->comment_post_ID ) ) { 348 $post = $this->get_post( $comment->comment_post_ID );348 $post = get_post( $comment->comment_post_ID ); 349 349 if ( empty( $post ) ) { 350 350 return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post id.' ), array( 'status' => 404 ) ); … … 390 390 } 391 391 392 if ( ! empty( $request['post'] ) && $post = $this->get_post( (int) $request['post'] ) ) {392 if ( ! empty( $request['post'] ) && $post = get_post( (int) $request['post'] ) ) { 393 393 if ( 'draft' === $post->post_status ) { 394 394 return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you cannot create a comment on this post.' ), array( 'status' => 403 ) ); … … 872 872 873 873 if ( 0 !== (int) $comment->comment_post_ID ) { 874 $post = $this->get_post( $comment->comment_post_ID );874 $post = get_post( $comment->comment_post_ID ); 875 875 876 876 if ( ! empty( $post->ID ) ) { -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
r39046 r39161 582 582 583 583 /** 584 * Retrieves post data given a post ID or post object.585 *586 * This is a subset of the functionality of the `get_post()` function, with587 * the additional functionality of having `the_post` action done on the588 * resultant post object. This is done so that plugins may manipulate the589 * post that is used in the REST API.590 *591 * @since 4.7.0592 * @access public593 *594 * @see get_post()595 * @global WP_Query $wp_query596 *597 * @param int|WP_Post $post Post ID or object. Defaults to global `$post` object.598 * @return WP_Post|null A WP_Post object when successful, otherwise null.599 */600 public function get_post( $post ) {601 $post_obj = get_post( $post );602 603 /**604 * Filters the post in the context of a REST request.605 *606 * Allows plugins to filter the post object as returned by WP_REST_Controller::get_post().607 *608 * @since 4.7.0609 *610 * @param WP_Post|null $post_obj The post object as returned by get_post().611 * @param int|WP_Post $post The original value used to obtain the post object.612 */613 $post = apply_filters( 'rest_the_post', $post_obj, $post );614 615 return $post;616 }617 618 /**619 584 * Sanitizes the slug value. 620 585 * -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r39155 r39161 351 351 public function get_item_permissions_check( $request ) { 352 352 353 $post = $this->get_post( (int) $request['id'] );353 $post = get_post( (int) $request['id'] ); 354 354 355 355 if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) { … … 420 420 public function get_item( $request ) { 421 421 $id = (int) $request['id']; 422 $post = $this->get_post( $id );422 $post = get_post( $id ); 423 423 424 424 if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) { … … 532 532 } 533 533 534 $post = $this->get_post( $post_id );534 $post = get_post( $post_id ); 535 535 536 536 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { … … 583 583 public function update_item_permissions_check( $request ) { 584 584 585 $post = $this->get_post( $request['id'] );585 $post = get_post( $request['id'] ); 586 586 $post_type = get_post_type_object( $this->post_type ); 587 587 … … 616 616 public function update_item( $request ) { 617 617 $id = (int) $request['id']; 618 $post = $this->get_post( $id );618 $post = get_post( $id ); 619 619 620 620 if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) { … … 668 668 } 669 669 670 $post = $this->get_post( $post_id );670 $post = get_post( $post_id ); 671 671 672 672 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { … … 705 705 public function delete_item_permissions_check( $request ) { 706 706 707 $post = $this->get_post( $request['id'] );707 $post = get_post( $request['id'] ); 708 708 709 709 if ( $post && ! $this->check_delete_permission( $post ) ) { … … 727 727 $force = (bool) $request['force']; 728 728 729 $post = $this->get_post( $id );729 $post = get_post( $id ); 730 730 731 731 if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) { … … 780 780 // the trash is disabled.) 781 781 $result = wp_trash_post( $id ); 782 $post = $this->get_post( $id );782 $post = get_post( $id ); 783 783 $response = $this->prepare_item_for_response( $post, $request ); 784 784 } … … 1072 1072 // Parent. 1073 1073 if ( ! empty( $schema['properties']['parent'] ) && ! empty( $request['parent'] ) ) { 1074 $parent = $this->get_post( (int) $request['parent'] );1074 $parent = get_post( (int) $request['parent'] ); 1075 1075 1076 1076 if ( empty( $parent ) ) { … … 1184 1184 */ 1185 1185 public function handle_template( $template, $post_id ) { 1186 if ( in_array( $template, array_keys( wp_get_theme()->get_page_templates( $this->get_post( $post_id ) ) ), true ) ) {1186 if ( in_array( $template, array_keys( wp_get_theme()->get_page_templates( get_post( $post_id ) ) ), true ) ) { 1187 1187 update_post_meta( $post_id, '_wp_page_template', $template ); 1188 1188 } else { … … 1301 1301 // Can we read the parent if we're inheriting? 1302 1302 if ( 'inherit' === $post->post_status && $post->post_parent > 0 ) { 1303 $parent = $this->get_post( $post->post_parent );1303 $parent = get_post( $post->post_parent ); 1304 1304 return $this->check_read_permission( $parent ); 1305 1305 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r39126 r39161 118 118 public function get_items_permissions_check( $request ) { 119 119 120 $parent = $this->get_post( $request['parent'] );120 $parent = get_post( $request['parent'] ); 121 121 if ( ! $parent ) { 122 122 return true; … … 140 140 */ 141 141 public function get_items( $request ) { 142 143 $parent = $this->get_post( $request['parent'] ); 142 $parent = get_post( $request['parent'] ); 144 143 if ( ! $request['parent'] || ! $parent || $this->parent_post_type !== $parent->post_type ) { 145 144 return new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent id.' ), array( 'status' => 404 ) ); … … 179 178 */ 180 179 public function get_item( $request ) { 181 182 $parent = $this->get_post( $request['parent'] ); 180 $parent = get_post( $request['parent'] ); 183 181 if ( ! $request['parent'] || ! $parent || $this->parent_post_type !== $parent->post_type ) { 184 182 return new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent id.' ), array( 'status' => 404 ) ); 185 183 } 186 184 187 $revision = $this->get_post( $request['id'] );185 $revision = get_post( $request['id'] ); 188 186 if ( ! $revision || 'revision' !== $revision->post_type ) { 189 187 return new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision id.' ), array( 'status' => 404 ) ); … … 210 208 } 211 209 212 $post = $this->get_post( $request['id'] );210 $post = get_post( $request['id'] ); 213 211 if ( ! $post ) { 214 212 return new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision id.' ), array( 'status' => 404 ) ); … … 235 233 } 236 234 237 $revision = $this->get_post( $request['id'] );235 $revision = get_post( $request['id'] ); 238 236 $previous = $this->prepare_item_for_response( $revision, $request ); 239 237 -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r38832 r39161 191 191 $this->assertEquals( 'a', $args['somedefault']['default'] ); 192 192 } 193 194 public $rest_the_post_filter_apply_count = 0;195 196 public function test_get_post() {197 $post_id = $this->factory()->post->create( array( 'post_title' => 'Original' ) );198 $controller = new WP_REST_Test_Controller();199 200 $post = $controller->get_post( $post_id );201 $this->assertEquals( 'Original', $post->post_title );202 203 $filter_apply_count = $this->rest_the_post_filter_apply_count;204 add_filter( 'rest_the_post', array( $this, 'filter_rest_the_post_for_test_get_post' ), 10, 2 );205 $post = $controller->get_post( $post_id );206 $this->assertEquals( 'Overridden', $post->post_title );207 $this->assertEquals( 1 + $filter_apply_count, $this->rest_the_post_filter_apply_count );208 }209 210 public function filter_rest_the_post_for_test_get_post( $post, $post_id ) {211 $this->assertInstanceOf( 'WP_Post', $post );212 $this->assertInternalType( 'int', $post_id );213 $post->post_title = 'Overridden';214 $this->rest_the_post_filter_apply_count += 1;215 return $post;216 }217 193 }
Note: See TracChangeset
for help on using the changeset viewer.