refactor(widget): simplify author card settings

This commit is contained in:
2026-08-15 18:07:52 +08:00
parent b7a3e433fa
commit 895b7b2014
+2 -5
View File
@@ -85,9 +85,8 @@ class WidgetAuthorCard extends \WP_Widget {
echo '</div>';
}
$cuid = get_current_user_id();
$show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']);
echo '<div class="aksrt-author-card__actions user-btns">';
if ($show_follow && $cuid > 0 && $cuid !== $author_id && class_exists('\AKSRT\User\Follow')) {
if ($cuid > 0 && $cuid !== $author_id && class_exists('\AKSRT\User\Follow')) {
$following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $author_id);
$label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
echo '<button type="button" class="aksrt-author-card__btn aksrt-author-card__follow but' . ($following ? ' is-following' : '') . '" data-aksrt-follow="' . (int) $author_id . '">' . esc_html($label) . '</button>';
@@ -105,8 +104,7 @@ class WidgetAuthorCard extends \WP_Widget {
?>
<p class="description"><?php esc_html_e('自动读取当前文章/帖子作者。', 'aksrt'); ?></p>
<p>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_follow')); ?>" value="1" <?php checked(!isset($instance['show_follow']) || !empty($instance['show_follow'])); ?>> <?php esc_html_e('显示关注按钮', 'aksrt'); ?></label>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label>
</p>
<?php
}
@@ -114,7 +112,6 @@ class WidgetAuthorCard extends \WP_Widget {
public function update($new_instance, $old_instance): array {
return [
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0,
];
}
}