feat(widgets): author/user card more-posts strip + ranking empty/TOP
Add shared aksrt-user-card helpers (mini list + swiper-scroll card), wire AuthorCard/UserCard show_posts options, ranking empty state and top_badge.
This commit is contained in:
1 parent
c0b7cb504b
commit
93fd6a93c2
6 files changed
+473
-36
No files matched your search
@@ -25,10 +25,9 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
|
||||
$desc_mode = sanitize_key((string) ($instance['desc'] ?? 'desc'));
|
||||
$users = $this->get_ranking($rank_by, $count, $desc_mode);
|
||||
if (empty($users)) return;
|
||||
|
||||
echo $args['before_widget'];
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
if (!empty($instance['checkin_btn']) && is_user_logged_in() && function_exists('aksrt_header_user_checkin_btn')) {
|
||||
$cbtn = aksrt_header_user_checkin_btn(get_current_user_id());
|
||||
@@ -37,6 +36,14 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($users)) {
|
||||
echo '<p class="aksrt-user-ranking__empty muted-2-color">' . esc_html__('暂无排行数据', 'aksrt') . '</p>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return;
|
||||
}
|
||||
|
||||
$top_badge = !empty($instance['top_badge']);
|
||||
|
||||
echo '<ul class="aksrt-user-ranking">';
|
||||
$rank = 0;
|
||||
foreach ($users as $user) {
|
||||
@@ -46,7 +53,12 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
? aksrt_get_user_home_url($user['id'])
|
||||
: get_author_posts_url($user['id']);
|
||||
|
||||
echo '<li class="aksrt-user-ranking__item' . esc_attr($rank_class) . '">';
|
||||
echo '<li class="aksrt-user-ranking__item relative' . esc_attr($rank_class) . '">';
|
||||
|
||||
if ($top_badge && $rank <= 3) {
|
||||
$tone = $rank === 1 ? 'jb-red' : ($rank === 2 ? 'jb-yellow' : 'b-gray');
|
||||
echo '<badge class="img-badge left hot ' . esc_attr($tone) . '"><i>TOP' . (int) $rank . '</i></badge>';
|
||||
}
|
||||
|
||||
// 排名
|
||||
echo '<span class="aksrt-user-ranking__rank">' . esc_html((string) $rank) . '</span>';
|
||||
@@ -76,7 +88,7 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
echo $args['after_widget'];
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
private function get_ranking(string $rank_by, int $count, string $desc_mode = 'desc'): array {
|
||||
@@ -287,6 +299,12 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
<?php esc_html_e('顶部显示签到按钮', 'aksrt'); ?>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo esc_attr($this->get_field_name('top_badge')); ?>" value="1" <?php checked(!empty($instance['top_badge'])); ?>>
|
||||
<?php esc_html_e('前三名 TOP 角标', 'aksrt'); ?>
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -297,6 +315,7 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
$instance['count'] = max(1, min(20, (int) ($new_instance['count'] ?? 5)));
|
||||
$instance['show_avatar'] = !empty($new_instance['show_avatar']);
|
||||
$instance['checkin_btn'] = !empty($new_instance['checkin_btn']);
|
||||
$instance['top_badge'] = !empty($new_instance['top_badge']);
|
||||
$instance['desc'] = in_array($new_instance['desc'] ?? '', ['desc', 'user_registered', 'last_login', 'last_checkin'], true) ? $new_instance['desc'] : 'desc';
|
||||
return $instance;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user