Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/22/2015 06:12:16 AM (11 years ago)
Author:
tw2113
Message:

Second pass at Messages Component docs cleanup.

See #6403.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-functions.php

    r10286 r10304  
    4040function messages_new_message( $args = '' ) {
    4141
    42     // Parse the default arguments
     42    // Parse the default arguments.
    4343    $r = bp_parse_args( $args, array(
    4444        '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.
    4646        'recipients' => array(), // Can be an array of usernames, user_ids or mixed.
    4747        'subject'    => false,
     
    5151    ), 'messages_new_message' );
    5252
    53     // Bail if no sender or no content
     53    // Bail if no sender or no content.
    5454    if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) {
    5555        if ( 'wp_error' === $r['error_type'] ) {
     
    6969    }
    7070
    71     // Create a new message object
     71    // Create a new message object.
    7272    $message            = new BP_Messages_Message;
    7373    $message->thread_id = $r['thread_id'];
     
    9090        }
    9191
    92         // Set a default reply subject if none was sent
     92        // Set a default reply subject if none was sent.
    9393        if ( empty( $message->subject ) ) {
    9494            $message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject );
     
    9898    } else {
    9999
    100         // Bail if no recipients
     100        // Bail if no recipients.
    101101        if ( empty( $r['recipients'] ) ) {
    102102            if ( 'wp_error' === $r['error_type'] ) {
     
    107107        }
    108108
    109         // Set a default subject if none exists
     109        // Set a default subject if none exists.
    110110        if ( empty( $message->subject ) ) {
    111111            $message->subject = __( 'No Subject', 'buddypress' );
    112112        }
    113113
    114         // Setup the recipients array
     114        // Setup the recipients array.
    115115        $recipient_ids      = array();
    116116
    117         // Invalid recipients are added to an array, for future enhancements
     117        // Invalid recipients are added to an array, for future enhancements.
    118118        $invalid_recipients = array();
    119119
    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.
    121121        foreach( (array) $r['recipients'] as $recipient ) {
    122122
    123             // Trim spaces and skip if empty
     123            // Trim spaces and skip if empty.
    124124            $recipient = trim( $recipient );
    125125            if ( empty( $recipient ) ) {
     
    128128
    129129            // Check user_login / nicename columns first
    130             // @see http://buddypress.trac.wordpress.org/ticket/5151
     130            // @see http://buddypress.trac.wordpress.org/ticket/5151.
    131131            if ( bp_is_username_compatibility_mode() ) {
    132132                $recipient_id = bp_core_get_userid( urldecode( $recipient ) );
     
    135135            }
    136136
    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.
    138138            if ( empty( $recipient_id ) && is_numeric( $recipient ) ) {
    139139                if ( bp_core_get_core_userdata( (int) $recipient ) ) {
     
    142142            }
    143143
    144             // Decide which group to add this recipient to
     144            // Decide which group to add this recipient to.
    145145            if ( empty( $recipient_id ) ) {
    146146                $invalid_recipients[] = $recipient;
     
    157157        }
    158158
    159         // Remove duplicates & bail if no recipients
     159        // Remove duplicates & bail if no recipients.
    160160        $recipient_ids = array_unique( $recipient_ids );
    161161        if ( empty( $recipient_ids ) ) {
     
    167167        }
    168168
    169         // Format this to match existing recipients
     169        // Format this to match existing recipients.
    170170        foreach( (array) $recipient_ids as $i => $recipient_id ) {
    171171            $message->recipients[$i]          = new stdClass;
     
    174174    }
    175175
    176     // Bail if message failed to send
     176    // Bail if message failed to send.
    177177    if ( ! $message->send() ) {
    178178        return false;
     
    188188    do_action_ref_array( 'messages_message_sent', array( &$message ) );
    189189
    190     // Return the thread ID
     190    // Return the thread ID.
    191191    return $message->thread_id;
    192192}
     
    197197 * @param string $subject Subject of the notice.
    198198 * @param string $message Content of the notice.
    199  *
    200199 * @return bool True on success, false on failure.
    201200 */
     
    211210        $notice->date_sent = bp_core_current_time();
    212211        $notice->is_active = 1;
    213         $notice->save(); // send it.
     212        $notice->save(); // Send it.
    214213
    215214        /**
     
    230229 * Delete message thread(s).
    231230 *
    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.
    234232 * @return bool True on success, false on failure.
    235233 */
     
    284282 * @param int $thread_id ID of the thread.
    285283 * @param int $user_id   Optional. ID of the user. Default: ID of the logged-in user.
    286  *
    287284 * @return int|null Message ID if the user has access, otherwise null.
    288285 */
     
    349346 *
    350347 * @param int $user_id Optional. ID of the user. Default: ID of the logged-in user.
    351  *
    352348 * @return int
    353349 */
     
    365361 * @param int $user_id    ID of the user.
    366362 * @param int $message_id ID of the message.
    367  *
    368363 * @return int|null Returns the ID of the message if the user is the
    369364 *                  sender, otherwise null.
     
    377372 *
    378373 * @param int $message_id ID of the message.
    379  *
    380374 * @return int|null The ID of the sender if found, otherwise null.
    381375 */
     
    388382 *
    389383 * @param int $thread_id ID of the thread.
    390  *
    391384 * @return int|null The message thread ID on success, null on failure.
    392385 */
     
    426419 * @param string|bool $meta_value Meta value to delete. Default false.
    427420 * @param bool        $delete_all Whether or not to delete all meta data.
    428  *
    429421 * @return bool
    430422 */
    431423function 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.
    433425    if ( empty( $meta_key ) ) {
    434426        global $wpdb;
     
    436428        $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->messagemeta} WHERE message_id = %d", $message_id ) );
    437429
    438         // With no meta_key, ignore $delete_all
     430        // With no meta_key, ignore $delete_all.
    439431        $delete_all = false;
    440432    } else {
     
    442434    }
    443435
    444     // no keys, so stop now!
     436    // No keys, so stop now!
    445437    if ( empty( $keys ) ) {
    446438        return false;
     
    468460 * @param string $meta_key   Meta key to retrieve. Default empty string.
    469461 * @param bool   $single     Whether or not to fetch all or a single value.
    470  *
    471462 * @return mixed
    472463 */
     
    490481 * @param string|bool $meta_value Meta value to update.
    491482 * @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.
    494484 * @return mixed
    495485 */
     
    513503 * @param string|bool $meta_value Meta value to update.
    514504 * @param bool        $unique     Whether the specified metadata key should be
    515  *                                unique for the object. If true, and the object
    516  *                                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,
    517507 *                                no change will be made.
    518508 * @return mixed
Note: See TracChangeset for help on using the changeset viewer.