Changeset 7621
- Timestamp:
- 11/30/2013 04:44:58 AM (11 years ago)
- Location:
- trunk/bp-messages
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-messages/bp-messages-functions.php
r7613 r7621 115 115 116 116 if ( $message->send() ) { 117 118 // Send screen notifications to the recipients119 foreach ( (array) $message->recipients as $recipient ) {120 bp_core_add_notification( $message->id, $recipient->user_id, 'messages', 'new_message', $message->sender_id );121 }122 123 // Send email notifications to the recipients124 messages_notification_new_message( array( 'message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id) );125 126 117 do_action_ref_array( 'messages_message_sent', array( &$message ) ); 127 118 … … 224 215 return BP_Messages_Thread::is_valid( $thread_id ); 225 216 } 226 227 /**228 * Format the BuddyBar/Toolbar notifications for the Messages component229 *230 * @package BuddyPress231 *232 * @param string $action The kind of notification being rendered233 * @param int $item_id The primary item id234 * @param int $secondary_item_id The secondary item id235 * @param int $total_items The total number of messaging-related notifications waiting for the user236 * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar237 */238 function messages_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {239 240 if ( 'new_message' == $action ) {241 $link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox' );242 $title = __( 'Inbox', 'buddypress' );243 244 if ( (int) $total_items > 1 ) {245 $text = sprintf( __('You have %d new messages', 'buddypress' ), (int) $total_items );246 $filter = 'bp_messages_multiple_new_message_notification';247 } else {248 if ( !empty( $secondary_item_id ) ) {249 $text = sprintf( __('You have %d new message from %s', 'buddypress' ), (int) $total_items, bp_core_get_user_displayname( $secondary_item_id ) );250 } else {251 $text = sprintf( __('You have %d new message', 'buddypress' ), (int) $total_items );252 }253 $filter = 'bp_messages_single_new_message_notification';254 }255 }256 257 if ( 'string' == $format ) {258 $return = apply_filters( $filter, '<a href="' . $link . '" title="' . $title . '">' . $text . '</a>', (int) $total_items, $text, $link, $item_id, $secondary_item_id );259 } else {260 $return = apply_filters( $filter, array(261 'text' => $text,262 'link' => $link263 ), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id );264 }265 266 do_action( 'messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items );267 268 return $return;269 } -
trunk/bp-messages/bp-messages-notifications.php
r6917 r7621 8 8 */ 9 9 10 11 10 // Exit if accessed directly 12 11 if ( !defined( 'ABSPATH' ) ) exit; 13 12 13 /** Email *********************************************************************/ 14 15 /** 16 * Email message recipients to alert them of a new unread private message 17 * 18 * @since BuddyPress (1.0) 19 * @param array $args 20 */ 14 21 function messages_notification_new_message( $args = array() ) { 22 23 // Cast possible $message object as an array 24 if ( is_object( $args ) ) { 25 $args = (array) $args; 26 } 15 27 16 28 // These should be extracted below 17 29 $recipients = array(); 18 30 $email_subject = $email_content = ''; 31 $sender_id = 0; 19 32 33 // Barf 20 34 extract( $args ); 21 35 36 // Get the sender display name 22 37 $sender_name = bp_core_get_user_displayname( $sender_id ); 23 38 … … 25 40 if ( ! empty( $recipients ) ) { 26 41 27 foreach ( $recipients as $recipient ) {42 foreach ( $recipients as $recipient ) { 28 43 29 if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) ) 44 if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) ) { 30 45 continue; 46 } 31 47 32 48 // User data and links 33 $ud 49 $ud = get_userdata( $recipient->user_id ); 34 50 35 51 // Bail if user cannot be found 36 if ( empty( $ud ) ) 52 if ( empty( $ud ) ) { 37 53 continue; 54 } 38 55 39 56 $message_link = bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() .'/'; … … 78 95 do_action( 'bp_messages_sent_notification_email', $recipients, $email_subject, $email_content, $args ); 79 96 } 97 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 ); 98 99 /** Notifications *************************************************************/ 100 101 /** 102 * Format the BuddyBar/Toolbar notifications for the Messages component 103 * 104 * @since BuddyPress (1.0) 105 * @param string $action The kind of notification being rendered 106 * @param int $item_id The primary item id 107 * @param int $secondary_item_id The secondary item id 108 * @param int $total_items The total number of messaging-related notifications waiting for the user 109 * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar 110 */ 111 function messages_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 112 113 if ( 'new_message' === $action ) { 114 $link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox' ); 115 $title = __( 'Inbox', 'buddypress' ); 116 117 if ( (int) $total_items > 1 ) { 118 $text = sprintf( __('You have %d new messages', 'buddypress' ), (int) $total_items ); 119 $filter = 'bp_messages_multiple_new_message_notification'; 120 } else { 121 if ( !empty( $secondary_item_id ) ) { 122 $text = sprintf( __('You have %d new message from %s', 'buddypress' ), (int) $total_items, bp_core_get_user_displayname( $secondary_item_id ) ); 123 } else { 124 $text = sprintf( __('You have %d new message', 'buddypress' ), (int) $total_items ); 125 } 126 $filter = 'bp_messages_single_new_message_notification'; 127 } 128 } 129 130 if ( 'string' === $format ) { 131 $return = apply_filters( $filter, '<a href="' . esc_url( $link ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $link, $item_id, $secondary_item_id ); 132 } else { 133 $return = apply_filters( $filter, array( 134 'text' => $text, 135 'link' => $link 136 ), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id ); 137 } 138 139 do_action( 'messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 140 141 return $return; 142 } 143 144 /** 145 * Send notifications to message recipients 146 * 147 * @since BuddyPress (1.9.0) 148 * @param obj $message 149 */ 150 function bp_messages_message_sent_add_notification( $message ) { 151 if ( bp_is_active( 'notifications' ) && ! empty( $message->recipients ) ) { 152 foreach ( (array) $message->recipients as $recipient ) { 153 bp_notifications_add_notification( array( 154 'user_id' => $recipient->user_id, 155 'item_id' => $message->id, 156 'secondary_item_id' => $message->sender_id, 157 'component_name' => buddypress()->messages->id, 158 'component_action' => 'new_message', 159 'date_notified' => bp_core_current_time(), 160 'is_new' => 1, 161 ) ); 162 } 163 } 164 } 165 add_action( 'messages_message_sent', 'bp_messages_message_sent_add_notification', 10 ); 166 167 /** 168 * Mark new message notifications when member views their inbox. 169 * 170 * @since BuddyPress (1.9.0) 171 */ 172 function bp_messages_screen_inbox_mark_notifications() { 173 if ( bp_is_active( 'notifications' ) ) { 174 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->messages->id, 'new_message' ); 175 } 176 } 177 add_action( 'messages_screen_inbox', 'bp_messages_screen_inbox_mark_notifications', 10 ); 178 179 /** 180 * Mark new message notification when member reads a message thread directly. 181 * 182 * @since BuddyPress (1.9.0) 183 */ 184 function bp_messages_screen_conversation_mark_notifications() { 185 if ( bp_is_active( 'notifications' ) ) { 186 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), (int) bp_action_variable( 0 ), buddypress()->messages->id, 'new_message' ); 187 } 188 } 189 add_action( 'messages_screen_conversation', 'bp_messages_screen_inbox_mark_notifications', 10 ); -
trunk/bp-messages/bp-messages-template.php
r7584 r7621 185 185 wp_redirect( bp_displayed_user_id() ); 186 186 } else { 187 if ( bp_is_current_action( 'inbox' ) ) {188 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->messages->id, 'new_message' );189 }190 191 187 if ( bp_is_current_action( 'sentbox' ) ) { 192 188 $box = 'sentbox';
Note: See TracChangeset
for help on using the changeset viewer.