问题
Using this tutorial, I am able to add to the transfer function like this:
add_action( 'mycred_transfer_form_start', 'mycred_pro_transfer_message_field' );
function mycred_pro_transfer_message_field() {
echo '<label>Custom Message</label><input type="text" name="custom_transfer-message" id="custom_mycred-transfer-message" value="" placeholder="Custom field placeholder" />';
}
Then I use the following to get the data from the form.
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 = 'Blank message';
// If a message is set
if ( isset( $post['custom_transfer-message'] ) )
$message = sanitize_text_field( $post['custom_transfer-message'] );
// Add to the data array
$data['custom_transfer-message'] = $message;
// return the results
return $data;
}
I can see the field is added as the database is adding custom_transfer-message
but it is only returning 'Blank message':
a:4:{s:8:"ref_type";s:4:"user";s:3:"tid";s:16:"TXID1604153101";
s:7:"message";s:3:"personal message";s:23:"custom_transfer-message";s:13:"Blank message";}
I assume this means that the message is not setting:
if ( isset( $post['custom_transfer-message'] ) )
$message = sanitize_text_field( $post['custom_transfer-message'] );
How can I get the value to load to the database correctly?
来源:https://stackoverflow.com/questions/64622714/posting-custom-mycred-transfer-form-value-to-wp-database