Advertisement
designbymerovingi

Limit View Content Hook to once per post per day

Mar 27th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. /**
  2.  * View Content Hook Adjustment
  3.  * Limit points to be awarded once per day per unique post.
  4.  * @version 1.0.2
  5.  */
  6. add_filter( 'mycred_add', 'mycred_pro_view_once_per_post', 10, 3 );
  7. function mycred_pro_view_once_per_post( $reply, $request, $mycred ) {
  8.  
  9.     if ( ! in_array( $request['ref'], array( 'view_content', 'completing_quiz_full' ) ) || $reply === false ) return $reply;
  10.  
  11.     if ( $request['ref'] == 'view_content' ) {
  12.  
  13.         $post_id             = absint( $request['ref_id'] );
  14.         $post_categories     = wp_get_post_categories( $post_id );
  15.  
  16.         if ( in_array( 89, (array) $post_categories ) || in_array( 90, (array) $post_categories ) )
  17.             return false;
  18.  
  19.     }
  20.  
  21.     global $wpdb;
  22.  
  23.     $until = current_time( 'timestamp' );
  24.     $check = $wpdb->get_row( $wpdb->prepare( "
  25.         SELECT *
  26.         FROM {$mycred->log_table}
  27.         WHERE ref   IN ( 'view_content', 'completing_quiz_full' )
  28.         AND user_id = %d
  29.         AND ref_id  = %d
  30.         AND time BETWEEN %d AND %d;", $request['user_id'], $request['ref_id'], mktime( 0, 0, 0, date( 'n', $until ), date( 'j', $until ), date( 'Y', $until ) ), $until ) );
  31.  
  32.     if ( isset( $check->ref_id ) )
  33.         return false;
  34.  
  35.     return $reply;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement