ap_get_user_reputation( integer $user_id, boolean $group = false )
Description #
Count reputation points of a user.
Parameters #
- $user_idinteger (Required) ID of user.
- $groupboolean (Optional) Return total count or group by event count. Default value: false
Source #
File: includes/reputation.php
function ap_get_user_reputation( $user_id, $group = false ) { global $wpdb; $events = $wpdb->get_results( $wpdb->prepare( "SELECT count(*) as count, rep_event FROM {$wpdb->ap_reputations} WHERE rep_user_id = %d GROUP BY rep_event", $user_id ) ); // phpcs:ignore WordPress.DB $event_counts = array(); foreach ( (array) $events as $count ) { $event_counts[ $count->rep_event ] = $count->count; } $count = array(); $reputation_events = ap_get_reputation_events(); if ( ! empty( $reputation_events ) ) { foreach ( $reputation_events as $slug => $event ) { $count[ $slug ] = isset( $event_counts[ $slug ] ) ? ( (int) $event_counts[ $slug ] * (int) $event['points'] ) : 0; } } if ( false === $group ) { return array_sum( $count ); } return $count; }
Expand full source code Collapse full source code View on GitHub: includes/reputation.php:232
Add your comment