Changeset 60814
- Timestamp:
- 09/30/2025 03:49:18 PM (8 weeks ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php (modified) (1 diff)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php (modified) (1 diff)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php (modified) (4 diffs)
-
tests/phpunit/tests/rest-api/rest-users-controller.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r60197 r60814 464 464 465 465 foreach ( $query_result as $post ) { 466 if ( ! $this->check_read_permission( $post ) ) { 466 if ( 'edit' === $request['context'] ) { 467 $permission = $this->check_update_permission( $post ); 468 } else { 469 $permission = $this->check_read_permission( $post ); 470 } 471 472 if ( ! $permission ) { 467 473 continue; 468 474 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r59970 r60814 366 366 $response = array(); 367 367 foreach ( $query_result as $term ) { 368 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) { 369 continue; 370 } 371 368 372 $data = $this->prepare_item_for_response( $term, $request ); 369 373 $response[] = $this->prepare_response_for_collection( $data ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r59970 r60814 221 221 return new WP_Error( 222 222 'rest_forbidden_context', 223 __( 'Sorry, you are not allowed to list users.' ),223 __( 'Sorry, you are not allowed to edit users.' ), 224 224 array( 'status' => rest_authorization_required_code() ) 225 225 ); … … 380 380 381 381 foreach ( $query->get_results() as $user ) { 382 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 383 continue; 384 } 385 382 386 $data = $this->prepare_item_for_response( $user, $request ); 383 387 $users[] = $this->prepare_response_for_collection( $data ); … … 480 484 } 481 485 482 if ( 'edit' === $request['context'] && ! current_user_can( ' list_users') ) {483 return new WP_Error( 484 'rest_ user_cannot_view',485 __( 'Sorry, you are not allowed to list users.' ),486 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 487 return new WP_Error( 488 'rest_forbidden_context', 489 __( 'Sorry, you are not allowed to edit this user.' ), 486 490 array( 'status' => rest_authorization_required_code() ) 487 491 ); 488 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { 492 } 493 494 if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) { 489 495 return new WP_Error( 490 496 'rest_user_cannot_view', … … 1087 1093 } 1088 1094 1089 if ( in_array( 'roles', $fields, true ) ) {1095 if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) { 1090 1096 // Defensively call array_values() to ensure an array is returned. 1091 1097 $data['roles'] = array_values( $user->roles ); -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r60251 r60814 1314 1314 $request->set_param( 'context', 'edit' ); 1315 1315 $response = rest_get_server()->dispatch( $request ); 1316 $this->assertErrorResponse( 'rest_ user_cannot_view', $response, 401 );1316 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 1317 1317 } 1318 1318
Note: See TracChangeset
for help on using the changeset viewer.