Changeset 60838 for branches/4.8/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
- Timestamp:
- 09/30/2025 05:06:32 PM (6 months ago)
- Location:
- branches/4.8
- 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.8
- Property svn:mergeinfo changed
/trunk merged: 60814-60816
- Property svn:mergeinfo changed
-
branches/4.8/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r56864 r60838 185 185 186 186 if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { 187 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );187 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) ); 188 188 } 189 189 … … 283 283 284 284 foreach ( $query->results as $user ) { 285 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 286 continue; 287 } 285 288 $data = $this->prepare_item_for_response( $user, $request ); 286 289 $users[] = $this->prepare_response_for_collection( $data ); … … 378 381 } 379 382 380 if ( 'edit' === $request['context'] && ! current_user_can( ' list_users') ) {381 return new WP_Error( 'rest_ user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );383 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 384 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); 382 385 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { 383 386 return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); … … 880 883 } 881 884 882 if ( ! empty( $schema['properties']['roles'] ) ) {885 if ( ! empty( $schema['properties']['roles'] ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) { 883 886 // Defensively call array_values() to ensure an array is returned. 884 887 $data['roles'] = array_values( $user->roles );
Note: See TracChangeset
for help on using the changeset viewer.