fix(admin): replicate reference post-feature settings page 1:1

- Rewrite post_list/feature schema (PHP + JS) with the reference theme's
  field set, order, defaults and dependencies; print/PDF toggles dropped
- Move the migrated reference fields off the post-page schema (lightbox
  six switches, post like, default view/like ranges) to kill the dual path
- Map PostDisplay::get_post_page_settings() to the new keys without legacy
  fallback: imagelightbox* (pc_s/m_s checkboxes merged), post_like_s,
  post_default_mate ranges, article_nav + article_nav_mobile_nav_s
- Wire article_nav runtime: content data-nav/no-nav gate with per-post
  override, mobile drawer TOC box, imgbox_type config
- Seed random views/likes on new posts from post_default_mate ranges
- Keep the print stylesheet enqueued unconditionally (no switch); drop the
  dead print/PDF settings and needs_print requirement
- Add post-feature settings reference contract test
This commit is contained in:
2026-09-24 14:29:04 +08:00
parent c331b2aeef
commit 4d6b2c6045
12 changed files with 469 additions and 85 deletions
+35 -18
View File
@@ -76,15 +76,7 @@ class SchemaPostList {
['key' => 'post_article_video_cover', 'label' => '视频封面', 'type' => 'switch', 'default' => true, 'description' => '文章有视频时以视频播放器作为封面'],
['key' => 'post_article_video_cover_scale', 'label' => '视频封面高度比例(%)', 'type' => 'number', 'default' => 56, 'min' => 20, 'max' => 100],
]],
['key' => 'media', 'title' => '媒体功能', 'fields' => [
['key' => 'post_lightbox', 'label' => '图片灯箱', 'type' => 'switch', 'default' => true],
['key' => 'post_lightbox_thumbs', 'label' => '灯箱缩略图', 'type' => 'switch', 'default' => true],
['key' => 'post_lightbox_zoom', 'label' => '灯箱缩放', 'type' => 'switch', 'default' => true],
['key' => 'post_lightbox_full', 'label' => '灯箱全屏', 'type' => 'switch', 'default' => true],
['key' => 'post_lightbox_down', 'label' => '灯箱下载', 'type' => 'switch', 'default' => false],
['key' => 'post_lightbox_play', 'label' => '灯箱播放', 'type' => 'switch', 'default' => false],
]],
['key' => 'related', 'title' => '相关推荐', 'fields' => [
['key' => 'related', 'title' => '相关推荐', 'fields' => [
['key' => 'post_related_s', 'label' => '显示相关推荐', 'type' => 'switch', 'default' => true],
['key' => 'post_related_type', 'label' => '展示样式', 'type' => 'radio', 'default' => 'img', 'options' => [
['label' => '图文卡片', 'value' => 'img'],
@@ -104,7 +96,6 @@ class SchemaPostList {
]],
]],
['key' => 'interactions', 'title' => '互动功能', 'fields' => [
['key' => 'post_like_enabled', 'label' => '点赞', 'type' => 'switch', 'default' => true],
['key' => 'post_favorite_enabled', 'label' => '收藏', 'type' => 'switch', 'default' => true],
['key' => 'share_s', 'label' => '分享按钮', 'type' => 'switch', 'default' => true],
['key' => 'post_copyright_enabled', 'label' => '版权信息', 'type' => 'switch', 'default' => true],
@@ -131,10 +122,6 @@ class SchemaPostList {
['key' => 'post_yiyan_box', 'label' => '一言盒子', 'type' => 'switch', 'default' => false],
]],
['key' => 'meta', 'title' => 'Meta设置', 'fields' => [
['key' => 'post_default_views_min', 'label' => '默认浏览最小值', 'type' => 'number', 'default' => 20, 'min' => 0, 'max' => 9999],
['key' => 'post_default_views_max', 'label' => '默认浏览最大值', 'type' => 'number', 'default' => 50, 'min' => 1, 'max' => 9999],
['key' => 'post_default_likes_min', 'label' => '默认点赞最小值', 'type' => 'number', 'default' => 5, 'min' => 0, 'max' => 9999],
['key' => 'post_default_likes_max', 'label' => '默认点赞最大值', 'type' => 'number', 'default' => 15, 'min' => 1, 'max' => 9999],
['key' => 'post_views_s', 'label' => '浏览统计', 'type' => 'switch', 'default' => true],
]],
],
@@ -186,12 +173,42 @@ class SchemaPostList {
'feature' => [
'key' => 'feature',
'title' => '文章功能',
'version' => '1.0.0',
'version' => '2.0.0',
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'tools', 'title' => '工具功能', 'fields' => [
['key' => 'feature_print', 'label' => '打印文章', 'type' => 'switch', 'default' => true],
['key' => 'feature_pdf_export', 'label' => 'PDF 导出', 'type' => 'switch', 'default' => false],
['key' => 'feature', 'title' => '文章功能', 'fields' => [
['key' => 'article_nav', 'label' => '文章目录树', 'type' => 'switcher', 'default' => true, 'description' => '默认开关,每篇文章可单独设置。开启后请自行添加文章目录树模块到侧边栏(文章内标题超过3个才会显示)'],
['key' => 'article_nav_mobile_nav_s', 'label' => '在移动端弹出菜单内显示', 'type' => 'switcher', 'default' => true, 'dependsOn' => ['key' => 'article_nav', 'value' => true], 'description' => '如需显示在侧边栏等其它位置,请使用小工具模块添加'],
['key' => 'imagelightbox', 'label' => '图片灯箱', 'type' => 'switcher', 'default' => true, 'description' => '点击图片查看原图功能,共两种模式'],
['key' => 'imagelightbox_type', 'label' => '图片灯箱模式', 'type' => 'radio', 'default' => 'group', 'dependsOn' => ['key' => 'imagelightbox', 'value' => true], 'options' => [
['label' => '组合模式(将文章的全部图片组合成一组灯箱)', 'value' => 'group'],
['label' => '单张模式(点击某张图片仅显示该图片)', 'value' => 'alone'],
]],
['key' => 'imagelightbox_thumbs_s', 'label' => '缩略图导航', 'type' => 'checkbox', 'default' => ['pc_s', 'm_s'], 'dependsOn' => ['all' => [['key' => 'imagelightbox', 'value' => true], ['key' => 'imagelightbox_type', 'value' => 'group']]], 'options' => [
['label' => 'PC端开启', 'value' => 'pc_s'],
['label' => '移动端开启', 'value' => 'm_s'],
]],
['key' => 'imagelightbox_play_s', 'label' => '播放按钮', 'type' => 'checkbox', 'default' => ['pc_s', 'm_s'], 'dependsOn' => ['all' => [['key' => 'imagelightbox', 'value' => true], ['key' => 'imagelightbox_type', 'value' => 'group']]], 'options' => [
['label' => 'PC端开启', 'value' => 'pc_s'],
['label' => '移动端开启', 'value' => 'm_s'],
]],
['key' => 'imagelightbox_zoom_s', 'label' => '缩放按钮', 'type' => 'checkbox', 'default' => ['pc_s'], 'dependsOn' => ['key' => 'imagelightbox', 'value' => true], 'options' => [
['label' => 'PC端开启', 'value' => 'pc_s'],
['label' => '移动端开启', 'value' => 'm_s'],
]],
['key' => 'imagelightbox_full_s', 'label' => '全屏按钮', 'type' => 'checkbox', 'default' => ['pc_s'], 'dependsOn' => ['key' => 'imagelightbox', 'value' => true], 'options' => [
['label' => 'PC端开启', 'value' => 'pc_s'],
['label' => '移动端开启', 'value' => 'm_s'],
]],
['key' => 'imagelightbox_down_s', 'label' => '下载按钮', 'type' => 'checkbox', 'default' => ['pc_s'], 'dependsOn' => ['key' => 'imagelightbox', 'value' => true], 'options' => [
['label' => 'PC端开启', 'value' => 'pc_s'],
['label' => '移动端开启', 'value' => 'm_s'],
]],
['key' => 'post_like_s', 'label' => '文章点赞', 'type' => 'switcher', 'default' => true],
['key' => 'post_default_mate', 'label' => '文章预置参数', 'type' => 'fieldset', 'default' => ['views' => ['min' => 20, 'max' => 50], 'like' => ['min' => 5, 'max' => 15]], 'fields' => [
['key' => 'views', 'label' => '阅读量', 'type' => 'between_number', 'default' => ['min' => 20, 'max' => 50]],
['key' => 'like', 'label' => '点赞数', 'type' => 'between_number', 'default' => ['min' => 5, 'max' => 15], 'description' => '新建文章时系统会根据此处设置的区间获取随机值填入对应项'],
]],
]],
],
],
+2 -1
View File
@@ -173,7 +173,8 @@ trait ScriptsPart1b {
$is_paid_content_single
);
if (!empty($singular_assets['needs_print'])) {
// 打印样式(media=print):内容页常驻,无设置开关(参考主题未提供该配置)。
if ($is_single_post || $is_single_resource || $is_static_page) {
$print_path = get_template_directory() . '/assets/css/frontend/print.css';
wp_enqueue_style(
'aksrt-print',
+5 -3
View File
@@ -41,7 +41,6 @@ trait ScriptsPart1c {
'needs_reward' => false,
'needs_yiyan' => false,
'needs_share' => false,
'needs_print' => false,
];
if (!is_singular()) {
@@ -139,7 +138,6 @@ trait ScriptsPart1c {
$requirements['needs_reward'] = $is_article && !empty($settings['rewards_enabled']);
$requirements['needs_yiyan'] = $has_yiyan;
$requirements['needs_share'] = $is_article && !empty($settings['share_enabled']);
$requirements['needs_print'] = !empty($settings['print_enabled']);
return $requirements;
}
@@ -157,6 +155,10 @@ trait ScriptsPart1c {
? \AKSRT\Settings\Settings::get_post_page_settings()
: [];
$lightbox_on = !isset($post_page_settings['lightbox']) || !empty($post_page_settings['lightbox']);
$lightbox_type = sanitize_key((string) ($post_page_settings['lightbox_type'] ?? 'group'));
if (!in_array($lightbox_type, ['group', 'alone'], true)) {
$lightbox_type = 'group';
}
wp_enqueue_script(
'bootstrap',
$base_uri . '/assets/js/runtime/libs/bootstrap.min.js',
@@ -187,7 +189,7 @@ trait ScriptsPart1c {
? \AKSRT\Settings\PaymentRuntime::get_paid_content_settings()['display']['currency_unit']
: __('元', 'aksrt'),
'imgbox' => $lightbox_on,
'imgbox_type' => 'group',
'imgbox_type' => $lightbox_on ? $lightbox_type : 'group',
'imgbox_thumbs' => $lightbox_on && (!isset($post_page_settings['lightbox_thumbs']) || !empty($post_page_settings['lightbox_thumbs'])),
'imgbox_zoom' => $lightbox_on && (!isset($post_page_settings['lightbox_zoom']) || !empty($post_page_settings['lightbox_zoom'])),
'imgbox_full' => $lightbox_on && (!isset($post_page_settings['lightbox_full']) || !empty($post_page_settings['lightbox_full'])),
+36 -13
View File
@@ -200,6 +200,28 @@ class PostDisplay {
$maxheight = 1000;
}
// 图片灯箱(参考主题 imagelightbox*):pc_s/m_s 复选框归并为单一开关。
$lightbox_type = sanitize_key((string) ($settings['imagelightbox_type'] ?? 'group'));
if (!in_array($lightbox_type, ['group', 'alone'], true)) {
$lightbox_type = 'group';
}
$lightbox_button = static function ($value, bool $default): bool {
if (!is_array($value)) {
return $default;
}
return !empty($value['pc_s']) || !empty($value['m_s']);
};
$lightbox_thumbs = $lightbox_button($settings['imagelightbox_thumbs_s'] ?? null, true);
$lightbox_zoom = $lightbox_button($settings['imagelightbox_zoom_s'] ?? null, true);
$lightbox_full = $lightbox_button($settings['imagelightbox_full_s'] ?? null, true);
$lightbox_down = $lightbox_button($settings['imagelightbox_down_s'] ?? null, true);
$lightbox_play = $lightbox_button($settings['imagelightbox_play_s'] ?? null, true);
// 文章预置参数:新建文章时按区间随机填入浏览/点赞(参考主题 post_default_mate)。
$default_mate = is_array($settings['post_default_mate'] ?? null) ? $settings['post_default_mate'] : [];
$views_range = is_array($default_mate['views'] ?? null) ? $default_mate['views'] : [];
$like_range = is_array($default_mate['like'] ?? null) ? $default_mate['like'] : [];
$related_style = sanitize_key((string) ($settings['post_related_type'] ?? 'img'));
if (!in_array($related_style, ['img', 'list', 'text'], true)) {
$related_style = 'img';
@@ -229,18 +251,19 @@ class PostDisplay {
'article_slide_cover' => !isset($settings['post_article_slide_cover']) || !empty($settings['post_article_slide_cover']),
'article_video_cover' => !isset($settings['post_article_video_cover']) || !empty($settings['post_article_video_cover']),
'article_video_cover_scale'=> max(20, min(100, (int) ($settings['post_article_video_cover_scale'] ?? 56))),
'lightbox' => !isset($settings['post_lightbox']) || !empty($settings['post_lightbox']),
'lightbox_thumbs' => !isset($settings['post_lightbox_thumbs']) || !empty($settings['post_lightbox_thumbs']),
'lightbox_zoom' => !isset($settings['post_lightbox_zoom']) || !empty($settings['post_lightbox_zoom']),
'lightbox_full' => !isset($settings['post_lightbox_full']) || !empty($settings['post_lightbox_full']),
'lightbox_down' => !empty($settings['post_lightbox_down']),
'lightbox_play' => !empty($settings['post_lightbox_play']),
'lightbox' => !isset($settings['imagelightbox']) || !empty($settings['imagelightbox']),
'lightbox_type' => $lightbox_type,
'lightbox_thumbs' => $lightbox_thumbs,
'lightbox_zoom' => $lightbox_zoom,
'lightbox_full' => $lightbox_full,
'lightbox_down' => $lightbox_down,
'lightbox_play' => $lightbox_play,
'related_enabled' => !isset($settings['post_related_s']) || !empty($settings['post_related_s']),
'related_count' => max(4, min(12, (int) ($settings['post_related_n'] ?? 6))),
'related_style' => $related_style,
'related_orderby' => $related_orderby,
'related_title' => sanitize_text_field((string) ($settings['related_title'] ?? '相关推荐')),
'like_enabled' => !isset($settings['post_like_enabled']) || !empty($settings['post_like_enabled']),
'like_enabled' => !isset($settings['post_like_s']) || !empty($settings['post_like_s']),
'favorite_enabled' => !isset($settings['post_favorite_enabled']) || !empty($settings['post_favorite_enabled']),
// Canonical + legacy share.
'share_enabled' => $share_enabled,
@@ -269,12 +292,12 @@ class PostDisplay {
'yiyan_header' => !empty($settings['post_yiyan_header']),
'yiyan_footer' => !empty($settings['post_yiyan_footer']),
'yiyan_box' => !empty($settings['post_yiyan_box']),
'default_views_min' => max(0, min(9999, (int) ($settings['post_default_views_min'] ?? 20))),
'default_views_max' => max(1, min(9999, (int) ($settings['post_default_views_max'] ?? 50))),
'default_likes_min' => max(0, min(9999, (int) ($settings['post_default_likes_min'] ?? 5))),
'default_likes_max' => max(1, min(9999, (int) ($settings['post_default_likes_max'] ?? 15))),
'print_enabled' => !isset($settings['feature_print']) || !empty($settings['feature_print']),
'pdf_export_enabled' => !empty($settings['feature_pdf_export']),
'default_views_min' => max(0, min(9999, (int) ($views_range['min'] ?? 20))),
'default_views_max' => max(1, min(9999, (int) ($views_range['max'] ?? 50))),
'default_likes_min' => max(0, min(9999, (int) ($like_range['min'] ?? 5))),
'default_likes_max' => max(1, min(9999, (int) ($like_range['max'] ?? 15))),
'article_nav' => !isset($settings['article_nav']) || !empty($settings['article_nav']),
'article_nav_mobile' => !isset($settings['article_nav_mobile_nav_s']) || !empty($settings['article_nav_mobile_nav_s']),
];
}