导入 AKSRT 主题开发源码
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* Author Hero — shared hero section for author archive and public user homepage.
|
||||
*
|
||||
* Expected variables (passed via get_template_part or set_query_var):
|
||||
* $user (WP_User) Target user object.
|
||||
* $dashboard (array) Data from aksrt_get_user_dashboard_view().
|
||||
* $user_home_settings (array) User home display settings.
|
||||
* $is_author_page (bool) True when rendering on author.php (archive context).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (empty($user) || !($user instanceof WP_User)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = (int) $user->ID;
|
||||
$dashboard = $dashboard ?? [];
|
||||
$settings = $user_home_settings ?? [];
|
||||
$is_author = !empty($is_author_page);
|
||||
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/');
|
||||
$show_cover = !empty($settings['cover']);
|
||||
$show_follow = !empty($settings['follow']);
|
||||
|
||||
$post_count = (int) ($dashboard['post_count'] ?? 0);
|
||||
$comment_count = (int) ($dashboard['comment_count'] ?? 0);
|
||||
$favorite_count = (int) ($dashboard['favorite_count'] ?? 0);
|
||||
$contacts = $dashboard['user_contacts'] ?? [];
|
||||
$social_on = !empty($dashboard['social_links_on']);
|
||||
$signals = $dashboard['profile_signals'] ?? [];
|
||||
$notice = $dashboard['profile_notice'] ?? null;
|
||||
$show_report = !empty($dashboard['show_report']);
|
||||
$bg_url = $dashboard['background_url'] ?? '';
|
||||
$is_own = !empty($dashboard['is_own_profile']);
|
||||
?>
|
||||
|
||||
<div class="aksrt-author-hero<?php echo $show_cover ? '' : ' aksrt-author-hero--no-cover'; ?>">
|
||||
<?php if ($show_cover) : ?>
|
||||
<div class="aksrt-author-hero__cover">
|
||||
<img class="aksrt-author-hero__cover-img"
|
||||
src="<?php echo esc_url($bg_url ? $bg_url : get_theme_file_uri('assets/img/person_background.png')); ?>"
|
||||
alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('cover') : ' loading="lazy"'; ?>>
|
||||
<div class="aksrt-author-hero__cover-mask"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="aksrt-author-hero__body">
|
||||
<div class="aksrt-author-hero__avatar">
|
||||
<?php
|
||||
if (function_exists('aksrt_get_avatar_html')) {
|
||||
echo aksrt_get_avatar_html($user_id, 120, ['loading' => 'lazy']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
echo get_avatar($user_id, 120, '', $user->display_name); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="aksrt-author-hero__info">
|
||||
<h1 class="aksrt-author-hero__name">
|
||||
<?php echo esc_html($user->display_name); ?>
|
||||
<?php
|
||||
$vip_badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($user_id) : '';
|
||||
if ($vip_badge) {
|
||||
echo $vip_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
?>
|
||||
</h1>
|
||||
|
||||
<?php if ($user->description) : ?>
|
||||
<p class="aksrt-author-hero__desc"><?php echo esc_html($user->description); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($signals)) : ?>
|
||||
<div class="aksrt-identity-chips">
|
||||
<?php foreach ($signals as $signal) : ?>
|
||||
<span class="aksrt-identity-chip aksrt-identity-chip--<?php echo esc_attr($signal['tone']); ?>">
|
||||
<i class="fas fa-<?php echo esc_attr($signal['icon']); ?>" aria-hidden="true"></i>
|
||||
<span><?php echo esc_html($signal['label']); ?></span>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="aksrt-author-hero__stats">
|
||||
<span class="aksrt-author-hero__stat">
|
||||
<strong><?php echo esc_html((string) $post_count); ?></strong>
|
||||
<span><?php esc_html_e('文章', 'aksrt'); ?></span>
|
||||
</span>
|
||||
<span class="aksrt-author-hero__stat">
|
||||
<strong><?php echo esc_html((string) $comment_count); ?></strong>
|
||||
<span><?php esc_html_e('评论', 'aksrt'); ?></span>
|
||||
</span>
|
||||
<span class="aksrt-author-hero__stat">
|
||||
<strong><?php echo esc_html((string) $favorite_count); ?></strong>
|
||||
<span><?php esc_html_e('收藏', 'aksrt'); ?></span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($contacts) && $social_on) : ?>
|
||||
<div class="aksrt-author-hero__contacts">
|
||||
<?php if (function_exists('aksrt_render_social_links')) : ?>
|
||||
<?php aksrt_render_social_links($contacts); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="aksrt-author-hero__actions">
|
||||
<?php if ($is_own) : ?>
|
||||
<a href="<?php echo esc_url(aksrt_get_user_center_url()); ?>" class="btn-ghost btn-sm">
|
||||
<i class="fas fa-cog" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('个人中心', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php elseif ($show_follow) : ?>
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<button type="button" class="btn-outline btn-sm aksrt-author-hero__follow-btn" data-aksrt-follow="<?php echo (int) $user_id; ?>" title="<?php esc_attr_e('关注该用户', 'aksrt'); ?>">
|
||||
<i class="far fa-heart" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<a href="<?php echo esc_url(aksrt_get_login_url($home_url)); ?>" class="btn-outline btn-sm aksrt-author-hero__follow-btn">
|
||||
<i class="far fa-heart" aria-hidden="true"></i>
|
||||
<span><?php esc_html_e('登录后关注', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($show_report) : ?>
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<button type="button" class="btn-ghost btn-sm aksrt-author-hero__report-btn" data-aksrt-report='{"target_type":"user","target_id":<?php echo (int) $user_id; ?>}' title="<?php esc_attr_e('举报该用户', 'aksrt'); ?>">
|
||||
<i class="far fa-flag" aria-hidden="true"></i>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<a href="<?php echo esc_url(aksrt_get_login_url($home_url)); ?>" class="btn-ghost btn-sm aksrt-author-hero__report-btn">
|
||||
<i class="far fa-flag" aria-hidden="true"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($is_author && function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/user-home', __('用户主页设置', 'aksrt')); } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($notice)) : ?>
|
||||
<div class="aksrt-author-hero__notice aksrt-author-hero__notice--<?php echo esc_attr($notice['state']); ?>">
|
||||
<i class="fas fa-exclamation-circle" aria-hidden="true"></i>
|
||||
<span><?php echo esc_html($notice['text']); ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user