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']); $show_posts = !isset($instance['show_posts']) || !empty($instance['show_posts']); $post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini')); if (!in_array($post_style, ['card', 'mini'], true)) { // Legacy show_img checkbox from zibll. if (isset($instance['show_img'])) { $post_style = !empty($instance['show_img']) ? 'card' : 'mini'; } else { $post_style = 'mini'; } } $limit = max(0, min(12, (int) ($instance['limit'] ?? 6))); $orderby = sanitize_key((string) ($instance['orderby'] ?? 'date')); // Zibll button palettes / button_2 type (shown only when viewer is the author). $show_button = !isset($instance['show_button']) || !empty($instance['show_button']); $btn1_text = (string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt')); $btn2_text = (string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt')); $btn1_class = WidgetUserCard::sanitize_palette((string) ($instance['button_1_class'] ?? 'jb-pink'), 'jb-pink'); $btn2_class = WidgetUserCard::sanitize_palette((string) ($instance['button_2_class'] ?? 'jb-blue'), 'jb-blue'); $btn2_type = (string) ($instance['button_2'] ?? 'center'); $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_cover', true); if ($cover === '') { $cover = (string) get_user_meta($author_id, 'custom_avatar_cover', true); } $post_count = count_user_posts($author_id, 'post', true); $topic_count = post_type_exists('aksrt_forum_topic') ? count_user_posts($author_id, 'aksrt_forum_topic', true) : 0; $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) . ''; $affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => '']; echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base); if ($title !== '') { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $card_cls = 'aksrt-author-card user-card author zib-widget' . ($show_bg ? ' has-cover' : '') . $affix['class']; echo '
render_common_form_section($instance); ?> update_common_fields($new_instance, $old_instance, [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'user_id' => 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, 'show_badge' => !empty($new_instance['show_badge']) ? 1 : 0, 'show_posts' => !empty($new_instance['show_posts']) ? 1 : 0, 'show_button' => !empty($new_instance['show_button']) ? 1 : 0, 'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))), 'post_style' => $post_style, 'orderby' => $orderby, 'button_1' => 'post', 'button_1_text'=> sanitize_text_field((string) ($new_instance['button_1_text'] ?? '')), 'button_1_class'=> WidgetUserCard::sanitize_palette((string) ($new_instance['button_1_class'] ?? 'jb-pink'), 'jb-pink'), 'button_2' => in_array((string) ($new_instance['button_2'] ?? 'center'), ['home', 'center'], true) ? $new_instance['button_2'] : 'center', 'button_2_text'=> sanitize_text_field((string) ($new_instance['button_2_text'] ?? '')), 'button_2_class'=> WidgetUserCard::sanitize_palette((string) ($new_instance['button_2_class'] ?? 'jb-blue'), 'jb-blue'), ]); } }