Skip to:
Content

BuddyPress.org

Ticket #6412: 6412.diff

File 6412.diff, 15.1 KB (added by pareshradadiya, 11 years ago)

Proposed fix

  • src/bp-messages/bp-messages-functions.php

     
    4040
    4141        // Parse the default arguments
    4242        $r = bp_parse_args( $args, array(
    43                 'sender_id'  => bp_loggedin_user_id(),
     43                'sender_id'  => bp_displayed_user_id(),
    4444                'thread_id'  => false,   // false for a new message, thread id for a reply to a thread.
    4545                'recipients' => array(), // Can be an array of usernames, user_ids or mixed.
    4646                'subject'    => false,
     
    328328 */
    329329function messages_get_unread_count( $user_id = 0 ) {
    330330        if ( empty( $user_id ) ) {
    331                 $user_id = bp_loggedin_user_id();
     331                $user_id = bp_displayed_user_id();
    332332        }
    333333
    334334        return BP_Messages_Thread::get_inbox_count( $user_id );
  • src/bp-messages/bp-messages-loader.php

     
    143143                        'name'                    => $nav_name,
    144144                        'slug'                    => $this->slug,
    145145                        'position'                => 50,
    146                         'show_for_displayed_user' => false,
     146                        'show_for_displayed_user' =>  bp_core_can_edit_settings(),
    147147                        'screen_function'         => 'messages_screen_inbox',
    148148                        'default_subnav_slug'     => 'inbox',
    149149                        'item_css_id'             => $this->id
  • src/bp-messages/bp-messages-screens.php

     
    9393                        if ( isset( $_POST['send-notice'] ) ) {
    9494                                if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) {
    9595                                        bp_core_add_message( __( 'Notice sent successfully!', 'buddypress' ) );
    96                                         bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/' );
     96                                        bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox/' );
    9797                                } else {
    9898                                        bp_core_add_message( __( 'There was an error sending that notice. Please try again.', 'buddypress' ), 'error' );
    9999                                }
     
    120120                                // Send the message
    121121                                if ( ! empty( $thread_id ) ) {
    122122                                        bp_core_add_message( __( 'Message sent successfully!', 'buddypress' ) );
    123                                         bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/' );
     123                                        bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/' );
    124124                                } else {
    125125                                        bp_core_add_message( __( 'There was an error sending that message. Please try again.', 'buddypress' ), 'error' );
    126126                                }
     
    223223                                bp_core_add_message( __('Notice deleted.', 'buddypress') );
    224224                        }
    225225                }
    226                 bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices' ) );
     226                bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/notices' ) );
    227227        }
    228228
    229229        if ( bp_action_variables() ) {
  • src/bp-messages/bp-messages-star.php

     
    3636 */
    3737function bp_messages_is_message_starred( $mid = 0, $user_id = 0 ) {
    3838        if ( empty( $user_id ) ) {
    39                 $user_id = bp_loggedin_user_id();
     39                $user_id = bp_displayed_user_id();
    4040        }
    4141
    4242        if ( empty( $mid ) ) {
     
    8989         */
    9090        function bp_get_the_message_star_action_link( $args = array() ) {
    9191                $r = bp_parse_args( $args, array(
    92                         'user_id'      => bp_loggedin_user_id(),
     92                        'user_id'      => bp_displayed_user_id(),
    9393                        'thread_id'    => 0,
    9494                        'message_id'   => (int) bp_get_the_thread_message_id(),
    9595                        'url_only'     => false,
     
    108108                }
    109109
    110110                // get user domain
    111                 if ( $r['user_id'] == bp_loggedin_user_id() ) {
     111                if ( $r['user_id'] == bp_displayed_user_id() ) {
    112112                        $user_domain = bp_loggedin_user_domain();
    113113                } elseif ( $r['user_id'] == bp_displayed_user_domain() ) {
    114114                        $user_domain = bp_displayed_user_domain();
     
    226226                'action'     => 'star',
    227227                'thread_id'  => 0,
    228228                'message_id' => 0,
    229                 'user_id'    => bp_loggedin_user_id(),
     229                'user_id'    => bp_displayed_user_id(),
    230230                'bulk'       => false
    231231        ) );
    232232
     
    330330        $r['user_id'] = 0;
    331331        $r['meta_query'] = array( array(
    332332                'key'   => 'starred_by_user',
    333                 'value' => bp_loggedin_user_id()
     333                'value' => bp_displayed_user_id()
    334334        ) );
    335335
    336336        return $r;
  • src/bp-messages/bp-messages-template.php

     
    144144                        'page_arg'     => 'mpage',
    145145                        'box'          => 'inbox',
    146146                        'type'         => 'all',
    147                         'user_id'      => bp_loggedin_user_id(),
     147                        'user_id'      => bp_displayed_user_id(),
    148148                        'max'          => false,
    149149                        'search_terms' => '',
    150150                        'meta_query'   => array(),
     
    322322                        if ( count($this->thread->messages) > 1 ) {
    323323                                if ( 'inbox' == $this->box ) {
    324324                                        foreach ( (array) $this->thread->messages as $key => $message ) {
    325                                                 if ( bp_loggedin_user_id() != $message->sender_id ) {
     325                                                if ( bp_displayed_user_id() != $message->sender_id ) {
    326326                                                        $last_message_index = $key;
    327327                                                        break;
    328328                                                }
     
    330330
    331331                                } elseif ( 'sentbox' == $this->box ) {
    332332                                        foreach ( (array) $this->thread->messages as $key => $message ) {
    333                                                 if ( bp_loggedin_user_id() == $message->sender_id ) {
     333                                                if ( bp_displayed_user_id() == $message->sender_id ) {
    334334                                                        $last_message_index = $key;
    335335                                                        break;
    336336                                                }
     
    400400
    401401        // Parse the arguments
    402402        $r = bp_parse_args( $args, array(
    403                 'user_id'      => bp_loggedin_user_id(),
     403                'user_id'      => bp_displayed_user_id(),
    404404                'box'          => $default_box,
    405405                'per_page'     => 10,
    406406                'max'          => false,
     
    641641                 *
    642642                 * @param string $value permalink of a particular thread.
    643643                 */
    644                 return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id ) );
     644                return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id ) );
    645645        }
    646646
    647647/**
     
    666666                 * @param string $value URL for deleting the current thread.
    667667                 * @param string $value Text indicating action being executed.
    668668                 */
    669                 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' ) );
     669                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' ) );
    670670        }
    671671
    672672/**
     
    698698                );
    699699
    700700                // Base unread URL.
    701                 $url = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
     701                $url = trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
    702702
    703703                // Add the args to the URL.
    704704                $url = add_query_arg( $args, $url );
     
    745745                );
    746746
    747747                // Base read URL.
    748                 $url = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
     748                $url = trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
    749749
    750750                // Add the args to the URL.
    751751                $url = add_query_arg( $args, $url );
     
    11551155                 *
    11561156                 * @param string The form action.
    11571157                 */
    1158                 return apply_filters( 'bp_get_messages_form_action', trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' . bp_action_variable( 0 ) ) );
     1158                return apply_filters( 'bp_get_messages_form_action', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' . bp_action_variable( 0 ) ) );
    11591159        }
    11601160
    11611161/**
     
    14741474                 * @param string $value URL for deleting the current notice.
    14751475                 * @param string $value Text indicating action being executed.
    14761476                 */
    1477                 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' ) );
     1477                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' ) );
    14781478        }
    14791479
    14801480/**
     
    14921492                global $messages_template;
    14931493
    14941494                if ( 1 === (int) $messages_template->thread->is_active ) {
    1495                         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
     1495                        $link = wp_nonce_url( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
    14961496                } else {
    1497                         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
     1497                        $link = wp_nonce_url( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
    14981498                }
    14991499
    15001500                /**
     
    15761576                return false;
    15771577        }
    15781578
    1579         $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true );
     1579        $closed_notices = bp_get_user_meta( bp_displayed_user_id(), 'closed_notices', true );
    15801580
    15811581        if ( empty( $closed_notices ) ) {
    15821582                $closed_notices = array();
     
    16211621                 *
    16221622                 * @param string $value URL for the Private Message link in member profile headers.
    16231623                 */
    1624                 return apply_filters( 'bp_get_send_private_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( bp_displayed_user_id() ) ) );
     1624                return apply_filters( 'bp_get_send_private_message_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( bp_displayed_user_id() ) ) );
    16251625        }
    16261626
    16271627/**
     
    21262126                $recipient_links = array();
    21272127
    21282128                foreach( (array) $thread_template->thread->recipients as $recipient ) {
    2129                         if ( (int) $recipient->user_id !== bp_loggedin_user_id() ) {
     2129                        if ( (int) $recipient->user_id !== bp_displayed_user_id() ) {
    21302130                                $recipient_link = bp_core_get_userlink( $recipient->user_id );
    21312131
    21322132                                if ( empty( $recipient_link ) ) {
     
    22062206                $classes[] = 'sent-by-' . intval( $thread_template->message->sender_id );
    22072207
    22082208                // Whether the sender is the same as the logged-in user
    2209                 if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) {
     2209                if ( bp_displayed_user_id() == $thread_template->message->sender_id ) {
    22102210                        $classes[] = 'sent-by-me';
    22112211                }
    22122212
     
    24052405                 * @param string $value URL for deleting the current thread.
    24062406                 * @param string $value Text indicating action being executed.
    24072407                 */
    2408                 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' ) );
     2408                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' ) );
    24092409        }
    24102410
    24112411/**
  • src/bp-messages/classes/class-bp_messages-thread.php

     
    167167                $this->recipients = $this->get_recipients();
    168168
    169169                // Get the unread count for the logged in user
    170                 if ( isset( $this->recipients[bp_loggedin_user_id()] ) ) {
    171                         $this->unread_count = $this->recipients[bp_loggedin_user_id()]->unread_count;
     170                if ( isset( $this->recipients[bp_displayed_user_id()] ) ) {
     171                        $this->unread_count = $this->recipients[bp_displayed_user_id()]->unread_count;
    172172                }
    173173
    174174                // Grab all message meta
     
    316316
    317317                // Mark messages as deleted
    318318                //
    319                 // @todo the reliance on bp_loggedin_user_id() sucks for plugins
     319                // @todo the reliance on bp_displayed_user_id() sucks for plugins
    320320                //       refactor this method to accept a $user_id parameter
    321                 $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() ) );
     321                $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_displayed_user_id() ) );
    322322
    323323                // Get the message ids in order to pass to the action
    324324                $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     
    555555                global $wpdb;
    556556
    557557                $bp  = buddypress();
    558                 $sql = $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 );
     558                $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_displayed_user_id(), $thread_id );
    559559                $wpdb->query($sql);
    560560
    561561                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    562                 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     562                wp_cache_delete( bp_displayed_user_id(), 'bp_messages_unread_count' );
    563563        }
    564564
    565565        /**
     
    573573                global $wpdb;
    574574
    575575                $bp  = buddypress();
    576                 $sql = $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 );
     576                $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_displayed_user_id(), $thread_id );
    577577                $wpdb->query($sql);
    578578
    579579                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    580                 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     580                wp_cache_delete( bp_displayed_user_id(), 'bp_messages_unread_count' );
    581581        }
    582582
    583583        /**
     
    628628                        return false;
    629629                }
    630630
    631                 return in_array( bp_loggedin_user_id(), $sender_ids );
     631                return in_array( bp_displayed_user_id(), $sender_ids );
    632632        }
    633633
    634634        /**
     
    663663                global $wpdb;
    664664
    665665                if ( empty( $user_id ) ) {
    666                         $user_id = bp_loggedin_user_id();
     666                        $user_id = bp_displayed_user_id();
    667667                }
    668668
    669669                $unread_count = wp_cache_get( $user_id, 'bp_messages_unread_count' );
     
    698698         */
    699699        public static function check_access( $thread_id, $user_id = 0 ) {
    700700                if ( empty( $user_id ) ) {
    701                         $user_id = bp_loggedin_user_id();
     701                        $user_id = bp_displayed_user_id();
    702702                }
    703703
    704704                $recipients = self::get_recipients_for_thread( $thread_id );