BP_REST_Group_Messages_Endpoint::bp_rest_groups_messages_new_message( array|string $args = '' )

Create New Group Message.

Description

— from bp_groups_messages_new_message();

Parameters

$args

(Optional) Array of arguments

Default value: ''

Return

(int|bool|WP_Error) ID of the message thread on success, false on failure.

Source

File: bp-messages/classes/class-bp-rest-group-messages-endpoint.php

1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
public function bp_rest_groups_messages_new_message( $args = '' ) {
    $send = '';
    remove_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
    add_action( 'messages_message_sent', 'group_messages_notification_new_message', 10 );
 
    $r = bp_parse_args(
        $args,
        array(
            'sender_id'     => bp_loggedin_user_id(),
            'thread_id'     => false,   // False for a new message, thread id for a reply to a thread.
            'recipients'    => array(), // Can be an array of usernames, user_ids or mixed.
            'subject'       => false,
            'content'       => false,
            'date_sent'     => bp_core_current_time(),
            'append_thread' => false,
            'is_hidden'     => false,
            'mark_visible'  => false,
            'group_thread'  => true,
            'error_type'    => 'wp_error',
        ),
        'bp_groups_messages_new_message'
    );
 
    // Attempt to send the message.
    $send = messages_new_message( $r );
 
    remove_action( 'messages_message_sent', 'group_messages_notification_new_message', 10 );
    add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
 
    return $send;
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.