You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This function produces a contextually-specific HTTP error code based on
whether the user is logged in. It should be used when producing an error
from a failed `current_user_can()` check, because it's helpful to the
client to be able to distinguish between 401 and 403
if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) {
24
-
returnnewWP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => 401 ) );
24
+
returnnewWP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_forbidden_context', __( 'Sorry, you cannot view comments with edit context.' ), array( 'status' => 403 ) );
368
+
returnnewWP_Error( 'rest_forbidden_context', __( 'Sorry, you cannot view comments with edit context.' ), array( 'status' => rest_authorization_required_code() ) );
369
369
}
370
370
371
371
returntrue;
@@ -387,17 +387,17 @@ public function get_item_permissions_check( $request ) {
387
387
}
388
388
389
389
if ( ! $this->check_read_permission( $comment ) ) {
390
-
returnnewWP_Error( 'rest_cannot_read', __( 'Sorry, you cannot read this comment.' ), array( 'status' => 403 ) );
390
+
returnnewWP_Error( 'rest_cannot_read', __( 'Sorry, you cannot read this comment.' ), array( 'status' => rest_authorization_required_code() ) );
391
391
}
392
392
393
393
$post = get_post( $comment->comment_post_ID );
394
394
395
395
if ( $post && ! $this->check_read_post_permission( $post ) ) {
396
-
returnnewWP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => 403 ) );
396
+
returnnewWP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_comment_invalid_status', __( 'Sorry, you cannot set status for comments.' ), array( 'status' => 403 ) );
422
+
returnnewWP_Error( 'rest_comment_invalid_status', __( 'Sorry, you cannot set status for comments.' ), array( 'status' => rest_authorization_required_code() ) );
423
423
}
424
424
425
425
// If the post id isn't specified, presume we can create.
@@ -432,7 +432,7 @@ public function create_item_permissions_check( $request ) {
432
432
if ( $post ) {
433
433
434
434
if ( ! $this->check_read_post_permission( $post ) ) {
435
-
returnnewWP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => 403 ) );
435
+
returnnewWP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
436
436
}
437
437
438
438
if ( ! comments_open( $post->ID ) ) {
@@ -456,7 +456,7 @@ public function update_item_permissions_check( $request ) {
456
456
$comment = get_comment( $id );
457
457
458
458
if ( $comment && ! $this->check_edit_permission( $comment ) ) {
459
-
returnnewWP_Error( 'rest_cannot_edit', __( 'Sorry, you can not edit this comment.' ), array( 'status' => 403 ) );
459
+
returnnewWP_Error( 'rest_cannot_edit', __( 'Sorry, you can not edit this comment.' ), array( 'status' => rest_authorization_required_code() ) );
if ( ! current_user_can( $post_type->cap->edit_post, $parent->ID ) ) {
57
-
returnnewWP_Error( 'rest_forbidden', __( 'Sorry, you cannot view the meta for this post.' ), array( 'status' => 403 ) );
57
+
returnnewWP_Error( 'rest_forbidden', __( 'Sorry, you cannot view the meta for this post.' ), array( 'status' => rest_authorization_required_code() ) );
58
58
}
59
59
returntrue;
60
60
}
@@ -103,12 +103,12 @@ public function delete_item_permissions_check( $request ) {
103
103
}
104
104
105
105
if ( ! $this->parent_controller->check_read_permission( $parent ) ) {
106
-
returnnewWP_Error( 'rest_forbidden', __( 'Sorry, you cannot view this post.' ), array( 'status' => 403 ) );
106
+
returnnewWP_Error( 'rest_forbidden', __( 'Sorry, you cannot view this post.' ), array( 'status' => rest_authorization_required_code() ) );
if ( ! current_user_can( $post_type->cap->delete_post, $parent->ID ) ) {
111
-
returnnewWP_Error( 'rest_forbidden', __( 'Sorry, you cannot delete the meta for this post.' ), array( 'status' => 403 ) );
111
+
returnnewWP_Error( 'rest_forbidden', __( 'Sorry, you cannot delete the meta for this post.' ), array( 'status' => rest_authorization_required_code() ) );
if ( ! $this->check_delete_permission( $post ) ) {
340
-
returnnewWP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => 401 ) );
340
+
returnnewWP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit these posts in this post type' ), array( 'status' => 403 ) );
402
+
returnnewWP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit these posts in this post type' ), array( 'status' => rest_authorization_required_code() ) );
403
403
}
404
404
405
405
returntrue;
@@ -416,7 +416,7 @@ public function get_item_permissions_check( $request ) {
returnnewWP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this post' ), array( 'status' => 403 ) );
419
+
returnnewWP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this post' ), array( 'status' => rest_authorization_required_code() ) );
420
420
}
421
421
422
422
if ( $post ) {
@@ -437,15 +437,15 @@ public function create_item_permissions_check( $request ) {
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create password protected posts in this post type' ), array( 'status' => 403 ) );
440
+
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create password protected posts in this post type' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_edit_others', __( 'You are not allowed to create posts as this user.' ), array( 'status' => 403 ) );
444
+
returnnewWP_Error( 'rest_cannot_edit_others', __( 'You are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_assign_sticky', __( 'You do not have permission to make posts sticky.' ), array( 'status' => 403 ) );
448
+
returnnewWP_Error( 'rest_cannot_assign_sticky', __( 'You do not have permission to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create password protected posts in this post type' ), array( 'status' => 403 ) );
470
+
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create password protected posts in this post type' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_edit_others', __( 'You are not allowed to update posts as this user.' ), array( 'status' => 403 ) );
474
+
returnnewWP_Error( 'rest_cannot_edit_others', __( 'You are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_assign_sticky', __( 'You do not have permission to make posts sticky.' ), array( 'status' => 403 ) );
478
+
returnnewWP_Error( 'rest_cannot_assign_sticky', __( 'You do not have permission to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
479
479
}
480
480
481
481
returntrue;
@@ -492,7 +492,7 @@ public function delete_item_permissions_check( $request ) {
492
492
$post = get_post( $request['id'] );
493
493
494
494
if ( $post && ! $this->check_delete_permission( $post ) ) {
495
-
returnnewWP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete posts.' ), array( 'status' => 403 ) );
495
+
returnnewWP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete posts.' ), array( 'status' => rest_authorization_required_code() ) );
if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
819
-
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create private posts in this post type' ), array( 'status' => 403 ) );
819
+
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create private posts in this post type' ), array( 'status' => rest_authorization_required_code() ) );
820
820
}
821
821
break;
822
822
case'publish':
823
823
case'future':
824
824
if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
825
-
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to publish posts in this post type' ), array( 'status' => 403 ) );
825
+
returnnewWP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to publish posts in this post type' ), array( 'status' => rest_authorization_required_code() ) );
826
826
}
827
827
break;
828
828
default:
@@ -1606,7 +1606,7 @@ public function validate_user_can_query_private_statuses( $value, $request, $par
1606
1606
if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
returnnewWP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this user with edit context' ), array( 'status' => 403 ) );
395
+
returnnewWP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this user with edit context' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this user with view context' ), array( 'status' => 403 ) );
397
+
returnnewWP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this user with view context' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_create_user', __( 'Sorry, you are not allowed to create users.' ), array( 'status' => 403 ) );
414
+
returnnewWP_Error( 'rest_cannot_create_user', __( 'Sorry, you are not allowed to create users.' ), array( 'status' => rest_authorization_required_code() ) );
415
415
}
416
416
417
417
returntrue;
@@ -428,11 +428,11 @@ public function update_item_permissions_check( $request ) {
428
428
$id = (int) $request['id'];
429
429
430
430
if ( ! current_user_can( 'edit_user', $id ) ) {
431
-
returnnewWP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => 403 ) );
431
+
returnnewWP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) );
returnnewWP_Error( 'rest_cannot_edit_roles', __( 'Sorry, you are not allowed to edit roles of users.' ), array( 'status' => 403 ) );
435
+
returnnewWP_Error( 'rest_cannot_edit_roles', __( 'Sorry, you are not allowed to edit roles of users.' ), array( 'status' => rest_authorization_required_code() ) );
436
436
}
437
437
438
438
returntrue;
@@ -450,7 +450,7 @@ public function delete_item_permissions_check( $request ) {
returnnewWP_Error( 'rest_user_cannot_delete', __( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => 403 ) );
453
+
returnnewWP_Error( 'rest_user_cannot_delete', __( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => rest_authorization_required_code() ) );
0 commit comments