Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/10/2012 09:02:53 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in Messages component. See #3989.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages/bp-messages-notifications.php

    r5445 r5696  
    11<?php
     2
     3/**
     4 * BuddyPress Messages Notifications
     5 *
     6 * @package BuddyPress
     7 * @subpackage MessagesNotifications
     8 */
     9
     10
    211// Exit if accessed directly
    312if ( !defined( 'ABSPATH' ) ) exit;
    413
    5 function messages_notification_new_message( $args ) {
    6         global $bp;
     14function messages_notification_new_message( $args = array() ) {
    715
    8         extract($args);
     16        // These should be extracted below
     17        $recipients    = array();
     18        $email_subject = $email_content = '';
    919
    10         $email_subject = $email_content = $args = '';
    11         $sender_name   = bp_core_get_user_displayname( $sender_id );
     20        extract( $args );
    1221
    13         foreach( $recipients as $recipient ) {
    14                 if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) )
    15                         continue;
     22        $sender_name = bp_core_get_user_displayname( $sender_id );
    1623
    17                 // User data and links
    18                 $ud            = get_userdata( $recipient->user_id );
    19                 $message_link  = bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() .'/';
    20                 $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    21                 $settings_link = bp_core_get_user_domain( $recipient->user_id ) . $settings_slug . '/notifications/';
     24        // Bail if no recipients
     25        if ( ! empty( $recipients ) ) {
    2226
    23                 // Sender info
    24                 $sender_name   = stripslashes( $sender_name );
    25                 $subject       = stripslashes( wp_filter_kses( $subject ) );
    26                 $content       = stripslashes( wp_filter_kses( $content ) );
     27                foreach( $recipients as $recipient ) {
    2728
    28                 // Set up and send the message
    29                 $email_to      = $ud->user_email;
    30                 $sitename      = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
    31                 $email_subject = '[' . $sitename . '] ' . sprintf( __( 'New message from %s', 'buddypress' ), $sender_name );
     29                        if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) )
     30                                continue;
    3231
    33                 $email_content = sprintf( __(
     32                        // User data and links
     33                        $ud            = get_userdata( $recipient->user_id );
     34                        $message_link  = bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() .'/';
     35                        $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
     36                        $settings_link = bp_core_get_user_domain( $recipient->user_id ) . $settings_slug . '/notifications/';
     37
     38                        // Sender info
     39                        $sender_name   = stripslashes( $sender_name );
     40                        $subject       = stripslashes( wp_filter_kses( $subject ) );
     41                        $content       = stripslashes( wp_filter_kses( $content ) );
     42
     43                        // Set up and send the message
     44                        $email_to      = $ud->user_email;
     45                        $sitename      = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
     46                        $email_subject = '[' . $sitename . '] ' . sprintf( __( 'New message from %s', 'buddypress' ), $sender_name );
     47
     48                        $email_content = sprintf( __(
    3449'%1$s sent you a new message:
    3550
     
    4358', 'buddypress' ), $sender_name, $subject, $content, $message_link );
    4459
    45                 $email_content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     60                        $email_content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    4661
    47                 // Send the message
    48                 $email_to = apply_filters( 'messages_notification_new_message_to', $email_to );
    49                 $email_subject = apply_filters( 'messages_notification_new_message_subject', $email_subject, $sender_name );
    50                 $email_content = apply_filters( 'messages_notification_new_message_message', $email_content, $sender_name, $subject, $content, $message_link, $settings_link );
     62                        // Send the message
     63                        $email_to      = apply_filters( 'messages_notification_new_message_to',      $email_to );
     64                        $email_subject = apply_filters( 'messages_notification_new_message_subject', $email_subject, $sender_name );
     65                        $email_content = apply_filters( 'messages_notification_new_message_message', $email_content, $sender_name, $subject, $content, $message_link, $settings_link );
    5166
    52                 wp_mail( $email_to, $email_subject, $email_content );
     67                        wp_mail( $email_to, $email_subject, $email_content );
     68                }
    5369        }
    5470
Note: See TracChangeset for help on using the changeset viewer.