Advertisement
designbymerovingi

custom hook

Oct 1st, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 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.3
  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 ctype = %s
  31. AND time BETWEEN %d AND %d;", $request['user_id'], $request['ref_id'], $request['ctype'], mktime( 0, 0, 0, date( 'n', $until ), date( 'j', $until ), date( 'Y', $until ) ), $until ) );
  32.  
  33. if ( isset( $check->ref_id ) )
  34. return false;
  35.  
  36. return $reply;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement