fix(single): restore author follow controls

This commit is contained in:
kate522 committed 2026-08-31 13:12:45 +08:00
1 parent 71444b139a
commit 8eb62e712b
19 files changed
+261 -615

No files matched your search

+4 -7
View File
@@ -68,13 +68,10 @@ if (!function_exists('aksrt_resolve_single_post_display_settings')) :
if (!array_key_exists('breadcrumbs_home', $settings) && array_key_exists('breadcrumbs_home_text', $settings)) {
$settings['breadcrumbs_home'] = (string) $settings['breadcrumbs_home_text'];
}
if (!array_key_exists('prevnext', $settings) && array_key_exists('prevnext_s', $settings)) {
$settings['prevnext'] = !empty($settings['prevnext_s']);
}
if (!array_key_exists('authordesc', $settings) && array_key_exists('authordesc_s', $settings)) {
$settings['authordesc'] = !empty($settings['authordesc_s']);
}
$meta = class_exists('\AKSRT\Core\PostMetaBox') ? \AKSRT\Core\PostMetaBox::get_meta($post->ID) : [];
if (!array_key_exists('prevnext', $settings) && array_key_exists('prevnext_s', $settings)) {
$settings['prevnext'] = !empty($settings['prevnext_s']);
}
$meta = class_exists('\AKSRT\Core\PostMetaBox') ? \AKSRT\Core\PostMetaBox::get_meta($post->ID) : [];
if (!empty($meta['article_maxheight_xz'])) {
$settings['maxheight_enabled'] = true;
} elseif (empty($settings['maxheight_enabled'])) {
+5 -20
View File
@@ -241,27 +241,12 @@ if (!function_exists('aksrt_author_minicard')) :
])
: '<a href="' . esc_url($home) . '">' . esc_html($user->display_name) . '</a>';
// Follow control (separate from name, legacy places both in dt).
// 服务端直接输出真实关注状态(legacy parity: zib_get_user_follow 恒渲染当前态)。
$follow = '';
$current = get_current_user_id();
if ($current !== $user_id) {
$is_following = false;
if (is_user_logged_in() && class_exists('\AKSRT\User\Follow')) {
$is_following = \AKSRT\User\Follow::get_instance()->is_following($current, $user_id);
}
$follow_label = $is_following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
$follow_title = $is_following ? __('点击取消关注', 'aksrt') : __('关注该用户', 'aksrt');
$follow_state = $is_following ? ' is-following' : '';
if (is_user_logged_in()) {
$follow = '<button type="button" class="focus-color px12 ml10 follow flex0 but' . $follow_state . '" data-aksrt-follow="' . (int) $user_id . '" title="' . esc_attr($follow_title) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html($follow_label) . '</button>';
} else {
$login = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url();
$follow = '<a class="focus-color px12 ml10 follow flex0 but" href="' . esc_url($login) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html__('关注', 'aksrt') . '</a>';
}
}
// Follow control (separate from name, legacy places both in dt).
$follow = function_exists('aksrt_get_user_follow')
? aksrt_get_user_follow('focus-color px12 ml10 follow flex0 but', $user_id)
: '';
$desc = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : trim((string) get_user_meta($user_id, 'description', true));
$desc = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : trim((string) get_user_meta($user_id, 'description', true));
$blur = '';
if ($blur_bg) {
+38 -16
View File
@@ -119,6 +119,37 @@ if (!function_exists('aksrt_render_user_identity_chips')) {
}
}
if (!function_exists('aksrt_get_user_follow')) {
/**
* Render the canonical user follow control.
*/
function aksrt_get_user_follow(string $class, int $follow_id, ?string $text = null, ?string $ok_text = null, ?string $guest_text = null): string {
$current_user_id = get_current_user_id();
if ($follow_id <= 0 || $current_user_id === $follow_id) {
return '';
}
$text = $text ?? __('关注', 'aksrt');
$ok_text = $ok_text ?? __('已关注', 'aksrt');
$guest_text = $guest_text ?? $text;
$class = trim($class);
if (!is_user_logged_in()) {
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url();
return '<a class="' . esc_attr($class) . '" href="' . esc_url($login_url) . '"><i class="fa far fa-heart em09" aria-hidden="true"></i> <span>' . esc_html($guest_text) . '</span></a>';
}
$is_following = class_exists('\AKSRT\User\Follow')
&& \AKSRT\User\Follow::get_instance()->is_following($current_user_id, $follow_id);
$state_class = $is_following ? ' is-following' : '';
$title = $is_following ? __('点击取消关注', 'aksrt') : __('关注该用户', 'aksrt');
$label = $is_following ? $ok_text : $text;
$icon_class = $is_following ? 'fa fas fa-heart em09' : 'fa far fa-heart em09';
return '<a href="javascript:;" class="' . esc_attr($class . $state_class) . '" data-aksrt-follow="' . $follow_id . '" title="' . esc_attr($title) . '"><i class="' . esc_attr($icon_class) . '" aria-hidden="true"></i> <span data-aksrt-follow-label>' . esc_html($label) . '</span></a>';
}
}
if (!function_exists('aksrt_get_user_name')) {
/**
* legacy parity: name link + auth + wear medal + level + optional follow.
@@ -155,7 +186,9 @@ if (!function_exists('aksrt_get_user_name')) {
return '';
}
$home = function_exists('get_author_posts_url') ? get_author_posts_url($user_id) : '';
$home = function_exists('aksrt_get_user_home_url')
? aksrt_get_user_home_url($user_id)
: get_author_posts_url($user_id);
$display = $user->display_name;
$vip_html = '';
if (!empty($args['vip']) && function_exists('aksrt_render_vip_badge')) {
@@ -220,22 +253,11 @@ if (!function_exists('aksrt_get_user_name')) {
}
}
$follow_html = '';
if (!empty($args['follow']) && get_current_user_id() !== $user_id) {
if (is_user_logged_in()) {
// 服务端直接输出真实关注状态(legacy parity: zib_get_user_follow 恒渲染当前态)。
$is_following = class_exists('\AKSRT\User\Follow') && \AKSRT\User\Follow::get_instance()->is_following(get_current_user_id(), $user_id);
$follow_label = $is_following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
$follow_title = $is_following ? __('点击取消关注', 'aksrt') : __('关注该用户', 'aksrt');
$follow_state = $is_following ? ' is-following' : '';
$follow_html = '<button type="button" class="focus-color ml10 follow flex0' . $follow_state . '" data-aksrt-follow="' . (int) $user_id . '" title="' . esc_attr($follow_title) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html($follow_label) . '</button>';
} else {
$login = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url();
$follow_html = '<a class="focus-color ml10 follow flex0" href="' . esc_url($login) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html__('关注', 'aksrt') . '</a>';
}
}
$follow_html = !empty($args['follow'])
? aksrt_get_user_follow('focus-color ml10 follow flex0', $user_id)
: '';
// Order: name → auth → wear medal → level → follow (legacy).
// Order: name → auth → wear medal → level → follow (legacy).
$html = '<name class="' . esc_attr((string) $args['class']) . '">' . $name_link . $vip_html . $auth_html . $medal_html . $level_html . $follow_html . '</name>';
/**
* Filter rendered user name chrome.
+7 -14
View File
@@ -156,13 +156,10 @@ if (!function_exists('aksrt_single_render_box_header')) :
<?php endif; ?>
<?php
// Author bar always shows in header (legacy).
// `authordesc` only controls the after-box author card.
aksrt_single_render_author_bar([
'show_actions' => true,
'show_time' => empty($settings['hide_time']),
'meta_html' => (string) ($ctx['meta_box_html'] ?? ''),
]);
get_template_part('templates/parts/single-author-bar', null, [
'show_time' => empty($settings['hide_time']),
'meta_html' => (string) ($ctx['meta_box_html'] ?? ''),
]);
?>
</div>
<?php
@@ -681,13 +678,9 @@ if (!function_exists('aksrt_single_render_after_box')) :
]);
}
// Accept both `authordesc` (Settings DTO) and legacy `authordesc_s`.
$show_author = array_key_exists('authordesc', $settings)
? !empty($settings['authordesc'])
: !empty($settings['authordesc_s']);
if ($show_author) {
aksrt_single_render_author_card($ctx);
}
if (!empty($settings['authordesc'])) {
aksrt_single_render_author_card($ctx);
}
aksrt_single_render_prevnext($ctx);
aksrt_single_render_related($ctx);
-17
View File
@@ -137,23 +137,6 @@ if (!function_exists('aksrt_single_is_docs_page')) :
}
endif;
if (!function_exists('aksrt_single_render_author_bar')) :
/**
* Render author bar from a real args array (no ambient query vars).
*
* @param array<string,mixed> $args Partial args.
*/
function aksrt_single_render_author_bar(array $args = []): void {
$args = wp_parse_args($args, [
'extra_class' => '',
'show_actions' => false,
'show_bio' => false,
'meta_items' => [],
]);
get_template_part('templates/parts/single-author-bar', null, $args);
}
endif;
if (!function_exists('aksrt_single')) :
/**
* Compose header + article + after-box (legacy equivalent).
@@ -47,7 +47,7 @@ $result = $follow
<div class="uc-follow-management__identity"><a href="<?php echo esc_url($home_url); ?>"><?php echo esc_html((string) ($item['display_name'] ?? '')); ?></a><span><?php echo esc_html(sprintf(__('关注于 %s', 'aksrt'), get_date_from_gmt((string) ($item['created_at'] ?? ''), get_option('date_format')))); ?></span></div>
<div class="uc-follow-management__actions">
<a class="btn-ghost btn-sm" href="<?php echo esc_url($home_url); ?>"><?php esc_html_e('主页', 'aksrt'); ?></a>
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm is-following" data-aksrt-follow="<?php echo esc_attr((string) $member_id); ?>"><i class="fa fas fa-heart" aria-hidden="true"></i><span><?php esc_html_e('已关注', 'aksrt'); ?></span></button><?php endif; ?>
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm is-following" data-aksrt-follow="<?php echo esc_attr((string) $member_id); ?>"><i class="fa fas fa-heart" aria-hidden="true"></i><span data-aksrt-follow-label><?php esc_html_e('已关注', 'aksrt'); ?></span></button><?php endif; ?>
</div>
</div>
<?php endforeach; ?>