Advertisement
designbymerovingi

Send points without being charged for it

Oct 24th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. // Add Give Rewards button under bbPress avatar
  2. add_action( 'bbp_theme_after_reply_author_details', 'mycred_pro_add_reward_button_in_bbp' );
  3. function mycred_pro_add_reward_button_in_bbp() {
  4.  
  5.     // Make sure myCRED is around
  6.     if ( ! function_exists( 'mycred_exclude_user' ) ) return;
  7.  
  8.     $reply_id = bbp_get_reply_id();
  9.     if ( bbp_is_reply_anonymous( $reply_id ) ) return;
  10.     $user_id  = bbp_get_reply_author_id( $reply_id );
  11.  
  12.     if ( mycred_exclude_user( $user_id ) ) return;
  13.  
  14.     echo do_shortcode( '[mycred_send amount="10" to="' . $user_id . '" ref="rewards_given" log="Rewards Given"]Give Rewards[/mycred_send]' );
  15.  
  16. }
  17.  
  18. // Stop point deduction when a member gives points to other
  19. add_filter( 'mycred_add', 'mycred_pro_give_rewards_without_loss', 999, 3 );
  20. function mycred_pro_give_rewards_without_loss( $reply, $request, $mycred ) {
  21.  
  22.     extract( $request );
  23.  
  24.     // Give the recipient points but decline the transaction so the user sending the points is not charged
  25.     if ( $reply === true && $ref == 'rewards_given' && $type === MYCRED_DEFAULT_TYPE_KEY ) {
  26.  
  27.         $amount = abs( $amount );
  28.  
  29.         $mycred->add_to_log(
  30.             $request['ref'],
  31.             $request['ref_id'],
  32.             $amount,
  33.             $request['entry'],
  34.             $request['user_id'],
  35.             $request['data'],
  36.             $request['type']
  37.         );
  38.  
  39.         $mycred->update_users_balance( (int) $request['ref_id'], $amount, $request['type'] );
  40.  
  41.         return false;
  42.  
  43.     }
  44.  
  45.     return $reply;
  46.  
  47. }
  48.  
  49. // Adjust the language
  50. add_filter( 'mycred_send_language', 'mycred_pro_adjust_send_language' );
  51. function mycred_pro_adjust_send_language( $js ) {
  52.  
  53.     $js['error'] = 'Sent';
  54.  
  55.     return $js;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement