Skip to:
Content

BuddyPress.org

Ticket #5193: 5193.01

File 5193.01, 28.4 KB (added by slaFFik, 9 years ago)

1 cumulative patch, please ignore all other non-5193 patches

Line 
1Index: src/bp-messages/bp-messages-classes.php
2===================================================================
3--- src/bp-messages/bp-messages-classes.php     (revision 9160)
4+++ src/bp-messages/bp-messages-classes.php     (working copy)
5@@ -109,7 +109,7 @@
6         *
7         * @since BuddyPress (1.0.0)
8         *
9-        * @param int $thread_id The message thread ID.
10+        * @param bool|int $thread_id The message thread ID.
11         * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'.
12         */
13        public function __construct( $thread_id = false, $order = 'ASC' ) {
14@@ -127,6 +127,7 @@
15         *
16         * @param int $thread_id The message thread ID.
17         * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'.
18+        * @return bool False on failure
19         */
20        public function populate( $thread_id, $order ) {
21                global $wpdb, $bp;
22@@ -135,7 +136,7 @@
23                        $order= 'ASC';
24                }
25 
26-               $this->messages_order = $order;
27+               $this->messages_order = apply_filters( 'messages_thread_populate_order', $order );
28                $this->thread_id      = $thread_id;
29 
30                if ( !$this->messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent " . $order, $this->thread_id ) ) ) {
31@@ -146,12 +147,14 @@
32                        $this->sender_ids[$message->sender_id] = $message->sender_id;
33                }
34 
35+               $this->sender_ids = apply_filters( 'messages_thread_populate_sender_ids', $this->sender_ids );
36+
37                // Fetch the recipients
38-               $this->recipients = $this->get_recipients();
39+               $this->recipients = apply_filters( 'messages_thread_populate_recipients', $this->get_recipients() );
40 
41                // Get the unread count for the logged in user
42                if ( isset( $this->recipients[bp_loggedin_user_id()] ) ) {
43-                       $this->unread_count = $this->recipients[bp_loggedin_user_id()]->unread_count;
44+                       $this->unread_count = apply_filters( 'messages_thread_populate_unread_count', $this->recipients[bp_loggedin_user_id()]->unread_count );
45                }
46        }
47 
48@@ -190,10 +193,11 @@
49                $recipients = array();
50                $results    = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
51 
52-               foreach ( (array) $results as $recipient )
53+               foreach ( (array) $results as $recipient ) {
54                        $recipients[$recipient->user_id] = $recipient;
55+               }
56 
57-               return $recipients;
58+               return apply_filters( 'messages_thread_get_recipients', $recipients, $this->thread_id );
59        }
60 
61        /** Static Functions ******************************************************/
62@@ -209,6 +213,8 @@
63        public static function delete( $thread_id ) {
64                global $wpdb, $bp;
65 
66+               do_action( 'messages_thread_delete_thread_before', $thread_id );
67+
68                // Mark messages as deleted
69                $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) );
70 
71@@ -250,7 +256,11 @@
72        public static function get_current_threads_for_user( $user_id, $box = 'inbox', $type = 'all', $limit = null, $page = null, $search_terms = '' ) {
73                global $wpdb, $bp;
74 
75-               $user_id_sql = $pag_sql = $type_sql = $search_sql = '';
76+               $user_id_sql  = $pag_sql = $type_sql = $search_sql = $total_threads = '';
77+               $thread_ids   = array();
78+               $box              = apply_filters( 'messages_thread_current_threads_box', $box );
79+               $type             = apply_filters( 'messages_thread_current_threads_type', $type );
80+               $search_terms = apply_filters( 'messages_thread_current_threads_search_terms', $search_terms );
81 
82                if ( $limit && $page ) {
83                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
84@@ -262,21 +272,28 @@
85                        $type_sql = " AND r.unread_count = 0 ";
86                }
87 
88+               $type_sql = apply_filters( 'messages_thread_current_threads_type_sql', $type_sql );
89+
90                if ( ! empty( $search_terms ) ) {
91                        $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
92                        $search_sql        = $wpdb->prepare( "AND ( subject LIKE %s OR message LIKE %s )", $search_terms_like, $search_terms_like );
93                }
94 
95+               $search_sql = apply_filters( 'messages_thread_current_threads_search_sql', $search_sql );
96+
97                if ( 'sentbox' == $box ) {
98-                       $user_id_sql = $wpdb->prepare( 'm.sender_id = %d', $user_id );
99-                       $thread_ids  = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND m.sender_id = r.user_id AND {$user_id_sql} AND r.is_deleted = 0 {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" );
100+                       $user_id_sql   = $wpdb->prepare( 'm.sender_id = %d', $user_id );
101+                       $thread_ids    = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND m.sender_id = r.user_id AND {$user_id_sql} AND r.is_deleted = 0 {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" );
102                        $total_threads = $wpdb->get_var( "SELECT COUNT( DISTINCT m.thread_id ) FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND m.sender_id = r.user_id AND {$user_id_sql} AND r.is_deleted = 0 {$search_sql} " );
103-               } else {
104-                       $user_id_sql = $wpdb->prepare( 'r.user_id = %d', $user_id );
105-                       $thread_ids = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND r.is_deleted = 0 AND {$user_id_sql} AND r.sender_only = 0 {$type_sql} {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" );
106+               } elseif ( 'inbox' == $box ) {
107+                       $user_id_sql   = $wpdb->prepare( 'r.user_id = %d', $user_id );
108+                       $thread_ids    = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND r.is_deleted = 0 AND {$user_id_sql} AND r.sender_only = 0 {$type_sql} {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" );
109                        $total_threads = $wpdb->get_var( "SELECT COUNT( DISTINCT m.thread_id ) FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND r.is_deleted = 0 AND {$user_id_sql} AND r.sender_only = 0 {$type_sql} {$search_sql}" );
110                }
111 
112+               $thread_ids    = apply_filters( 'messages_thread_current_threads_thread_ids',    $thread_ids );
113+               $total_threads = apply_filters( 'messages_thread_current_threads_total_threads', $total_threads );
114+
115                if ( empty( $thread_ids ) ) {
116                        return false;
117                }
118@@ -293,7 +310,7 @@
119                        $threads[] = new BP_Messages_Thread( $thread_id );
120                }
121 
122-               return array( 'threads' => &$threads, 'total' => (int) $total_threads );
123+               return apply_filters( 'messages_thread_current_threads', array( 'threads' => &$threads, 'total' => (int) $total_threads ) );
124        }
125 
126        /**
127@@ -306,10 +323,14 @@
128        public static function mark_as_read( $thread_id ) {
129                global $wpdb, $bp;
130 
131-               $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
132+               $user_id = bp_loggedin_user_id();
133+
134+               $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id );
135                $wpdb->query($sql);
136 
137-               wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
138+               do_action( 'messages_thread_marked_as_read', $user_id, $thread_id );
139+
140+               wp_cache_delete( $user_id, 'bp_messages_unread_count' );
141        }
142 
143        /**
144@@ -322,10 +343,14 @@
145        public static function mark_as_unread( $thread_id ) {
146                global $wpdb, $bp;
147 
148-               $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
149+               $user_id = bp_loggedin_user_id();
150+
151+               $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id );
152                $wpdb->query($sql);
153 
154-               wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
155+               do_action( 'messages_thread_marked_as_unread', $user_id, $thread_id );
156+
157+               wp_cache_delete( $user_id, 'bp_messages_unread_count' );
158        }
159 
160        /**
161@@ -343,16 +368,23 @@
162        public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
163                global $wpdb, $bp;
164 
165-               $exclude_sender = '';
166-               if ( $box != 'sentbox' )
167-                       $exclude_sender = ' AND sender_only != 1';
168+               $exclude_sender_sql = $type_sql = '';
169 
170-               if ( $type == 'unread' )
171+               if ( $box != 'sentbox' ) {
172+                       $exclude_sender_sql = ' AND sender_only != 1';
173+               }
174+
175+               $exclude_sender_sql = apply_filters( 'messages_thread_total_threads_for_user_exclude_sender_sql', $exclude_sender_sql, $user_id );
176+
177+               if ( $type == 'unread' ) {
178                        $type_sql = " AND unread_count != 0 ";
179-               else if ( $type == 'read' )
180+               } else if ( $type == 'read' ) {
181                        $type_sql = " AND unread_count = 0 ";
182+               }
183 
184-               return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0{$exclude_sender} {$type_sql}", $user_id ) );
185+               $type_sql = apply_filters( 'messages_thread_total_threads_for_user_type_sql', $type_sql, $user_id );
186+
187+               return apply_filters( 'messages_thread_total_threads_for_user', (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0{$exclude_sender_sql} {$type_sql}", $user_id ) ), $user_id, $box, $type );
188        }
189 
190        /**
191@@ -361,7 +393,7 @@
192         * @since BuddyPress (1.0.0)
193         *
194         * @param int $thread_id The message thread ID.
195-        * @param bool
196+        * @return bool
197         */
198        public static function user_is_sender( $thread_id ) {
199                global $wpdb, $bp;
200@@ -434,7 +466,7 @@
201                if ( empty( $user_id ) )
202                        $user_id = bp_loggedin_user_id();
203 
204-               return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0 AND user_id = %d", $thread_id, $user_id ) );
205+               return apply_filters( 'messages_thread_check_access', $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0 AND user_id = %d", $thread_id, $user_id ) ), $thread_id, $user_id );
206        }
207 
208        /**
209@@ -455,7 +487,7 @@
210 
211                $bp = buddypress();
212 
213-               return $wpdb->get_var( $wpdb->prepare( "SELECT thread_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d LIMIT 1", $thread_id ) );
214+               return apply_filters( 'messages_thread_is_valid', $wpdb->get_var( $wpdb->prepare( "SELECT thread_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d LIMIT 1", $thread_id ) ), $thread_id );
215        }
216 
217        /**
218@@ -468,12 +500,13 @@
219         *
220         * @since BuddyPress (1.0.0)
221         *
222-        * @param object $recipients Object containing the message recipients.
223+        * @param array $recipients Array containing the message recipients (array of objects).
224         * @return string
225         */
226        public static function get_recipient_links( $recipients ) {
227-               if ( count( $recipients ) >= 5 )
228-                       return sprintf( __( '%s Recipients', 'buddypress' ), number_format_i18n( count( $recipients ) ) );
229+               if ( count( $recipients ) >= 5 ) {
230+                       return sprintf(__('%s Recipients', 'buddypress'), number_format_i18n(count($recipients)));
231+               }
232 
233                $recipient_links = array();
234 
235@@ -487,6 +520,8 @@
236                        $recipient_links[] = $recipient_link;
237                }
238 
239+               $recipient_links = apply_filters( 'messages_thread_recipient_links', $recipient_links );
240+
241                return implode( ', ', (array) $recipient_links );
242        }
243 
244@@ -607,11 +642,11 @@
245 
246                if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) {
247                        $this->id        = $message->id;
248-                       $this->thread_id = $message->thread_id;
249-                       $this->sender_id = $message->sender_id;
250-                       $this->subject   = $message->subject;
251-                       $this->message   = $message->message;
252-                       $this->date_sent = $message->date_sent;
253+                       $this->thread_id = apply_filters( 'messages_message_populate_thread_id', $message->thread_id );
254+                       $this->sender_id = apply_filters( 'messages_message_populate_sender_id', $message->sender_id );
255+                       $this->subject   = apply_filters( 'messages_message_populate_subject',   $message->subject   );
256+                       $this->message   = apply_filters( 'messages_message_populate_message',   $message->message   );
257+                       $this->date_sent = apply_filters( 'messages_message_populate_date_sent', $message->date_sent );
258                }
259        }
260 
261@@ -633,8 +668,9 @@
262                do_action_ref_array( 'messages_message_before_save', array( &$this ) );
263 
264                // Make sure we have at least one recipient before sending.
265-               if ( empty( $this->recipients ) )
266+               if ( empty( $this->recipients ) ) {
267                        return false;
268+               }
269 
270                $new_thread = false;
271 
272@@ -645,8 +681,9 @@
273                }
274 
275                // First insert the message into the messages table
276-               if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) )
277+               if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) ) {
278                        return false;
279+               }
280 
281                $this->id = $wpdb->insert_id;
282 
283@@ -681,7 +718,7 @@
284         */
285        public function get_recipients() {
286                global $bp, $wpdb;
287-               return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
288+               return apply_filters( 'messages_message_get_recipients', $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) ), $this->thread_id );
289        }
290 
291        /** Static Functions **************************************************/
292@@ -693,9 +730,12 @@
293         * @return array
294         */
295        public static function get_recipient_ids( $recipient_usernames ) {
296-               if ( !$recipient_usernames )
297+               if ( !$recipient_usernames ) {
298                        return false;
299+               }
300 
301+               $recipient_ids = array();
302+
303                if ( is_array( $recipient_usernames ) ) {
304                        for ( $i = 0, $count = count( $recipient_usernames ); $i < $count; ++$i ) {
305                                if ( $rid = bp_core_get_userid( trim($recipient_usernames[$i]) ) ) {
306@@ -704,7 +744,7 @@
307                        }
308                }
309 
310-               return $recipient_ids;
311+               return apply_filters( 'messages_message_get_recipient_ids', $recipient_ids, $recipient_usernames );
312        }
313 
314        /**
315@@ -715,7 +755,7 @@
316         */
317        public static function get_last_sent_for_user( $thread_id ) {
318                global $wpdb, $bp;
319-               return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) );
320+               return apply_filters( 'messages_message_last_sent_for_user', $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) ), $thread_id );
321        }
322 
323        /**
324@@ -790,6 +830,7 @@
325         * Constructor.
326         *
327         * @since BuddyPress (1.0.0)
328+        * @param null $id
329         */
330        public function __construct( $id = null ) {
331                if ( $id ) {
332@@ -811,10 +852,10 @@
333                $notice = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ) );
334 
335                if ( $notice ) {
336-                       $this->subject   = $notice->subject;
337-                       $this->message   = $notice->message;
338-                       $this->date_sent = $notice->date_sent;
339-                       $this->is_active = $notice->is_active;
340+                       $this->subject   = apply_filters( 'messages_notice_populate_subject',   $notice->subject   );
341+                       $this->message   = apply_filters( 'messages_notice_populate_message',   $notice->message   );
342+                       $this->date_sent = apply_filters( 'messages_notice_populate_date_sent', $notice->date_sent );
343+                       $this->is_active = apply_filters( 'messages_notice_populate_is_active', $notice->is_active );
344                }
345        }
346 
347@@ -865,7 +906,7 @@
348         * @return bool
349         */
350        public function activate() {
351-               $this->is_active = 1;
352+               $this->is_active = apply_filters( 'messages_notice_activate', 1 );
353                return (bool) $this->save();
354        }
355 
356@@ -877,7 +918,7 @@
357         * @return bool
358         */
359        public function deactivate() {
360-               $this->is_active = 0;
361+               $this->is_active = apply_filters( 'messages_notice_deactivate', 0 );
362                return (bool) $this->save();
363        }
364 
365@@ -899,6 +940,8 @@
366                        return false;
367                }
368 
369+               do_action( 'messages_notice_after_delete' );
370+
371                return true;
372        }
373 
374@@ -911,7 +954,7 @@
375         *
376         * @since BuddyPress (1.0.0)
377         *
378-        * @param array $data {
379+        * @param array $args {
380         *     Array of parameters.
381         *     @type int $pag_num Number of notices per page. Defaults to 20.
382         *     @type int $pag_page The page number.  Defaults to 1.
383@@ -926,6 +969,8 @@
384                        'pag_page' => 1   // Page number
385                ) );
386 
387+               $r = apply_filters( 'messages_notice_get_notices_arg', $r);
388+
389                $limit_sql = '';
390                if ( (int) $r['pag_num'] >= 0 ) {
391                        $limit_sql = $wpdb->prepare( "LIMIT %d, %d", (int) ( ( $r['pag_page'] - 1 ) * $r['pag_num'] ), (int) $r['pag_num'] );
392@@ -948,7 +993,7 @@
393 
394                $notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM " . $bp->messages->table_name_notices );
395 
396-               return $notice_count;
397+               return apply_filters( 'messages_notice_total_count', $notice_count );
398        }
399 
400        /**
401Index: src/bp-messages/bp-messages-template.php
402===================================================================
403--- src/bp-messages/bp-messages-template.php    (revision 9160)
404+++ src/bp-messages/bp-messages-template.php    (working copy)
405@@ -130,17 +130,17 @@
406                $this->pag_page = isset( $_GET[$page_arg] ) ? intval( $_GET[$page_arg] ) : 1;
407                $this->pag_num  = isset( $_GET['num'] )   ? intval( $_GET['num'] )   : $per_page;
408 
409-               $this->user_id      = $user_id;
410-               $this->box          = $box;
411-               $this->type         = $type;
412-               $this->search_terms = $search_terms;
413+               $this->user_id      = apply_filters( 'bp_messages_box_template_user_id',          $user_id );
414+               $this->box          = apply_filters( 'bp_messages_box_template_box',              $box );
415+               $this->type         = apply_filters( 'bp_messages_box_template_type',             $type );
416+               $this->search_terms = apply_filters( 'bp_messages_box_template_search_terms', $search_terms );
417 
418                if ( 'notices' == $this->box ) {
419                        $this->threads = BP_Messages_Notice::get_notices( array(
420                                'pag_num'  => $this->pag_num,
421                                'pag_page' => $this->pag_page
422                        ) );
423-               } else {
424+               } elseif ( 'sentbox' == $this->box || 'inbox' == $this->box ) {
425                        $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page, $this->search_terms );
426 
427                        $this->threads            = $threads['threads'];
428@@ -172,6 +172,11 @@
429                        }
430                }
431 
432+               // These hooks needed for other boxes, which might not be processed above
433+               $this->threads                    = apply_filters( 'messages_box_template_threads',                $this->threads );
434+               $this->thread_count       = apply_filters( 'messages_box_template_thread_count',           $this->thread_count );
435+               $this->total_thread_count = apply_filters( 'messages_box_template_total_thread_count', $this->total_thread_count );
436+
437                if ( (int) $this->total_thread_count && (int) $this->pag_num ) {
438                        $pag_args = array(
439                                $page_arg => '%#%',
440@@ -350,6 +355,8 @@
441                $default_box = 'inbox';
442        }
443 
444+       $default_box = apply_filters( 'messages_has_message_threads_default_box', $default_box );
445+
446        // Parse the arguments
447        $r = bp_parse_args( $args, array(
448                'user_id'      => bp_loggedin_user_id(),
449@@ -656,7 +663,7 @@
450  *
451  * @see bp_get_message_thread_avatar() for a description of arguments.
452  *
453- * @param array $args See {@link bp_get_message_thread_avatar()}.
454+ * @param array|string $args See {@link bp_get_message_thread_avatar()}.
455  */
456 function bp_message_thread_avatar( $args = '' ) {
457        echo bp_get_message_thread_avatar( $args );
458@@ -667,7 +674,7 @@
459         * @see bp_core_fetch_avatar() For a description of arguments and
460         *      return values.
461         *
462-        * @param array $args {
463+        * @param array|string $args {
464         *     Arguments are listed here with an explanation of their defaults.
465         *     For more information about the arguments, see
466         *     {@link bp_core_fetch_avatar()}.
467@@ -678,7 +685,7 @@
468         *     @type string|bool $id Default: false.
469         *     @type string $alt Default: 'Profile picture of [display name]'.
470         * }
471-        * @return User avatar string.
472+        * @return string User avatar string.
473         */
474        function bp_get_message_thread_avatar( $args = '' ) {
475                global $messages_template;
476@@ -745,10 +752,10 @@
477 function bp_messages_pagination_count() {
478        global $messages_template;
479 
480-       $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1;
481-       $from_num  = bp_core_number_format( $start_num );
482-       $to_num    = bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) );
483-       $total     = bp_core_number_format( $messages_template->total_thread_count );
484+       $start_num = apply_filters( 'bp_messages_pagination_count_start_num', intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1, $messages_template );
485+       $from_num  = apply_filters( 'bp_messages_pagination_count_from_number', bp_core_number_format( $start_num ), $start_num );
486+       $to_num    = apply_filters( 'bp_messages_pagination_count_to_num', bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) ), $start_num, $messages_template );
487+       $total     = apply_filters( 'bp_messages_pagination_count_total', bp_core_number_format( $messages_template->total_thread_count ), $messages_template );
488 
489        echo sprintf( _n( 'Viewing 1 message', 'Viewing %1$s - %2$s of %3$s messages', $total, 'buddypress' ), $from_num, $to_num, number_format_i18n( $total ) );
490 }
491@@ -763,6 +770,7 @@
492        $default_search_value = bp_get_search_default_text( 'messages' );
493        $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
494 
495+       <!--suppress ALL -->
496        <form action="" method="get" id="search-message-form">
497                <label><input type="text" name="s" id="messages_search" <?php if ( $search_value === $default_search_value ) : ?>placeholder="<?php echo esc_html( $search_value ); ?>"<?php endif; ?> <?php if ( $search_value !== $default_search_value ) : ?>value="<?php echo esc_html( $search_value ); ?>"<?php endif; ?> /></label>
498                <input type="submit" id="messages_search_submit" name="messages_search_submit" value="<?php esc_attr_e( 'Search', 'buddypress' ) ?>" />
499@@ -798,11 +806,15 @@
500         * @return string
501         */
502        function bp_get_messages_username_value() {
503+               $user_name = '';
504+
505                if ( isset( $_COOKIE['bp_messages_send_to'] ) ) {
506-                       return apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );
507+                       $user_name = apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );
508                } else if ( isset( $_GET['r'] ) && !isset( $_COOKIE['bp_messages_send_to'] ) ) {
509-                       return apply_filters( 'bp_get_messages_username_value', $_GET['r'] );
510+                       $user_name = apply_filters( 'bp_get_messages_username_value', $_GET['r'] );
511                }
512+
513+               return $user_name;
514        }
515 
516 /**
517@@ -854,17 +866,29 @@
518  * Output the markup for the message type dropdown.
519  */
520 function bp_messages_options() {
521-?>
522 
523+       $messages_types = apply_filters( 'bp_messages_options_types', array(
524+               'empty'  => '',
525+               'read'   => _x('Read', 'Message dropdown filter', 'buddypress'),
526+               'unread' => _x('Unread', 'Message dropdown filter', 'buddypress'),
527+               'all'    => _x('All', 'Message dropdown filter', 'buddypress')
528+       ) );
529+       ?>
530+
531        <?php _e( 'Select:', 'buddypress' ) ?>
532 
533        <select name="message-type-select" id="message-type-select">
534-               <option value=""></option>
535-               <option value="read"><?php _ex('Read', 'Message dropdown filter', 'buddypress') ?></option>
536-               <option value="unread"><?php _ex('Unread', 'Message dropdown filter', 'buddypress') ?></option>
537-               <option value="all"><?php _ex('All', 'Message dropdown filter', 'buddypress') ?></option>
538+
539+               <?php foreach($messages_types as $value => $label) : ?>
540+
541+                       <option value="<?php echo $value; ?>"><?php echo $label; ?></option>
542+
543+               <?php endforeach; ?>
544+
545        </select> &nbsp;
546 
547+       <?php do_action( 'bp_messages_options_before_actions' ); ?>
548+
549        <?php if ( ! bp_is_current_action( 'sentbox' ) && ! bp_is_current_action( 'notices' ) ) : ?>
550 
551                <a href="#" id="mark_as_read"><?php _ex('Mark as Read', 'Message management markup', 'buddypress') ?></a> &nbsp;
552@@ -874,6 +898,8 @@
553 
554        <a href="#" id="delete_<?php echo bp_current_action(); ?>_messages"><?php _e( 'Delete Selected', 'buddypress' ); ?></a> &nbsp;
555 
556+       <?php do_action( 'bp_messages_options_after_actions' ); ?>
557+
558 <?php
559 }
560 
561@@ -1308,11 +1334,11 @@
562                $this->message_count = count( $this->thread->messages );
563 
564                $last_message_index                 = $this->message_count - 1;
565-               $this->thread->last_message_id      = $this->thread->messages[ $last_message_index ]->id;
566-               $this->thread->last_message_date    = $this->thread->messages[ $last_message_index ]->date_sent;
567-               $this->thread->last_sender_id       = $this->thread->messages[ $last_message_index ]->sender_id;
568-               $this->thread->last_message_subject = $this->thread->messages[ $last_message_index ]->subject;
569-               $this->thread->last_message_content = $this->thread->messages[ $last_message_index ]->message;
570+               $this->thread->last_message_id      = apply_filters( 'messages_thread_template_id',        $this->thread->messages[ $last_message_index ]->id );
571+               $this->thread->last_message_date    = apply_filters( 'messages_thread_template_date_sent', $this->thread->messages[ $last_message_index ]->date_sent );
572+               $this->thread->last_sender_id       = apply_filters( 'messages_thread_template_sender_id', $this->thread->messages[ $last_message_index ]->sender_id );
573+               $this->thread->last_message_subject = apply_filters( 'messages_thread_template_subject',   $this->thread->messages[ $last_message_index ]->subject );
574+               $this->thread->last_message_content = apply_filters( 'messages_thread_template_message',   $this->thread->messages[ $last_message_index ]->message );
575        }
576 
577        /**
578@@ -1399,7 +1425,7 @@
579 /**
580  * Initialize the messages template loop for a specific thread.
581  *
582- * @param array $args {
583+ * @param array|string $args {
584  *     Array of arguments. All are optional.
585  *     @type int $thread_id ID of the thread whose messages you are displaying.
586  *           Default: if viewing a thread, the thread ID will be parsed from
587@@ -1411,10 +1437,10 @@
588 function bp_thread_has_messages( $args = '' ) {
589        global $thread_template;
590 
591-       $r = bp_parse_args( $args, array(
592+       $r = apply_filters( 'messages_thread_has_messages_args', bp_parse_args( $args, array(
593                'thread_id' => false,
594                'order'     => 'ASC'
595-       ), 'thread_has_messages' );
596+       ), 'thread_has_messages' ) );
597 
598        if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) {
599                $r['thread_id'] = (int) bp_action_variable( 0 );
600@@ -1422,7 +1448,7 @@
601 
602        $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'] );
603 
604-       return $thread_template->has_messages();
605+       return apply_filters( 'bp_thread_has_messages', $thread_template->has_messages(), $thread_template );
606 }
607 
608 /**
609@@ -1438,7 +1464,7 @@
610         */
611        function bp_get_thread_messages_order() {
612                global $thread_template;
613-               return $thread_template->thread->messages_order;
614+               return apply_filters( 'bp_get_thread_messages_order', $thread_template->thread->messages_order );
615        }
616 
617 /**
618@@ -1525,7 +1551,7 @@
619  */
620 function bp_get_thread_recipients_count() {
621        global $thread_template;
622-       return count( $thread_template->thread->recipients );
623+       return apply_filters( 'bp_get_thread_recipients_count', count( $thread_template->thread->recipients ) );
624 }
625 
626 /**
627@@ -1675,7 +1701,7 @@
628 /**
629  * Output the avatar for the current message sender.
630  *
631- * @param array $args See {@link bp_get_the_thread_message_sender_avatar_thumb()}
632+ * @param array|string $args See {@link bp_get_the_thread_message_sender_avatar_thumb()}
633  *        for a description.
634  */
635 function bp_the_thread_message_sender_avatar( $args = '' ) {
636@@ -1684,7 +1710,7 @@
637        /**
638         * Get the avatar for the current message sender.
639         *
640-        * @param array $args {
641+        * @param array|string $args {
642         *     Array of arguments. See {@link bp_core_fetch_avatar()} for more
643         *     complete details. All arguments are optional.
644         *     @type string $type Avatar type. Default: 'thumb'.