Changeset 60829 for branches/5.7/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
- Timestamp:
- 09/30/2025 05:03:26 PM (6 weeks ago)
- Location:
- branches/5.7
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/5.7
- Property svn:mergeinfo changed
/trunk merged: 60814-60816
- Property svn:mergeinfo changed
-
branches/5.7/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r56886 r60829 202 202 return new WP_Error( 203 203 'rest_forbidden_context', 204 __( 'Sorry, you are not allowed to list users.' ),204 __( 'Sorry, you are not allowed to edit users.' ), 205 205 array( 'status' => rest_authorization_required_code() ) 206 206 ); … … 325 325 326 326 foreach ( $query->results as $user ) { 327 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 328 continue; 329 } 330 327 331 $data = $this->prepare_item_for_response( $user, $request ); 328 332 $users[] = $this->prepare_response_for_collection( $data ); … … 424 428 } 425 429 426 if ( 'edit' === $request['context'] && ! current_user_can( ' list_users') ) {427 return new WP_Error( 428 'rest_ user_cannot_view',429 __( 'Sorry, you are not allowed to list users.' ),430 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 431 return new WP_Error( 432 'rest_forbidden_context', 433 __( 'Sorry, you are not allowed to edit this user.' ), 430 434 array( 'status' => rest_authorization_required_code() ) 431 435 ); 432 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { 436 } 437 438 if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) { 433 439 return new WP_Error( 434 440 'rest_user_cannot_view', … … 1025 1031 } 1026 1032 1027 if ( in_array( 'roles', $fields, true ) ) {1033 if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) { 1028 1034 // Defensively call array_values() to ensure an array is returned. 1029 1035 $data['roles'] = array_values( $user->roles );
Note: See TracChangeset
for help on using the changeset viewer.