Advertisement
designbymerovingi

Testing custom hook

Jun 28th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. add_filter( 'mycred_add',                        'm4d_mycred_limit_per_day',   10, 3 );
  2. function m4d_mycred_limit_per_day( $reply, $request, $mycred ) {
  3.     $reply              = TRUE;
  4.     $max_points_per_day = 50;
  5.     $uid_points_today   = 0;
  6.     $uid                = $request['user_id'];
  7.  
  8.     $log = new myCRED_Query_Log( "user_id={$uid}&time=today" );
  9.  
  10.  
  11.     if ( $log->have_entries() ) {
  12.         foreach ( $log->results as $log_entry ) {
  13.             $uid_points_today = $uid_points_today + $log_entry->creds;
  14.         }
  15.     }
  16.  
  17.     if ( $uid_points_today >= 50 ) {
  18.         $mycred->add_to_log(
  19.         $request['ref'],
  20.         $request['user_id'],
  21.         $request['amount'],
  22.         'No points for [' . $request['ref'] . "] awarded since max daily points reached ($uid_points_today / $max_points_per_day)",
  23.             $request['ref_id'],
  24.             $request['data'],
  25.             $request['type']
  26.     );
  27.  
  28.         $reply = FALSE;
  29.     } elseif ( $uid_points_today + $request['amount'] > $max_points_per_day ) {
  30.         // Add just enough to hit max_points_per_day
  31.         $request['amount'] = $max_points_per_day - $uid_points_today;
  32.  
  33.         $mycred->add_to_log(
  34.         'max_points_reached',
  35.         $request['user_id'],
  36.         $request['amount'],
  37.         'Adjusted points for [' . $request['ref'] . "] to {$request['amount']} so user would not exceed max daily points ($uid_points_today / $max_points_per_day)",
  38.             $request['ref_id'],
  39.             $request['data'],
  40.             $request['type']
  41.     );
  42.     }
  43.  
  44.  
  45.     return( $reply );
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement