Advertisement
designbymerovingi

daily link click limit

Mar 25th, 2014
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. add_filter( 'mycred_add', 'daily_link_click_limit', 10, 3 );
  2. function daily_link_click_limit( $reply, $request, $mycred )
  3. {
  4.     if ( $request['ref'] != 'link_click' || $reply === false ) return $reply;
  5.  
  6.     $max_per_day = 25;
  7.     $user_id = absint( $request['user_id'] );
  8.  
  9.     global $wpdb;
  10.     $count = $wpdb->get_var( $wpdb->prepare( "
  11.         SELECT COUNT( * )
  12.         FROM {$mycred->log_table}
  13.         WHERE ref = %s
  14.             AND user_id = %d
  15.             AND time > %d;", 'link_click', $user_id, date_i18n( 'U', strtotime( 'today midnight' ) ) ) );
  16.  
  17.     if ( $count >= $max_per_day )
  18.         return false;
  19.  
  20.     return $reply;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement