bp_messages_get_avatars (整数thread_id美元,整数user_id美元)
通过线程id获取消息线程头像。
描述
参数
- thread_id美元
-
(整数)(必需)消息线程id。
- user_id美元
-
(整数)(必需)用户id。
返回
(数组)
源
文件:bp-messages / bp-messages-functions.php
函数bp_messages_get_avatars($thread_id, $user_id) {global $wpdb;If(空($user_id)) {$user_id = bp_loggedin_user_id();} $avatar_urls = array();数组$ avatars_user_ids = ();$thread_messages = BP_Messages_Thread::get_messages($thread_id, null, 99999999);$ receivers = BP_Messages_Thread::get_recipients_for_thread($thread_id);If ($message->sender_id !== $user_id) {If (count($avatars_user_ids) >= 2){继续;} if (!In_array ($message->sender_id, $avatars_user_ids)) {$avatars_user_ids[] = $message->sender_id;}}}} else {unset($ receivers [$user_id]); $avatars_user_ids[] = current( $recepients )->user_id; } if ( count( $recepients ) > 2 && count( $avatars_user_ids ) < 2 ) { unset( $recepients[ $user_id ] ); if ( count( $avatars_user_ids ) === 0 ) { $avatars_user_ids = array_slice( array_keys( $recepients ), 0, 2 ); } else { unset( $recepients[ $avatars_user_ids[0] ] ); $avatars_user_ids = array_merge( $avatars_user_ids, array_slice( array_keys( $recepients ), 0, 1 ) ); } } if ( ! empty( $avatars_user_ids ) ) { $avatars_user_ids = array_reverse( $avatars_user_ids ); foreach ( (array) $avatars_user_ids as $avatar_user_id ) { $avatar_urls[] = array( 'url' => esc_url( bp_core_fetch_avatar( array( 'item_id' => $avatar_user_id, 'object' => 'user', 'type' => 'thumb', 'width' => BP_AVATAR_THUMB_WIDTH, 'height' => BP_AVATAR_THUMB_HEIGHT, 'html' => false, ) ) ), 'name' => esc_attr( bp_core_get_user_displayname( $avatar_user_id ) ) ); } } $first_message = end( $thread_messages ); $first_message_id = ( ! empty( $first_message ) ? $first_message->id : false ); $group_id = ( isset( $first_message_id ) ) ? (int) bp_messages_get_meta( $first_message_id, 'group_id', true ) : 0; if ( ! empty( $first_message_id ) && ! empty( $group_id ) ) { $message_from = bp_messages_get_meta( $first_message_id, 'message_from', true ); // group $message_users = bp_messages_get_meta( $first_message_id, 'group_message_users', true ); // all - individual $message_type = bp_messages_get_meta( $first_message_id, 'group_message_type', true ); // open - private if ( 'group' === $message_from && 'all' === $message_users && 'open' === $message_type ) { if ( bp_is_active( 'groups' ) ) { $group_name = bp_get_group_name( groups_get_group( $group_id ) ); $group_avatar = array( 'url' => bp_core_fetch_avatar( array( 'item_id' => $group_id, 'object' => 'group', 'type' => 'full', 'avatar_dir' => 'group-avatars', 'alt' => sprintf( __( 'Group logo of %s', 'buddyboss' ), $group_name ), 'title' => $group_name, 'html' => false, ) ), 'name' => $group_name ); } else { /** * * Filters table prefix. * * @param int $wpdb->base_prefix table prefix * * @since BuddyBoss 1.4.7 */ $prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix ); $groups_table = $prefix . 'bp_groups'; $group_name = $wpdb->get_var( "SELECT `name` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" ); // db call ok; no-cache ok; $group_avatar = buddypress()->plugin_url . 'bp-core/images/mystery-group.png'; $legacy_group_avatar_name = '-groupavatar-full'; $legacy_user_avatar_name = '-avatar2'; if ( ! empty( $group_name ) ) { $directory = 'group-avatars'; $avatar_size = '-bpfull'; $avatar_folder_dir = bp_core_avatar_upload_path() . '/' . $directory . '/' . $group_id; $avatar_folder_url = bp_core_avatar_url() . '/' . $directory . '/' . $group_id; $avatar = bp_core_get_group_avatar( $legacy_user_avatar_name, $legacy_group_avatar_name, $avatar_size, $avatar_folder_dir, $avatar_folder_url ); if ( '' !== $avatar ) { $group_avatar = array( 'url' => $avatar, 'name' => $group_name ); } } } if ( ! empty( $group_avatar ) ) { $avatar_urls = array( $group_avatar ); } } } /** * * Filters the avatar url array to be applied in message thread. * * @param array $avatar_urls avatar urls in * @param int $thread_id Message thread id * @param int $user_id user id * * @since BuddyBoss 1.4.7 */ return apply_filters( 'bp_messages_get_avatars', $avatar_urls, $thread_id, $user_id ); }
更新日志
版本 | 描述 |
---|---|
BuddyBoss 1.4.7 | 介绍了。 |