Adding additional fields to new thread

You are here:
< All Topics

add_action( 'bp_messages_new_thread_form_before_send_button', function() { ?>
    <label for="reason_for_contact">Reason for message</label>

    <select name="extra-field-1" placeholder="">
        <option value="opt_1" >New Contact</option>
        <option value="opt_2">Arrange a meeting</option>
        <option class="message-store" value="Request pricelist" >Request pricelist</option>
        <option class="message-store" value="Request samples">Request samples</option>
        <option class="message-store" value="Request merchandise">Request merchandise</option>
        <option class="message-sponsor" value="Offer pricelist" >Offer pricelist</option>
        <option class="message-sponsor" value="Offer samples">Offer samples</option>
    </select>
    <?php

} );

add_action('bp_better_messages_new_thread_created', function( $thread_id, $first_message_id ){
    if ( isset( $_POST['extra-field-1'] ) ) {
        bp_messages_update_meta( $first_message_id, '_extra_field_1', $_POST['extra-field-1'] );
    }
}, 10, 2 );

Then we can use next filter to show additional content based on that meta:

add_filter('bp_better_messages_after_format_message', function($message, $message_id, $context, $user_id){
    if( $context === 'stack' ) {
        $append_content = '<br><br>Reason For message: ' . bp_messages_get_meta( $message_id, '_extra_field_1', true ) . PHP_EOL;
        return $message . $append_content;
    }

    return $message;
}, 9, 4);

And that will be the result:

Next Control if user can make audio/video call with hooks
Table of Contents