修复用户个人信息卡片

This commit is contained in:
2026-08-23 14:20:13 +08:00
parent 84321801a6
commit c3f66e9a14
4 changed files with 58 additions and 15 deletions
+5
View File
@@ -55,6 +55,11 @@
color: var(--color-primary, #f04494);
}
/* .widget a 的链接色不得覆盖 .but 按钮自身配色(zibll 的 zib-widget 不设置链接色) */
.widget a.but {
color: var(--this-color, #fff);
}
/* Widget 标签云 */
.widget-tag-cloud .tagcloud {
display: flex;
+43 -12
View File
@@ -22,23 +22,54 @@ final class UserRenderer {
private static function user_card(array $i): string {
$user_id = get_current_user_id();
if ($user_id <= 0) {
$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();
$oauth_html = '';
if (class_exists('AKSRT\\Auth\\OAuth')) {
$oauth = \AKSRT\Auth\OAuth::get_instance();
if (is_callable([$oauth, 'render_social_buttons'])) {
$oauth_html = (string) $oauth->render_social_buttons(__('社交账号登录', 'aksrt'));
} elseif (is_callable([$oauth, 'get_login_buttons'])) {
$oauth_html = (string) $oauth->get_login_buttons();
}
}
return '<div class="aksrt-user-card is-guest"><div class="aksrt-user-card__cover"></div><div class="aksrt-user-card__body">' . (function_exists('aksrt_get_avatar_html') ? aksrt_get_avatar_html(0, 88) : get_avatar(0, 88)) . '<h3>' . esc_html__('Hi,请登录', 'aksrt') . '</h3><p>' . esc_html__('登录后管理课程、会员、订单与创作内容。', 'aksrt') . '</p><div class="aksrt-user-card__actions"><a class="aksrt-widget-button is-primary signin-loader" href="' . esc_url($login) . '">' . esc_html__('登录', 'aksrt') . '</a><a class="aksrt-widget-button is-secondary signup-loader" href="' . esc_url($register) . '">' . esc_html__('注册', 'aksrt') . '</a></div>' . ($oauth_html !== '' ? '<div class="aksrt-user-card__oauth">' . $oauth_html . '</div>' : '') . '</div></div>';
return self::guest_card($i);
}
$user = get_userdata($user_id);
return $user instanceof \WP_User ? self::profile_card($user, $i, true) : '';
}
/**
* 未登录卡片 — legacy parity zib_widget_ui_user(zibll inc/widgets/widget-user.php:29-43)
* 与 zib_get_user_singin_page_box(zibll inc/functions/user/user.php:178-203)。
*/
private static function guest_card(array $i): string {
$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();
$title = trim((string) ($i['loged_title'] ?? ''));
if ($title === '') {
$title = __('Hi!请登录', 'aksrt');
}
$cover = '';
if (!empty($i['show_cover'])) {
$cover = '<div class="user-cover graphic" style="padding-bottom:50%;"><img' . aksrt_get_lazy_attr('lazy_cover', get_theme_file_uri('assets/img/person_background.png'), 'lazyload fit-cover', aksrt_get_lazy_thumb('lg')) . ' alt=""></div>';
}
$buttons = '<a class="signin-loader but jb-blue padding-lg" href="' . esc_url($login) . '"><i class="fa fa-fw fa-sign-in" aria-hidden="true"></i>' . esc_html__('登录', 'aksrt') . '</a>';
if (get_option('users_can_register')) {
$buttons .= '<a class="signup-loader but jb-yellow padding-lg ml10" href="' . esc_url($register) . '"><i class="fa fa-fw fa-user-plus" aria-hidden="true"></i>' . esc_html__('注册', 'aksrt') . '</a>';
}
$oauth_html = '';
if (class_exists('AKSRT\\Auth\\OAuth')) {
$oauth = \AKSRT\Auth\OAuth::get_instance();
if (is_callable([$oauth, 'render_social_buttons'])) {
$oauth_html = (string) $oauth->render_social_buttons(__('社交账号登录', 'aksrt'));
}
}
$avatar = '<span class="avatar-img avatar-lg">' . aksrt_get_avatar_html(0, 80, ['class' => 'avatar fit-cover']) . '</span>';
return '<div class="user-card widget">' . $cover
. '<div class="card-content mt10"><div class="user-content">'
. '<div class="user-avatar">' . $avatar . '</div>'
. '<div class="user-info mt10 text-center">'
. '<p class="muted-color box-body em12">' . esc_html($title) . '</p>'
. '<p class="box-body">' . $buttons . '</p>'
. $oauth_html
. '</div></div></div></div>';
}
private static function author_card(array $i): string {
$post = get_post();
if (!$post instanceof \WP_Post) {
+5 -1
View File
@@ -251,13 +251,17 @@ final class WidgetSchemas {
['id' => 'orderby', 'type' => 'select', 'label' => '排序', 'default' => 'registered', 'options' => ['registered' => '注册时间', 'display_name' => '名称', 'post_count' => '文章数', 'points' => '积分', 'followers' => '粉丝']],
];
}
return [
$fields = [
['id' => 'show_cover', 'type' => 'switcher', 'label' => '显示封面', 'default' => true],
['id' => 'show_posts', 'type' => 'switcher', 'label' => '显示文章', 'default' => $slug === 'author_card'],
['id' => 'show_buttons', 'type' => 'switcher', 'label' => '显示快捷按钮', 'default' => true],
['id' => 'primary_action', 'type' => 'select', 'label' => '主按钮', 'default' => 'submit', 'options' => self::user_actions()],
['id' => 'secondary_action', 'type' => 'select', 'label' => '次按钮', 'default' => 'home', 'options' => self::user_actions()],
];
if ($slug === 'user_card') {
$fields[] = ['id' => 'loged_title', 'type' => 'text', 'label' => '未登录文案', 'default' => 'Hi!请登录'];
}
return $fields;
}
private static function icon_card_fields(): array {
@@ -264,8 +264,11 @@ test('user profile widget owns its only card surface and keeps membership below
assert.match(userRenderer, /aksrt-user-card__identity.*aksrt_render_user_identity_chips\(\$user_id, 'widget'\)/s)
assert.doesNotMatch(userRenderer, /display_name\) \. '<\/a>' \. \(function_exists\('aksrt_render_vip_badge'/)
assert.match(userRenderer, /\$variant = \$primary \? ' is-primary' : ' is-secondary'/)
assert.match(userRenderer, /aksrt-widget-button is-primary signin-loader/)
assert.match(userRenderer, /aksrt-widget-button is-secondary signup-loader/)
// 未登录卡片复刻 zibll user-card 结构(zib_widget_ui_user + zib_get_user_singin_page_box)
assert.match(userRenderer, /user-card widget/)
assert.match(userRenderer, /signin-loader but jb-blue/)
assert.match(userRenderer, /signup-loader but jb-yellow/)
assert.doesNotMatch(userRenderer, /aksrt-user-card is-guest/)
assert.doesNotMatch(userRenderer, /aksrt-widget-button is-ghost/)
})