BP_REST_消息_端点::BP_REST_消息_获取_化身(intthread_id美元,int$user\u id)
获取消息线程的头像。
描述
参数
- thread_id美元
-
(int)(必选)线程ID。
- $user\u id
-
(int)(必选)用户ID。
返回
(混合|无效)
来源
文件:bp messages/classes/class-bp-rest-messages-endpoint.php
Public function bp_rest_messages_get_avatars($thread_id, $user_id = 0) {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( 'full' => bp_core_fetch_avatar( array( 'item_id' => $avatar_user_id, 'html' => false, 'type' => 'full', 'object' => 'user', ) ), 'thumb' => bp_core_fetch_avatar( array( 'item_id' => $avatar_user_id, 'html' => false, 'object' => 'user', ) ), ); } } $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( 'thumb' => bp_core_fetch_avatar( array( 'html' => false, 'object' => 'group', 'item_id' => $group_id, 'type' => 'thumb', ) ), 'full' => bp_core_fetch_avatar( array( 'html' => false, 'object' => 'group', 'item_id' => $group_id, 'type' => 'full', ) ), ); } else { $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( 'thumb' => $avatar, 'full' => $avatar, ); } } } if ( ! empty( $group_avatar ) ) { $avatar_urls = array( $group_avatar ); } } } return apply_filters( 'bp_rest_messages_get_avatars', $avatar_urls, $thread_id, $user_id ); }