esc_html__('在文章/帖子侧栏显示当前内容作者信息。', 'aksrt'), 'classname' => 'widget_aksrt_author_card', ] ); } public function widget($args, $instance): void { $author_id = 0; if (is_singular()) { $post = get_queried_object(); if ($post instanceof \WP_Post) { $author_id = (int) $post->post_author; } } if ($author_id <= 0 && !empty($instance['user_id'])) { $author_id = (int) $instance['user_id']; } if ($author_id <= 0) { return; } $user = get_userdata($author_id); if (!$user) { return; } $show_bg = !isset($instance['show_img_bg']) || !empty($instance['show_img_bg']); $show_stats = !isset($instance['show_stats']) || !empty($instance['show_stats']); $avatar = function_exists('aksrt_get_avatar_url') ? aksrt_get_avatar_url($author_id, ['size' => 120]) : get_avatar_url($author_id, ['size' => 120]); $home = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($author_id) : get_author_posts_url($author_id); $bio = get_user_meta($author_id, 'description', true); if (!is_string($bio) || $bio === '') { $bio = (string) $user->description; } $cover = (string) get_user_meta($author_id, 'aksrt_background_image', true); if ($cover === '') { $cover = get_theme_file_uri('assets/img/person_background.png'); } $post_count = count_user_posts($author_id, 'post', true); $followers = 0; if (class_exists('\AKSRT\User\Follow')) { $followers = \AKSRT\User\Follow::get_instance()->get_follower_count($author_id); } $name_html = function_exists('aksrt_get_user_name') ? aksrt_get_user_name(['id' => $author_id, 'follow' => false, 'class' => 'flex ac jc']) : '' . esc_html($user->display_name) . ''; echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $card_cls = 'aksrt-author-card user-card author' . ($show_bg ? ' has-cover' : ''); echo '
'; if ($show_bg) { $bg = $cover !== '' ? ' style="background-image:url(' . esc_url($cover) . ')"' : ''; echo '
'; } echo '
'; echo '
'; $ph = get_template_directory_uri() . '/assets/img/placeholder.svg'; echo ''; echo '
' . $name_html . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($bio !== '') { echo '
' . esc_html(wp_trim_words($bio, 28)) . '
'; } if ($show_stats) { echo '
'; echo '' . esc_html((string) $post_count) . '' . esc_html__('文章', 'aksrt') . ''; echo '' . esc_html((string) $followers) . '' . esc_html__('粉丝', 'aksrt') . ''; echo '
'; } $cuid = get_current_user_id(); $show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']); echo '
'; if ($show_follow && $cuid > 0 && $cuid !== $author_id && class_exists('\AKSRT\User\Follow')) { $following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $author_id); $label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt'); echo ''; } echo '' . esc_html__('查看主页', 'aksrt') . ''; echo '
'; echo '
'; // .user-content echo '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } public function form($instance): void { ?>



max(0, (int) ($new_instance['user_id'] ?? 0)), 'show_img_bg' => !empty($new_instance['show_img_bg']) ? 1 : 0, 'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0, 'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0, ]; } }