refactor(color): use wpColorPicker for page config nav color

Replace the native input[type=color] in the page config meta box with a
wpColorPicker-enhanced text input, enqueued only on page edit screens, and
contract-lock that no native color inputs remain in theme PHP.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-10-28 21:01:54 +08:00
1 parent ed1487d505
commit fcec5b996f
2 files changed
+32 -1

No files matched your search

+15 -1
View File
@@ -18,6 +18,20 @@ final class PageConfigMetaBox {
public static function init(): void {
add_action('add_meta_boxes_page', [self::class, 'register']);
add_action('save_post_page', [self::class, 'save']);
add_action('admin_enqueue_scripts', [self::class, 'enqueue']);
}
public static function enqueue(string $hook): void {
if (!in_array($hook, ['post.php', 'post-new.php'], true)) {
return;
}
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
if (!$screen || 'page' !== $screen->post_type) {
return;
}
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wp-color-picker');
wp_add_inline_script('wp-color-picker', "jQuery(function($){ $('.aksrt-page-config-color').wpColorPicker(); });");
}
public static function register(): void {
@@ -64,7 +78,7 @@ final class PageConfigMetaBox {
</div>
<label for="aksrt-header-slider-nav-color"><?php esc_html_e('导航栏文字颜色', 'aksrt'); ?></label>
<div><input id="aksrt-header-slider-nav-color" type="color" name="page_config[header_slider_nav_color]" value="<?php echo esc_attr((string) ($config['header_slider_nav_color'] ?? '#ffffff')); ?>"></div>
<div><input id="aksrt-header-slider-nav-color" class="aksrt-page-config-color" type="text" name="page_config[header_slider_nav_color]" value="<?php echo esc_attr((string) ($config['header_slider_nav_color'] ?? '#ffffff')); ?>" data-default-color="#ffffff"></div>
<?php self::render_json_field('header_slider', __('背景内容', 'aksrt'), $config['header_slider'] ?? self::slide_defaults(), 16); ?>
<?php self::render_json_field('header_slider_option', __('背景显示设置', 'aksrt'), $config['header_slider_option'] ?? self::slider_defaults(), 12); ?>