Changeset 60835 for branches/5.1/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
- Timestamp:
- 09/30/2025 05:05:30 PM (8 months ago)
- Location:
- branches/5.1
- 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.1
- Property svn:mergeinfo changed
/trunk merged: 60814-60816
- Property svn:mergeinfo changed
-
branches/5.1/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r56873 r60835 192 192 193 193 if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { 194 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );194 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) ); 195 195 } 196 196 … … 306 306 307 307 foreach ( $query->results as $user ) { 308 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 309 continue; 310 } 311 308 312 $data = $this->prepare_item_for_response( $user, $request ); 309 313 $users[] = $this->prepare_response_for_collection( $data ); … … 400 404 } 401 405 402 if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { 403 return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); 404 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { 406 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 407 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); 408 } 409 410 if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) { 405 411 return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); 406 412 } … … 923 929 } 924 930 925 if ( in_array( 'roles', $fields, true ) ) {931 if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) { 926 932 // Defensively call array_values() to ensure an array is returned. 927 933 $data['roles'] = array_values( $user->roles );
Note: See TracChangeset
for help on using the changeset viewer.