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