Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/22/2016 08:46:36 PM (5 years ago)
Author:
r-a-y
Message:

Load all notification-related code conditionally for each component.

If the notifications component isn't active, there is no need to load all
notification code.

See #6712.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-functions.php

    r10654 r11022  
    525525    return $retval;
    526526}
     527
     528/** Email *********************************************************************/
     529
     530/**
     531 * Email message recipients to alert them of a new unread private message.
     532 *
     533 * @since 1.0.0
     534 *
     535 * @param array|BP_Messages_Message $raw_args {
     536 *     Array of arguments. Also accepts a BP_Messages_Message object.
     537 *     @type array  $recipients    User IDs of recipients.
     538 *     @type string $email_subject Subject line of message.
     539 *     @type string $email_content Content of message.
     540 *     @type int    $sender_id     User ID of sender.
     541 * }
     542 */
     543function messages_notification_new_message( $raw_args = array() ) {
     544    if ( is_object( $raw_args ) ) {
     545        $args = (array) $raw_args;
     546    } else {
     547        $args = $raw_args;
     548    }
     549
     550    // These should be extracted below.
     551    $recipients    = array();
     552    $email_subject = $email_content = '';
     553    $sender_id     = 0;
     554
     555    // Barf.
     556    extract( $args );
     557
     558    if ( empty( $recipients ) ) {
     559        return;
     560    }
     561
     562    $sender_name = bp_core_get_user_displayname( $sender_id );
     563
     564    // Send an email to each recipient.
     565    foreach ( $recipients as $recipient ) {
     566        if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) ) {
     567            continue;
     568        }
     569
     570        // User data and links.
     571        $ud = get_userdata( $recipient->user_id );
     572        if ( empty( $ud ) ) {
     573            continue;
     574        }
     575
     576        $unsubscribe_args = array(
     577            'user_id'           => $recipient->user_id,
     578            'notification_type' => 'messages-unread',
     579        );
     580
     581        $args = array(
     582            'tokens' => array(
     583                'usermessage' => wp_strip_all_tags( stripslashes( $message ) ),
     584                'message.url' => esc_url( bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() . '/view/' . $thread_id . '/' ),
     585                'sender.name' => $sender_name,
     586                'usersubject' => sanitize_text_field( stripslashes( $subject ) ),
     587                'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     588            ),
     589        );
     590        bp_send_email( 'messages-unread', $ud, $args );
     591    }
     592
     593    /**
     594     * Fires after the sending of a new message email notification.
     595     *
     596     * @since 1.5.0
     597     * @deprecated 2.5.0 Use the filters in BP_Email.
     598     *                   $email_subject and $email_content arguments unset and deprecated.
     599     *
     600     * @param array  $recipients    User IDs of recipients.
     601     * @param string $email_subject Deprecated in 2.5; now an empty string.
     602     * @param string $email_content Deprecated in 2.5; now an empty string.
     603     * @param array  $args          Array of originally provided arguments.
     604     */
     605    do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args );
     606}
     607add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
Note: See TracChangeset for help on using the changeset viewer.