Skip to:
Content

BuddyPress.org

Changeset 11578


Ignore:
Timestamp:
06/06/2017 05:46:21 PM (9 years ago)
Author:
dcavins
Message:

Show displayed user's messages on messages screens.

When a site administrator visits another user’s messages, she is shown
her own messages because the display logic for messages refers to the
logged-in user rather than the displayed user. This changeset updates
the logic to allow the site admin to view and interact with another
user’s messages.

Fixes #7096.

Location:
trunk/src
Files:
9 edited

Legend:

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

    r11537 r11578  
    248248        }
    249249
    250         // Mark message read.
    251         messages_mark_thread_read( $thread_id );
     250        /*
     251         * Mark message read, but only run on the logged-in user's profile.
     252         * If an admin visits a thread, it shouldn't change the read status.
     253         */
     254        if ( bp_is_my_profile() ) {
     255                messages_mark_thread_read( $thread_id );
     256        }
    252257
    253258        /**
    … …  
    320325
    321326        // Check access to the message and mark as read.
    322         if ( messages_check_thread_access( $id ) ) {
     327        if ( messages_check_thread_access( $id ) || bp_current_user_can( 'bp_moderate' ) ) {
    323328                messages_mark_thread_read( $id );
    324329                bp_core_add_message( __( 'Message marked as read.', 'buddypress' ) );
    … …  
    361366
    362367        // Check access to the message and mark unread.
    363         if ( messages_check_thread_access( $id ) ) {
     368        if ( messages_check_thread_access( $id ) || bp_current_user_can( 'bp_moderate' ) ) {
    364369                messages_mark_thread_unread( $id );
    365370                bp_core_add_message( __( 'Message marked unread.', 'buddypress' ) );
    … …  
    405410        // Make sure the user has access to all notifications before managing them.
    406411        foreach ( $messages as $message ) {
    407                 if ( ! messages_check_thread_access( $message ) ) {
     412                if ( ! messages_check_thread_access( $message ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    408413                        bp_core_add_message( __( 'There was a problem managing your messages.', 'buddypress' ), 'error' );
    409414                        bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
  • trunk/src/bp-messages/bp-messages-cache.php

    r10417 r11578  
    7575 * @param int|array $thread_ids If single thread, the thread ID.
    7676 *                              Otherwise, an array of thread IDs.
     77 * @param int       $user_id    ID of the user that the threads were deleted for.
    7778 */
    78 function bp_messages_clear_cache_on_message_delete( $thread_ids ) {
     79function bp_messages_clear_cache_on_message_delete( $thread_ids, $user_id ) {
    7980        // Delete thread and thread recipient cache.
    8081        foreach( (array) $thread_ids as $thread_id ) {
    … …  
    8485
    8586        // Delete unread count for logged-in user.
    86         wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     87        wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    8788}
    88 add_action( 'messages_delete_thread', 'bp_messages_clear_cache_on_message_delete' );
     89add_action( 'messages_delete_thread', 'bp_messages_clear_cache_on_message_delete', 10, 2 );
    8990
    9091/**
  • trunk/src/bp-messages/bp-messages-functions.php

    r11562 r11578  
    255255
    256256        if ( empty( $user_id ) ) {
    257                 $user_id = bp_loggedin_user_id();
     257                $user_id =
     258                        bp_displayed_user_id() ?
     259                        bp_displayed_user_id() :
     260                        bp_loggedin_user_id();
    258261        }
    259262
    … …  
    381384 */
    382385function messages_get_unread_count( $user_id = 0 ) {
    383         if ( empty( $user_id ) ) {
    384                 $user_id = bp_loggedin_user_id();
    385         }
    386 
    387386        return BP_Messages_Thread::get_inbox_count( $user_id );
    388387}
  • trunk/src/bp-messages/bp-messages-notifications.php

    r11022 r11578  
    172172        global $thread_template;
    173173
     174        /*
     175         * Only run on the logged-in user's profile.
     176         * If an admin visits a thread, it shouldn't change the read status.
     177         */
     178        if ( ! bp_is_my_profile() ) {
     179                return;
     180        }
     181
    174182        // Get unread PM notifications for the user.
    175183        $new_pm_notifications = BP_Notifications_Notification::get( array(
  • trunk/src/bp-messages/bp-messages-star.php

    r10417 r11578  
    4242function bp_messages_is_message_starred( $mid = 0, $user_id = 0 ) {
    4343        if ( empty( $user_id ) ) {
    44                 $user_id = bp_loggedin_user_id();
     44                $user_id = bp_displayed_user_id();
    4545        }
    4646
    … …  
    255255                'thread_id'  => 0,
    256256                'message_id' => 0,
    257                 'user_id'    => bp_loggedin_user_id(),
     257                'user_id'    => bp_displayed_user_id(),
    258258                'bulk'       => false
    259259        ) );
    … …  
    398398
    399399        // Redirect back to previous screen.
    400         $redirect = wp_get_referer() ? wp_get_referer() : bp_loggedin_user_domain() . bp_get_messages_slug();
     400        $redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain() . bp_get_messages_slug();
    401401        bp_core_redirect( $redirect );
    402402        die();
  • trunk/src/bp-messages/bp-messages-template.php

    r11576 r11578  
    5959        // User ID
    6060        // @todo displayed user for moderators that get this far?
    61         $user_id = bp_loggedin_user_id();
     61        $user_id = bp_displayed_user_id();
    6262
    6363        // Search Terms.
    … …  
    305305                 * @param int    $thread_id ID of the thread.
    306306                 */
    307                 return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id ), $thread_id );
     307                return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id ), $thread_id );
    308308        }
    309309
    … …  
    330330                 * @param string $value Text indicating action being executed.
    331331                 */
    332                 return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ) );
     332                return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ) );
    333333        }
    334334
    … …  
    362362
    363363                // Base unread URL.
    364                 $url = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
     364                $url = trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
    365365
    366366                // Add the args to the URL.
    … …  
    409409
    410410                // Base read URL.
    411                 $url = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
     411                $url = trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
    412412
    413413                // Add the args to the URL.
    … …  
    697697/**
    698698 * Output the unread messages count for the current inbox.
    699  */
    700 function bp_total_unread_messages_count() {
    701         echo bp_get_total_unread_messages_count();
     699 *
     700 * @since 2.6.x Added $user_id argument.
     701 *
     702 * @param int $user_id The user ID.
     703 *
     704 * @return int $unread_count Total inbox unread count for user.
     705 */
     706function bp_total_unread_messages_count( $user_id = 0 ) {
     707        echo bp_get_total_unread_messages_count( $user_id );
    702708}
    703709        /**
    704710         * Get the unread messages count for the current inbox.
    705711         *
    706          * @return int
    707          */
    708         function bp_get_total_unread_messages_count() {
     712         * @since 2.6.x Added $user_id argument.
     713         *
     714         * @param int $user_id The user ID.
     715         *
     716         * @return int $unread_count Total inbox unread count for user.
     717         */
     718        function bp_get_total_unread_messages_count( $user_id = 0 ) {
    709719
    710720                /**
    … …  
    715725                 * @param int $value Unread messages count for the current inbox.
    716726                 */
    717                 return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count() );
     727                return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count( $user_id ) );
    718728        }
    719729
    … …  
    825835                 * @param string $value The form action.
    826836                 */
    827                 return apply_filters( 'bp_get_messages_form_action', trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' . bp_action_variable( 0 ) ) );
     837                return apply_filters( 'bp_get_messages_form_action', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' . bp_action_variable( 0 ) ) );
    828838        }
    829839
    … …  
    11541164                 * @param string $value Text indicating action being executed.
    11551165                 */
    1156                 return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/delete/' . $messages_template->thread->id, 'messages_delete_thread' ) );
     1166                return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/notices/delete/' . $messages_template->thread->id, 'messages_delete_thread' ) );
    11571167        }
    11581168
    … …  
    11721182
    11731183                if ( 1 === (int) $messages_template->thread->is_active ) {
    1174                         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
     1184                        $link = wp_nonce_url( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
    11751185                } else {
    1176                         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
     1186                        $link = wp_nonce_url( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
    11771187                }
    11781188
    … …  
    19251935                 * @param string $value Text indicating action being executed.
    19261936                 */
    1927                 return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) );
     1937                return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) );
    19281938        }
    19291939
  • trunk/src/bp-messages/classes/class-bp-messages-component.php

    r11577 r11578  
    146146                // Only grab count if we're on a user page and current user has access.
    147147                if ( bp_is_user() && bp_user_has_access() ) {
    148                         $count    = bp_get_total_unread_messages_count();
     148                        $count    = bp_get_total_unread_messages_count( bp_displayed_user_id() );
    149149                        $class    = ( 0 === $count ) ? 'no-count' : 'count';
    150150                        $nav_name = sprintf(
    … …  
    253253
    254254                        // Unread message count.
    255                         $count = messages_get_unread_count();
     255                        $count = messages_get_unread_count( bp_loggedin_user_id() );
    256256                        if ( !empty( $count ) ) {
    257257                                $title = sprintf(
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r11447 r11578  
    145145                }
    146146
     147                $user_id =
     148                        bp_displayed_user_id() ?
     149                        bp_displayed_user_id() :
     150                        bp_loggedin_user_id();
     151
    147152                // Merge $args with our defaults.
    148153                $r = wp_parse_args( $args, array(
    149                         'user_id'           => bp_loggedin_user_id(),
     154                        'user_id'           => $user_id,
    150155                        'update_meta_cache' => true
    151156                ) );
    … …  
    614619                global $wpdb;
    615620
     621                $user_id =
     622                        bp_displayed_user_id() ?
     623                        bp_displayed_user_id() :
     624                        bp_loggedin_user_id();
     625
    616626                $bp     = buddypress();
    617                 $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ) );
     627                $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) );
    618628
    619629                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    620                 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     630                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    621631
    622632                /**
    … …  
    644654                global $wpdb;
    645655
     656                $user_id =
     657                        bp_displayed_user_id() ?
     658                        bp_displayed_user_id() :
     659                        bp_loggedin_user_id();
     660
    646661                $bp     = buddypress();
    647                 $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ) );
     662                $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) );
    648663
    649664                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    650                 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     665                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    651666
    652667                /**
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/messages/messages-loop.php

    r11166 r11578  
    5151        do_action( 'bp_before_member_messages_threads' ); ?>
    5252
    53         <form action="<?php echo bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() ?>/bulk-manage/" method="post" id="messages-bulk-management">
     53        <form action="<?php echo bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() ?>/bulk-manage/" method="post" id="messages-bulk-management">
    5454
    5555                <table id="message-threads" class="messages-notices">
Note: See TracChangeset for help on using the changeset viewer.