BP_Messages_Box_Template::the_message_thread()
Set up the current thread inside the loop.
Description Description
Used by bp_message_thread() to set up the current thread data while looping, so that template tags used during that iteration make reference to the current thread.
See also See also
Source Source
File: bp-messages/classes/class-bp-messages-box-template.php
public function the_message_thread() {
$this->in_the_loop = true;
$this->thread = $this->next_thread();
if ( ! bp_is_current_action( 'notices' ) ) {
$last_message_index = count( $this->thread->messages ) - 1;
$this->thread->messages = array_reverse( (array) $this->thread->messages );
// Set up the last message data.
if ( count($this->thread->messages) > 1 ) {
if ( 'inbox' == $this->box ) {
foreach ( (array) $this->thread->messages as $key => $message ) {
if ( bp_loggedin_user_id() != $message->sender_id ) {
$last_message_index = $key;
break;
}
}
} elseif ( 'sentbox' == $this->box ) {
foreach ( (array) $this->thread->messages as $key => $message ) {
if ( bp_loggedin_user_id() == $message->sender_id ) {
$last_message_index = $key;
break;
}
}
}
}
$this->thread->last_message_id = $this->thread->messages[ $last_message_index ]->id;
$this->thread->last_message_date = $this->thread->messages[ $last_message_index ]->date_sent;
$this->thread->last_sender_id = $this->thread->messages[ $last_message_index ]->sender_id;
$this->thread->last_message_subject = $this->thread->messages[ $last_message_index ]->subject;
$this->thread->last_message_content = $this->thread->messages[ $last_message_index ]->message;
}
// Loop has just started.
if ( 0 == $this->current_thread ) {
/**
* Fires if at the start of the message thread loop.
*
* @since 1.5.0
*/
do_action( 'messages_box_loop_start' );
}
}