Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
59 lines
2.8 KiB
PHP
59 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Shortcode template: [aksrt_profile]
|
|
*
|
|
* 当前登录用户的资料卡。供 \AKSRT\Core\Shortcodes::render_profile() 通过
|
|
* \AKSRT\Core\Templates::render_profile_shortcode() 以输出缓冲方式 include。
|
|
*
|
|
* 可用变量:$attrs(短代码属性,支持 user="<ID 或 login>" 指定用户)、$content。
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
// 解析目标用户:属性指定 > 当前登录用户。
|
|
$target = isset($attrs['user']) ? trim((string) $attrs['user']) : '';
|
|
$user = null;
|
|
if ($target !== '') {
|
|
$user = is_numeric($target) ? get_user_by('id', (int) $target) : get_user_by('login', $target);
|
|
} elseif (is_user_logged_in()) {
|
|
$user = wp_get_current_user();
|
|
}
|
|
|
|
if (!($user instanceof WP_User) || $user->ID <= 0) {
|
|
echo '<div class="aksrt-profile-card aksrt-profile-card--shortcode aksrt-profile-card--guest">'
|
|
. '<p>' . esc_html__('登录后查看个人资料。', 'aksrt') . '</p>';
|
|
if (function_exists('aksrt_get_login_url')) {
|
|
echo '<a class="btn-primary btn-sm" href="' . esc_url(aksrt_get_login_url()) . '">' . esc_html__('登录', 'aksrt') . '</a>';
|
|
}
|
|
echo '</div>';
|
|
return;
|
|
}
|
|
|
|
$user_id = (int) $user->ID;
|
|
$avatar = function_exists('aksrt_get_avatar_url') ? aksrt_get_avatar_url($user_id, ['size' => 96]) : get_avatar_url($user_id, ['size' => 96]);
|
|
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : get_author_posts_url($user_id);
|
|
$credits = function_exists('aksrt_user_credits') ? (int) aksrt_user_credits($user_id) : 0;
|
|
$post_count = (int) count_user_posts($user_id, 'post', true);
|
|
$bio = (string) get_the_author_meta('description', $user_id);
|
|
$show_credits = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::credits_enabled() : true;
|
|
?>
|
|
<div class="aksrt-profile-card aksrt-profile-card--shortcode">
|
|
<a class="aksrt-profile-card__avatar" href="<?php echo esc_url($home_url); ?>">
|
|
<img src="<?php echo esc_url($avatar); ?>" alt="<?php echo esc_attr($user->display_name); ?>" width="64" height="64"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('avatar') : ' loading="lazy"'; ?>>
|
|
</a>
|
|
<div class="aksrt-profile-card__body">
|
|
<a class="aksrt-profile-card__name" href="<?php echo esc_url($home_url); ?>"><?php echo esc_html($user->display_name); ?></a>
|
|
<?php if ($bio !== '') : ?>
|
|
<p class="aksrt-profile-card__bio"><?php echo esc_html(wp_trim_words($bio, 24, '…')); ?></p>
|
|
<?php endif; ?>
|
|
<div class="aksrt-profile-card__stats">
|
|
<span class="aksrt-profile-card__stat"><strong><?php echo esc_html(number_format_i18n($post_count)); ?></strong><?php esc_html_e('文章', 'aksrt'); ?></span>
|
|
<?php if ($show_credits) : ?>
|
|
<span class="aksrt-profile-card__stat"><strong><?php echo esc_html(number_format_i18n($credits)); ?></strong><?php esc_html_e('积分', 'aksrt'); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|