__('在侧栏显示当前登录用户或指定用户的信息卡片。', '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 '
' . esc_html(wp_trim_words($bio, 20)) . '
'; } // 统计 if ($show_stats) { echo '