Changeset 10304
- Timestamp:
- 10/22/2015 06:12:16 AM (9 years ago)
- Location:
- trunk/src/bp-messages
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-actions.php
r10286 r10304 23 23 function bp_messages_action_create_message() { 24 24 25 // Bail if not posting to the compose message screen 25 // Bail if not posting to the compose message screen. 26 26 if ( ! bp_is_post_request() || ! bp_is_messages_component() || ! bp_is_current_action( 'compose' ) ) { 27 27 return false; 28 28 } 29 29 30 // Check the nonce 30 // Check the nonce. 31 31 check_admin_referer( 'messages_send_message' ); 32 32 33 // Define local variables 33 // Define local variables. 34 34 $redirect_to = ''; 35 35 $feedback = ''; 36 36 $success = false; 37 37 38 // Missing subject or content 38 // Missing subject or content. 39 39 if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) { 40 40 $success = false; … … 46 46 } 47 47 48 // Subject and content present 48 // Subject and content present. 49 49 } else { 50 50 51 // Setup the link to the logged-in user's messages 51 // Setup the link to the logged-in user's messages. 52 52 $member_messages = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 53 53 54 // Site-wide notice 54 // Site-wide notice. 55 55 if ( isset( $_POST['send-notice'] ) ) { 56 56 57 // Attempt to save the notice and redirect to notices 57 // Attempt to save the notice and redirect to notices. 58 58 if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) { 59 59 $success = true; … … 61 61 $redirect_to = trailingslashit( $member_messages . 'notices' ); 62 62 63 // Notice could not be sent 63 // Notice could not be sent. 64 64 } else { 65 65 $success = false; … … 67 67 } 68 68 69 // Private conversation 69 // Private conversation. 70 70 } else { 71 71 72 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ) 72 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ). 73 73 $autocomplete_recipients = (array) explode( ',', $_POST['send-to-input'] ); 74 74 $typed_recipients = (array) explode( ' ', $_POST['send_to_usernames'] ); … … 84 84 $recipients = apply_filters( 'bp_messages_recipients', $recipients ); 85 85 86 // Attempt to send the message 86 // Attempt to send the message. 87 87 $send = messages_new_message( array( 88 88 'recipients' => $recipients, … … 92 92 ) ); 93 93 94 // Send the message and redirect to it 94 // Send the message and redirect to it. 95 95 if ( true === is_int( $send ) ) { 96 96 $success = true; … … 99 99 $redirect_to = trailingslashit( $view . $send ); 100 100 101 // Message could not be sent 101 // Message could not be sent. 102 102 } else { 103 103 $success = false; … … 107 107 } 108 108 109 // Feedback 109 // Feedback. 110 110 if ( ! empty( $feedback ) ) { 111 111 112 // Determine message type 112 // Determine message type. 113 113 $type = ( true === $success ) 114 114 ? 'success' 115 115 : 'error'; 116 116 117 // Add feedback message 117 // Add feedback message. 118 118 bp_core_add_message( $feedback, $type ); 119 119 } 120 120 121 // Maybe redirect 121 // Maybe redirect. 122 122 if ( ! empty( $redirect_to ) ) { 123 123 bp_core_redirect( $redirect_to ); … … 127 127 128 128 /** 129 * Handle editing of sitewide notices 129 * Handle editing of sitewide notices. 130 130 * 131 131 * @since 2.4.0 This function was split from messages_screen_notices(). See #6505. … … 138 138 global $notice_id; 139 139 140 // Bail if not viewing a single notice URL 140 // Bail if not viewing a single notice URL. 141 141 if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || ! bp_action_variable( 1 ) ) { 142 142 return false; 143 143 } 144 144 145 // Get action variables 146 $action = bp_action_variable( 0 ); // deactivate|activate|delete 145 // Get action variables. 146 $action = bp_action_variable( 0 ); // deactivate|activate|delete. 147 147 $notice_id = bp_action_variable( 1 ); // 1|2|3|etc... 148 148 149 // Bail if notice ID is not numeric 149 // Bail if notice ID is not numeric. 150 150 if ( ! is_numeric( $notice_id ) ) { 151 151 return; 152 152 } 153 153 154 // Define local variables 154 // Define local variables. 155 155 $redirect_to = ''; 156 156 $feedback = ''; 157 157 $success = false; 158 158 159 // Get the notice from database 159 // Get the notice from database. 160 160 $notice = new BP_Messages_Notice( $notice_id ); 161 161 162 // Take action 162 // Take action. 163 163 switch ( $action ) { 164 164 165 // Deactivate 165 // Deactivate. 166 166 case 'deactivate' : 167 167 $success = $notice->deactivate(); … … 171 171 break; 172 172 173 // Activate 173 // Activate. 174 174 case 'activate' : 175 175 $success = $notice->activate(); … … 179 179 break; 180 180 181 // Delete 181 // Delete. 182 182 case 'delete' : 183 183 $success = $notice->delete(); … … 188 188 } 189 189 190 // Feedback 190 // Feedback. 191 191 if ( ! empty( $feedback ) ) { 192 192 193 // Determine message type 193 // Determine message type. 194 194 $type = ( true === $success ) 195 195 ? 'success' 196 196 : 'error'; 197 197 198 // Add feedback message 198 // Add feedback message. 199 199 bp_core_add_message( $feedback, $type ); 200 200 } 201 201 202 // Redirect 202 // Redirect. 203 203 $member_notices = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 204 204 $redirect_to = trailingslashit( $member_notices . 'notices' ); … … 213 213 function messages_action_conversation() { 214 214 215 // Bail if not viewing a single conversation 215 // Bail if not viewing a single conversation. 216 216 if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) { 217 217 return false; 218 218 } 219 219 220 // Get the thread ID from the action variable 220 // Get the thread ID from the action variable. 221 221 $thread_id = (int) bp_action_variable( 0 ); 222 222 … … 225 225 } 226 226 227 // Check if a new reply has been submitted 227 // Check if a new reply has been submitted. 228 228 if ( isset( $_POST['send'] ) ) { 229 229 230 // Check the nonce 230 // Check the nonce. 231 231 check_admin_referer( 'messages_send_message', 'send_message_nonce' ); 232 232 … … 237 237 ) ); 238 238 239 // Send the reply 239 // Send the reply. 240 240 if ( ! empty( $new_reply ) ) { 241 241 bp_core_add_message( __( 'Your reply was sent successfully', 'buddypress' ) ); … … 247 247 } 248 248 249 // Mark message read 249 // Mark message read. 250 250 messages_mark_thread_read( $thread_id ); 251 251 … … 279 279 } 280 280 281 // Delete message 281 // Delete message. 282 282 if ( !messages_delete_thread( $thread_id ) ) { 283 283 bp_core_add_message( __('There was an error deleting that message.', 'buddypress'), 'error' ); -
trunk/src/bp-messages/bp-messages-cache.php
r10139 r10304 36 36 } 37 37 38 // List actions to clear super cached pages on, if super cache is installed 38 // List actions to clear super cached pages on, if super cache is installed. 39 39 add_action( 'messages_delete_thread', 'bp_core_clear_cache' ); 40 40 add_action( 'messages_send_notice', 'bp_core_clear_cache' ); 41 41 add_action( 'messages_message_sent', 'bp_core_clear_cache' ); 42 42 43 // Don't cache message inbox/sentbox/compose as it's too problematic 43 // Don't cache message inbox/sentbox/compose as it's too problematic. 44 44 add_action( 'messages_screen_compose', 'bp_core_clear_cache' ); 45 45 add_action( 'messages_screen_sentbox', 'bp_core_clear_cache' ); … … 51 51 * @since 2.0.0 52 52 * 53 * @param BP_Messages_Message $message 53 * @param BP_Messages_Message $message Message being saved. 54 54 */ 55 55 function bp_messages_clear_cache_on_message_save( BP_Messages_Message $message ) { 56 // Delete thread cache 56 // Delete thread cache. 57 57 wp_cache_delete( $message->thread_id, 'bp_messages_threads' ); 58 58 59 // Delete unread count for each recipient 59 // Delete unread count for each recipient. 60 60 foreach ( (array) $message->recipients as $recipient ) { 61 61 wp_cache_delete( $recipient->user_id, 'bp_messages_unread_count' ); 62 62 } 63 63 64 // Delete thread recipient cache 64 // Delete thread recipient cache. 65 65 wp_cache_delete( 'thread_recipients_' . $message->thread_id, 'bp_messages' ); 66 66 } … … 76 76 */ 77 77 function bp_messages_clear_cache_on_message_delete( $thread_ids ) { 78 // Delete thread and thread recipient cache 78 // Delete thread and thread recipient cache. 79 79 foreach( (array) $thread_ids as $thread_id ) { 80 80 wp_cache_delete( $thread_id, 'bp_messages_threads' ); … … 82 82 } 83 83 84 // Delete unread count for logged-in user 84 // Delete unread count for logged-in user. 85 85 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 86 86 } … … 94 94 * @since 2.0.0 95 95 * 96 * @param BP_Messages_Notice $notice 96 * @param BP_Messages_Notice $notice Notice that was saved. 97 97 */ 98 98 function bp_notices_clear_cache( $notice ) { -
trunk/src/bp-messages/bp-messages-filters.php
r10139 r10304 75 75 * 76 76 * @param array|string $args See {@link bp_has_message_threads()}. 77 * @return array 77 78 */ 78 79 function bp_messages_enforce_current_user( $args = array() ) { 79 80 80 // Non-community moderators can only ever see their own messages 81 // Non-community moderators can only ever see their own messages. 81 82 if ( is_user_logged_in() && ! bp_current_user_can( 'bp_moderate' ) ) { 82 83 $_user_id = (int) bp_loggedin_user_id(); … … 86 87 } 87 88 88 // Return possibly modified $args array 89 // Return possibly modified $args array. 89 90 return $args; 90 91 } -
trunk/src/bp-messages/bp-messages-functions.php
r10286 r10304 40 40 function messages_new_message( $args = '' ) { 41 41 42 // Parse the default arguments 42 // Parse the default arguments. 43 43 $r = bp_parse_args( $args, array( 44 44 'sender_id' => bp_loggedin_user_id(), 45 'thread_id' => false, // false for a new message, thread id for a reply to a thread.45 'thread_id' => false, // False for a new message, thread id for a reply to a thread. 46 46 'recipients' => array(), // Can be an array of usernames, user_ids or mixed. 47 47 'subject' => false, … … 51 51 ), 'messages_new_message' ); 52 52 53 // Bail if no sender or no content 53 // Bail if no sender or no content. 54 54 if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) { 55 55 if ( 'wp_error' === $r['error_type'] ) { … … 69 69 } 70 70 71 // Create a new message object 71 // Create a new message object. 72 72 $message = new BP_Messages_Message; 73 73 $message->thread_id = $r['thread_id']; … … 90 90 } 91 91 92 // Set a default reply subject if none was sent 92 // Set a default reply subject if none was sent. 93 93 if ( empty( $message->subject ) ) { 94 94 $message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject ); … … 98 98 } else { 99 99 100 // Bail if no recipients 100 // Bail if no recipients. 101 101 if ( empty( $r['recipients'] ) ) { 102 102 if ( 'wp_error' === $r['error_type'] ) { … … 107 107 } 108 108 109 // Set a default subject if none exists 109 // Set a default subject if none exists. 110 110 if ( empty( $message->subject ) ) { 111 111 $message->subject = __( 'No Subject', 'buddypress' ); 112 112 } 113 113 114 // Setup the recipients array 114 // Setup the recipients array. 115 115 $recipient_ids = array(); 116 116 117 // Invalid recipients are added to an array, for future enhancements 117 // Invalid recipients are added to an array, for future enhancements. 118 118 $invalid_recipients = array(); 119 119 120 // Loop the recipients and convert all usernames to user_ids where needed 120 // Loop the recipients and convert all usernames to user_ids where needed. 121 121 foreach( (array) $r['recipients'] as $recipient ) { 122 122 123 // Trim spaces and skip if empty 123 // Trim spaces and skip if empty. 124 124 $recipient = trim( $recipient ); 125 125 if ( empty( $recipient ) ) { … … 128 128 129 129 // Check user_login / nicename columns first 130 // @see http://buddypress.trac.wordpress.org/ticket/5151 130 // @see http://buddypress.trac.wordpress.org/ticket/5151. 131 131 if ( bp_is_username_compatibility_mode() ) { 132 132 $recipient_id = bp_core_get_userid( urldecode( $recipient ) ); … … 135 135 } 136 136 137 // Check against user ID column if no match and if passed recipient is numeric 137 // Check against user ID column if no match and if passed recipient is numeric. 138 138 if ( empty( $recipient_id ) && is_numeric( $recipient ) ) { 139 139 if ( bp_core_get_core_userdata( (int) $recipient ) ) { … … 142 142 } 143 143 144 // Decide which group to add this recipient to 144 // Decide which group to add this recipient to. 145 145 if ( empty( $recipient_id ) ) { 146 146 $invalid_recipients[] = $recipient; … … 157 157 } 158 158 159 // Remove duplicates & bail if no recipients 159 // Remove duplicates & bail if no recipients. 160 160 $recipient_ids = array_unique( $recipient_ids ); 161 161 if ( empty( $recipient_ids ) ) { … … 167 167 } 168 168 169 // Format this to match existing recipients 169 // Format this to match existing recipients. 170 170 foreach( (array) $recipient_ids as $i => $recipient_id ) { 171 171 $message->recipients[$i] = new stdClass; … … 174 174 } 175 175 176 // Bail if message failed to send 176 // Bail if message failed to send. 177 177 if ( ! $message->send() ) { 178 178 return false; … … 188 188 do_action_ref_array( 'messages_message_sent', array( &$message ) ); 189 189 190 // Return the thread ID 190 // Return the thread ID. 191 191 return $message->thread_id; 192 192 } … … 197 197 * @param string $subject Subject of the notice. 198 198 * @param string $message Content of the notice. 199 *200 199 * @return bool True on success, false on failure. 201 200 */ … … 211 210 $notice->date_sent = bp_core_current_time(); 212 211 $notice->is_active = 1; 213 $notice->save(); // send it.212 $notice->save(); // Send it. 214 213 215 214 /** … … 230 229 * Delete message thread(s). 231 230 * 232 * @param int|array Thread ID or array of thread IDs. 233 * 231 * @param int|array $thread_ids Thread ID or array of thread IDs. 234 232 * @return bool True on success, false on failure. 235 233 */ … … 284 282 * @param int $thread_id ID of the thread. 285 283 * @param int $user_id Optional. ID of the user. Default: ID of the logged-in user. 286 *287 284 * @return int|null Message ID if the user has access, otherwise null. 288 285 */ … … 349 346 * 350 347 * @param int $user_id Optional. ID of the user. Default: ID of the logged-in user. 351 *352 348 * @return int 353 349 */ … … 365 361 * @param int $user_id ID of the user. 366 362 * @param int $message_id ID of the message. 367 *368 363 * @return int|null Returns the ID of the message if the user is the 369 364 * sender, otherwise null. … … 377 372 * 378 373 * @param int $message_id ID of the message. 379 *380 374 * @return int|null The ID of the sender if found, otherwise null. 381 375 */ … … 388 382 * 389 383 * @param int $thread_id ID of the thread. 390 *391 384 * @return int|null The message thread ID on success, null on failure. 392 385 */ … … 426 419 * @param string|bool $meta_value Meta value to delete. Default false. 427 420 * @param bool $delete_all Whether or not to delete all meta data. 428 *429 421 * @return bool 430 422 */ 431 423 function bp_messages_delete_meta( $message_id, $meta_key = false, $meta_value = false, $delete_all = false ) { 432 // Legacy - if no meta_key is passed, delete all for the item 424 // Legacy - if no meta_key is passed, delete all for the item. 433 425 if ( empty( $meta_key ) ) { 434 426 global $wpdb; … … 436 428 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->messagemeta} WHERE message_id = %d", $message_id ) ); 437 429 438 // With no meta_key, ignore $delete_all 430 // With no meta_key, ignore $delete_all. 439 431 $delete_all = false; 440 432 } else { … … 442 434 } 443 435 444 // no keys, so stop now!436 // No keys, so stop now! 445 437 if ( empty( $keys ) ) { 446 438 return false; … … 468 460 * @param string $meta_key Meta key to retrieve. Default empty string. 469 461 * @param bool $single Whether or not to fetch all or a single value. 470 *471 462 * @return mixed 472 463 */ … … 490 481 * @param string|bool $meta_value Meta value to update. 491 482 * @param string $prev_value If specified, only update existing metadata entries with 492 * the specified value. Otherwise, update all entries. 493 * 483 * the specified value. Otherwise, update all entries. 494 484 * @return mixed 495 485 */ … … 513 503 * @param string|bool $meta_value Meta value to update. 514 504 * @param bool $unique Whether the specified metadata key should be 515 * 516 * 505 * unique for the object. If true, and the object 506 * already has a value for the specified metadata key, 517 507 * no change will be made. 518 508 * @return mixed -
trunk/src/bp-messages/bp-messages-loader.php
r10139 r10304 54 54 public function includes( $includes = array() ) { 55 55 56 // Files to include 56 // Files to include. 57 57 $includes = array( 58 58 'cssjs', … … 68 68 ); 69 69 70 // Conditional includes 70 // Conditional includes. 71 71 if ( bp_is_active( $this->id, 'star' ) ) { 72 72 $includes[] = 'star'; … … 89 89 $bp = buddypress(); 90 90 91 // Define a slug, if necessary 91 // Define a slug, if necessary. 92 92 if ( ! defined( 'BP_MESSAGES_SLUG' ) ) { 93 93 define( 'BP_MESSAGES_SLUG', $this->id ); 94 94 } 95 95 96 // Global tables for messaging component 96 // Global tables for messaging component. 97 97 $global_tables = array( 98 98 'table_name_notices' => $bp->table_prefix . 'bp_messages_notices', … … 102 102 ); 103 103 104 // Metadata tables for messaging component 104 // Metadata tables for messaging component. 105 105 $meta_tables = array( 106 106 'message' => $bp->table_prefix . 'bp_messages_meta', … … 129 129 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 130 130 131 // Determine user to use 131 // Determine user to use. 132 132 if ( bp_displayed_user_domain() ) { 133 133 $user_domain = bp_displayed_user_domain(); … … 142 142 $messages_link = trailingslashit( $user_domain . $slug ); 143 143 144 // Only grab count if we're on a user page and current user has access 144 // Only grab count if we're on a user page and current user has access. 145 145 if ( bp_is_user() && bp_user_has_access() ) { 146 146 $count = bp_get_total_unread_messages_count(); … … 151 151 } 152 152 153 // Add 'Messages' to the main navigation 153 // Add 'Messages' to the main navigation. 154 154 $main_nav = array( 155 155 'name' => $nav_name, … … 162 162 ); 163 163 164 // Add the subnav items to the profile 164 // Add the subnav items to the profile. 165 165 $sub_nav[] = array( 166 166 'name' => __( 'Inbox', 'buddypress' ), … … 223 223 * Set up the Toolbar. 224 224 * 225 * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()} 226 * for details. 225 * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()} for details. 227 226 */ 228 227 public function setup_admin_bar( $wp_admin_nav = array() ) { 229 228 230 // Menus for logged in user 229 // Menus for logged in user. 231 230 if ( is_user_logged_in() ) { 232 231 233 // Setup the logged in user variables 232 // Setup the logged in user variables. 234 233 $messages_link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 235 234 236 // Unread message count 235 // Unread message count. 237 236 $count = messages_get_unread_count(); 238 237 if ( !empty( $count ) ) { … … 244 243 } 245 244 246 // Add main Messages menu 245 // Add main Messages menu. 247 246 $wp_admin_nav[] = array( 248 247 'parent' => buddypress()->my_account_menu_id, … … 252 251 ); 253 252 254 // Inbox 253 // Inbox. 255 254 $wp_admin_nav[] = array( 256 255 'parent' => 'my-account-' . $this->id, … … 260 259 ); 261 260 262 // Starred 261 // Starred. 263 262 if ( bp_is_active( $this->id, 'star' ) ) { 264 263 $wp_admin_nav[] = array( … … 270 269 } 271 270 272 // Sent Messages 271 // Sent Messages. 273 272 $wp_admin_nav[] = array( 274 273 'parent' => 'my-account-' . $this->id, … … 278 277 ); 279 278 280 // Compose Message 279 // Compose Message. 281 280 $wp_admin_nav[] = array( 282 281 'parent' => 'my-account-' . $this->id, … … 286 285 ); 287 286 288 // Site Wide Notices 287 // Site Wide Notices. 289 288 if ( bp_current_user_can( 'bp_moderate' ) ) { 290 289 $wp_admin_nav[] = array( … … 330 329 public function setup_cache_groups() { 331 330 332 // Global groups 331 // Global groups. 333 332 wp_cache_add_global_groups( array( 334 333 'bp_messages', -
trunk/src/bp-messages/bp-messages-notifications.php
r10139 r10304 27 27 function messages_notification_new_message( $raw_args = array() ) { 28 28 29 // Cast possible $message object as an array 29 // Cast possible $message object as an array. 30 30 if ( is_object( $raw_args ) ) { 31 31 $args = (array) $raw_args; … … 34 34 } 35 35 36 // These should be extracted below 36 // These should be extracted below. 37 37 $recipients = array(); 38 38 $email_subject = $email_content = ''; 39 39 $sender_id = 0; 40 40 41 // Barf 41 // Barf. 42 42 extract( $args ); 43 43 44 // Get the sender display name 44 // Get the sender display name. 45 45 $sender_name = bp_core_get_user_displayname( $sender_id ); 46 46 47 // Bail if no recipients 47 // Bail if no recipients. 48 48 if ( ! empty( $recipients ) ) { 49 49 … … 54 54 } 55 55 56 // User data and links 56 // User data and links. 57 57 $ud = get_userdata( $recipient->user_id ); 58 58 59 // Bail if user cannot be found 59 // Bail if user cannot be found. 60 60 if ( empty( $ud ) ) { 61 61 continue; … … 66 66 $settings_link = bp_core_get_user_domain( $recipient->user_id ) . $settings_slug . '/notifications/'; 67 67 68 // Sender info 68 // Sender info. 69 69 $sender_name = stripslashes( $sender_name ); 70 70 $subject = stripslashes( wp_filter_kses( $subject ) ); 71 71 $content = stripslashes( wp_filter_kses( $message ) ); 72 72 73 // Set up and send the message 73 // Set up and send the message. 74 74 $email_to = $ud->user_email; 75 75 $email_subject = bp_get_email_subject( array( 'text' => sprintf( __( 'New message from %s', 'buddypress' ), $sender_name ) ) ); … … 87 87 ', 'buddypress' ), $sender_name, $subject, $content, $message_link ); 88 88 89 // Only show the disable notifications line if the settings component is enabled 89 // Only show the disable notifications line if the settings component is enabled. 90 90 if ( bp_is_active( 'settings' ) ) { 91 91 $email_content .= sprintf( __( 'To disable these notifications, please log in and go to: %s', 'buddypress' ), $settings_link ); … … 160 160 * @param string $format Return value format. 'string' for BuddyBar-compatible 161 161 * notifications; 'array' for WP Toolbar. Default: 'string'. 162 *163 162 * @return string|array Formatted notifications. 164 163 */ … … 176 175 $amount = 'single'; 177 176 178 // get message thread ID177 // Get message thread ID. 179 178 $message = new BP_Messages_Message( $item_id ); 180 179 $thread_id = $message->thread_id; … … 268 267 global $thread_template; 269 268 270 // get unread PM notifications for the user269 // Get unread PM notifications for the user. 271 270 $new_pm_notifications = BP_Notifications_Notification::get( array( 272 271 'user_id' => bp_loggedin_user_id(), … … 277 276 $unread_message_ids = wp_list_pluck( $new_pm_notifications, 'item_id' ); 278 277 279 // no unread PMs, so stop!278 // No unread PMs, so stop! 280 279 if ( empty( $unread_message_ids ) ) { 281 280 return; 282 281 } 283 282 284 // get the unread message ids for this thread only283 // Get the unread message ids for this thread only. 285 284 $message_ids = array_intersect( $unread_message_ids, wp_list_pluck( $thread_template->thread->messages, 'id' ) ); 286 285 287 // mark each notification for each PM message as read286 // Mark each notification for each PM message as read. 288 287 foreach ( $message_ids as $message_id ) { 289 288 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' ); -
trunk/src/bp-messages/bp-messages-screens.php
r10231 r10304 113 113 function messages_screen_conversation() { 114 114 115 // Bail if not viewing a single message 115 // Bail if not viewing a single message. 116 116 if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) { 117 117 return false; … … 124 124 } 125 125 126 // Load up BuddyPress one time 126 // Load up BuddyPress one time. 127 127 $bp = buddypress(); 128 128 129 // Decrease the unread count in the nav before it's rendered 129 // Decrease the unread count in the nav before it's rendered. 130 130 $count = bp_get_total_unread_messages_count(); 131 131 $class = ( 0 === $count ) ? 'no-count' : 'count'; -
trunk/src/bp-messages/bp-messages-star.php
r10141 r10304 38 38 * 39 39 * @param int $mid The message ID. Please note that this isn't the message thread ID. 40 * @param int $user_id The user ID 40 * @param int $user_id The user ID. 41 41 * @return bool 42 42 */ … … 96 96 function bp_get_the_message_star_action_link( $args = array() ) { 97 97 98 // Default user ID 98 // Default user ID. 99 99 $user_id = bp_displayed_user_id() 100 100 ? bp_displayed_user_id() … … 114 114 ), 'messages_star_action_link' ); 115 115 116 // Check user ID and determine base user URL 116 // Check user ID and determine base user URL. 117 117 switch ( $r['user_id'] ) { 118 118 119 // Current user 119 // Current user. 120 120 case bp_loggedin_user_id() : 121 121 $user_domain = bp_loggedin_user_domain(); 122 122 break; 123 123 124 // Displayed user 124 // Displayed user. 125 125 case bp_displayed_user_id() : 126 126 $user_domain = bp_displayed_user_domain(); 127 127 break; 128 128 129 // Empty or other 129 // Empty or other. 130 130 default : 131 131 $user_domain = bp_core_get_user_domain( $r['user_id'] ); … … 133 133 } 134 134 135 // Bail if no user domain was calculated 135 // Bail if no user domain was calculated. 136 136 if ( empty( $user_domain ) ) { 137 137 return ''; 138 138 } 139 139 140 // Define local variables 140 // Define local variables. 141 141 $retval = $bulk_attr = ''; 142 142 143 // thread ID143 // Thread ID. 144 144 if ( (int) $r['thread_id'] > 0 ) { 145 145 146 // see if we're in the loop146 // See if we're in the loop. 147 147 if ( bp_get_message_thread_id() == $r['thread_id'] ) { 148 148 149 // grab all message ids149 // Grab all message ids. 150 150 $mids = wp_list_pluck( $GLOBALS['messages_template']->thread->messages, 'id' ); 151 151 152 // make sure order is ASC153 // order is DESC when used in the thread loop by default152 // Make sure order is ASC. 153 // Order is DESC when used in the thread loop by default. 154 154 $mids = array_reverse( $mids ); 155 155 156 // pull up the thread156 // Pull up the thread. 157 157 } else { 158 158 $thread = new BP_Messages_Thread( $r['thread_id'] ); … … 164 164 foreach ( $mids as $mid ) { 165 165 166 // try to find the first msg that is starred in a thread166 // Try to find the first msg that is starred in a thread. 167 167 if ( true === bp_messages_is_message_starred( $mid ) ) { 168 168 $is_starred = true; … … 172 172 } 173 173 174 // no star, so default to first message in thread174 // No star, so default to first message in thread. 175 175 if ( empty( $message_id ) ) { 176 176 $message_id = $mids[0]; … … 179 179 $message_id = (int) $message_id; 180 180 181 // nonce181 // Nonce. 182 182 $nonce = wp_create_nonce( "bp-messages-star-{$message_id}" ); 183 183 … … 193 193 $title = $r["title_{$action}_thread"]; 194 194 195 // message ID195 // Message ID. 196 196 } else { 197 197 $message_id = (int) $r['message_id']; … … 260 260 ) ); 261 261 262 // Set thread ID 262 // Set thread ID. 263 263 if ( ! empty( $r['thread_id'] ) ) { 264 264 $thread_id = (int) $r['thread_id']; … … 270 270 } 271 271 272 // Check if user has access to thread 272 // Check if user has access to thread. 273 273 if( ! messages_check_thread_access( $thread_id, $r['user_id'] ) ) { 274 274 return false; … … 277 277 $is_starred = bp_messages_is_message_starred( $r['message_id'], $r['user_id'] ); 278 278 279 // star279 // Star. 280 280 if ( 'star' == $r['action'] ) { 281 281 if ( true === $is_starred ) { … … 285 285 return true; 286 286 } 287 // unstar287 // Unstar. 288 288 } else { 289 // unstar one message289 // Unstar one message. 290 290 if ( false === $r['bulk'] ) { 291 291 if ( false === $is_starred ) { … … 296 296 } 297 297 298 // unstar all messages in a thread298 // Unstar all messages in a thread. 299 299 } else { 300 300 $thread = new BP_Messages_Thread( $thread_id ); … … 338 338 */ 339 339 function bp_messages_star_content() { 340 // add our message thread filter340 // Add our message thread filter. 341 341 add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' ); 342 342 343 // load the message loop template part343 // Load the message loop template part. 344 344 bp_get_template_part( 'members/single/messages/messages-loop' ); 345 345 346 // remove our filter346 // Remove our filter. 347 347 remove_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' ); 348 348 } … … 354 354 * 355 355 * @param array $r Current message thread arguments. 356 * @return array 356 * @return array $r Array of starred message threads. 357 357 */ 358 358 function bp_messages_filter_starred_message_threads( $r = array() ) { … … 386 386 } 387 387 388 // Check capability 388 // Check capability. 389 389 if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) { 390 390 return; 391 391 } 392 392 393 // mark the star393 // Mark the star. 394 394 bp_messages_star_set_action( array( 395 395 'action' => bp_current_action(), … … 398 398 ) ); 399 399 400 // redirect back to previous screen400 // Redirect back to previous screen. 401 401 $redirect = wp_get_referer() ? wp_get_referer() : bp_loggedin_user_domain() . bp_get_messages_slug(); 402 402 bp_core_redirect( $redirect ); … … 420 420 } 421 421 422 // Check capability 422 // Check capability. 423 423 if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) { 424 424 return; … … 439 439 $count = count( $threads ); 440 440 441 // if we're starring a thread, we only star the first message in the thread441 // If we're starring a thread, we only star the first message in the thread. 442 442 foreach ( $threads as $thread ) { 443 443 $thread = new BP_Messages_thread( $thread ); … … 512 512 * @since 2.3.0 513 513 * 514 * @param array $retval Current CSS classes 514 * @param array $retval Current CSS classes. 515 515 * @return array 516 516 */ … … 522 522 } 523 523 524 // add css class based on star status for the current message524 // Add css class based on star status for the current message. 525 525 $retval[] = "message-{$status}"; 526 526 -
trunk/src/bp-messages/bp-messages-template.php
r10248 r10304 108 108 public function __construct( $args = array() ) { 109 109 110 // Backward compatibility with old method of passing arguments 110 // Backward compatibility with old method of passing arguments. 111 111 if ( ! is_array( $args ) || func_num_args() > 1 ) { 112 112 _deprecated_argument( __METHOD__, '2.2.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 280 280 */ 281 281 do_action( 'messages_box_loop_end' ); 282 // Do some cleaning up after the loop 282 // Do some cleaning up after the loop. 283 283 $this->rewind_threads(); 284 284 } … … 306 306 $this->thread->messages = array_reverse( (array) $this->thread->messages ); 307 307 308 // Set up the last message data 308 // Set up the last message data. 309 309 if ( count($this->thread->messages) > 1 ) { 310 310 if ( 'inbox' == $this->box ) { … … 333 333 } 334 334 335 // loop has just started335 // Loop has just started. 336 336 if ( 0 == $this->current_thread ) { 337 337 … … 379 379 global $messages_template; 380 380 381 // The default box the user is looking at 381 // The default box the user is looking at. 382 382 $current_action = bp_current_action(); 383 383 switch ( $current_action ) { … … 396 396 $user_id = bp_loggedin_user_id(); 397 397 398 // Search Terms 398 // Search Terms. 399 399 $search_terms = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; 400 400 401 // Parse the arguments 401 // Parse the arguments. 402 402 $r = bp_parse_args( $args, array( 403 403 'user_id' => $user_id, … … 407 407 'type' => 'all', 408 408 'search_terms' => $search_terms, 409 'page_arg' => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679 409 'page_arg' => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679. 410 410 'meta_query' => array() 411 411 ), 'has_message_threads' ); 412 412 413 // Load the messages loop global up with messages 413 // Load the messages loop global up with messages. 414 414 $messages_template = new BP_Messages_Box_Template( $r ); 415 415 … … 542 542 * 543 543 * @since 2.0.0 544 * 544 545 * @return string The raw content of the last message in the thread. 545 546 */ … … 856 857 * @param int|bool $thread_id Optional. ID of the thread. 857 858 * Defaults to current thread ID. 858 *859 859 * @return int 860 860 */ … … 897 897 * 898 898 * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID. 899 *900 899 * @return string Markup displaying the total and unread count for the thread. 901 900 */ … … 1073 1072 /** 1074 1073 * Generate the "Viewing message x to y (of z messages)" string for a loop. 1075 *1076 * @return string1077 1074 */ 1078 1075 function bp_messages_pagination_count() { … … 1101 1098 function bp_message_search_form() { 1102 1099 1103 // Get the default search text 1100 // Get the default search text. 1104 1101 $default_search_value = bp_get_search_default_text( 'messages' ); 1105 1102 1106 // Setup a few values based on what's being searched for 1103 // Setup a few values based on what's being searched for. 1107 1104 $search_submitted = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; 1108 1105 $search_placeholder = ( $search_submitted === $default_search_value ) ? ' placeholder="' . esc_attr( $search_submitted ) . '"' : ''; 1109 1106 $search_value = ( $search_submitted !== $default_search_value ) ? ' value="' . esc_attr( $search_submitted ) . '"' : ''; 1110 1107 1111 // Start the output buffer, so form can be filtered 1108 // Start the output buffer, so form can be filtered. 1112 1109 ob_start(); ?> 1113 1110 … … 1120 1117 <?php 1121 1118 1122 // Get the search form from the above output buffer 1119 // Get the search form from the above output buffer. 1123 1120 $search_form_html = ob_get_clean(); 1124 1121 … … 1203 1200 function bp_get_messages_subject_value() { 1204 1201 1205 // Sanitized in bp-messages-filters.php 1202 // Sanitized in bp-messages-filters.php. 1206 1203 $subject = ! empty( $_POST['subject'] ) 1207 1204 ? $_POST['subject'] … … 1234 1231 function bp_get_messages_content_value() { 1235 1232 1236 // Sanitized in bp-messages-filters.php 1233 // Sanitized in bp-messages-filters.php. 1237 1234 $content = ! empty( $_POST['content'] ) 1238 1235 ? $_POST['content'] … … 1651 1648 function bp_get_send_message_button() { 1652 1649 // Note: 'bp_get_send_message_button' is a legacy filter. Use 1653 // 'bp_get_send_message_button_args' instead. See #4536 1650 // 'bp_get_send_message_button_args' instead. See #4536. 1654 1651 return apply_filters( 'bp_get_send_message_button', 1655 1652 … … 1736 1733 function bp_get_message_get_recipient_usernames() { 1737 1734 1738 // Sanitized in bp-messages-filters.php 1735 // Sanitized in bp-messages-filters.php. 1739 1736 $recipients = isset( $_GET['r'] ) 1740 1737 ? $_GET['r'] … … 1751 1748 } 1752 1749 1753 1754 1750 /** 1755 1751 * Message Thread Template Class … … 1825 1821 * @see BP_Messages_Thread::populate() for full parameter info. 1826 1822 * 1827 * @param int $thread_id 1828 * @param string $order 1829 * @param array $args 1823 * @param int $thread_id ID of the message thread to display. 1824 * @param string $order Order to show the thread's messages in. 1825 * @param array $args Array of arguments for the query. 1830 1826 */ 1831 1827 public function __construct( $thread_id = 0, $order = 'ASC', $args = array() ) { … … 1893 1889 */ 1894 1890 do_action( 'thread_loop_end' ); 1895 // Do some cleaning up after the loop 1891 // Do some cleaning up after the loop. 1896 1892 $this->rewind_messages(); 1897 1893 } … … 1914 1910 $this->message = $this->next_message(); 1915 1911 1916 // loop has just started1912 // Loop has just started. 1917 1913 if ( 0 === $this->current_message ) { 1918 1914 … … 1954 1950 } 1955 1951 1956 // Set up extra args 1952 // Set up extra args. 1957 1953 $extra_args = $r; 1958 1954 unset( $extra_args['thread_id'], $extra_args['order'] ); … … 2192 2188 $classes = array(); 2193 2189 2194 // Zebra-striping 2190 // Zebra-striping. 2195 2191 $classes[] = bp_get_the_thread_message_alt_class(); 2196 2192 2197 // ID of the sender 2193 // ID of the sender. 2198 2194 $classes[] = 'sent-by-' . intval( $thread_template->message->sender_id ); 2199 2195 2200 // Whether the sender is the same as the logged-in user 2196 // Whether the sender is the same as the logged-in user. 2201 2197 if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) { 2202 2198 $classes[] = 'sent-by-me'; … … 2325 2321 /** 2326 2322 * Output a link to the sender of the current message. 2323 * 2324 * @since 1.1.0 2327 2325 */ 2328 2326 function bp_the_thread_message_sender_link() { … … 2332 2330 * Get a link to the sender of the current message. 2333 2331 * 2332 * @since 1.1.0 2333 * 2334 2334 * @return string 2335 2335 */ … … 2349 2349 /** 2350 2350 * Output the display name of the sender of the current message. 2351 * 2352 * @since 1.1.0 2351 2353 */ 2352 2354 function bp_the_thread_message_sender_name() { … … 2356 2358 * Get the display name of the sender of the current message. 2357 2359 * 2360 * @since 1.1.0 2361 * 2358 2362 * @return string 2359 2363 */ … … 2379 2383 /** 2380 2384 * Output the URL for deleting the current thread. 2385 * 2386 * @since 1.5.0 2381 2387 */ 2382 2388 function bp_the_thread_delete_link() { … … 2386 2392 * Get the URL for deleting the current thread. 2387 2393 * 2394 * @since 1.5.0 2395 * 2388 2396 * @return string URL 2389 2397 */ … … 2403 2411 /** 2404 2412 * Output the 'Sent x hours ago' string for the current message. 2413 * 2414 * @since 1.1.0 2405 2415 */ 2406 2416 function bp_the_thread_message_time_since() { … … 2410 2420 * Generate the 'Sent x hours ago' string for the current message. 2411 2421 * 2422 * @since 1.1.0 2423 * 2412 2424 * @return string 2413 2425 */ … … 2456 2468 /** 2457 2469 * Output the content of the current message in the loop. 2470 * 2471 * @since 1.1.0 2458 2472 */ 2459 2473 function bp_the_thread_message_content() { … … 2462 2476 /** 2463 2477 * Get the content of the current message in the loop. 2478 * 2479 * @since 1.1.0 2464 2480 * 2465 2481 * @return string … … 2505 2521 * @param int $id The ID of the message item. 2506 2522 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 2507 *2508 2523 * @return mixed The cached embeds for this message item. 2509 2524 */ … … 2523 2538 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 2524 2539 * @param int $id The ID of the message item. 2525 *2526 * @return bool True on success, false on failure.2527 2540 */ 2528 2541 function bp_embed_message_save_cache( $cache, $cachekey, $id ) { -
trunk/src/bp-messages/bp-messages-widgets.php
r10139 r10304 20 20 add_action( 'bp_register_widgets', 'bp_messages_register_widgets' ); 21 21 22 /** Sitewide Notices widget ***************************************************/23 24 22 /** 25 23 * A widget that displays sitewide notices. … … 30 28 31 29 /** 32 * Constructor method 30 * Constructor method. 33 31 */ 34 32 function __construct() { … … 57 55 } 58 56 59 // Don't display the widget if there are no Notices to show 57 // Don't display the widget if there are no Notices to show. 60 58 $notices = BP_Messages_Notice::get_active(); 61 59 if ( empty( $notices ) ) { … … 99 97 * @param array $new_instance See {@WP_Widget::update()}. 100 98 * @param array $old_instance See {@WP_Widget::update()}. 101 *102 99 * @return array $instance See {@WP_Widget::update()}. 103 100 */ -
trunk/src/bp-messages/classes/class-bp-messages-message.php
r10139 r10304 100 100 * Send a message. 101 101 * 102 * @return int|bool ID of the newly created message on success, false 103 * on failure. 102 * @return int|bool ID of the newly created message on success, false on failure. 104 103 */ 105 104 public function send() { … … 137 136 } 138 137 139 // First insert the message into the messages table 138 // First insert the message into the messages table. 140 139 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 ) ) ) 141 140 return false; … … 146 145 147 146 if ( $new_thread ) { 148 // Add an recipient entry for all recipients 147 // Add an recipient entry for all recipients. 149 148 foreach ( (array) $this->recipients as $recipient ) { 150 149 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count ) VALUES ( %d, %d, 1 )", $recipient->user_id, $this->thread_id ) ); … … 152 151 } 153 152 154 // Add a sender recipient entry if the sender is not in the list of recipients 153 // Add a sender recipient entry if the sender is not in the list of recipients. 155 154 if ( !in_array( $this->sender_id, $recipient_ids ) ) 156 155 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, sender_only ) VALUES ( %d, %d, 1 )", $this->sender_id, $this->thread_id ) ); 157 156 } else { 158 // Update the unread count for all recipients 157 // Update the unread count for all recipients. 159 158 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = unread_count + 1, sender_only = 0, is_deleted = 0 WHERE thread_id = %d AND user_id != %d", $this->thread_id, $this->sender_id ) ); 160 159 } … … 177 176 * Get a list of recipients for a message. 178 177 * 179 * @return array178 * @return object $value List of recipients for a message. 180 179 */ 181 180 public function get_recipients() { … … 193 192 * 194 193 * @param array $recipient_usernames Usernames of recipients. 195 * 196 * @return array 194 * @return array $recipient_ids Array of Recepient IDs. 197 195 */ 198 196 public static function get_recipient_ids( $recipient_usernames ) { … … 215 213 * 216 214 * @param int $thread_id ID of the thread. 217 *218 215 * @return int|null ID of the message if found, otherwise null. 219 216 */ … … 231 228 * @param int $user_id ID of the user. 232 229 * @param int $message_id ID of the message. 233 *234 230 * @return int|null Returns the ID of the message if the user is the 235 231 * sender, otherwise null. … … 247 243 * 248 244 * @param int $message_id ID of the message. 249 *250 245 * @return int|null The ID of the sender if found, otherwise null. 251 246 */ -
trunk/src/bp-messages/classes/class-bp-messages-notice.php
r10139 r10304 57 57 * 58 58 * @since 1.0.0 59 * 59 60 * @param int $id Optional. The ID of the current notice. 60 61 */ … … 212 213 * @type int $pag_page The page number. Defaults to 1. 213 214 * } 214 * @return array215 * @return object List of notices to display. 215 216 */ 216 217 public static function get_notices( $args = array() ) { … … 218 219 219 220 $r = wp_parse_args( $args, array( 220 'pag_num' => 20, // Number of notices per page 221 'pag_page' => 1 // Page number 221 'pag_num' => 20, // Number of notices per page. 222 'pag_page' => 1 // Page number. 222 223 ) ); 223 224 -
trunk/src/bp-messages/classes/class-bp-messages-thread.php
r10139 r10304 112 112 * @see BP_Messages_Thread::populate() for full description of parameters. 113 113 * 114 * @param bool $thread_id 115 * @param string $order 116 * @param array $args 114 * @param bool $thread_id ID for the message thread. 115 * @param string $order Order to display the messages in. 116 * @param array $args Array of arguments for thread querying. 117 117 */ 118 118 public function __construct( $thread_id = false, $order = 'ASC', $args = array() ) { … … 131 131 * @param int $thread_id The message thread ID. 132 132 * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'. 133 * @param array $args {133 * @param array $args { 134 134 * Array of arguments. 135 135 * @type bool $update_meta_cache Whether to pre-fetch metadata for … … 144 144 } 145 145 146 // merge $args with our defaults146 // Merge $args with our defaults. 147 147 $r = wp_parse_args( $args, array( 148 148 'user_id' => bp_loggedin_user_id(), … … 153 153 $this->thread_id = (int) $thread_id; 154 154 155 // get messages for thread155 // Get messages for thread. 156 156 $this->messages = self::get_messages( $this->thread_id ); 157 157 … … 160 160 } 161 161 162 // flip if order is DESC162 // Flip if order is DESC. 163 163 if ( 'DESC' === $order ) { 164 164 $this->messages = array_reverse( $this->messages ); … … 176 176 } 177 177 178 // Fetch the recipients 178 // Fetch the recipients. 179 179 $this->recipients = $this->get_recipients(); 180 180 181 // Get the unread count for the logged in user 181 // Get the unread count for the logged in user. 182 182 if ( isset( $this->recipients[ $r['user_id'] ] ) ) { 183 183 $this->unread_count = $this->recipients[ $r['user_id'] ]->unread_count; 184 184 } 185 185 186 // Grab all message meta 186 // Grab all message meta. 187 187 if ( true === (bool) $r['update_meta_cache'] ) { 188 188 bp_messages_update_meta_cache( wp_list_pluck( $this->messages, 'id' ) ); … … 228 228 * 229 229 * @param int $thread_id The thread ID. 230 *231 230 * @return array 232 231 */ … … 275 274 * @param int $thread_id The message thread ID. 276 275 * 277 * @return array276 * @return object List of messages associated with a thread. 278 277 */ 279 278 public static function get_messages( $thread_id = 0 ) { … … 286 285 $bp = buddypress(); 287 286 288 // always sort by ASC by default287 // Always sort by ASC by default. 289 288 $messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent ASC", $thread_id ) ); 290 289 … … 300 299 * @since 2.3.0 301 300 * 302 * @param int $thread_id The thread ID. 303 * 301 * @param int $thread_id The thread ID. 304 302 * @return array 305 303 */ … … 318 316 * 319 317 * @param int $thread_id The message thread ID. 320 *321 318 * @return bool 322 319 */ … … 340 337 // 341 338 // @todo the reliance on bp_loggedin_user_id() sucks for plugins 342 // refactor this method to accept a $user_id parameter339 // refactor this method to accept a $user_id parameter. 343 340 $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() ) ); 344 341 345 // Get the message ids in order to pass to the action 342 // Get the message ids in order to pass to the action. 346 343 $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 347 344 348 // Check to see if any more recipients remain for this message 345 // Check to see if any more recipients remain for this message. 349 346 $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0", $thread_id ) ); 350 347 351 // No more recipients so delete all messages associated with the thread 348 // No more recipients so delete all messages associated with the thread. 352 349 if ( empty( $recipients ) ) { 353 350 … … 362 359 do_action( 'bp_messages_thread_before_delete', $thread_id, $message_ids ); 363 360 364 // Delete all the messages 361 // Delete all the messages. 365 362 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 366 363 367 // Do something for each message ID 364 // Do something for each message ID. 368 365 foreach ( $message_ids as $message_id ) { 369 366 370 // Delete message meta 367 // Delete message meta. 371 368 bp_messages_delete_meta( $message_id ); 372 369 … … 381 378 } 382 379 383 // Delete all the recipients 380 // Delete all the recipients. 384 381 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) ); 385 382 } … … 420 417 global $wpdb; 421 418 422 // Backward compatibility with old method of passing arguments 419 // Backward compatibility with old method of passing arguments. 423 420 if ( ! is_array( $args ) || func_num_args() > 1 ) { 424 421 _deprecated_argument( __METHOD__, '2.2.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 470 467 $r['user_id'] = (int) $r['user_id']; 471 468 472 // Default deleted SQL 469 // Default deleted SQL. 473 470 $deleted_sql = 'r.is_deleted = 0'; 474 471 … … 485 482 486 483 default : 487 // Omit user-deleted threads from all other custom message boxes 484 // Omit user-deleted threads from all other custom message boxes. 488 485 $deleted_sql = $wpdb->prepare( '( r.user_id = %d AND r.is_deleted = 0 )', $r['user_id'] ); 489 486 break; 490 487 } 491 488 492 // Process meta query into SQL 489 // Process meta query into SQL. 493 490 $meta_query = self::get_meta_query_sql( $r['meta_query'] ); 494 491 if ( ! empty( $meta_query['join'] ) ) { … … 501 498 $bp = buddypress(); 502 499 503 // set up SQL array500 // Set up SQL array. 504 501 $sql = array(); 505 502 $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent'; … … 508 505 $sql['misc'] = "GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}"; 509 506 510 // get thread IDs507 // Get thread IDs. 511 508 $thread_ids = $wpdb->get_results( implode( ' ', $sql ) ); 512 509 if ( empty( $thread_ids ) ) { … … 514 511 } 515 512 516 // adjust $sql to work for thread total513 // Adjust $sql to work for thread total. 517 514 $sql['select'] = 'SELECT COUNT( DISTINCT m.thread_id )'; 518 515 unset( $sql['misc'] ); 519 516 $total_threads = $wpdb->get_var( implode( ' ', $sql ) ); 520 517 521 // Sort threads by date_sent 518 // Sort threads by date_sent. 522 519 foreach( (array) $thread_ids as $thread ) { 523 520 $sorted_threads[ $thread->thread_id ] = strtotime( $thread->date_sent ); … … 559 556 * @param array $meta_query An array of meta_query filters. See the 560 557 * documentation for WP_Meta_Query for details. 561 *562 558 * @return array $sql_array 'join' and 'where' clauses. 563 559 */ … … 574 570 575 571 // WP_Meta_Query expects the table name at 576 // $wpdb->messagemeta 572 // $wpdb->messagemeta. 577 573 $wpdb->messagemeta = buddypress()->messages->table_name_meta; 578 574 … … 629 625 * @param string $type The type of messages to get. Either 'all' or 'unread'. 630 626 * or 'read'. Defaults to 'all'. 631 * @return int 627 * @return int $value Total thread count for the provided user. 632 628 */ 633 629 public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) { … … 656 652 * 657 653 * @param int $thread_id The message thread ID. 658 *659 654 * @return bool 660 655 */ … … 679 674 * 680 675 * @param int $thread_id The message thread ID. 681 *682 676 * @return string|bool The user link on success. Boolean false on failure. 683 677 */ … … 700 694 * 701 695 * @param int $user_id The user ID. 702 * 703 * @return int 696 * @return int $unread_count Total inbox unread count for user. 704 697 */ 705 698 public static function get_inbox_count( $user_id = 0 ) { … … 738 731 * @param int $thread_id The message thread ID. 739 732 * @param int $user_id The user ID. 740 *741 733 * @return int|null The recorded recipient ID on success, null on failure. 742 734 */ … … 762 754 * 763 755 * @param int $thread_id The message thread ID. 764 *765 756 * @return int|null The message thread ID on success, null on failure. 766 757 */ 767 758 public static function is_valid( $thread_id = 0 ) { 768 759 769 // Bail if no thread ID is passed 760 // Bail if no thread ID is passed. 770 761 if ( empty( $thread_id ) ) { 771 762 return false; … … 792 783 * 793 784 * @param array $recipients Array containing the message recipients (array of objects). 794 * 795 * @return string 785 * @return string $value String of message recipent userlinks. 796 786 */ 797 787 public static function get_recipient_links( $recipients ) { … … 831 821 $threads = $wpdb->get_results( "SELECT * FROM {$bp_prefix}bp_messages_threads" ); 832 822 833 // Nothing to update, just return true to remove the table 823 // Nothing to update, just return true to remove the table. 834 824 if ( empty( $threads ) ) { 835 825 return true; … … 844 834 $message_ids = implode( ',', $message_ids ); 845 835 846 // Add the thread_id to the messages table 836 // Add the thread_id to the messages table. 847 837 if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_messages} SET thread_id = %d WHERE id IN ({$message_ids})", $thread->id ) ) ) { 848 838 $errors = true;
Note: See TracChangeset
for help on using the changeset viewer.