Changeset 60837 for branches/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
- Timestamp:
- 09/30/2025 05:06:24 PM (3 months ago)
- Location:
- branches/4.9
- 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/4.9
- Property svn:mergeinfo changed
/trunk merged: 60814-60816
- Property svn:mergeinfo changed
-
branches/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r56865 r60837 180 180 181 181 if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { 182 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );182 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) ); 183 183 } 184 184 … … 294 294 295 295 foreach ( $query->results as $user ) { 296 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 297 continue; 298 } 299 296 300 $data = $this->prepare_item_for_response( $user, $request ); 297 301 $users[] = $this->prepare_response_for_collection( $data ); … … 388 392 } 389 393 390 if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { 391 return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); 392 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { 394 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 395 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); 396 } 397 398 if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) { 393 399 return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); 394 400 } … … 891 897 } 892 898 893 if ( in_array( 'roles', $fields, true ) ) {899 if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) { 894 900 // Defensively call array_values() to ensure an array is returned. 895 901 $data['roles'] = array_values( $user->roles );
Note: See TracChangeset
for help on using the changeset viewer.