From d787f3ff976c6f334cec2590a27cd2742693aa73 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 17 Sep 2026 12:19:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(payment):=20=E5=AF=BC=E5=85=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=86=8D=E4=BD=BF=E7=94=A8=20WP=20notice=20?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E9=81=BF=E5=85=8D=E8=A2=AB=20common.js=20?= =?UTF-8?q?=E6=90=AC=E5=88=B0=E9=A1=B5=E9=9D=A2=E9=A1=B6=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 真因:wp-admin/js/common.js 在 DOM 就绪时执行 $('div.updated, div.error, div.notice').not('.inline, .below-h2').insertAfter($headerEnd) 它会把页面上所有「非 inline」的 notice 搬到 .wp-header-end(不存在时取 .wrap 内首个 h1/h2)之后。提示块原先输出 class="aksrt-submsg notice notice-warning",被判定为 notice,于是在求值之后被整块搬到页头:既脱离「添加方式—卡密数据」之间的字段区, 又因为搬迁发生在 evalDeps 之后,行内显隐逻辑无从纠正。 这也是同一现象反复出现的真因:四条提示都可见时会被整体搬到页面最上方;给提示块 补上初始隐藏后看起来像「提示不见了」;改为全文档求值后则表现为「提示显示在页面 最顶部」。此前的 foster-parenting 判断有误——服务端输出的表格结构始终合法。 改动: - submessage_row() 只输出自有类名 aksrt-submsg,不再复用 .notice / .notice-warning。 - 外观(底色 #fef8ee + 左侧 4px #f0b849 色条)改由 .aksrt-submsg 自带,与参考主题 CSF content 字段的做法一致;元素内联样式只保留初始隐藏状态。 - 新增契约用例:提示块不得带 notice;.aksrt-submsg 必须自带 background 与 border-left; 并确认页面级错误通知仍正常使用 notice(不误伤其它通知输出)。 --- src/Admin/Native/PayChargeCards.php | 19 +++++++---- tests/admin/charge-cards-dependency.test.cjs | 35 +++++++++++++++++--- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/Admin/Native/PayChargeCards.php b/src/Admin/Native/PayChargeCards.php index fe392193..05b9e97e 100644 --- a/src/Admin/Native/PayChargeCards.php +++ b/src/Admin/Native/PayChargeCards.php @@ -855,12 +855,16 @@ class PayChargeCards { */ private function submessage_row(array $deps, string $content): void { $dep_attr = ' data-dep="' . esc_attr((string) wp_json_encode($deps)) . '"'; - $hidden = $this->deps_visible($deps) ? '' : 'display:none;'; - // data-dep 与初始隐藏状态必须同时挂在 和内层提示块上,不能只依赖行: - // 提示块一旦脱离所在行(表格上下文里出现不被允许的节点时,HTML 解析器会把它 - // foster-parent 到 之前),只有 带状态会让四条提示永久铺开、 - // 且切换卡密类型/添加方式时求值结果无处落地。自带状态后两种结构都成立。 - echo ''; // phpcs:ignore WordPress.Security.EscapeOutput -- 文案已转义。 + $hidden = $this->deps_visible($deps) ? '' : ' style="display:none;"'; + // 提示块**不要**挂 WP 的 .notice / .notice-warning:wp-admin/js/common.js 在 DOM + // 就绪时会执行 + // $('div.updated, div.error, div.notice').not('.inline, .below-h2').insertAfter($headerEnd) + // 把页面上所有「非 inline」的 notice 整块搬到 .wp-header-end(不存在时取 .wrap 内首个 + // h1/h2)之后。提示块一旦带上 notice,就会被搬到页面顶部、脱离「添加方式—卡密数据」 + // 之间的字段区,而且搬迁发生在求值之后,行内的显隐逻辑无从纠正。 + // 外观改由 .aksrt-submsg 自带(见 print_assets),与参考主题 CSF content 字段一致。 + // data-dep 与初始隐藏状态同时挂在 和内层提示块上:提示块若脱离所在行,仍能自行显隐。 + echo ''; // phpcs:ignore WordPress.Security.EscapeOutput -- 文案已转义。 } /** @@ -1053,6 +1057,9 @@ class PayChargeCards { .aksrt-btnset-item input { position: absolute; opacity: 0; pointer-events: none; } .aksrt-btnset-item span { display: inline-block; padding: 3px 12px; border: 1px solid #c3c4c7; border-radius: 3px; background: #fff; } .aksrt-btnset-item input:checked + span { background: #2271b1; border-color: #2271b1; color: #fff; } + /* 导入提示:复刻后台 notice-warning 的外观,但**不用** .notice 类 —— 见 submessage_row() + 的说明,带 .notice 会被 wp-admin/js/common.js 搬到页面顶部。改这里请连带改那里。 */ + .aksrt-submsg { margin: 6px 0; padding: 6px 12px; background: #fef8ee; border-left: 4px solid #f0b849; } .aksrt-copy-tip { margin-left: 6px; color: #00a32a; font-size: 12px; white-space: nowrap; }
' . $content . '
' . $content . '