BP_Messages_Thread::populate( int $thread_id, string $order = 'DESC', array $args = array() )
Populate method.
Description
Used in constructor.
Parameters
- $thread_id
-
(Required) The message thread ID.
- $order
-
(Optional) The order to sort the messages. Either 'ASC' or 'DESC'.
Default value: 'DESC'
- $args
-
(Optional) Array of arguments
Default value: array()
Return
(bool) False on failure.
Source
File: bp-messages/classes/class-bp-messages-thread.php
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | public function populate( $thread_id = 0, $order = 'DESC' , $args = array () ) { if ( 'ASC' !== $order || 'DESC' !== $order ) { $order = 'DESC' ; } $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(); // Merge $args with our defaults. $r = wp_parse_args( $args , array ( 'user_id' => $user_id , 'update_meta_cache' => true, 'per_page' => apply_filters( 'bp_messages_default_per_page' , 10), 'before' => null ) ); $this ->messages_order = $order ; $this ->messages_perpage = $r [ 'per_page' ]; $this ->messages_before = $r [ 'before' ]; $this ->thread_id = (int) $thread_id ; // get the last message deleted for the thread static ::get_user_last_deleted_message( $this ->thread_id ); // Get messages for thread. $this ->messages = self::get_messages( $this ->thread_id, $this ->messages_before, $this ->messages_perpage, $this ->messages_order ); $this ->last_message = self::get_last_message( $this ->thread_id ); $this ->total_messages = self::get_messages_count( $this ->thread_id ); if ( empty ( $this ->messages ) || is_wp_error( $this ->messages ) ) { return false; } $this ->last_message_id = $this ->last_message->id; $this ->last_message_date = $this ->last_message->date_sent; $this ->last_sender_id = $this ->last_message->sender_id; $this ->last_message_subject = $this ->last_message->subject; $this ->last_message_content = $this ->last_message->message; $this ->first_message_date = self::get_messages_started( $this ->thread_id );; foreach ( ( array ) $this ->messages as $key => $message ) { $this ->sender_ids[ $message ->sender_id ] = $message ->sender_id; } // Fetch the recipients. $this ->recipients = $this ->get_recipients(); // Get the unread count for the logged in user. if ( isset( $this ->recipients[ $r [ 'user_id' ] ] ) ) { $this ->unread_count = $this ->recipients[ $r [ 'user_id' ] ]->unread_count; } // Grab all message meta. if ( true === (bool) $r [ 'update_meta_cache' ] ) { bp_messages_update_meta_cache( wp_list_pluck( $this ->messages, 'id' ) ); } /** * Fires after a BP_Messages_Thread object has been populated. * * @since BuddyPress 2.2.0 * * @param BP_Messages_Thread $this Message thread object. */ do_action( 'bp_messages_thread_post_populate' , $this ); } |
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.