messages_notification_new_message( array|BP_Messages_Message $raw_args = array() )
Email message recipients to alert them of a new unread private message.
Description
Parameters
- $raw_args
-
(Optional) Array of arguments. Also accepts a BP_Messages_Message object
Default value: array()
Source
File: bp-messages/bp-messages-functions.php
function messages_notification_new_message( $raw_args = array() ) { if ( is_object( $raw_args ) ) { $args = (array) $raw_args; } else { $args = $raw_args; } // These should be extracted below. $recipients = array(); $email_subject = $email_content = ''; $sender_id = 0; // Barf. extract( $args ); if ( empty( $recipients ) ) { return; } $sender_name = bp_core_get_user_displayname( $sender_id ); if ( isset( $message ) ) { $message = wpautop( $message ); } else { $message = ''; } // Send an email to each recipient. foreach ( $recipients as $recipient ) { if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) ) { continue; } // User data and links. $ud = get_userdata( $recipient->user_id ); if ( empty( $ud ) ) { continue; } $unsubscribe_args = array( 'user_id' => $recipient->user_id, 'notification_type' => 'messages-unread', ); bp_send_email( 'messages-unread', $ud, array( 'tokens' => array( 'message_id' => $id, 'usermessage' => stripslashes( $message ), 'message.url' => esc_url( bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() . '/view/' . $thread_id . '/' ), 'sender.name' => $sender_name, 'usersubject' => sanitize_text_field( stripslashes( $subject ) ), 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ), ), ) ); } /** * Fires after the sending of a new message email notification. * * @since BuddyPress 1.5.0 * @deprecated 2.5.0 Use the filters in BP_Email. * $email_subject and $email_content arguments unset and deprecated. * * @param array $recipients User IDs of recipients. * @param string $email_subject Deprecated in 2.5; now an empty string. * @param string $email_content Deprecated in 2.5; now an empty string. * @param array $args Array of originally provided arguments. */ do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
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.