Custom Message with myCRED Transfer

Custom Message With MyCRED Transfer

Share This Post

Custom Message with myCRED Transfer

MyCred assigns different points to the users but it’s been sometime noticed that the users want to transfer points to another user and MyCred has a transfer form as default but to send a custom message with the transfer like a reason for transferring points which is not available with default form. Below snippets will help you to add custom message.

Also, see this if you don’t know how to allow the transfer of points with myCred.

Note: MyCred Plugin must be configured in order to use these snippets.

Let’s check how it is working…

Snippet 1: Display new fields to the form

This snippet will display a new field to the forum.

				
					/**
 * Display new fields to the form
 */
function ldninjas_add_message_field_in_transfer_form() {
    ?>
    <div>
        <label for="mycred-transfer-custom-message"><?php echo __( 'Reason to Transfer: ', 'ldninjas' ); ?></label>
        <input type="text" placeholder="Reason" class="form-control" name="mycred_new_transfer[message][transfer_reason]" id="mycred-transfer-custom-message" value="" />
    </div>
    <?php
}
add_action( 'mycred_transfer_form_extra', 'ldninjas_add_message_field_in_transfer_form' );
				
			

Snippet 2: Save field value

The snippet will save the custom message field value into the myCred database.

				
					/**
 * Save field value
 */
function ldninjas_save_message_field_values_data( $data, $transaction_id, $post ) {

    $reason_to_transfer = isset( $post['message']['transfer_reason'] ) ? sanitize_textarea_field( $post['message']['transfer_reason'] ) : '';
    $data['reason_to_transfer'] = $reason_to_transfer;

    return $data;
}
add_filter( 'mycred_transfer_data', 'ldninjas_save_message_field_values_data', 10, 3 );
				
			

Snippet 3: Adds new column in myCred log

The snippet will add a new column in MyCred log where custom message will be displayed.

				
					/**
 * Adds new column in myCred log
 */
function ldninjas_add_extra_column_in_log( $columns, $class, $is_admin ) {
    $columns['transfer-message'] = 'Reason to transfer';
    return $columns;
}
add_filter( 'mycred_log_column_headers', 'ldninjas_add_extra_column_in_log', 10, 3 );
				
			

Snippet 4: Display message on myCred log

The snippet will display custom message on myCred log.

				
					/**
 * Display message on myCred log
 */
function ldninjas_display_message_content_log_column( $content, $log_entry ) {

    if( empty( $log_entry->data ) ) {
        return '';
    }

    $type = $log_entry->ref;
    if( $type != 'transfer' ) {
        return '';
    }

    $data = maybe_unserialize( $log_entry->data );
    return $data['reason_to_transfer'];
}
add_filter( 'mycred_log_transfer-message', 'ldninjas_display_message_content_log_column', 10, 2 );
				
			

Conclusion

So, All you need to add this code snippet to your theme functions.php file to display custom message with myCred transfer. Enjoy!

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

How To Get Admin User ID

How to get admin user ID

Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so

Award GamiPress On RCPro Membership Renewal

Award GamiPress on RCPro Membership Renewal

Share This Post Award GamiPress on RCPro Membership Renewal Do you think users can also be awarded points/badges/ranks while RCPro Membership renewal? Yes, you can

Custom Message With MyCRED Transfer

Custom Message with myCRED Transfer

Share This Post Custom Message with myCRED Transfer MyCred assigns different points to the users but it’s been sometime noticed that the users want to

Want To Know About Our Services?

small_c_popup-300x296

Let’s Talk To Us With Your Concerns

    Once you send the details, we will be shortly back to you. Thanks!

    Use coupon code "FSBFCM2023" to get 30% discount on any plugin purchase!
    small_c_popup-300x296

    Become a valuable part of Team LDninjas

    small_c_popup-300x296

    Be updated with new release by LDninjas!