refactor(widget): simplify author card settings
This commit is contained in:
@@ -85,9 +85,8 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
$cuid = get_current_user_id();
|
$cuid = get_current_user_id();
|
||||||
$show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']);
|
|
||||||
echo '<div class="aksrt-author-card__actions user-btns">';
|
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);
|
$following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $author_id);
|
||||||
$label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
|
$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>';
|
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 class="description"><?php esc_html_e('自动读取当前文章/帖子作者。', 'aksrt'); ?></p>
|
||||||
<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_stats')); ?>" value="1" <?php checked(!isset($instance['show_stats']) || !empty($instance['show_stats'])); ?>> <?php esc_html_e('显示统计', 'aksrt'); ?></label>
|
||||||
<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>
|
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@@ -114,7 +112,6 @@ class WidgetAuthorCard extends \WP_Widget {
|
|||||||
public function update($new_instance, $old_instance): array {
|
public function update($new_instance, $old_instance): array {
|
||||||
return [
|
return [
|
||||||
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
||||||
'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user