__('未登录显示登录入口;登录后显示当前用户卡片、签到、快捷按钮与更多文章。', 'aksrt')] ); } public function widget($args, $instance): void { $show_cover = !isset($instance['show_img_bg']) || !empty($instance['show_img_bg']); $show_stats = !empty($instance['show_stats']) || !isset($instance['show_stats']); $show_actions = !empty($instance['show_button']) || !isset($instance['show_button']); $show_checkin = !empty($instance['show_checkin']) || !isset($instance['show_checkin']); // zibll user widget forces show_posts=false; author widget enables it. // AKSRT keeps optional show_posts for current-user card (default off). $show_posts = !empty($instance['show_posts']); $loged_title = (string) ($instance['loged_title'] ?? __('Hi!请登录', 'aksrt')); $btn1_text = (string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt')); $btn2_text = (string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt')); $post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini')); if (!in_array($post_style, ['card', 'mini'], true)) { $post_style = 'mini'; } $limit = max(0, min(12, (int) ($instance['limit'] ?? 6))); $orderby = sanitize_key((string) ($instance['orderby'] ?? 'date')); // Fixed user id wins; else current user. $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(); } 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 } if ($user_id <= 0) { $this->render_guest($show_cover, $loged_title); echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return; } $user = get_userdata($user_id); if (!$user) { echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return; } $is_self = is_user_logged_in() && (int) get_current_user_id() === $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); $center_url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : $profile_url; $compose_url = home_url('/'); if (function_exists('get_pages')) { $pages = get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'templates/pages/page-submit.php', 'number' => 1]); if (!empty($pages[0])) { $compose_url = get_permalink($pages[0]); } } if ($compose_url === home_url('/') && function_exists('aksrt_get_user_center_url')) { $compose_url = aksrt_get_user_center_url('posts'); } $bio = get_user_meta($user_id, 'description', true); if (!is_string($bio) || $bio === '') { $bio = (string) $user->description; } $cover = (string) get_user_meta($user_id, 'aksrt_cover', true); if ($cover === '') { $cover = (string) get_user_meta($user_id, 'custom_avatar_cover', true); } $post_count = count_user_posts($user_id, 'post', true); $follower_count = 0; $following_count = 0; if (class_exists('\AKSRT\User\Follow')) { $follower_count = \AKSRT\User\Follow::get_instance()->get_follower_count($user_id); $following_count = \AKSRT\User\Follow::get_instance()->get_following_count($user_id); } $name_html = function_exists('aksrt_get_user_name') ? aksrt_get_user_name(['id' => $user_id, 'follow' => !$is_self, 'class' => 'flex ac jc']) : '' . esc_html($user->display_name) . ''; echo '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } private function render_guest(bool $show_cover, string $loged_title): void { $login = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(); $register = function_exists('aksrt_get_register_url') ? aksrt_get_register_url() : wp_registration_url(); $default_avatar = function_exists('get_avatar_url') ? get_avatar_url(0, ['size' => 144, 'force_default' => true]) : includes_url('images/blank.gif'); $oauth_html = ''; if (class_exists('\AKSRT\Auth\OAuth')) { $oauth = \AKSRT\Auth\OAuth::get_instance(); if (method_exists($oauth, 'render_social_buttons')) { $oauth_html = (string) $oauth->render_social_buttons(__('社交账号登录', 'aksrt')); } elseif (method_exists($oauth, 'get_login_buttons')) { $oauth_html = (string) $oauth->get_login_buttons(); } } echo ''; } public function form($instance): void { $post_style = sanitize_key((string) ($instance['post_style'] ?? 'mini')); if (!in_array($post_style, ['card', 'mini'], true)) { $post_style = 'mini'; } ?>
sanitize_text_field((string) ($new_instance['title'] ?? '')), 'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)), 'loged_title' => sanitize_text_field((string) ($new_instance['loged_title'] ?? '')), 'button_1_text' => sanitize_text_field((string) ($new_instance['button_1_text'] ?? '')), 'button_2_text' => sanitize_text_field((string) ($new_instance['button_2_text'] ?? '')), 'show_img_bg' => !empty($new_instance['show_img_bg']) ? 1 : 0, 'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0, 'show_button' => !empty($new_instance['show_button']) ? 1 : 0, 'show_checkin' => !empty($new_instance['show_checkin']) ? 1 : 0, 'show_posts' => !empty($new_instance['show_posts']) ? 1 : 0, 'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))), 'post_style' => $post_style, 'orderby' => $orderby, ]; } }