add_section( 'aics_colors', array( 'title' => __( 'サイトカラー設定', 'ai-creative-studio' ), 'priority' => 30, 'description' => __( 'サイト全体のカラーテーマを設定します。', 'ai-creative-studio' ), ) ); // メインカラー $wp_customize->add_setting( 'aics_primary_color', array( 'default' => '#1e40af', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', // リアルタイムプレビュー ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'aics_primary_color', array( 'label' => __( 'メインカラー', 'ai-creative-studio' ), 'section' => 'aics_colors', 'settings' => 'aics_primary_color', ) ) ); // アクセントカラー $wp_customize->add_setting( 'aics_accent_color', array( 'default' => '#f59e0b', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'aics_accent_color', array( 'label' => __( 'アクセントカラー', 'ai-creative-studio' ), 'section' => 'aics_colors', 'settings' => 'aics_accent_color', ) ) ); /** * セクション2: サイト情報設定 */ $wp_customize->add_section( 'aics_site_info', array( 'title' => __( 'サイト情報設定', 'ai-creative-studio' ), 'priority' => 35, 'description' => __( 'サイトの基本情報を設定します。', 'ai-creative-studio' ), ) ); // コピーライトテキスト $wp_customize->add_setting( 'aics_copyright_text', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'aics_copyright_text', array( 'label' => __( 'コピーライトテキスト', 'ai-creative-studio' ), 'section' => 'aics_site_info', 'type' => 'text', 'description' => __( '空欄の場合はサイト名と年が自動表示されます。', 'ai-creative-studio' ), ) ); /** * セクション3: ヒーローセクション設定 */ $wp_customize->add_section( 'aics_hero_section', array( 'title' => __( 'ヒーローセクション設定', 'ai-creative-studio' ), 'priority' => 40, 'description' => __( 'トップページのヒーローセクションを設定します。', 'ai-creative-studio' ), ) ); // ヒーローセクションメインテキスト $wp_customize->add_setting( 'aics_hero_main_text', array( 'default' => __( 'AIで未来を創造する\nクリエイティブスタジオ', 'ai-creative-studio' ), 'sanitize_callback' => 'aics_sanitize_textarea', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'aics_hero_main_text', array( 'label' => __( 'ヒーローメインテキスト', 'ai-creative-studio' ), 'section' => 'aics_hero_section', 'type' => 'textarea', 'description' => __( 'トップページの大見出しテキストです。', 'ai-creative-studio' ), ) ); // ヒーローセクションサブテキスト $wp_customize->add_setting( 'aics_hero_sub_text', array( 'default' => __( '最先端のAI技術で、あなたのビジネスを次のステージへ。', 'ai-creative-studio' ), 'sanitize_callback' => 'aics_sanitize_textarea', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'aics_hero_sub_text', array( 'label' => __( 'ヒーローサブテキスト', 'ai-creative-studio' ), 'section' => 'aics_hero_section', 'type' => 'textarea', 'description' => __( 'メインテキスト下の説明文です。', 'ai-creative-studio' ), ) ); // ヒーローボタンテキスト $wp_customize->add_setting( 'aics_hero_button_text', array( 'default' => __( '無料相談を予約', 'ai-creative-studio' ), 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'aics_hero_button_text', array( 'label' => __( 'ヒーローボタンテキスト', 'ai-creative-studio' ), 'section' => 'aics_hero_section', 'type' => 'text', ) ); // ヒーローボタンURL $wp_customize->add_setting( 'aics_hero_button_url', array( 'default' => '#contact', 'sanitize_callback' => 'esc_url_raw', ) ); $wp_customize->add_control( 'aics_hero_button_url', array( 'label' => __( 'ヒーローボタンリンク先', 'ai-creative-studio' ), 'section' => 'aics_hero_section', 'type' => 'url', ) ); } add_action( 'customize_register', 'aics_customize_register' ); /** * ======================================== * カスタマイザー用サニタイズ関数 * ======================================== */ /** * テキストエリア用サニタイズ関数 */ function aics_sanitize_textarea( $text ) { return wp_kses_post( $text ); } /** * ======================================== * CSS変数出力 * ======================================== */ /** * カスタマイザー設定をCSS変数として出力 */ function aics_customizer_css() { $primary_color = get_theme_mod( 'aics_primary_color', '#1e40af' ); $accent_color = get_theme_mod( 'aics_accent_color', '#f59e0b' ); // 明度調整された色を生成 $primary_dark = aics_adjust_brightness( $primary_color, -20 ); $primary_light = aics_adjust_brightness( $primary_color, 20 ); $accent_dark = aics_adjust_brightness( $accent_color, -20 ); $custom_css = " :root { --color-primary: {$primary_color}; --color-primary-dark: {$primary_dark}; --color-primary-light: {$primary_light}; --color-accent: {$accent_color}; --color-accent-dark: {$accent_dark}; } "; wp_add_inline_style( 'aics-style', $custom_css ); } add_action( 'wp_enqueue_scripts', 'aics_customizer_css' ); /** * 色の明度を調整するヘルパー関数 */ function aics_adjust_brightness( $hex, $steps ) { // #を削除 $hex = str_replace( '#', '', $hex ); // 不正な値の場合はそのまま返す if ( strlen( $hex ) !== 6 ) { return '#' . $hex; } // RGBに変換 $r = hexdec( substr( $hex, 0, 2 ) ); $g = hexdec( substr( $hex, 2, 2 ) ); $b = hexdec( substr( $hex, 4, 2 ) ); // 明度を調整 $r = max( 0, min( 255, $r + $steps ) ); $g = max( 0, min( 255, $g + $steps ) ); $b = max( 0, min( 255, $b + $steps ) ); // HEXに戻す return '#' . str_pad( dechex( $r ), 2, '0', STR_PAD_LEFT ) . str_pad( dechex( $g ), 2, '0', STR_PAD_LEFT ) . str_pad( dechex( $b ), 2, '0', STR_PAD_LEFT ); } /** * ======================================== * リアルタイムプレビュー用JavaScript * ======================================== */ /** * カスタマイザープレビュー用スクリプトの読み込み */ function aics_customizer_live_preview() { wp_enqueue_script( 'aics-customizer-preview', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), AICS_VERSION, true ); } add_action( 'customize_preview_init', 'aics_customizer_live_preview' ); /** * ======================================== * ヘルパー関数 * ======================================== */ /** * コピーライトテキストを取得 */ function aics_get_copyright_text() { $custom_text = get_theme_mod( 'aics_copyright_text', '' ); if ( ! empty( $custom_text ) ) { return $custom_text; } return sprintf( '© %s %s. %s', date_i18n( 'Y' ), get_bloginfo( 'name' ), __( 'All rights reserved.', 'ai-creative-studio' ) ); } /** * ヒーローセクションのメインテキストを取得 */ function aics_get_hero_main_text() { return get_theme_mod( 'aics_hero_main_text', __( 'AIで未来を創造する\nクリエイティブスタジオ', 'ai-creative-studio' ) ); } /** * ヒーローセクションのサブテキストを取得 */ function aics_get_hero_sub_text() { return get_theme_mod( 'aics_hero_sub_text', __( '最先端のAI技術で、あなたのビジネスを次のステージへ。', 'ai-creative-studio' ) ); }