Files
wordpress-theme-aksrt/templates/parts/single-author-bar.php
T
kate522andClaude Fable 5 d40906b4a3 feat(single): align author bar follow and reward actions with the site flows
- guests get the sign-in trigger instead of a redirect to the login page,
  for both follow and wallet reward controls
- follow requests swap the label for an inline loader and block a second
  submit; the followed state uses the .actived hook
- follower counts sync through data-follow-count on the user homepage
  (the previous selector matched nothing) and only for the viewed profile
- reward button uses the secondary action colour; the reward template is
  only rendered for signed-in visitors
- drop the unused author-hero aria-disabled rule and stale wording in the
  touched comments

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-11-04 13:34:34 +08:00

130 lines
5.1 KiB
PHP

<?php
/**
* Article header author bar.
*
* Contract: get_template_part(..., null, $args)
* show_time bool Relative publish/update time (default true)
* meta_html string Prebuilt single-metabox HTML
*
* @package Jio
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
$show_time = !array_key_exists('show_time', $args) || !empty($args['show_time']);
$meta_html = (string) ($args['meta_html'] ?? '');
$author_id = (int) get_the_author_meta('ID');
$author_name = get_the_author();
$author_url = function_exists('jio_get_user_home_url') ? jio_get_user_home_url($author_id) : get_author_posts_url($author_id);
// 时间显示分支顺序:
// 1) 数据源 date → 发布时间
// 2) 非已发布状态 → 更新时间
// 3) 更新时间 > 发布时间 → 文案用更新时间+「更新」,tooltip 仍为发布时间+「发布」
// 4) 其余 → 发布时间
$time_source = '';
if (class_exists('\Jio\Settings\Settings')) {
$list_settings = \Jio\Settings\Settings::get_post_list_style_settings();
$time_source = (string) ($list_settings['post_time_source'] ?? 'modified');
}
$is_published = (string) get_post_status(get_the_ID()) === 'publish';
$published_mysql = (string) get_the_time('Y-m-d H:i:s');
$modified_mysql = (string) get_the_modified_time('Y-m-d H:i:s');
$has_update = (int) strtotime($modified_mysql) > (int) strtotime($published_mysql);
$published_title = sprintf(__('%s发布', 'jio'), get_the_time('Y年m月d日 H:i'));
$modified_title = sprintf(__('%s更新', 'jio'), get_the_modified_time('Y年m月d日 H:i'));
if ($time_source === 'date') {
// 1) 强制发布时间源。
$time_mysql = $published_mysql;
$rel_label = __('发布', 'jio');
$abs_fmt = $published_title;
} elseif (!$is_published) {
// 2) 草稿/待审等:固定展示更新时间。
$time_mysql = $modified_mysql;
$rel_label = __('更新', 'jio');
$abs_fmt = $modified_title;
} elseif ($has_update) {
// 3) 已发布且有更新:文案取更新时间,tooltip 仍标注发布时间。
$time_mysql = $modified_mysql;
$rel_label = __('更新', 'jio');
$abs_fmt = $published_title;
} else {
// 4) 未更新过:发布时间。
$time_mysql = $published_mysql;
$rel_label = __('发布', 'jio');
$abs_fmt = $published_title;
}
// 相对时间本身已含「前」,只拼接「发布 / 更新」。
$time_ago = function_exists('jio_time_ago')
? jio_time_ago($time_mysql)
: human_time_diff((int) strtotime($time_mysql), (int) current_time('timestamp')) . __('前', 'jio');
$time_text = $time_ago . $rel_label;
$description = function_exists('jio_get_user_description')
? jio_get_user_description($author_id)
: trim((string) get_the_author_meta('description'));
$name_html = jio_get_user_name([
'id' => $author_id,
'class' => 'name flex ac flex1',
'name_class' => '',
'vip' => true,
'medal' => true,
'auth' => true,
'level' => true,
'follow' => false,
]);
$follow_html = jio_get_user_follow('px12-sm ml10 follow but c-red', $author_id);
$reward_button = get_current_user_id() !== $author_id && function_exists('jio_get_rewards_button')
? jio_get_rewards_button($author_id, 'ml6 but c-blue px12-sm', get_the_ID())
: '';
?>
<div class="article-avatar">
<div class="user-info flex ac article-avatar">
<a href="<?php echo esc_url($author_url); ?>">
<span class="avatar-img">
<?php if (function_exists('jio_get_avatar_html')) : ?>
<?php echo jio_get_avatar_html($author_id, 42, ['class' => 'avatar avatar-id-' . $author_id]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<?php echo get_avatar($author_id, 42, '', esc_attr($author_name), ['class' => 'avatar avatar-id-' . $author_id]); ?>
<?php endif; ?>
</span>
</a>
<div class="user-right flex flex1 ac jsb ml10">
<div class="flex1">
<?php echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="px12-sm muted-2-color text-ellipsis">
<?php if ($show_time) : ?>
<span data-toggle="tooltip" data-placement="bottom" title="<?php echo esc_attr($abs_fmt); ?>"><?php echo esc_html($time_text); ?></span>
<?php elseif ($description !== '') : ?>
<span><?php echo esc_html($description); ?></span>
<?php endif; ?>
<?php
$post_city = function_exists('jio_get_post_author_city_badge_html')
? jio_get_post_author_city_badge_html($author_id, 'badg badg-sm')
: '';
if ($post_city !== '') {
echo $post_city; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</div>
</div>
<div class="flex0 user-action">
<?php echo $follow_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ($reward_button !== '') : ?>
<?php echo $reward_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php jio_render_rewards_template_for_user($author_id, get_the_ID()); ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="single-meta-row">
<i class="line-form-line" aria-hidden="true"></i>
<?php echo $meta_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>