Merge branch main into 做logo for favicon release

This commit is contained in:
2026-09-27 11:35:40 +08:00
6 changed files with 124 additions and 10 deletions
+114 -2
View File
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'MING_VERSION', '1.7.3' );
define( 'MING_VERSION', '1.7.4' );
/**
* Theme setup.
@@ -52,6 +52,66 @@ function ming_setup() {
}
add_action( 'after_setup_theme', 'ming_setup' );
/**
* Return the site's WordPress locale in a form suitable for comparisons.
*
* @return string
*/
function ming_site_locale() {
return strtolower( str_replace( '-', '_', get_locale() ) );
}
/**
* Build font stacks for the language selected in WordPress settings.
*
* Self-hosted TC font files are used for Traditional Chinese. Other site
* languages use the appropriate platform font stack and do not request a
* Chinese Traditional web font.
*
* @return string CSS custom-property declarations.
*/
function ming_font_stack_css() {
$locale = ming_site_locale();
$fonts = array(
'sans' => "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
'serif' => "Georgia, 'Times New Roman', serif",
'latin' => "'Cormorant Garamond', Georgia, 'Times New Roman', serif",
);
if ( preg_match( '/^zh_(?:hant(?:_|$)|tw(?:_|$)|hk(?:_|$)|mo(?:_|$))/', $locale ) ) {
$fonts = array(
'sans' => "'Noto Sans TC', 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft JhengHei', 'Heiti TC', sans-serif",
'serif' => "'Noto Serif TC', 'Noto Serif CJK TC', 'Songti TC', 'PMingLiU', 'MingLiU', serif",
'latin' => "'Cormorant Garamond', 'Noto Serif TC', 'Noto Serif CJK TC', 'Songti TC', serif",
);
} elseif ( preg_match( '/^zh_/', $locale ) ) {
$fonts = array(
'sans' => "'Noto Sans SC', 'Noto Sans CJK SC', 'PingFang SC', 'Microsoft YaHei', 'Heiti SC', sans-serif",
'serif' => "'Noto Serif SC', 'Noto Serif CJK SC', 'Songti SC', SimSun, serif",
'latin' => "'Cormorant Garamond', 'Noto Serif SC', 'Noto Serif CJK SC', 'Songti SC', serif",
);
} elseif ( preg_match( '/^ja(?:_|$)/', $locale ) ) {
$fonts = array(
'sans' => "'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif",
'serif' => "'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif",
'latin' => "'Cormorant Garamond', 'Noto Serif JP', 'Hiragino Mincho ProN', serif",
);
} elseif ( preg_match( '/^ko(?:_|$)/', $locale ) ) {
$fonts = array(
'sans' => "'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif",
'serif' => "'Noto Serif KR', AppleMyungjo, Batang, serif",
'latin' => "'Cormorant Garamond', 'Noto Serif KR', AppleMyungjo, serif",
);
}
return sprintf(
":root {\n\t--serif: %1\$s;\n\t--latin: %2\$s;\n\t--sans: %3\$s;\n}\n",
$fonts['serif'],
$fonts['latin'],
$fonts['sans']
);
}
/**
* Enqueue assets.
*/
@@ -65,6 +125,7 @@ function ming_assets() {
);
wp_enqueue_style( 'ming-main', get_template_directory_uri() . '/assets/css/main.css', array( 'ming-fonts' ), MING_VERSION );
wp_add_inline_style( 'ming-main', ming_font_stack_css() );
wp_enqueue_script( 'ming-main', get_template_directory_uri() . '/assets/js/main.js', array(), MING_VERSION, true );
// Pass image directory to JS (product grid).
@@ -739,6 +800,57 @@ add_action( 'after_switch_theme', 'ming_seed_footer_content' );
* ==========================================================*/
/* ---------- OG / Twitter 分享標籤 ---------- */
/**
* Return an Open Graph locale derived from the WordPress site language.
*
* @return string
*/
function ming_og_locale() {
$locale = ming_site_locale();
if ( 0 === strpos( $locale, 'zh_' ) ) {
if ( preg_match( '/(?:hk)/', $locale ) ) {
return 'zh_HK';
}
if ( preg_match( '/(?:mo)/', $locale ) ) {
return 'zh_MO';
}
return preg_match( '/(?:hant|tw)/', $locale ) ? 'zh_TW' : 'zh_CN';
}
$parts = explode( '_', $locale );
$language = isset( $parts[0] ) ? $parts[0] : 'en';
$region = '';
foreach ( array_reverse( $parts ) as $part ) {
if ( 2 === strlen( $part ) && ctype_alpha( $part ) ) {
$region = strtoupper( $part );
break;
}
}
if ( $region ) {
return $language . '_' . $region;
}
$default_regions = array(
'ar' => 'SA',
'de' => 'DE',
'en' => 'US',
'es' => 'ES',
'fr' => 'FR',
'it' => 'IT',
'ja' => 'JP',
'ko' => 'KR',
'nl' => 'NL',
'pl' => 'PL',
'pt' => 'BR',
'ru' => 'RU',
);
return isset( $default_regions[ $language ] ) ? $language . '_' . $default_regions[ $language ] : 'en_US';
}
add_action( 'wp_head', 'ming_og_tags', 5 );
function ming_og_tags() {
if ( is_admin() || ( function_exists( 'is_embed' ) && is_embed() ) ) { return; }
@@ -784,7 +896,7 @@ function ming_og_tags() {
echo '<meta property="og:description" content="' . esc_attr( $desc ) . '">' . "\n";
echo '<meta property="og:url" content="' . esc_url( $url ) . '">' . "\n";
echo '<meta property="og:type" content="' . esc_attr( $type ) . '">' . "\n";
echo '<meta property="og:locale" content="zh_TW">' . "\n";
echo '<meta property="og:locale" content="' . esc_attr( ming_og_locale() ) . '">' . "\n";
if ( $image ) {
echo '<meta property="og:image" content="' . esc_url( $image ) . '">' . "\n";
}