Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'mycred_add', 'm4d_mycred_limit_per_day', 10, 3 );
- function m4d_mycred_limit_per_day( $reply, $request, $mycred ) {
- $reply = TRUE;
- $max_points_per_day = 50;
- $uid_points_today = 0;
- $uid = $request['user_id'];
- $log = new myCRED_Query_Log( "user_id={$uid}&time=today" );
- if ( $log->have_entries() ) {
- foreach ( $log->results as $log_entry ) {
- $uid_points_today = $uid_points_today + $log_entry->creds;
- }
- }
- if ( $uid_points_today >= 50 ) {
- $mycred->add_to_log(
- $request['ref'],
- $request['user_id'],
- $request['amount'],
- 'No points for [' . $request['ref'] . "] awarded since max daily points reached ($uid_points_today / $max_points_per_day)",
- $request['ref_id'],
- $request['data'],
- $request['type']
- );
- $reply = FALSE;
- } elseif ( $uid_points_today + $request['amount'] > $max_points_per_day ) {
- // Add just enough to hit max_points_per_day
- $request['amount'] = $max_points_per_day - $uid_points_today;
- $mycred->add_to_log(
- 'max_points_reached',
- $request['user_id'],
- $request['amount'],
- 'Adjusted points for [' . $request['ref'] . "] to {$request['amount']} so user would not exceed max daily points ($uid_points_today / $max_points_per_day)",
- $request['ref_id'],
- $request['data'],
- $request['type']
- );
- }
- return( $reply );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement