esc_html__('登录状态面板:未登录显示登录/注册按钮,已登录显示用户信息与快捷入口', 'aksrt'), 'customize_selective_refresh' => true, ] ); } /** * 前端渲染 */ public function widget($args, $instance): void { echo $args['before_widget']; $title = apply_filters('widget_title', $instance['title'] ?? '', $instance, $this->id_base); if ($title) { echo $args['before_title'] . esc_html($title) . $args['after_title']; } // 判断登录状态 if (is_user_logged_in()) { $this->render_logged_in(); } else { $this->render_logged_out($instance); } // 输出内联样式 & JS(仅在本 widget 实例加载时注入一次) $this->inline_assets(); echo $args['after_widget']; } // ========================================== // 已登录状态渲染(Zibll 风格用户卡片) // ========================================== private function render_logged_in(): void { $u = wp_get_current_user(); $avatar = get_avatar_url($u->ID, ['size' => 160]); $profile = aksrt_get_user_center_url(); $logout = aksrt_get_logout_url(home_url('/')); // 封面图:用户在用户中心上传的背景图 > 默认背景图 $cover = get_user_meta($u->ID, 'aksrt_background_image', true); if (! $cover) { $cover = get_theme_file_uri('assets/img/person_background.png'); } ?>
>
>
display_name); ?>
user_email); ?>
默认 $cover = ! empty($instance['cover']) ? $instance['cover'] : get_theme_file_uri('assets/img/widgets-original.png'); $avatar = get_avatar_url(0, ['size' => 160, 'default' => 'mystery']); $oauth_html = ''; if (function_exists('AKSRT_OAuth') && method_exists(AKSRT_OAuth::get_instance(), 'get_login_buttons')) { $oauth_html = AKSRT_OAuth::get_instance()->get_login_buttons(); } ?>
>
>

sanitize_text_field($new_instance['title'] ?? ''), 'cover' => esc_url_raw($new_instance['cover'] ?? ''), ]; } } // ============================================================ // 2. 分类目录小工具 // ============================================================ class AKSRT_Categories_Widget extends WP_Widget { public function __construct() { parent::__construct( 'aksrt_categories', esc_html__('AKSRT 分类目录', 'aksrt'), array( 'description' => esc_html__('以列表形式展示文章分类', 'aksrt'), 'customize_selective_refresh' => true, ) ); } public function widget($args, $instance) { echo $args['before_widget']; $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); if ($title): ?>

$count, 'orderby' => 'count', 'order' => 'DESC')); ?>

sanitize_text_field($new['title']), 'count' => absint($new['count']), ]; } } // ============================================================ // 3. 标签云小工具 // ============================================================ class AKSRT_Tag_Cloud_Widget extends WP_Widget { public function __construct() { parent::__construct( 'aksrt_tag_cloud', esc_html__('AKSRT 标签云', 'aksrt'), array( 'description' => esc_html__('展示文章标签云', 'aksrt'), 'customize_selective_refresh' => true, ) ); } public function widget($args, $instance) { echo $args['before_widget']; $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $count = absint($instance['count'] ?: 15); if ($title): ?>

$count, 'orderby' => 'count', 'order' => 'DESC']); foreach ($tags as $tag): $size = 12 + min(4, (int)($tag->count / 5)); ?> #name); ?>

sanitize_text_field($new['title']), 'count' => absint($new['count']), ]; } } // 注册函数已迁移至 class-aksrt-widgets.php(注册中心)