Skip to:
Content

BuddyPress.org

Changeset 10304


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

Second pass at Messages Component docs cleanup.

See #6403.

Location:
trunk/src/bp-messages
Files:
13 edited

Legend:

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

    r10286 r10304  
    2323function bp_messages_action_create_message() {
    2424
    25     // Bail if not posting to the compose message screen
     25    // Bail if not posting to the compose message screen.
    2626    if ( ! bp_is_post_request() || ! bp_is_messages_component() || ! bp_is_current_action( 'compose' ) ) {
    2727        return false;
    2828    }
    2929
    30     // Check the nonce
     30    // Check the nonce.
    3131    check_admin_referer( 'messages_send_message' );
    3232
    33     // Define local variables
     33    // Define local variables.
    3434    $redirect_to = '';
    3535    $feedback    = '';
    3636    $success     = false;
    3737
    38     // Missing subject or content
     38    // Missing subject or content.
    3939    if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) {
    4040        $success  = false;
     
    4646        }
    4747
    48     // Subject and content present
     48    // Subject and content present.
    4949    } else {
    5050
    51         // Setup the link to the logged-in user's messages
     51        // Setup the link to the logged-in user's messages.
    5252        $member_messages = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
    5353
    54         // Site-wide notice
     54        // Site-wide notice.
    5555        if ( isset( $_POST['send-notice'] ) ) {
    5656
    57             // Attempt to save the notice and redirect to notices
     57            // Attempt to save the notice and redirect to notices.
    5858            if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) {
    5959                $success     = true;
     
    6161                $redirect_to = trailingslashit( $member_messages . 'notices' );
    6262
    63             // Notice could not be sent
     63            // Notice could not be sent.
    6464            } else {
    6565                $success  = false;
     
    6767            }
    6868
    69         // Private conversation
     69        // Private conversation.
    7070        } else {
    7171
    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' ).
    7373            $autocomplete_recipients = (array) explode( ',', $_POST['send-to-input']     );
    7474            $typed_recipients        = (array) explode( ' ', $_POST['send_to_usernames'] );
     
    8484            $recipients = apply_filters( 'bp_messages_recipients', $recipients );
    8585
    86             // Attempt to send the message
     86            // Attempt to send the message.
    8787            $send = messages_new_message( array(
    8888                'recipients' => $recipients,
     
    9292            ) );
    9393
    94             // Send the message and redirect to it
     94            // Send the message and redirect to it.
    9595            if ( true === is_int( $send ) ) {
    9696                $success     = true;
     
    9999                $redirect_to = trailingslashit( $view . $send );
    100100
    101             // Message could not be sent
     101            // Message could not be sent.
    102102            } else {
    103103                $success  = false;
     
    107107    }
    108108
    109     // Feedback
     109    // Feedback.
    110110    if ( ! empty( $feedback ) ) {
    111111
    112         // Determine message type
     112        // Determine message type.
    113113        $type = ( true === $success )
    114114            ? 'success'
    115115            : 'error';
    116116
    117         // Add feedback message
     117        // Add feedback message.
    118118        bp_core_add_message( $feedback, $type );
    119119    }
    120120
    121     // Maybe redirect
     121    // Maybe redirect.
    122122    if ( ! empty( $redirect_to ) ) {
    123123        bp_core_redirect( $redirect_to );
     
    127127
    128128/**
    129  * Handle editing of sitewide notices
     129 * Handle editing of sitewide notices.
    130130 *
    131131 * @since 2.4.0 This function was split from messages_screen_notices(). See #6505.
     
    138138    global $notice_id;
    139139
    140     // Bail if not viewing a single notice URL
     140    // Bail if not viewing a single notice URL.
    141141    if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || ! bp_action_variable( 1 ) ) {
    142142        return false;
    143143    }
    144144
    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.
    147147    $notice_id = bp_action_variable( 1 ); // 1|2|3|etc...
    148148
    149     // Bail if notice ID is not numeric
     149    // Bail if notice ID is not numeric.
    150150    if ( ! is_numeric( $notice_id ) ) {
    151151        return;
    152152    }
    153153
    154     // Define local variables
     154    // Define local variables.
    155155    $redirect_to = '';
    156156    $feedback    = '';
    157157    $success     = false;
    158158
    159     // Get the notice from database
     159    // Get the notice from database.
    160160    $notice = new BP_Messages_Notice( $notice_id );
    161161
    162     // Take action
     162    // Take action.
    163163    switch ( $action ) {
    164164
    165         // Deactivate
     165        // Deactivate.
    166166        case 'deactivate' :
    167167            $success  = $notice->deactivate();
     
    171171            break;
    172172
    173         // Activate
     173        // Activate.
    174174        case 'activate' :
    175175            $success  = $notice->activate();
     
    179179            break;
    180180
    181         // Delete
     181        // Delete.
    182182        case 'delete' :
    183183            $success  = $notice->delete();
     
    188188    }
    189189
    190     // Feedback
     190    // Feedback.
    191191    if ( ! empty( $feedback ) ) {
    192192
    193         // Determine message type
     193        // Determine message type.
    194194        $type = ( true === $success )
    195195            ? 'success'
    196196            : 'error';
    197197
    198         // Add feedback message
     198        // Add feedback message.
    199199        bp_core_add_message( $feedback, $type );
    200200    }
    201201
    202     // Redirect
     202    // Redirect.
    203203    $member_notices = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
    204204    $redirect_to    = trailingslashit( $member_notices . 'notices' );
     
    213213function messages_action_conversation() {
    214214
    215     // Bail if not viewing a single conversation
     215    // Bail if not viewing a single conversation.
    216216    if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) {
    217217        return false;
    218218    }
    219219
    220     // Get the thread ID from the action variable
     220    // Get the thread ID from the action variable.
    221221    $thread_id = (int) bp_action_variable( 0 );
    222222
     
    225225    }
    226226
    227     // Check if a new reply has been submitted
     227    // Check if a new reply has been submitted.
    228228    if ( isset( $_POST['send'] ) ) {
    229229
    230         // Check the nonce
     230        // Check the nonce.
    231231        check_admin_referer( 'messages_send_message', 'send_message_nonce' );
    232232
     
    237237        ) );
    238238
    239         // Send the reply
     239        // Send the reply.
    240240        if ( ! empty( $new_reply ) ) {
    241241            bp_core_add_message( __( 'Your reply was sent successfully', 'buddypress' ) );
     
    247247    }
    248248
    249     // Mark message read
     249    // Mark message read.
    250250    messages_mark_thread_read( $thread_id );
    251251
     
    279279        }
    280280
    281         // Delete message
     281        // Delete message.
    282282        if ( !messages_delete_thread( $thread_id ) ) {
    283283            bp_core_add_message( __('There was an error deleting that message.', 'buddypress'), 'error' );
  • trunk/src/bp-messages/bp-messages-cache.php

    r10139 r10304  
    3636}
    3737
    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.
    3939add_action( 'messages_delete_thread',  'bp_core_clear_cache' );
    4040add_action( 'messages_send_notice',    'bp_core_clear_cache' );
    4141add_action( 'messages_message_sent',   'bp_core_clear_cache' );
    4242
    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.
    4444add_action( 'messages_screen_compose', 'bp_core_clear_cache' );
    4545add_action( 'messages_screen_sentbox', 'bp_core_clear_cache' );
     
    5151 * @since 2.0.0
    5252 *
    53  * @param BP_Messages_Message $message
     53 * @param BP_Messages_Message $message Message being saved.
    5454 */
    5555function bp_messages_clear_cache_on_message_save( BP_Messages_Message $message ) {
    56     // Delete thread cache
     56    // Delete thread cache.
    5757    wp_cache_delete( $message->thread_id, 'bp_messages_threads' );
    5858
    59     // Delete unread count for each recipient
     59    // Delete unread count for each recipient.
    6060    foreach ( (array) $message->recipients as $recipient ) {
    6161        wp_cache_delete( $recipient->user_id, 'bp_messages_unread_count' );
    6262    }
    6363
    64     // Delete thread recipient cache
     64    // Delete thread recipient cache.
    6565    wp_cache_delete( 'thread_recipients_' . $message->thread_id, 'bp_messages' );
    6666}
     
    7676 */
    7777function bp_messages_clear_cache_on_message_delete( $thread_ids ) {
    78     // Delete thread and thread recipient cache
     78    // Delete thread and thread recipient cache.
    7979    foreach( (array) $thread_ids as $thread_id ) {
    8080        wp_cache_delete( $thread_id, 'bp_messages_threads' );
     
    8282    }
    8383
    84     // Delete unread count for logged-in user
     84    // Delete unread count for logged-in user.
    8585    wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
    8686}
     
    9494 * @since 2.0.0
    9595 *
    96  * @param BP_Messages_Notice $notice
     96 * @param BP_Messages_Notice $notice Notice that was saved.
    9797 */
    9898function bp_notices_clear_cache( $notice ) {
  • trunk/src/bp-messages/bp-messages-filters.php

    r10139 r10304  
    7575 *
    7676 * @param array|string $args See {@link bp_has_message_threads()}.
     77 * @return array
    7778 */
    7879function bp_messages_enforce_current_user( $args = array() ) {
    7980
    80     // Non-community moderators can only ever see their own messages
     81    // Non-community moderators can only ever see their own messages.
    8182    if ( is_user_logged_in() && ! bp_current_user_can( 'bp_moderate' ) ) {
    8283        $_user_id = (int) bp_loggedin_user_id();
     
    8687    }
    8788
    88     // Return possibly modified $args array
     89    // Return possibly modified $args array.
    8990    return $args;
    9091}
  • 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
  • trunk/src/bp-messages/bp-messages-loader.php

    r10139 r10304  
    5454    public function includes( $includes = array() ) {
    5555
    56         // Files to include
     56        // Files to include.
    5757        $includes = array(
    5858            'cssjs',
     
    6868        );
    6969
    70         // Conditional includes
     70        // Conditional includes.
    7171        if ( bp_is_active( $this->id, 'star' ) ) {
    7272            $includes[] = 'star';
     
    8989        $bp = buddypress();
    9090
    91         // Define a slug, if necessary
     91        // Define a slug, if necessary.
    9292        if ( ! defined( 'BP_MESSAGES_SLUG' ) ) {
    9393            define( 'BP_MESSAGES_SLUG', $this->id );
    9494        }
    9595
    96         // Global tables for messaging component
     96        // Global tables for messaging component.
    9797        $global_tables = array(
    9898            'table_name_notices'    => $bp->table_prefix . 'bp_messages_notices',
     
    102102        );
    103103
    104         // Metadata tables for messaging component
     104        // Metadata tables for messaging component.
    105105        $meta_tables = array(
    106106            'message' => $bp->table_prefix . 'bp_messages_meta',
     
    129129    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    130130
    131         // Determine user to use
     131        // Determine user to use.
    132132        if ( bp_displayed_user_domain() ) {
    133133            $user_domain = bp_displayed_user_domain();
     
    142142        $messages_link = trailingslashit( $user_domain . $slug );
    143143
    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.
    145145        if ( bp_is_user() && bp_user_has_access() ) {
    146146            $count    = bp_get_total_unread_messages_count();
     
    151151        }
    152152
    153         // Add 'Messages' to the main navigation
     153        // Add 'Messages' to the main navigation.
    154154        $main_nav = array(
    155155            'name'                    => $nav_name,
     
    162162        );
    163163
    164         // Add the subnav items to the profile
     164        // Add the subnav items to the profile.
    165165        $sub_nav[] = array(
    166166            'name'            => __( 'Inbox', 'buddypress' ),
     
    223223     * Set up the Toolbar.
    224224     *
    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.
    227226     */
    228227    public function setup_admin_bar( $wp_admin_nav = array() ) {
    229228
    230         // Menus for logged in user
     229        // Menus for logged in user.
    231230        if ( is_user_logged_in() ) {
    232231
    233             // Setup the logged in user variables
     232            // Setup the logged in user variables.
    234233            $messages_link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
    235234
    236             // Unread message count
     235            // Unread message count.
    237236            $count = messages_get_unread_count();
    238237            if ( !empty( $count ) ) {
     
    244243            }
    245244
    246             // Add main Messages menu
     245            // Add main Messages menu.
    247246            $wp_admin_nav[] = array(
    248247                'parent' => buddypress()->my_account_menu_id,
     
    252251            );
    253252
    254             // Inbox
     253            // Inbox.
    255254            $wp_admin_nav[] = array(
    256255                'parent' => 'my-account-' . $this->id,
     
    260259            );
    261260
    262             // Starred
     261            // Starred.
    263262            if ( bp_is_active( $this->id, 'star' ) ) {
    264263                $wp_admin_nav[] = array(
     
    270269            }
    271270
    272             // Sent Messages
     271            // Sent Messages.
    273272            $wp_admin_nav[] = array(
    274273                'parent' => 'my-account-' . $this->id,
     
    278277            );
    279278
    280             // Compose Message
     279            // Compose Message.
    281280            $wp_admin_nav[] = array(
    282281                'parent' => 'my-account-' . $this->id,
     
    286285            );
    287286
    288             // Site Wide Notices
     287            // Site Wide Notices.
    289288            if ( bp_current_user_can( 'bp_moderate' ) ) {
    290289                $wp_admin_nav[] = array(
     
    330329    public function setup_cache_groups() {
    331330
    332         // Global groups
     331        // Global groups.
    333332        wp_cache_add_global_groups( array(
    334333            'bp_messages',
  • trunk/src/bp-messages/bp-messages-notifications.php

    r10139 r10304  
    2727function messages_notification_new_message( $raw_args = array() ) {
    2828
    29     // Cast possible $message object as an array
     29    // Cast possible $message object as an array.
    3030    if ( is_object( $raw_args ) ) {
    3131        $args = (array) $raw_args;
     
    3434    }
    3535
    36     // These should be extracted below
     36    // These should be extracted below.
    3737    $recipients    = array();
    3838    $email_subject = $email_content = '';
    3939    $sender_id     = 0;
    4040
    41     // Barf
     41    // Barf.
    4242    extract( $args );
    4343
    44     // Get the sender display name
     44    // Get the sender display name.
    4545    $sender_name = bp_core_get_user_displayname( $sender_id );
    4646
    47     // Bail if no recipients
     47    // Bail if no recipients.
    4848    if ( ! empty( $recipients ) ) {
    4949
     
    5454            }
    5555
    56             // User data and links
     56            // User data and links.
    5757            $ud = get_userdata( $recipient->user_id );
    5858
    59             // Bail if user cannot be found
     59            // Bail if user cannot be found.
    6060            if ( empty( $ud ) ) {
    6161                continue;
     
    6666            $settings_link = bp_core_get_user_domain( $recipient->user_id ) . $settings_slug . '/notifications/';
    6767
    68             // Sender info
     68            // Sender info.
    6969            $sender_name   = stripslashes( $sender_name );
    7070            $subject       = stripslashes( wp_filter_kses( $subject ) );
    7171            $content       = stripslashes( wp_filter_kses( $message ) );
    7272
    73             // Set up and send the message
     73            // Set up and send the message.
    7474            $email_to      = $ud->user_email;
    7575            $email_subject = bp_get_email_subject( array( 'text' => sprintf( __( 'New message from %s', 'buddypress' ), $sender_name ) ) );
     
    8787', 'buddypress' ), $sender_name, $subject, $content, $message_link );
    8888
    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.
    9090            if ( bp_is_active( 'settings' ) ) {
    9191                $email_content .= sprintf( __( 'To disable these notifications, please log in and go to: %s', 'buddypress' ), $settings_link );
     
    160160 * @param string $format            Return value format. 'string' for BuddyBar-compatible
    161161 *                                  notifications; 'array' for WP Toolbar. Default: 'string'.
    162  *
    163162 * @return string|array Formatted notifications.
    164163 */
     
    176175            $amount = 'single';
    177176
    178             // get message thread ID
     177            // Get message thread ID.
    179178            $message   = new BP_Messages_Message( $item_id );
    180179            $thread_id = $message->thread_id;
     
    268267        global $thread_template;
    269268
    270         // get unread PM notifications for the user
     269        // Get unread PM notifications for the user.
    271270        $new_pm_notifications = BP_Notifications_Notification::get( array(
    272271            'user_id'           => bp_loggedin_user_id(),
     
    277276        $unread_message_ids = wp_list_pluck( $new_pm_notifications, 'item_id' );
    278277
    279         // no unread PMs, so stop!
     278        // No unread PMs, so stop!
    280279        if ( empty( $unread_message_ids ) ) {
    281280            return;
    282281        }
    283282
    284         // get the unread message ids for this thread only
     283        // Get the unread message ids for this thread only.
    285284        $message_ids = array_intersect( $unread_message_ids, wp_list_pluck( $thread_template->thread->messages, 'id' ) );
    286285
    287         // mark each notification for each PM message as read
     286        // Mark each notification for each PM message as read.
    288287        foreach ( $message_ids as $message_id ) {
    289288            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  
    113113function messages_screen_conversation() {
    114114
    115     // Bail if not viewing a single message
     115    // Bail if not viewing a single message.
    116116    if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) {
    117117        return false;
     
    124124    }
    125125
    126     // Load up BuddyPress one time
     126    // Load up BuddyPress one time.
    127127    $bp = buddypress();
    128128
    129     // Decrease the unread count in the nav before it's rendered
     129    // Decrease the unread count in the nav before it's rendered.
    130130    $count    = bp_get_total_unread_messages_count();
    131131    $class    = ( 0 === $count ) ? 'no-count' : 'count';
  • trunk/src/bp-messages/bp-messages-star.php

    r10141 r10304  
    3838 *
    3939 * @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.
    4141 * @return bool
    4242 */
     
    9696    function bp_get_the_message_star_action_link( $args = array() ) {
    9797
    98         // Default user ID
     98        // Default user ID.
    9999        $user_id = bp_displayed_user_id()
    100100            ? bp_displayed_user_id()
     
    114114        ), 'messages_star_action_link' );
    115115
    116         // Check user ID and determine base user URL
     116        // Check user ID and determine base user URL.
    117117        switch ( $r['user_id'] ) {
    118118
    119             // Current user
     119            // Current user.
    120120            case bp_loggedin_user_id() :
    121121                $user_domain = bp_loggedin_user_domain();
    122122                break;
    123123
    124             // Displayed user
     124            // Displayed user.
    125125            case bp_displayed_user_id() :
    126126                $user_domain = bp_displayed_user_domain();
    127127                break;
    128128
    129             // Empty or other
     129            // Empty or other.
    130130            default :
    131131                $user_domain = bp_core_get_user_domain( $r['user_id'] );
     
    133133        }
    134134
    135         // Bail if no user domain was calculated
     135        // Bail if no user domain was calculated.
    136136        if ( empty( $user_domain ) ) {
    137137            return '';
    138138        }
    139139
    140         // Define local variables
     140        // Define local variables.
    141141        $retval = $bulk_attr = '';
    142142
    143         // thread ID
     143        // Thread ID.
    144144        if ( (int) $r['thread_id'] > 0 ) {
    145145
    146             // see if we're in the loop
     146            // See if we're in the loop.
    147147            if ( bp_get_message_thread_id() == $r['thread_id'] ) {
    148148
    149                 // grab all message ids
     149                // Grab all message ids.
    150150                $mids = wp_list_pluck( $GLOBALS['messages_template']->thread->messages, 'id' );
    151151
    152                 // make sure order is ASC
    153                 // order is DESC when used in the thread loop by default
     152                // Make sure order is ASC.
     153                // Order is DESC when used in the thread loop by default.
    154154                $mids = array_reverse( $mids );
    155155
    156             // pull up the thread
     156            // Pull up the thread.
    157157            } else {
    158158                $thread = new BP_Messages_Thread( $r['thread_id'] );
     
    164164            foreach ( $mids as $mid ) {
    165165
    166                 // try to find the first msg that is starred in a thread
     166                // Try to find the first msg that is starred in a thread.
    167167                if ( true === bp_messages_is_message_starred( $mid ) ) {
    168168                    $is_starred = true;
     
    172172            }
    173173
    174             // no star, so default to first message in thread
     174            // No star, so default to first message in thread.
    175175            if ( empty( $message_id ) ) {
    176176                $message_id = $mids[0];
     
    179179            $message_id = (int) $message_id;
    180180
    181             // nonce
     181            // Nonce.
    182182            $nonce = wp_create_nonce( "bp-messages-star-{$message_id}" );
    183183
     
    193193            $title = $r["title_{$action}_thread"];
    194194
    195         // message ID
     195        // Message ID.
    196196        } else {
    197197            $message_id = (int) $r['message_id'];
     
    260260    ) );
    261261
    262     // Set thread ID
     262    // Set thread ID.
    263263    if ( ! empty( $r['thread_id'] ) ) {
    264264        $thread_id = (int) $r['thread_id'];
     
    270270    }
    271271
    272     // Check if user has access to thread
     272    // Check if user has access to thread.
    273273    if( ! messages_check_thread_access( $thread_id, $r['user_id'] ) ) {
    274274        return false;
     
    277277    $is_starred = bp_messages_is_message_starred( $r['message_id'], $r['user_id'] );
    278278
    279     // star
     279    // Star.
    280280    if ( 'star' == $r['action'] ) {
    281281        if ( true === $is_starred ) {
     
    285285            return true;
    286286        }
    287     // unstar
     287    // Unstar.
    288288    } else {
    289         // unstar one message
     289        // Unstar one message.
    290290        if ( false === $r['bulk'] ) {
    291291            if ( false === $is_starred ) {
     
    296296            }
    297297
    298         // unstar all messages in a thread
     298        // Unstar all messages in a thread.
    299299        } else {
    300300            $thread = new BP_Messages_Thread( $thread_id );
     
    338338 */
    339339function bp_messages_star_content() {
    340     // add our message thread filter
     340    // Add our message thread filter.
    341341    add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
    342342
    343     // load the message loop template part
     343    // Load the message loop template part.
    344344    bp_get_template_part( 'members/single/messages/messages-loop' );
    345345
    346     // remove our filter
     346    // Remove our filter.
    347347    remove_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
    348348}
     
    354354 *
    355355 * @param  array $r Current message thread arguments.
    356  * @return array
     356 * @return array $r Array of starred message threads.
    357357 */
    358358function bp_messages_filter_starred_message_threads( $r = array() ) {
     
    386386    }
    387387
    388     // Check capability
     388    // Check capability.
    389389    if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) {
    390390        return;
    391391    }
    392392
    393     // mark the star
     393    // Mark the star.
    394394    bp_messages_star_set_action( array(
    395395        'action'     => bp_current_action(),
     
    398398    ) );
    399399
    400     // redirect back to previous screen
     400    // Redirect back to previous screen.
    401401    $redirect = wp_get_referer() ? wp_get_referer() : bp_loggedin_user_domain() . bp_get_messages_slug();
    402402    bp_core_redirect( $redirect );
     
    420420    }
    421421
    422     // Check capability
     422    // Check capability.
    423423    if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) {
    424424        return;
     
    439439            $count = count( $threads );
    440440
    441             // if we're starring a thread, we only star the first message in the thread
     441            // If we're starring a thread, we only star the first message in the thread.
    442442            foreach ( $threads as $thread ) {
    443443                $thread = new BP_Messages_thread( $thread );
     
    512512 * @since 2.3.0
    513513 *
    514  * @param  array $retval Current CSS classes
     514 * @param  array $retval Current CSS classes.
    515515 * @return array
    516516 */
     
    522522    }
    523523
    524     // add css class based on star status for the current message
     524    // Add css class based on star status for the current message.
    525525    $retval[] = "message-{$status}";
    526526
  • trunk/src/bp-messages/bp-messages-template.php

    r10248 r10304  
    108108    public function __construct( $args = array() ) {
    109109
    110         // Backward compatibility with old method of passing arguments
     110        // Backward compatibility with old method of passing arguments.
    111111        if ( ! is_array( $args ) || func_num_args() > 1 ) {
    112112            _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__ ) );
     
    280280             */
    281281            do_action( 'messages_box_loop_end' );
    282             // Do some cleaning up after the loop
     282            // Do some cleaning up after the loop.
    283283            $this->rewind_threads();
    284284        }
     
    306306            $this->thread->messages = array_reverse( (array) $this->thread->messages );
    307307
    308             // Set up the last message data
     308            // Set up the last message data.
    309309            if ( count($this->thread->messages) > 1 ) {
    310310                if ( 'inbox' == $this->box ) {
     
    333333        }
    334334
    335         // loop has just started
     335        // Loop has just started.
    336336        if ( 0 == $this->current_thread ) {
    337337
     
    379379    global $messages_template;
    380380
    381     // The default box the user is looking at
     381    // The default box the user is looking at.
    382382    $current_action = bp_current_action();
    383383    switch ( $current_action ) {
     
    396396    $user_id = bp_loggedin_user_id();
    397397
    398     // Search Terms
     398    // Search Terms.
    399399    $search_terms = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    400400
    401     // Parse the arguments
     401    // Parse the arguments.
    402402    $r = bp_parse_args( $args, array(
    403403        'user_id'      => $user_id,
     
    407407        'type'         => 'all',
    408408        '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.
    410410        'meta_query'   => array()
    411411    ), 'has_message_threads' );
    412412
    413     // Load the messages loop global up with messages
     413    // Load the messages loop global up with messages.
    414414    $messages_template = new BP_Messages_Box_Template( $r );
    415415
     
    542542     *
    543543     * @since 2.0.0
     544     *
    544545     * @return string The raw content of the last message in the thread.
    545546     */
     
    856857     * @param int|bool $thread_id Optional. ID of the thread.
    857858     *                            Defaults to current thread ID.
    858      *
    859859     * @return int
    860860     */
     
    897897     *
    898898     * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID.
    899      *
    900899     * @return string Markup displaying the total and unread count for the thread.
    901900     */
     
    10731072/**
    10741073 * Generate the "Viewing message x to y (of z messages)" string for a loop.
    1075  *
    1076  * @return string
    10771074 */
    10781075function bp_messages_pagination_count() {
     
    11011098function bp_message_search_form() {
    11021099
    1103     // Get the default search text
     1100    // Get the default search text.
    11041101    $default_search_value = bp_get_search_default_text( 'messages' );
    11051102
    1106     // Setup a few values based on what's being searched for
     1103    // Setup a few values based on what's being searched for.
    11071104    $search_submitted     = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
    11081105    $search_placeholder   = ( $search_submitted === $default_search_value ) ? ' placeholder="' .  esc_attr( $search_submitted ) . '"' : '';
    11091106    $search_value         = ( $search_submitted !== $default_search_value ) ? ' value="'       .  esc_attr( $search_submitted ) . '"' : '';
    11101107
    1111     // Start the output buffer, so form can be filtered
     1108    // Start the output buffer, so form can be filtered.
    11121109    ob_start(); ?>
    11131110
     
    11201117    <?php
    11211118
    1122     // Get the search form from the above output buffer
     1119    // Get the search form from the above output buffer.
    11231120    $search_form_html = ob_get_clean();
    11241121
     
    12031200    function bp_get_messages_subject_value() {
    12041201
    1205         // Sanitized in bp-messages-filters.php
     1202        // Sanitized in bp-messages-filters.php.
    12061203        $subject = ! empty( $_POST['subject'] )
    12071204            ? $_POST['subject']
     
    12341231    function bp_get_messages_content_value() {
    12351232
    1236         // Sanitized in bp-messages-filters.php
     1233        // Sanitized in bp-messages-filters.php.
    12371234        $content = ! empty( $_POST['content'] )
    12381235            ? $_POST['content']
     
    16511648    function bp_get_send_message_button() {
    16521649        // 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.
    16541651        return apply_filters( 'bp_get_send_message_button',
    16551652
     
    17361733    function bp_get_message_get_recipient_usernames() {
    17371734
    1738         // Sanitized in bp-messages-filters.php
     1735        // Sanitized in bp-messages-filters.php.
    17391736        $recipients = isset( $_GET['r'] )
    17401737            ? $_GET['r']
     
    17511748    }
    17521749
    1753 
    17541750/**
    17551751 * Message Thread Template Class
     
    18251821     * @see BP_Messages_Thread::populate() for full parameter info.
    18261822     *
    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.
    18301826     */
    18311827    public function __construct( $thread_id = 0, $order = 'ASC', $args = array() ) {
     
    18931889             */
    18941890            do_action( 'thread_loop_end' );
    1895             // Do some cleaning up after the loop
     1891            // Do some cleaning up after the loop.
    18961892            $this->rewind_messages();
    18971893        }
     
    19141910        $this->message     = $this->next_message();
    19151911
    1916         // loop has just started
     1912        // Loop has just started.
    19171913        if ( 0 === $this->current_message ) {
    19181914
     
    19541950    }
    19551951
    1956     // Set up extra args
     1952    // Set up extra args.
    19571953    $extra_args = $r;
    19581954    unset( $extra_args['thread_id'], $extra_args['order'] );
     
    21922188        $classes = array();
    21932189
    2194         // Zebra-striping
     2190        // Zebra-striping.
    21952191        $classes[] = bp_get_the_thread_message_alt_class();
    21962192
    2197         // ID of the sender
     2193        // ID of the sender.
    21982194        $classes[] = 'sent-by-' . intval( $thread_template->message->sender_id );
    21992195
    2200         // Whether the sender is the same as the logged-in user
     2196        // Whether the sender is the same as the logged-in user.
    22012197        if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) {
    22022198            $classes[] = 'sent-by-me';
     
    23252321/**
    23262322 * Output a link to the sender of the current message.
     2323 *
     2324 * @since 1.1.0
    23272325 */
    23282326function bp_the_thread_message_sender_link() {
     
    23322330     * Get a link to the sender of the current message.
    23332331     *
     2332     * @since 1.1.0
     2333     *
    23342334     * @return string
    23352335     */
     
    23492349/**
    23502350 * Output the display name of the sender of the current message.
     2351 *
     2352 * @since 1.1.0
    23512353 */
    23522354function bp_the_thread_message_sender_name() {
     
    23562358     * Get the display name of the sender of the current message.
    23572359     *
     2360     * @since 1.1.0
     2361     *
    23582362     * @return string
    23592363     */
     
    23792383/**
    23802384 * Output the URL for deleting the current thread.
     2385 *
     2386 * @since 1.5.0
    23812387 */
    23822388function bp_the_thread_delete_link() {
     
    23862392     * Get the URL for deleting the current thread.
    23872393     *
     2394     * @since 1.5.0
     2395     *
    23882396     * @return string URL
    23892397     */
     
    24032411/**
    24042412 * Output the 'Sent x hours ago' string for the current message.
     2413 *
     2414 * @since 1.1.0
    24052415 */
    24062416function bp_the_thread_message_time_since() {
     
    24102420     * Generate the 'Sent x hours ago' string for the current message.
    24112421     *
     2422     * @since 1.1.0
     2423     *
    24122424     * @return string
    24132425     */
     
    24562468/**
    24572469 * Output the content of the current message in the loop.
     2470 *
     2471 * @since 1.1.0
    24582472 */
    24592473function bp_the_thread_message_content() {
     
    24622476    /**
    24632477     * Get the content of the current message in the loop.
     2478     *
     2479     * @since 1.1.0
    24642480     *
    24652481     * @return string
     
    25052521 * @param int    $id       The ID of the message item.
    25062522 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
    2507  *
    25082523 * @return mixed The cached embeds for this message item.
    25092524 */
     
    25232538 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
    25242539 * @param int    $id       The ID of the message item.
    2525  *
    2526  * @return bool True on success, false on failure.
    25272540 */
    25282541function bp_embed_message_save_cache( $cache, $cachekey, $id ) {
  • trunk/src/bp-messages/bp-messages-widgets.php

    r10139 r10304  
    2020add_action( 'bp_register_widgets', 'bp_messages_register_widgets' );
    2121
    22 /** Sitewide Notices widget ***************************************************/
    23 
    2422/**
    2523 * A widget that displays sitewide notices.
     
    3028
    3129    /**
    32      * Constructor method
     30     * Constructor method.
    3331     */
    3432    function __construct() {
     
    5755        }
    5856
    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.
    6058        $notices = BP_Messages_Notice::get_active();
    6159        if ( empty( $notices ) ) {
     
    9997     * @param array $new_instance See {@WP_Widget::update()}.
    10098     * @param array $old_instance See {@WP_Widget::update()}.
    101      *
    10299     * @return array $instance See {@WP_Widget::update()}.
    103100     */
  • trunk/src/bp-messages/classes/class-bp-messages-message.php

    r10139 r10304  
    100100     * Send a message.
    101101     *
    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.
    104103     */
    105104    public function send() {
     
    137136        }
    138137
    139         // First insert the message into the messages table
     138        // First insert the message into the messages table.
    140139        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 ) ) )
    141140            return false;
     
    146145
    147146        if ( $new_thread ) {
    148             // Add an recipient entry for all recipients
     147            // Add an recipient entry for all recipients.
    149148            foreach ( (array) $this->recipients as $recipient ) {
    150149                $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 ) );
     
    152151            }
    153152
    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.
    155154            if ( !in_array( $this->sender_id, $recipient_ids ) )
    156155                $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 ) );
    157156        } else {
    158             // Update the unread count for all recipients
     157            // Update the unread count for all recipients.
    159158            $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 ) );
    160159        }
     
    177176     * Get a list of recipients for a message.
    178177     *
    179      * @return array
     178     * @return object $value List of recipients for a message.
    180179     */
    181180    public function get_recipients() {
     
    193192     *
    194193     * @param array $recipient_usernames Usernames of recipients.
    195      *
    196      * @return array
     194     * @return array $recipient_ids Array of Recepient IDs.
    197195     */
    198196    public static function get_recipient_ids( $recipient_usernames ) {
     
    215213     *
    216214     * @param int $thread_id ID of the thread.
    217      *
    218215     * @return int|null ID of the message if found, otherwise null.
    219216     */
     
    231228     * @param int $user_id    ID of the user.
    232229     * @param int $message_id ID of the message.
    233      *
    234230     * @return int|null Returns the ID of the message if the user is the
    235231     *                  sender, otherwise null.
     
    247243     *
    248244     * @param int $message_id ID of the message.
    249      *
    250245     * @return int|null The ID of the sender if found, otherwise null.
    251246     */
  • trunk/src/bp-messages/classes/class-bp-messages-notice.php

    r10139 r10304  
    5757     *
    5858     * @since 1.0.0
     59     *
    5960     * @param int $id Optional. The ID of the current notice.
    6061     */
     
    212213     *     @type int $pag_page The page number.  Defaults to 1.
    213214     * }
    214      * @return array
     215     * @return object List of notices to display.
    215216     */
    216217    public static function get_notices( $args = array() ) {
     
    218219
    219220        $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.
    222223        ) );
    223224
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r10139 r10304  
    112112     * @see BP_Messages_Thread::populate() for full description of parameters.
    113113     *
    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.
    117117     */
    118118    public function __construct( $thread_id = false, $order = 'ASC', $args = array() ) {
     
    131131     * @param int    $thread_id The message thread ID.
    132132     * @param string $order     The order to sort the messages. Either 'ASC' or 'DESC'.
    133      * @param array $args {
     133     * @param array  $args {
    134134     *     Array of arguments.
    135135     *     @type bool $update_meta_cache Whether to pre-fetch metadata for
     
    144144        }
    145145
    146         // merge $args with our defaults
     146        // Merge $args with our defaults.
    147147        $r = wp_parse_args( $args, array(
    148148            'user_id'           => bp_loggedin_user_id(),
     
    153153        $this->thread_id      = (int) $thread_id;
    154154
    155         // get messages for thread
     155        // Get messages for thread.
    156156        $this->messages = self::get_messages( $this->thread_id );
    157157
     
    160160        }
    161161
    162         // flip if order is DESC
     162        // Flip if order is DESC.
    163163        if ( 'DESC' === $order ) {
    164164            $this->messages = array_reverse( $this->messages );
     
    176176        }
    177177
    178         // Fetch the recipients
     178        // Fetch the recipients.
    179179        $this->recipients = $this->get_recipients();
    180180
    181         // Get the unread count for the logged in user
     181        // Get the unread count for the logged in user.
    182182        if ( isset( $this->recipients[ $r['user_id'] ] ) ) {
    183183            $this->unread_count = $this->recipients[ $r['user_id'] ]->unread_count;
    184184        }
    185185
    186         // Grab all message meta
     186        // Grab all message meta.
    187187        if ( true === (bool) $r['update_meta_cache'] ) {
    188188            bp_messages_update_meta_cache( wp_list_pluck( $this->messages, 'id' ) );
     
    228228     *
    229229     * @param int $thread_id The thread ID.
    230      *
    231230     * @return array
    232231     */
     
    275274     * @param int $thread_id The message thread ID.
    276275     *
    277      * @return array
     276     * @return object List of messages associated with a thread.
    278277     */
    279278    public static function get_messages( $thread_id = 0 ) {
     
    286285            $bp = buddypress();
    287286
    288             // always sort by ASC by default
     287            // Always sort by ASC by default.
    289288            $messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent ASC", $thread_id ) );
    290289
     
    300299     * @since 2.3.0
    301300     *
    302      * @param  int $thread_id The thread ID.
    303      *
     301     * @param int $thread_id The thread ID.
    304302     * @return array
    305303     */
     
    318316     *
    319317     * @param int $thread_id The message thread ID.
    320      *
    321318     * @return bool
    322319     */
     
    340337        //
    341338        // @todo the reliance on bp_loggedin_user_id() sucks for plugins
    342         //       refactor this method to accept a $user_id parameter
     339        // refactor this method to accept a $user_id parameter.
    343340        $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() ) );
    344341
    345         // Get the message ids in order to pass to the action
     342        // Get the message ids in order to pass to the action.
    346343        $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
    347344
    348         // Check to see if any more recipients remain for this message
     345        // Check to see if any more recipients remain for this message.
    349346        $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0", $thread_id ) );
    350347
    351         // No more recipients so delete all messages associated with the thread
     348        // No more recipients so delete all messages associated with the thread.
    352349        if ( empty( $recipients ) ) {
    353350
     
    362359            do_action( 'bp_messages_thread_before_delete', $thread_id, $message_ids );
    363360
    364             // Delete all the messages
     361            // Delete all the messages.
    365362            $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
    366363
    367             // Do something for each message ID
     364            // Do something for each message ID.
    368365            foreach ( $message_ids as $message_id ) {
    369366
    370                 // Delete message meta
     367                // Delete message meta.
    371368                bp_messages_delete_meta( $message_id );
    372369
     
    381378            }
    382379
    383             // Delete all the recipients
     380            // Delete all the recipients.
    384381            $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) );
    385382        }
     
    420417        global $wpdb;
    421418
    422         // Backward compatibility with old method of passing arguments
     419        // Backward compatibility with old method of passing arguments.
    423420        if ( ! is_array( $args ) || func_num_args() > 1 ) {
    424421            _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__ ) );
     
    470467        $r['user_id'] = (int) $r['user_id'];
    471468
    472         // Default deleted SQL
     469        // Default deleted SQL.
    473470        $deleted_sql = 'r.is_deleted = 0';
    474471
     
    485482
    486483            default :
    487                 // Omit user-deleted threads from all other custom message boxes
     484                // Omit user-deleted threads from all other custom message boxes.
    488485                $deleted_sql = $wpdb->prepare( '( r.user_id = %d AND r.is_deleted = 0 )', $r['user_id'] );
    489486                break;
    490487        }
    491488
    492         // Process meta query into SQL
     489        // Process meta query into SQL.
    493490        $meta_query = self::get_meta_query_sql( $r['meta_query'] );
    494491        if ( ! empty( $meta_query['join'] ) ) {
     
    501498        $bp = buddypress();
    502499
    503         // set up SQL array
     500        // Set up SQL array.
    504501        $sql = array();
    505502        $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent';
     
    508505        $sql['misc']   = "GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}";
    509506
    510         // get thread IDs
     507        // Get thread IDs.
    511508        $thread_ids = $wpdb->get_results( implode( ' ', $sql ) );
    512509        if ( empty( $thread_ids ) ) {
     
    514511        }
    515512
    516         // adjust $sql to work for thread total
     513        // Adjust $sql to work for thread total.
    517514        $sql['select'] = 'SELECT COUNT( DISTINCT m.thread_id )';
    518515        unset( $sql['misc'] );
    519516        $total_threads = $wpdb->get_var( implode( ' ', $sql ) );
    520517
    521         // Sort threads by date_sent
     518        // Sort threads by date_sent.
    522519        foreach( (array) $thread_ids as $thread ) {
    523520            $sorted_threads[ $thread->thread_id ] = strtotime( $thread->date_sent );
     
    559556     * @param array $meta_query An array of meta_query filters. See the
    560557     *                          documentation for WP_Meta_Query for details.
    561      *
    562558     * @return array $sql_array 'join' and 'where' clauses.
    563559     */
     
    574570
    575571            // WP_Meta_Query expects the table name at
    576             // $wpdb->messagemeta
     572            // $wpdb->messagemeta.
    577573            $wpdb->messagemeta = buddypress()->messages->table_name_meta;
    578574
     
    629625     * @param string $type    The type of messages to get. Either 'all' or 'unread'.
    630626     *                        or 'read'. Defaults to 'all'.
    631      * @return int
     627     * @return int $value Total thread count for the provided user.
    632628     */
    633629    public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
     
    656652     *
    657653     * @param int $thread_id The message thread ID.
    658      *
    659654     * @return bool
    660655     */
     
    679674     *
    680675     * @param int $thread_id The message thread ID.
    681      *
    682676     * @return string|bool The user link on success. Boolean false on failure.
    683677     */
     
    700694     *
    701695     * @param int $user_id The user ID.
    702      *
    703      * @return int
     696     * @return int $unread_count Total inbox unread count for user.
    704697     */
    705698    public static function get_inbox_count( $user_id = 0 ) {
     
    738731     * @param int $thread_id The message thread ID.
    739732     * @param int $user_id   The user ID.
    740      *
    741733     * @return int|null The recorded recipient ID on success, null on failure.
    742734     */
     
    762754     *
    763755     * @param int $thread_id The message thread ID.
    764      *
    765756     * @return int|null The message thread ID on success, null on failure.
    766757     */
    767758    public static function is_valid( $thread_id = 0 ) {
    768759
    769         // Bail if no thread ID is passed
     760        // Bail if no thread ID is passed.
    770761        if ( empty( $thread_id ) ) {
    771762            return false;
     
    792783     *
    793784     * @param array $recipients Array containing the message recipients (array of objects).
    794      *
    795      * @return string
     785     * @return string $value String of message recipent userlinks.
    796786     */
    797787    public static function get_recipient_links( $recipients ) {
     
    831821        $threads   = $wpdb->get_results( "SELECT * FROM {$bp_prefix}bp_messages_threads" );
    832822
    833         // Nothing to update, just return true to remove the table
     823        // Nothing to update, just return true to remove the table.
    834824        if ( empty( $threads ) ) {
    835825            return true;
     
    844834                $message_ids = implode( ',', $message_ids );
    845835
    846                 // Add the thread_id to the messages table
     836                // Add the thread_id to the messages table.
    847837                if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_messages} SET thread_id = %d WHERE id IN ({$message_ids})", $thread->id ) ) ) {
    848838                    $errors = true;
Note: See TracChangeset for help on using the changeset viewer.