__('在侧栏显示当前登录用户或指定用户的信息卡片。', 'aksrt')] ); } public function widget($args, $instance): void { $title = !empty($instance['title']) ? $instance['title'] : ''; $show_stats = !empty($instance['show_stats']); $show_actions = !empty($instance['show_actions']); // 获取目标用户 $user_id = !empty($instance['user_id']) ? (int) $instance['user_id'] : 0; if ($user_id <= 0 && is_user_logged_in()) { $user_id = get_current_user_id(); } if ($user_id <= 0) return; $user = get_userdata($user_id); if (!$user) return; // 获取用户统计 $post_count = count_user_posts($user_id, 'post', true); $comment_count = get_comments(['user_id' => $user_id, 'count' => true]); $follower_count = 0; $following_count = 0; if (class_exists('AKSRT_Follow')) { $follower_count = AKSRT_Follow::get_instance()->get_follower_count($user_id); $following_count = AKSRT_Follow::get_instance()->get_following_count($user_id); } // 头像 $avatar_url = function_exists('aksrt_get_avatar_url') ? aksrt_get_avatar_url($user_id, ['size' => 144]) : get_avatar_url($user_id, ['size' => 144]); // 用户主页链接 $profile_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id); // 简介 $bio = get_user_meta($user_id, 'description', true); if (!$bio) $bio = $user->description ?: ''; echo $args['before_widget']; if ($title) { echo $args['before_title'] . esc_html($title) . $args['after_title']; } echo '
'; // 头像 echo '
'; echo ''; echo '' . esc_attr($user->display_name) . ''; echo ''; echo '
'; // 昵称 echo '

'; echo '' . esc_html($user->display_name) . ''; echo '

'; // 简介 if ($bio) { echo '

' . esc_html(wp_trim_words($bio, 20)) . '

'; } // 统计 if ($show_stats) { echo '
'; echo '
' . number_format_i18n($post_count) . '' . esc_html__('文章', 'aksrt') . '
'; echo '
' . number_format_i18n($follower_count) . '' . esc_html__('粉丝', 'aksrt') . '
'; echo '
' . number_format_i18n($following_count) . '' . esc_html__('关注', 'aksrt') . '
'; echo '
'; } // 操作按钮 if ($show_actions) { echo '
'; if (is_user_logged_in() && (int) get_current_user_id() === $user_id) { echo '' . esc_html__('个人主页', 'aksrt') . ''; if (function_exists('aksrt_get_user_center_url')) { echo '' . esc_html__('设置', 'aksrt') . ''; } } else { echo '' . esc_html__('查看主页', 'aksrt') . ''; } echo '
'; } echo '
'; echo $args['after_widget']; } public function form($instance): void { $title = !empty($instance['title']) ? $instance['title'] : ''; $user_id = !empty($instance['user_id']) ? (int) $instance['user_id'] : 0; $show_stats = !empty($instance['show_stats']); $show_actions = !empty($instance['show_actions']); ?>