Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Example 1: Transfer Messages
* Step 1 : Insert Message Field
* @version 1.0
*/
add_action( 'mycred_transfer_form_to', 'mycred_pro_transfer_message_field' );
function mycred_pro_transfer_message_field() {
echo '<label>Message</label><input type="text" name="transfer-message" id="mycred-transfer-message" value="" placeholder="Optional message to recipient" />';
}
/**
* Step 2 : Save Message
* @version 1.0
*/
add_filter( 'mycred_transfer_data', 'mycred_pro_save_transfer_message', 10, 3 );
function mycred_pro_save_transfer_message( $data, $transaction_id, $post ) {
// Default message.
$message = 'No message';
// If a message is set
if ( $post['transfer-message'] != '' )
$message = sanitize_text_field( $post['transfer-message'] );
// Add to the data array
$data['message'] = $message;
// return the results
return $data;
}
/**
* Step 3 : Show the message
* @version 1.0
*/
add_filter( 'mycred_parse_log_entry_transfer', 'mycred_pro_show_message_in_log', 10, 2 );
function mycred_pro_show_message_in_log( $content, $log_entry ) {
// Unserialize data
$data = maybe_unserialize( $log_entry->data );
// Default message
$message = 'No message';
if ( isset( $data['message'] ) )
$message = $data['message'];
// Replace and return
return str_replace( '%message%', $message, $content );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.