refactor: 死代码清理 + CDN SRI 加固 + 面包屑组件 + 代码规范文档

- 删除 7 个死模板文件 (products/services/quality/process/projects/customization/rfq)
- 删除 13 个旧图片素材 (jpg/png/webp)
- 新增 CDN SRI 完整性校验 (Bootstrap CSS/JS)
- 新增面包屑导航模板组件
- 新增代码清理方案与代码审查标准文档
- 更新 README.md
This commit is contained in:
2026-07-24 17:48:00 +08:00
parent 8a2890f8b4
commit 43272d25eb
39 changed files with 848 additions and 332 deletions
-43
View File
@@ -52,16 +52,9 @@ function fragrance_trade_customize_register( $wp_customize ) {
$sections = array(
'fragrance_b2b_hero' => __( '首屏定位', 'fragrance-trade' ),
'fragrance_b2b_trust' => __( '信任栏', 'fragrance-trade' ),
'fragrance_b2b_services' => __( '服务项目', 'fragrance-trade' ),
'fragrance_b2b_products' => __( '产品能力', 'fragrance-trade' ),
'fragrance_b2b_customization' => __( '定制选项', 'fragrance-trade' ),
'fragrance_b2b_factory' => __( '门店环境与参观', 'fragrance-trade' ),
'fragrance_b2b_quality' => __( '品质管控', 'fragrance-trade' ),
'fragrance_b2b_process' => __( '项目流程', 'fragrance-trade' ),
'fragrance_b2b_projects' => __( '项目案例', 'fragrance-trade' ),
'fragrance_b2b_documents' => __( '文档支持', 'fragrance-trade' ),
'fragrance_b2b_faq' => __( '常见问题', 'fragrance-trade' ),
'fragrance_b2b_rfq' => __( '预约表单', 'fragrance-trade' ),
'fragrance_contact_social' => __( '联系方式与社交链接', 'fragrance-trade' ),
);
$priority = 10;
@@ -79,12 +72,6 @@ function fragrance_trade_customize_register( $wp_customize ) {
array( 'b2b_hero_secondary_label', 'fragrance_b2b_hero', __( '次按钮文字', 'fragrance-trade' ), 'text' ),
array( 'b2b_hero_secondary_url', 'fragrance_b2b_hero', __( '次按钮链接', 'fragrance-trade' ), 'url' ),
array( 'b2b_trust_title', 'fragrance_b2b_trust', __( '信任栏标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_services_title', 'fragrance_b2b_services', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_services_text', 'fragrance_b2b_services', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_products_title', 'fragrance_b2b_products', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_products_text', 'fragrance_b2b_products', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_custom_title', 'fragrance_b2b_customization', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_custom_text', 'fragrance_b2b_customization', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_factory_eyebrow', 'fragrance_b2b_factory', __( '眉标', 'fragrance-trade' ), 'text' ),
array( 'b2b_factory_title', 'fragrance_b2b_factory', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_factory_text', 'fragrance_b2b_factory', __( '门店简介', 'fragrance-trade' ), 'textarea' ),
@@ -93,21 +80,11 @@ function fragrance_trade_customize_register( $wp_customize ) {
array( 'b2b_video_text', 'fragrance_b2b_factory', __( '视频描述', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_video_url', 'fragrance_b2b_factory', __( 'YouTube、Vimeo 或视频链接', 'fragrance-trade' ), 'url' ),
array( 'b2b_video_image', 'fragrance_b2b_factory', __( '视频封面图', 'fragrance-trade' ), 'image' ),
array( 'b2b_quality_title', 'fragrance_b2b_quality', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_quality_text', 'fragrance_b2b_quality', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_process_title', 'fragrance_b2b_process', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_process_text', 'fragrance_b2b_process', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_show_projects', 'fragrance_b2b_projects', __( '显示项目案例', 'fragrance-trade' ), 'checkbox' ),
array( 'b2b_projects_title', 'fragrance_b2b_projects', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_projects_text', 'fragrance_b2b_projects', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_show_documents', 'fragrance_b2b_documents', __( '显示文档板块', 'fragrance-trade' ), 'checkbox' ),
array( 'b2b_documents_title', 'fragrance_b2b_documents', __( '板块标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_documents_text', 'fragrance_b2b_documents', __( '板块简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_show_faq', 'fragrance_b2b_faq', __( '显示常见问题', 'fragrance-trade' ), 'checkbox' ),
array( 'b2b_faq_title', 'fragrance_b2b_faq', __( '常见问题标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_rfq_title', 'fragrance_b2b_rfq', __( '预约标题', 'fragrance-trade' ), 'text' ),
array( 'b2b_rfq_text', 'fragrance_b2b_rfq', __( '预约简介', 'fragrance-trade' ), 'textarea' ),
array( 'b2b_rfq_button_label', 'fragrance_b2b_rfq', __( '提交按钮文字', 'fragrance-trade' ), 'text' ),
array( 'inquiry_email', 'fragrance_contact_social', __( '预约收件邮箱', 'fragrance-trade' ), 'email' ),
array( 'whatsapp', 'fragrance_contact_social', __( 'WhatsApp 号码(含国家代码)', 'fragrance-trade' ), 'text' ),
array( 'facebook_url', 'fragrance_contact_social', __( 'Facebook 链接', 'fragrance-trade' ), 'url' ),
@@ -125,35 +102,15 @@ function fragrance_trade_customize_register( $wp_customize ) {
for ( $index = 1; $index <= 4; $index++ ) {
$fields[] = array( 'b2b_metric_' . $index . '_value', 'fragrance_b2b_trust', sprintf( __( '信任点 %d 数值', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_metric_' . $index . '_label', 'fragrance_b2b_trust', sprintf( __( '信任点 %d 标签', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_service_' . $index . '_title', 'fragrance_b2b_services', sprintf( __( '服务 %d 标题', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_service_' . $index . '_text', 'fragrance_b2b_services', sprintf( __( '服务 %d 描述', 'fragrance-trade' ), $index ), 'textarea' );
$fields[] = array( 'b2b_factory_point_' . $index, 'fragrance_b2b_factory', sprintf( __( '门店亮点 %d', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_factory_image_' . $index, 'fragrance_b2b_factory', sprintf( __( '门店图片 %d', 'fragrance-trade' ), $index ), 'image' );
$fields[] = array( 'b2b_document_' . $index . '_title', 'fragrance_b2b_documents', sprintf( __( '文档卡片 %d 标题', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_document_' . $index . '_text', 'fragrance_b2b_documents', sprintf( __( '文档卡片 %d 描述', 'fragrance-trade' ), $index ), 'textarea' );
}
for ( $index = 1; $index <= 7; $index++ ) {
$fields[] = array( 'b2b_product_' . $index . '_title', 'fragrance_b2b_products', sprintf( __( '产品参考 %d 标题', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_product_' . $index . '_text', 'fragrance_b2b_products', sprintf( __( '产品参考 %d 描述', 'fragrance-trade' ), $index ), 'textarea' );
$fields[] = array( 'b2b_product_' . $index . '_specs', 'fragrance_b2b_products', sprintf( __( '产品参考 %d 规格行', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_product_' . $index . '_image', 'fragrance_b2b_products', sprintf( __( '产品参考 %d 图片', 'fragrance-trade' ), $index ), 'image' );
}
for ( $index = 1; $index <= 8; $index++ ) {
$fields[] = array( 'b2b_custom_' . $index . '_title', 'fragrance_b2b_customization', sprintf( __( '定制项 %d', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_process_' . $index . '_title', 'fragrance_b2b_process', sprintf( __( '流程步骤 %d 标题', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_process_' . $index . '_text', 'fragrance_b2b_process', sprintf( __( '流程步骤 %d 描述', 'fragrance-trade' ), $index ), 'textarea' );
$fields[] = array( 'b2b_faq_' . $index . '_question', 'fragrance_b2b_faq', sprintf( __( '问题 %d', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_faq_' . $index . '_answer', 'fragrance_b2b_faq', sprintf( __( '回答 %d', 'fragrance-trade' ), $index ), 'textarea' );
}
for ( $index = 1; $index <= 6; $index++ ) {
$fields[] = array( 'b2b_quality_' . $index . '_title', 'fragrance_b2b_quality', sprintf( __( '品质步骤 %d 标题', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_quality_' . $index . '_text', 'fragrance_b2b_quality', sprintf( __( '品质步骤 %d 描述', 'fragrance-trade' ), $index ), 'textarea' );
}
for ( $index = 1; $index <= 3; $index++ ) {
$fields[] = array( 'b2b_project_' . $index . '_title', 'fragrance_b2b_projects', sprintf( __( '项目案例 %d 标题', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_project_' . $index . '_meta', 'fragrance_b2b_projects', sprintf( __( '项目案例 %d 标签', 'fragrance-trade' ), $index ), 'text' );
$fields[] = array( 'b2b_project_' . $index . '_text', 'fragrance_b2b_projects', sprintf( __( '项目案例 %d 描述', 'fragrance-trade' ), $index ), 'textarea' );
}
foreach ( $fields as $field ) {
fragrance_trade_customize_add_field( $wp_customize, $field[0], $field[1], $field[2], $field[3] );
+22
View File
@@ -64,3 +64,25 @@ function fragrance_trade_notice_message( $code ) {
);
return isset( $messages[ $code ] ) ? $messages[ $code ] : '';
}
add_action(
'admin_notices',
function () {
$locations = get_nav_menu_locations();
$menu_id = isset( $locations['primary'] ) ? $locations['primary'] : 0;
if ( ! $menu_id ) {
return;
}
$items = wp_get_nav_menu_items( $menu_id );
$count = $items ? count( $items ) : 0;
if ( $count < 2 ) {
printf(
'<div class="notice notice-warning is-dismissible"><p><strong>%s</strong> %s <a href="%s">%s</a></p></div>',
esc_html__( '主导航菜单项过少', 'fragrance-trade' ),
esc_html__( '手机端和桌面端导航目前只显示一个菜单项。请前往后台添加:首页、服务项目、案例作品、关于门店、常见问题、预约联系。', 'fragrance-trade' ),
esc_url( admin_url( 'nav-menus.php' ) ),
esc_html__( '编辑菜单', 'fragrance-trade' )
);
}
}
);
+9 -1
View File
@@ -1,5 +1,13 @@
<?php
/** Secure B2B RFQ handling. @package Fragrance_Trade */
/**
* Secure RFQ form handler (deprecated).
*
* @package Fragrance_Trade
* @deprecated 2.1.0 Contact page no longer has a form. This handler remains
* registered but is never triggered. Kept as a security reference
* implementation (nonce + honeypot + rate-limit + header injection
* guard) in case a booking form is re-introduced.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
+50 -7
View File
@@ -28,6 +28,28 @@ function fragrance_trade_setup() {
}
add_action( 'after_setup_theme', 'fragrance_trade_setup' );
/**
* Add Bootstrap 5 nav-item / nav-link classes to primary menu.
*
* Without these classes the offcanvas mobile menu items may not render
* properly because Bootstrap's offcanvas CSS relies on them for display.
*/
function fragrance_trade_nav_menu_css_class( $classes, $item, $args ) {
if ( 'primary' === $args->theme_location ) {
$classes[] = 'nav-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'fragrance_trade_nav_menu_css_class', 10, 3 );
function fragrance_trade_nav_menu_link_attributes( $atts, $item, $args ) {
if ( 'primary' === $args->theme_location ) {
$atts['class'] = isset( $atts['class'] ) ? $atts['class'] . ' nav-link' : 'nav-link';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'fragrance_trade_nav_menu_link_attributes', 10, 3 );
/**
* Return a cache-busting version for a local theme asset.
*
@@ -54,12 +76,33 @@ function fragrance_trade_enqueue_assets() {
wp_enqueue_script( 'fragrance-bootstrap', 'https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0-alpha3/js/bootstrap.bundle.min.js', array(), '5.3.0-alpha3', true );
wp_enqueue_script( 'fragrance-plugins', get_template_directory_uri() . '/assets/js/plugins.js', array( 'jquery' ), fragrance_trade_asset_version( 'assets/js/plugins.js', $version ), true );
wp_enqueue_script( 'fragrance-theme', get_template_directory_uri() . '/assets/js/theme.js', array( 'jquery', 'fragrance-bootstrap', 'fragrance-plugins' ), fragrance_trade_asset_version( 'assets/js/theme.js', $version ), true );
wp_localize_script(
'fragrance-theme',
'fragranceTrade',
array(
'motionQuery' => '(prefers-reduced-motion: reduce)',
)
);
}
add_action( 'wp_enqueue_scripts', 'fragrance_trade_enqueue_assets' );
/**
* SRI integrity hashes for CDN-hosted resources.
*
* Computed 2026-07-24 from cdn.bootcdn.net.
* Verify/update via: curl -sL <url> | openssl dgst -sha384 -binary | openssl base64 -A
*/
function fragrance_trade_style_sri( $html, $handle ) {
$sri = array(
'fragrance-bootstrap' => 'sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ',
);
if ( isset( $sri[ $handle ] ) ) {
$html = str_replace( '/>', ' integrity="' . esc_attr( $sri[ $handle ] ) . '" crossorigin="anonymous" />', $html );
}
return $html;
}
add_filter( 'style_loader_tag', 'fragrance_trade_style_sri', 10, 2 );
function fragrance_trade_script_sri( $html, $handle ) {
$sri = array(
'fragrance-bootstrap' => 'sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe',
);
if ( isset( $sri[ $handle ] ) ) {
$html = str_replace( '></script>', ' integrity="' . esc_attr( $sri[ $handle ] ) . '" crossorigin="anonymous"></script>', $html );
}
return $html;
}
add_filter( 'script_loader_tag', 'fragrance_trade_script_sri', 10, 2 );