Changeset 43897 for branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
- Timestamp:
- 11/15/2018 12:56:54 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
r43768 r43897 80 80 register_rest_route( 81 81 $this->rest_namespace, 82 '/' . $this->parent_base . '/(?P< parent>[\d]+)/' . $this->rest_base,82 '/' . $this->parent_base . '/(?P<id>[\d]+)/' . $this->rest_base, 83 83 array( 84 84 'args' => array( … … 91 91 'methods' => WP_REST_Server::READABLE, 92 92 'callback' => array( $this, 'get_items' ), 93 'permission_callback' => array( $this ->revisions_controller, 'get_items_permissions_check' ),93 'permission_callback' => array( $this, 'get_items_permissions_check' ), 94 94 'args' => $this->get_collection_params(), 95 95 ), … … 98 98 'callback' => array( $this, 'create_item' ), 99 99 'permission_callback' => array( $this, 'create_item_permissions_check' ), 100 'args' => $this-> get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),100 'args' => $this->parent_controller->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 101 101 ), 102 102 'schema' => array( $this, 'get_public_item_schema' ), … … 145 145 146 146 /** 147 * Checks if a given request has access to get autosaves. 148 * 149 * @since 5.0.0 150 * 151 * @param WP_REST_Request $request Full data about the request. 152 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. 153 */ 154 public function get_items_permissions_check( $request ) { 155 $parent = $this->get_parent( $request['id'] ); 156 if ( is_wp_error( $parent ) ) { 157 return $parent; 158 } 159 160 $parent_post_type_obj = get_post_type_object( $parent->post_type ); 161 if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) { 162 return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view autosaves of this post.' ), array( 'status' => rest_authorization_required_code() ) ); 163 } 164 165 return true; 166 } 167 168 /** 147 169 * Checks if a given request has access to create an autosave revision. 148 170 * … … 178 200 } 179 201 180 $post = get_post( $request ->get_param( 'id' ));202 $post = get_post( $request['id'] ); 181 203 182 204 if ( is_wp_error( $post ) ) { … … 246 268 */ 247 269 public function get_items( $request ) { 248 $parent = $this->get_parent( $request ->get_param( 'parent' ));270 $parent = $this->get_parent( $request['id'] ); 249 271 if ( is_wp_error( $parent ) ) { 250 272 return $parent; … … 390 412 return apply_filters( 'rest_prepare_autosave', $response, $post, $request ); 391 413 } 414 415 /** 416 * Retrieves the query params for the autosaves collection. 417 * 418 * @since 5.0.0 419 * 420 * @return array Collection parameters. 421 */ 422 public function get_collection_params() { 423 return array( 424 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 425 ); 426 } 392 427 }
Note: See TracChangeset
for help on using the changeset viewer.