thread = new BP_Messages_Thread( $thread_id, $order, $args ); $this->message_count = count( $this->thread->messages ); } /** * Whether there are messages available in the loop. * * @see bp_thread_has_messages() * * @return bool True if there are items in the loop, otherwise false. */ public function has_messages() { return ( ! empty( $this->message_count ) ); } /** * Set up the next message and iterate index. * * @return BP_Messages_Message The next message to iterate over. */ public function next_message() { $this->current_message++; $this->message = $this->thread->messages[ $this->current_message ]; return $this->message; } /** * Rewind the messages and reset message index. */ public function rewind_messages() { $this->current_message = -1; if ( $this->message_count > 0 ) { $this->message = $this->thread->messages[0]; } } /** * Whether there are messages left in the loop to iterate over. * * This method is used by {@link bp_thread_messages()} as part of the * while loop that controls iteration inside the messages loop, eg: * while ( bp_thread_messages() ) { ... * * @see bp_thread_messages() * * @return bool True if there are more messages to show, otherwise false. */ public function messages() { if ( ( $this->current_message + 1 ) < $this->message_count ) { return true; } elseif ( ( $this->current_message + 1 ) === $this->message_count ) { /** * Fires when at the end of messages to iterate over. * * @since 1.1.0 */ do_action( 'thread_loop_end' ); // Do some cleaning up after the loop. $this->rewind_messages(); } $this->in_the_loop = false; return false; } /** * Set up the current message inside the loop. * * Used by {@link bp_thread_the_message()} to set up the current * message data while looping, so that template tags used during * that iteration make reference to the current message. * * @see bp_thread_the_message() */ public function the_message() { $this->in_the_loop = true; $this->message = $this->next_message(); // Loop has just started. if ( 0 === $this->current_message ) { /** * Fires if at the start of the message loop. * * @since 1.1.0 */ do_action( 'thread_loop_start' ); } } }