Changeset 10304 for trunk/src/bp-messages/bp-messages-functions.php
- Timestamp:
- 10/22/2015 06:12:16 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-messages/bp-messages-functions.php (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 * unique for the object. If true, and the object516 * already has a value for the specified metadata key,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
Note: See TracChangeset
for help on using the changeset viewer.