You can store the ratings as user meta. When a rating is added, add it to the user's ratings using add_user_meta()
:
add_user_meta( $user_id, '_ratings', $rating, false );
The last parameter tells it to add the current rating to the meta as a new item, not to replace the existing. All ratings can then be retrieved using get_user_meta()
:
get_user_meta( $user_id, '_ratings', false );
The last parameter tells it to turn the ratings as an array:
Array
(
[0] => 5
[1] => 5
[2] => 3
)
You can loop through these to get the average rating. You may want to calculate and store the average as a separate meta each time the ratings meta is updated, so you can just pull that meta on each page load rather than calculating every time.
You'll probably want to limit users to only rating other users once. Each time a user rates another user you could update another meta that contains a list of user ids that they've udpated:
add_user_meta( $rating_user_id, '_rated', $rated_user_id, false );
You can then check against that before allowing them to rate a user:
$rated = get_user_meta( $rating_user_id, '_rated', 'false' );
if ( ! in_array( $rated_user_id, $rated ) ) {
// do stuff here to allow rating
}