- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r46729 r47122 139 139 */ 140 140 protected function get_parent( $parent ) { 141 $error = new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); 141 $error = new WP_Error( 142 'rest_post_invalid_parent', 143 __( 'Invalid post parent ID.' ), 144 array( 'status' => 404 ) 145 ); 142 146 if ( (int) $parent <= 0 ) { 143 147 return $error; … … 167 171 168 172 $parent_post_type_obj = get_post_type_object( $parent->post_type ); 173 169 174 if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) { 170 return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); 175 return new WP_Error( 176 'rest_cannot_read', 177 __( 'Sorry, you are not allowed to view revisions of this post.' ), 178 array( 'status' => rest_authorization_required_code() ) 179 ); 171 180 } 172 181 … … 183 192 */ 184 193 protected function get_revision( $id ) { 185 $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision ID.' ), array( 'status' => 404 ) ); 194 $error = new WP_Error( 195 'rest_post_invalid_id', 196 __( 'Invalid revision ID.' ), 197 array( 'status' => 404 ) 198 ); 199 186 200 if ( (int) $id <= 0 ) { 187 201 return $error; … … 212 226 // Ensure a search string is set in case the orderby is set to 'relevance'. 213 227 if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) { 214 return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); 228 return new WP_Error( 229 'rest_no_search_term_defined', 230 __( 'You need to define a search term to order by relevance.' ), 231 array( 'status' => 400 ) 232 ); 215 233 } 216 234 217 235 // Ensure an include parameter is set in case the orderby is set to 'include'. 218 236 if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) { 219 return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); 237 return new WP_Error( 238 'rest_orderby_include_missing_include', 239 __( 'You need to define an include parameter to order by include.' ), 240 array( 'status' => 400 ) 241 ); 220 242 } 221 243 … … 282 304 if ( $total_revisions > 0 ) { 283 305 if ( $offset >= $total_revisions ) { 284 return new WP_Error( 'rest_revision_invalid_offset_number', __( 'The offset number requested is larger than or equal to the number of available revisions.' ), array( 'status' => 400 ) ); 306 return new WP_Error( 307 'rest_revision_invalid_offset_number', 308 __( 'The offset number requested is larger than or equal to the number of available revisions.' ), 309 array( 'status' => 400 ) 310 ); 285 311 } elseif ( ! $offset && $page > $max_pages ) { 286 return new WP_Error( 'rest_revision_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); 312 return new WP_Error( 313 'rest_revision_invalid_page_number', 314 __( 'The page number requested is larger than the number of pages available.' ), 315 array( 'status' => 400 ) 316 ); 287 317 } 288 318 } … … 295 325 296 326 $response = array(); 327 297 328 foreach ( $revisions as $revision ) { 298 329 $data = $this->prepare_item_for_response( $revision, $request ); … … 355 386 356 387 $parent_post_type = get_post_type_object( $parent->post_type ); 388 357 389 if ( ! current_user_can( $parent_post_type->cap->delete_post, $parent->ID ) ) { 358 return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); 390 return new WP_Error( 391 'rest_cannot_delete', 392 __( 'Sorry, you are not allowed to delete revisions of this post.' ), 393 array( 'status' => rest_authorization_required_code() ) 394 ); 359 395 } 360 396 … … 395 431 396 432 if ( ! current_user_can( $post_type->cap->delete_post, $revision->ID ) ) { 397 return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this revision.' ), array( 'status' => rest_authorization_required_code() ) ); 433 return new WP_Error( 434 'rest_cannot_delete', 435 __( 'Sorry, you are not allowed to delete this revision.' ), 436 array( 'status' => rest_authorization_required_code() ) 437 ); 398 438 } 399 439 … … 419 459 // We don't support trashing for revisions. 420 460 if ( ! $force ) { 421 /* translators: %s: force=true */ 422 return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); 461 return new WP_Error( 462 'rest_trash_not_supported', 463 /* translators: %s: force=true */ 464 sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), 465 array( 'status' => 501 ) 466 ); 423 467 } 424 468 … … 440 484 441 485 if ( ! $result ) { 442 return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); 486 return new WP_Error( 487 'rest_cannot_delete', 488 __( 'The post cannot be deleted.' ), 489 array( 'status' => 500 ) 490 ); 443 491 } 444 492 … … 702 750 703 751 $this->schema = $schema; 752 704 753 return $this->add_additional_fields_schema( $this->schema ); 705 754 }
Note: See TracChangeset
for help on using the changeset viewer.