feat(widgets): phase 4 align user/author/slider widgets 1:1 with zibll
Align the 5 user/author/slider widgets with Zibll CSF widget definitions in widget-user.php / widget-slider.php and options-module.php (add_slider / slide / zib_palette): - WidgetUserCard (widget_ui_user): add Zibll button palettes (button_1_class/button_2_class via new palette_opts()/ sanitize_palette() replicating CFS_Module::zib_palette c/b/jb) and button_2 type (home/center) → profile/center URL. - WidgetAuthorCard (widget_ui_avatar): add show_button + button_1/button_2 (class/text/type) rendered only when the logged-in viewer is the author (zibll parity); expand orderby to modified/like/favorite. - WidgetUserRanking (zib_widget_ui_user_ranking): rename field to Zibll `orderby` (default checkin_all_day) with the exact 4 dims (checkin_all_day/checkin_continuous_day/points→credits /followed-user-count→followers) + `number` (was count); keep rank_by/count aliases for legacy instances; reword desc options to match Zibll labels. - WidgetSlider (zib_widget_ui_slider): add direction/speed/ spacebetween/scale_height+scale/autoplay to form+update+render, pass through to aksrt_render_slider (effect/loop/button/ pagination/pc·m_height/interval already present); widen interval min to 0, height default to 400 (zibll pc_height). - aksrt_user_card_query_posts: support like/favorite orderby (meta _aksrt_like_count / _aksrt_favorite_count) so the author/user-card more-posts strip honors the expanded orderby. Acceptance: php -l clean on all changed files; audit exit 0; all widget files <=383 lines. Phase 4 done-when marked. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3595ccbb44
commit
aa098fe870
6 files changed
+271
-67
No files matched your search
@@ -58,6 +58,13 @@ class WidgetAuthorCard extends \WP_Widget {
|
||||
}
|
||||
$limit = max(0, min(12, (int) ($instance['limit'] ?? 6)));
|
||||
$orderby = sanitize_key((string) ($instance['orderby'] ?? 'date'));
|
||||
// Zibll button palettes / button_2 type (shown only when viewer is the author).
|
||||
$show_button = !isset($instance['show_button']) || !empty($instance['show_button']);
|
||||
$btn1_text = (string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt'));
|
||||
$btn2_text = (string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt'));
|
||||
$btn1_class = WidgetUserCard::sanitize_palette((string) ($instance['button_1_class'] ?? 'jb-pink'), 'jb-pink');
|
||||
$btn2_class = WidgetUserCard::sanitize_palette((string) ($instance['button_2_class'] ?? 'jb-blue'), 'jb-blue');
|
||||
$btn2_type = (string) ($instance['button_2'] ?? 'center');
|
||||
|
||||
$avatar = function_exists('aksrt_get_avatar_url')
|
||||
? aksrt_get_avatar_url($author_id, ['size' => 120])
|
||||
@@ -147,6 +154,17 @@ class WidgetAuthorCard extends \WP_Widget {
|
||||
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 '<a class="aksrt-author-card__btn but" href="' . esc_url($home) . '">' . esc_html__('查看主页', 'aksrt') . '</a>';
|
||||
// Zibll: button_1 / button_2 only render when the logged-in viewer IS the author.
|
||||
if ($show_button && $cuid > 0 && $cuid === $author_id) {
|
||||
$center_url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : $home;
|
||||
$btn2_url = $btn2_type === 'home' ? $home : $center_url;
|
||||
$compose_url = $home;
|
||||
if (function_exists('aksrt_get_user_center_url')) {
|
||||
$compose_url = aksrt_get_user_center_url('posts');
|
||||
}
|
||||
echo '<a class="aksrt-author-card__btn but ' . esc_attr($btn1_class) . '" href="' . esc_url($compose_url) . '">' . esc_html($btn1_text) . '</a>';
|
||||
echo '<a class="aksrt-author-card__btn but ' . esc_attr($btn2_class) . '" href="' . esc_url($btn2_url) . '">' . esc_html($btn2_text) . '</a>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '</div>'; // .user-content
|
||||
|
||||
@@ -207,12 +225,50 @@ class WidgetAuthorCard extends \WP_Widget {
|
||||
<label><?php esc_html_e('排序', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('orderby')); ?>">
|
||||
<option value="date" <?php selected(($instance['orderby'] ?? 'date'), 'date'); ?>><?php esc_html_e('最新', 'aksrt'); ?></option>
|
||||
<option value="modified" <?php selected(($instance['orderby'] ?? ''), 'modified'); ?>><?php esc_html_e('最近更新', 'aksrt'); ?></option>
|
||||
<option value="views" <?php selected(($instance['orderby'] ?? ''), 'views'); ?>><?php esc_html_e('阅读量', 'aksrt'); ?></option>
|
||||
<option value="like" <?php selected(($instance['orderby'] ?? ''), 'like'); ?>><?php esc_html_e('点赞', 'aksrt'); ?></option>
|
||||
<option value="comment_count" <?php selected(($instance['orderby'] ?? ''), 'comment_count'); ?>><?php esc_html_e('评论数', 'aksrt'); ?></option>
|
||||
<option value="favorite" <?php selected(($instance['orderby'] ?? ''), 'favorite'); ?>><?php esc_html_e('收藏', 'aksrt'); ?></option>
|
||||
<option value="rand" <?php selected(($instance['orderby'] ?? ''), 'rand'); ?>><?php esc_html_e('随机', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<hr style="margin:12px 0;">
|
||||
<p style="font-weight:600;margin-bottom:8px;"><?php esc_html_e('按钮(仅当登录用户为作者时显示)', 'aksrt'); ?></p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_button')); ?>" value="1" <?php checked(!isset($instance['show_button']) || !empty($instance['show_button'])); ?>> <?php esc_html_e('显示按钮', 'aksrt'); ?></label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('按钮1文案', 'aksrt'); ?>
|
||||
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('button_1_text')); ?>" value="<?php echo esc_attr((string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt'))); ?>">
|
||||
</label>
|
||||
<label><?php esc_html_e('按钮1颜色', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('button_1_class')); ?>">
|
||||
<?php foreach (WidgetUserCard::palette_opts() as $k => $label) : ?>
|
||||
<option value="<?php echo esc_attr($k); ?>" <?php selected(($instance['button_1_class'] ?? 'jb-pink'), $k); ?>><?php echo esc_html($label); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('按钮2类型', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('button_2')); ?>">
|
||||
<option value="home" <?php selected(($instance['button_2'] ?? 'center'), 'home'); ?>><?php esc_html_e('个人主页', 'aksrt'); ?></option>
|
||||
<option value="center" <?php selected(($instance['button_2'] ?? 'center'), 'center'); ?>><?php esc_html_e('用户中心', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
<label><?php esc_html_e('按钮2文案', 'aksrt'); ?>
|
||||
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('button_2_text')); ?>" value="<?php echo esc_attr((string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt'))); ?>">
|
||||
</label>
|
||||
<label><?php esc_html_e('按钮2颜色', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('button_2_class')); ?>">
|
||||
<?php foreach (WidgetUserCard::palette_opts() as $k => $label) : ?>
|
||||
<option value="<?php echo esc_attr($k); ?>" <?php selected(($instance['button_2_class'] ?? 'jb-blue'), $k); ?>><?php echo esc_html($label); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<?php $this->render_common_form_section($instance); ?>
|
||||
<?php
|
||||
}
|
||||
@@ -223,20 +279,27 @@ class WidgetAuthorCard extends \WP_Widget {
|
||||
$post_style = 'mini';
|
||||
}
|
||||
$orderby = sanitize_key((string) ($new_instance['orderby'] ?? 'date'));
|
||||
if (!in_array($orderby, ['date', 'views', 'comment_count', 'modified', 'rand'], true)) {
|
||||
if (!in_array($orderby, ['date', 'views', 'comment_count', 'modified', 'like', 'favorite', 'rand'], true)) {
|
||||
$orderby = 'date';
|
||||
}
|
||||
return $this->update_common_fields($new_instance, $old_instance, [
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
||||
'show_img_bg' => !empty($new_instance['show_img_bg']) ? 1 : 0,
|
||||
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
||||
'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0,
|
||||
'show_badge' => !empty($new_instance['show_badge']) ? 1 : 0,
|
||||
'show_posts' => !empty($new_instance['show_posts']) ? 1 : 0,
|
||||
'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))),
|
||||
'post_style' => $post_style,
|
||||
'orderby' => $orderby,
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
||||
'show_img_bg' => !empty($new_instance['show_img_bg']) ? 1 : 0,
|
||||
'show_stats' => !empty($new_instance['show_stats']) ? 1 : 0,
|
||||
'show_follow' => !empty($new_instance['show_follow']) ? 1 : 0,
|
||||
'show_badge' => !empty($new_instance['show_badge']) ? 1 : 0,
|
||||
'show_posts' => !empty($new_instance['show_posts']) ? 1 : 0,
|
||||
'show_button' => !empty($new_instance['show_button']) ? 1 : 0,
|
||||
'limit' => max(0, min(12, (int) ($new_instance['limit'] ?? 6))),
|
||||
'post_style' => $post_style,
|
||||
'orderby' => $orderby,
|
||||
'button_1' => 'post',
|
||||
'button_1_text'=> sanitize_text_field((string) ($new_instance['button_1_text'] ?? '')),
|
||||
'button_1_class'=> WidgetUserCard::sanitize_palette((string) ($new_instance['button_1_class'] ?? 'jb-pink'), 'jb-pink'),
|
||||
'button_2' => in_array((string) ($new_instance['button_2'] ?? 'center'), ['home', 'center'], true) ? $new_instance['button_2'] : 'center',
|
||||
'button_2_text'=> sanitize_text_field((string) ($new_instance['button_2_text'] ?? '')),
|
||||
'button_2_class'=> WidgetUserCard::sanitize_palette((string) ($new_instance['button_2_class'] ?? 'jb-blue'), 'jb-blue'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user