Advertisement
designbymerovingi

myCRED Add message to transfers

Dec 28th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. /**
  2.  * Adjust Transfers
  3.  */
  4. add_filter( 'mycred_add', 'mycred_pro_custom_transfer_message', 99, 3 );
  5. function mycred_pro_custom_transfer_message( $reply, $request, $mycred ) {
  6.     // If declined or not a transfer, bail
  7.     if ( $reply === false || $request['ref'] != 'transfer' ) return $reply;
  8.  
  9.     // We want to insert the message to the recipient
  10.     // Recipients can be identified by a positive value
  11.     // as the sender will have a negative one.
  12.     // This is not needed if you want to show the message to
  13.     // both the sender and the recipient!
  14.     if ( $request['amount'] > 0 ) {
  15.  
  16.         // Sanitize the message (also removed all html elements)
  17.         $message = sanitize_text_field( $_POST['message_to_recipient'] );
  18.  
  19.         // Add points now
  20.         $mycred->update_balance( $request['user_id'], $request['amount'] );
  21.  
  22.         // Add custom log entry
  23.         // In this example we will append the message to the end
  24.         // of the log entry but you could also just use a custom
  25.         // template tag that you replace with the message i.e. %message%
  26.         $mycred->add_to_log(
  27.             $request['ref'],
  28.             $request['user_id'],
  29.             $request['amount'],
  30.             $request['entry'] . $message,
  31.             $request['ref_id'],
  32.             $request['data'],
  33.             $request['type']
  34.         );
  35.  
  36.         // Since we just added points we need to return
  37.         // "done" to prevent duplicates!!!
  38.         return 'done';
  39.     }
  40.  
  41.     // Always return a reply or you brake things
  42.     return $reply;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement