ap_get_users_reputation( array $user_ids )
Description #
Get reputation of multiple users.
Parameters #
- $user_idsarray (Required) User ids.
Source #
File: includes/reputation.php
function ap_get_users_reputation( $user_ids ) { global $wpdb; $user_counts = array(); foreach ( (array) $user_ids as $id ) { $user_counts[ (int) $id ] = array(); } $sanitized = implode( ',', array_keys( $user_counts ) ); $query = "SELECT count(*) as count, rep_event, rep_user_id FROM {$wpdb->ap_reputations} WHERE rep_user_id IN ({$sanitized}) GROUP BY rep_event, rep_user_id"; $events = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB foreach ( (array) $events as $count ) { if ( empty( $event_counts[ $count->rep_user_id ] ) ) { $event_counts[ $count->rep_user_id ] = array(); } $user_counts[ $count->rep_user_id ][ $count->rep_event ] = $count->count; } $counts = array(); $all_events = ap_get_reputation_events(); foreach ( $user_counts as $user_id => $events ) { $counts[ $user_id ] = array(); foreach ( $all_events as $slug => $event ) { $counts[ $user_id ][ $slug ] = isset( $events[ $slug ] ) ? ( (int) $events[ $slug ] * (int) $event['points'] ) : 0; } } return $counts; }
Expand full source code Collapse full source code View on GitHub: includes/reputation.php:301
Add your comment