laoyang
|
db2e9c4230
|
3.2.47: 修 [Archives] 首字母大写不生效(WP 短代码标签区分大小写)#17
用户线上实测:页面 /blogtime 写 [Archives] 原样输出 <p>[Archives]</p>,
看起来像"短代码没装/被 markdown 插件转义",实际是标签名大小写对不上。
根因(内核证据,wp-includes/shortcodes.php):
· get_shortcode_regex() 用 implode('|', array_map('preg_quote',$tagnames))
拼正则,不做任何大小写归一化
· do_shortcode() 的 preg_match_all('/'.get_shortcode_regex().'/') 没有 i 修饰符
· do_shortcode_tag() 用 $m[2] 精确查 $shortcode_tags
⇒ add_shortcode('archives') 只匹配全小写,[Archives] 完全匹配不上。
线上实测(真实 WP 环境跑 do_shortcode):
[archives] 长度=209239 解析=是
[Archives] 长度=10 解析=否(原样返回)
[ARCHIVES] 长度=10 解析=否(原样返回)
3.2.46 里我写的注释"WP 短代码标签大小写不敏感、内部统一 strtolower"
是错的,这一版一并改正。
改动:
· inc/theme-archives.php
- 同时注册 archives / Archives / ARCHIVES 三种写法
(不为任意混合大小写膨胀正则,[aRcHiVeS] 刻意不支持,已加断言锁住)
- 修短代码签名:$atts, $content, $tag —— 补上中间的 $content
WP 通过 call_user_func($fn, $attr, $content, $tag) 传三个参数,
漏掉 $content 会让 $tag 落到第 2 个形参上,实际收到空串,
shortcode_atts_{$tag} 退化成无主的 shortcode_atts_
- shortcode_atts 第 3 参数改为实际命中的 $tag(原来写死 'archives')
· style.css 版本号 3.2.46 -> 3.2.47
测试也一并修(这才是本轮最值得记的):
· _archives_unit.php 的 add_shortcode 桩原来写了 strtolower($tag),
比真实 WP 宽容 ⇒ 产品坏着、94 条断言全绿。
现在照抄内核不归一化,并新增真实的 do_shortcode 解析实现。
· ⑪ 组从"查注册表有没有 archives 这个键"改成"拿真实写法解析一遍"
· 新增断言:三种写法都渲染出 .yang-archives、
混合大小写原样返回(刻意不支持)、未注册标签原样保留、
shortcode_atts 收到的 tag 恰好是实际命中的那个
· _archives_unit_falsify.py 新增 R5~R8 四条注入:
R5 只注册小写(3.2.46 的错误形态)→ 红 10 条
R6 大写注册指向不存在的回调 → 红 4 条
R7 shortcode_atts 的 tag 写死小写 → 红 2 条
R8 签名去掉中间的 $content → 红 3 条
验证:
2j 评论关闭零输出 通过 54 / 0 失败
2k 评论关闭反向验证 真红 13 / 0 无效
2l 归档单测 通过 109 / 0 失败(原 94,新增 15 条)
2m 归档端到端 通过 109 / 0 失败
2n 归档端到端反向 真红 21 / 0 无效
2o 归档源码级反向 真红 10 / 0 无效(原 6,新增 4 条)
lint 96 个 PHP 文件全过
线上验证(真实 WordPress,不是模拟):
补注册前:只 ["archives"],[Archives] 原样返回
补注册后:["archives","Archives","ARCHIVES"],三种写法长度全是 209239
发布:已推 3.2.47 到 /theme-update/,update.json 已落 3.2.47;
服务器 wp-content/themes/kratos_yang/ 仍为 3.2.46(未覆盖,
等用户在后台点升级)。
|
2026-10-26 14:04:12 +08:00 |
|
laoyang
|
7047ab3ece
|
3.2.46: 新增 [Archives] 归档短代码 + 评论关闭时整块零输出 #15
需求一:[Archives] 短代码 —— 归档式全站文章列表
· 在文章/页面正文写一行 [Archives],该位置渲染全站文章的年月归档
· 默认显示今年,按月份归类;每篇带浏览/评论/点赞三个数
· 上下两排各有一组「上一年 / 下一年」按钮(四角),JS 切换不刷新页面
· 地址栏同步 ?arc_year=,刷新与分享链接都能保持同一年
· 只在用到短代码的页面才加载 assets/js|css/archives.js|css
· 参数:year="2025" 指定首年;month="0" 不按月分组
需求二:评论关闭时评论区整块消失
· comments.php 在**任何输出之前** `if (!comments_open()) return;`
—— 零字节,不是空容器、不是 display:none、不留提示文字
· 已有评论的老文章关评论后也不再显示(需求原话:正文之外什么都没有)
· inc/theme-comments.php 的资源守卫与之同口径:关评论时不加载
约 10KB 的 comments.css / comments.js
· 删掉 .comments-closed 样式与两处「评论已关闭」提示分支
开发中实测抓到并修掉的三个真实 bug(都是"测试把期望值写对之后"才显形):
· 年份标题 / 导航年份过了 number_format_i18n() ⇒ 输出「2,025」,
而 JS 侧 String(year) 输出「2025」⇒ 首屏与切年后不一致
· 月份标题同样过 number_format_i18n(),与 JS 侧 String(m) 口径不一致
· yang_archives_render_nav() 把 ar-nav-top 写死,而下排也调它生成
⇒ 下排被叫成 top(视觉上被更高特异性规则压住,看不出问题)
验证:
归档 _archives_unit.php 94 通过 / 0 失败
_archives_e2e.js 109 通过 / 0 失败
_archives_e2e_falsify.js 反证 25 真红 / 0 无效
_archives_unit_falsify.py 反证 6 真红 / 0 无效
评论 _comments_closed_test.php 54 通过 / 0 失败
_comments_closed_falsify.py 反证 13 真红 / 0 无效
回归 _test_comments.php 64 通过 / 0 失败
_hl_unit_run.py 24 通过 / 0 失败
全量 96 个 PHP 文件语法检查通过;包内 lint 通过
发布 已推 3.2.46 到 /theme-update/,update.json 已落 3.2.46;
服务器 wp-content/themes/kratos_yang/ 仍为 3.2.45(未覆盖)
另:把 _archives_unit.php 从 `__DIR__` 定位改为接受根目录参数,
否则它无法登记进 verify_all.sh,只能手动跑(手动跑 = 长期不跑)。
5 个新套件已登记进 verify_all.sh(2j ~ 2o)。
|
2026-10-26 13:25:51 +08:00 |
|