fix(frontend): match the reference post format options in the page set modal
参考主题把文章格式固定为标准/图像/画廊/视频四项,动态读取
get_theme_support('post-formats') 会让本站多出 aside/quote/link
等注册格式,选项集偏离参考主题,故改为固定列表。
This commit is contained in:
@@ -412,13 +412,21 @@ class PageAdminSet {
|
||||
return $this->render_inputs($inputs);
|
||||
}
|
||||
|
||||
/** AKSRT 注册的文章格式(standard + add_theme_support 注册项)。 */
|
||||
/**
|
||||
* 文章格式选项(1:1 对齐参考主题的固定列表)。
|
||||
*
|
||||
* 参考主题把标准/图像/画廊/视频四个格式写死在弹窗里,不读
|
||||
* get_theme_support('post-formats')。本站注册的格式比参考主题多
|
||||
* (aside/quote/link 等),动态枚举会让选项集偏离参考主题,
|
||||
* 因此同样固定这四项。
|
||||
*/
|
||||
private function post_format_options(): array {
|
||||
$options = ['standard' => __('标准', 'aksrt')];
|
||||
foreach (get_theme_support('post-formats') ? (array) get_theme_support('post-formats')[0] : [] as $format) {
|
||||
$options[$format] = esc_html(get_post_format_string($format));
|
||||
}
|
||||
return $options;
|
||||
return [
|
||||
'standard' => __('标准', 'aksrt'),
|
||||
'image' => __('图像', 'aksrt'),
|
||||
'gallery' => __('画廊', 'aksrt'),
|
||||
'video' => __('视频', 'aksrt'),
|
||||
];
|
||||
}
|
||||
|
||||
/** 分类术语的弹窗字段(对齐参考主题 tax 分支)。 */
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace {
|
||||
$GLOBALS['aksrt_set_page_templates'] = [];
|
||||
$GLOBALS['aksrt_set_can'] = true;
|
||||
$GLOBALS['aksrt_set_scripts'] = [];
|
||||
$GLOBALS['aksrt_set_post_format'] = '';
|
||||
|
||||
function __(string $text, string $domain = ''): string { return $text; }
|
||||
function esc_html__($t, $d = ''): string { return (string) $t; }
|
||||
@@ -48,7 +49,7 @@ namespace {
|
||||
function update_post_meta($id, $key, $value): void { $GLOBALS['aksrt_set_meta'][$key] = $value; }
|
||||
function get_the_title($id): string { return '示例标题'; }
|
||||
function get_the_permalink($id): string { return 'https://example.test/post'; }
|
||||
function get_post_format($id) { return ''; }
|
||||
function get_post_format($id) { return $GLOBALS['aksrt_set_post_format'] ?? ''; }
|
||||
function set_post_format($id, $format): void { $GLOBALS['aksrt_set_meta']['__format'] = $format; }
|
||||
function post_type_supports($type, $feature): bool { return $feature === 'post-formats'; }
|
||||
function get_theme_support($feature) { return $feature === 'post-formats' ? [['image', 'video']] : false; }
|
||||
@@ -290,6 +291,29 @@ namespace {
|
||||
}
|
||||
set_check(strpos($modal_icons, 'class="fa fa-') === false, 'modal must not use bare FA4 icon classes');
|
||||
|
||||
// 文章格式:参考主题固定 standard/图像/画廊/视频 四项,不读主题注册集。
|
||||
// 无格式时 WP 的 selected() 不选中任何项,浏览器默认落到第一项 standard。
|
||||
$format_block = substr($modal_icons, (int) strpos($modal_icons, 'name="post_format"'));
|
||||
$format_block = substr($format_block, 0, (int) strpos($format_block, '</select>'));
|
||||
set_check($format_block !== '', 'post inputs must include the post_format select');
|
||||
$option_order = [];
|
||||
preg_match_all('/<option[^>]*value="([^"]*)"/', $format_block, $m);
|
||||
$option_order = $m[1];
|
||||
set_check($option_order === ['standard', 'image', 'gallery', 'video'], 'post format options must mirror the reference order');
|
||||
set_check(strpos($format_block, '>图像<') !== false, 'post format must use the reference 图像 label');
|
||||
set_check(strpos($format_block, '>画廊<') !== false, 'post format must use the reference 画廊 label');
|
||||
set_check(strpos($format_block, '>视频<') !== false, 'post format must use the reference 视频 label');
|
||||
foreach (['aside', 'quote', 'link'] as $extra) {
|
||||
set_check(strpos($modal_icons, "value=\"{$extra}\"") === false, "post format options must not leak the theme-only format {$extra}");
|
||||
}
|
||||
// 已设置格式时必须回显选中项。
|
||||
$GLOBALS['aksrt_set_meta']['__format'] = '';
|
||||
$GLOBALS['aksrt_set_post_format'] = 'image';
|
||||
ob_start();
|
||||
(new PageAdminSet())->render_modal();
|
||||
$modal_image = (string) ob_get_clean();
|
||||
set_check(strpos($modal_image, '<option selected="selected" value="image">') !== false, 'the active format must render as selected');
|
||||
|
||||
$gear = (new PageAdminSet())->float_button('', false);
|
||||
set_check(strpos($gear, 'fa fas fa-cog fa-spin') !== false, 'the gear must use the FA5 cog class');
|
||||
|
||||
|
||||
@@ -197,6 +197,11 @@ test('frontend page edit ships gate, footer modal, and legacy ajax-save contract
|
||||
assert.match(pageAdminSet, /update_post_meta\(\$post_id, '_aksrt_like_count', max\(0, \(int\) \$_POST\['like'\]\)\)/);
|
||||
assert.match(pageAdminSet, /wp_update_term\(\$term_id, \(string\) \$term->taxonomy, \$data\)/);
|
||||
assert.match(pageAdminSet, /set_post_format\(\$post_id, \$format === 'standard' \? '' : \$format\)/);
|
||||
// 文章格式 mirrors the reference's fixed four-option list, not the theme's
|
||||
// wider add_theme_support('post-formats') registration.
|
||||
assert.match(pageAdminSet, /return \[\s*'standard' => __\('标准', 'aksrt'\),\s*'image' => __\('图像', 'aksrt'\),\s*'gallery' => __\('画廊', 'aksrt'\),\s*'video' => __\('视频', 'aksrt'\),\s*\];/s);
|
||||
assert.doesNotMatch(pageAdminSet, /get_theme_support\('post-formats'\)\s*\?/);
|
||||
assert.doesNotMatch(pageAdminSet, /get_post_format_string\(/);
|
||||
// Page branch: 标题样式 + 模块布局(widgets_register) + 容器位置.
|
||||
assert.match(pageAdminSet, /esc_attr\(\(string\) \(\$meta\['id'\] \?\? ''\)\) \. '\[\]" id="'/);
|
||||
assert.match(pageAdminSet, /'page_header_style'/);
|
||||
|
||||
Reference in New Issue
Block a user