修复了一些小问题
This commit is contained in:
1 parent
1b4928d69b
commit
ed914d2eec
12 files changed
+339
-349
No files matched your search
@@ -243,6 +243,80 @@ if (!function_exists('aksrt_get_user_name')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_user_posts_meta_sum')) {
|
||||
/**
|
||||
* 求和用户已发布文章的某个 meta(legacy get_user_posts_meta_sum parity)。
|
||||
*
|
||||
* @param int $user_id 用户 ID。
|
||||
* @param string $meta_key 文章 meta 键。
|
||||
*/
|
||||
function aksrt_get_user_posts_meta_sum(int $user_id, string $meta_key): int {
|
||||
global $wpdb;
|
||||
if ($user_id <= 0 || $meta_key === '') {
|
||||
return 0;
|
||||
}
|
||||
$cache_group = 'aksrt_user_posts_' . $meta_key . '_sum';
|
||||
$cached = wp_cache_get($user_id, $cache_group);
|
||||
if (false !== $cached) {
|
||||
return (int) $cached;
|
||||
}
|
||||
$sum = $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT SUM(_m.meta_value + 0) FROM {$wpdb->posts} _p INNER JOIN {$wpdb->postmeta} _m ON _p.ID = _m.post_id"
|
||||
. " WHERE _p.post_author = %d AND _m.meta_key = %s AND _p.post_status = 'publish'",
|
||||
$user_id,
|
||||
$meta_key
|
||||
));
|
||||
$sum = $sum ? (int) $sum : 0;
|
||||
wp_cache_set($user_id, $sum, $cache_group, 43200);
|
||||
return $sum;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_user_badges')) {
|
||||
/**
|
||||
* legacy parity: 作者资料卡统计徽章行(文章 / 评论 / 粉丝|点赞 / 人气值)。
|
||||
*
|
||||
* @param int $user_id 用户 ID。
|
||||
*/
|
||||
function aksrt_get_user_badges(int $user_id): string {
|
||||
if ($user_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$home = aksrt_get_user_home_url($user_id);
|
||||
$post_n = aksrt_cut_count(count_user_posts($user_id, 'post', true));
|
||||
$com_n = aksrt_cut_count((int) get_comments([
|
||||
'user_id' => $user_id,
|
||||
'status' => 'approve',
|
||||
'count' => true,
|
||||
'post_type' => ['post'],
|
||||
]));
|
||||
$followed_n = class_exists('\AKSRT\User\Follow')
|
||||
? aksrt_cut_count((int) \AKSRT\User\Follow::get_instance()->get_follower_count($user_id))
|
||||
: 0;
|
||||
$like_n = aksrt_cut_count(aksrt_get_user_posts_meta_sum($user_id, '_aksrt_like_count'));
|
||||
$view_n = aksrt_cut_count(aksrt_get_user_posts_meta_sum($user_id, 'aksrt_post_views'));
|
||||
|
||||
$html = '';
|
||||
$html .= '<a class="but c-blue tag-posts" data-toggle="tooltip" title="' . esc_attr(sprintf(__('共%s篇文章', 'aksrt'), $post_n)) . '" href="' . esc_url($home) . '">' . aksrt_renderer_svg_icon('post') . $post_n . '</a>';
|
||||
$html .= '<a class="but c-green tag-comment" data-toggle="tooltip" title="' . esc_attr(sprintf(__('共%s条评论', 'aksrt'), $com_n)) . '" href="' . esc_url($home) . '">' . aksrt_renderer_svg_icon('comment') . $com_n . '</a>';
|
||||
if ($followed_n) {
|
||||
$html .= '<a class="but c-yellow tag-follow" data-toggle="tooltip" title="' . esc_attr(sprintf(__('共%s个粉丝', 'aksrt'), $followed_n)) . '" href="' . esc_url($home) . '"><i class="fa fa-heart em09" aria-hidden="true"></i>' . $followed_n . '</a>';
|
||||
} elseif ($like_n) {
|
||||
$html .= '<span class="badg c-yellow tag-like" data-toggle="tooltip" title="' . esc_attr(sprintf(__('获得%s个点赞', 'aksrt'), $like_n)) . '">' . aksrt_renderer_svg_icon('like') . $like_n . '</span>';
|
||||
}
|
||||
$html .= '<span class="badg c-red tag-view" data-toggle="tooltip" title="' . esc_attr(sprintf(__('人气值 %s', 'aksrt'), $view_n)) . '">' . aksrt_renderer_svg_icon('hot') . $view_n . '</span>';
|
||||
|
||||
/**
|
||||
* Filter the author-card count badges row.
|
||||
*
|
||||
* @param string $html Badges HTML.
|
||||
* @param int $user_id User ID.
|
||||
*/
|
||||
return (string) apply_filters('aksrt_user_count_badges', $html, $user_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_render_user_medal_entry')) {
|
||||
/**
|
||||
* Render the compact legacy-style badge overview entry.
|
||||
|
||||
Reference in new issue
Block a user