Changeset 60820 for branches/6.6/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
- Timestamp:
- 09/30/2025 05:00:33 PM (5 months ago)
- Location:
- branches/6.6
- 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/6.6
- Property svn:mergeinfo changed
/trunk merged: 60814-60816
- Property svn:mergeinfo changed
-
branches/6.6/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r58408 r60820 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 ); … … 351 351 352 352 foreach ( $query->results as $user ) { 353 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 354 continue; 355 } 356 353 357 $data = $this->prepare_item_for_response( $user, $request ); 354 358 $users[] = $this->prepare_response_for_collection( $data ); … … 450 454 } 451 455 452 if ( 'edit' === $request['context'] && ! current_user_can( ' list_users') ) {453 return new WP_Error( 454 'rest_ user_cannot_view',455 __( 'Sorry, you are not allowed to list users.' ),456 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) { 457 return new WP_Error( 458 'rest_forbidden_context', 459 __( 'Sorry, you are not allowed to edit this user.' ), 456 460 array( 'status' => rest_authorization_required_code() ) 457 461 ); 458 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { 462 } 463 464 if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) { 459 465 return new WP_Error( 460 466 'rest_user_cannot_view', … … 1051 1057 } 1052 1058 1053 if ( in_array( 'roles', $fields, true ) ) {1059 if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) { 1054 1060 // Defensively call array_values() to ensure an array is returned. 1055 1061 $data['roles'] = array_values( $user->roles );
Note: See TracChangeset
for help on using the changeset viewer.