Files
peptide-starter-theme/inc/customizer.php
peptiderepo 9da702e746 v1.5.0: extend theme with navigation dropdowns, 9 page templates, auth UI, newsletter, contact panel
Major theme extension adding full-featured navigation with dropdown submenus (Tools, My Data, Resources),
9 new page templates (Calculator, Protocol Builder, Tracker, Subject Log, Documentation, Directory,
Science Feed, Profile, Sign In/Register), documentation page with sidebar ToC and scroll spy,
branded AJAX authentication forms, newsletter signup with admin export, slide-out contact/support panel,
Research Modules 6-card grid on front page, and comprehensive footer update.

Split functions.php (554→206 lines) into 6 focused inc/ modules: helpers, customizer, auth-handlers,
contact-handler, page-setup, newsletter-admin. All new components include dark mode support, CSRF
protection, input sanitization, output escaping, and graceful plugin degradation via shortcode_exists().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 08:38:30 +07:00

152 lines
4.4 KiB
PHP

<?php
/**
* Theme Customizer Settings
*
* Registers all Customizer sections, settings, and controls for
* the theme: branding, hero, footer, and dark mode.
*
* @see functions.php — includes this file
* @see front-page.php — reads hero settings
* @see footer.php — reads footer copyright
*
* What: Customizer API registration for theme options.
* Who calls it: WordPress customize_register action.
* Dependencies: WordPress Customizer API.
*
* @package peptide-starter
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Register theme customizer options.
*
* @param WP_Customize_Manager $wp_customize Customizer manager.
* @return void
*/
function peptide_starter_customize_register( $wp_customize ) {
// Branding section.
$wp_customize->add_section(
'peptide_starter_branding',
array(
'title' => esc_html__( 'Branding', 'peptide-starter' ),
'priority' => 30,
)
);
// Hero settings section.
$wp_customize->add_section(
'peptide_starter_hero',
array(
'title' => esc_html__( 'Hero Section', 'peptide-starter' ),
'priority' => 40,
)
);
// Hero Title.
$wp_customize->add_setting( 'hero_title', array(
'default' => get_bloginfo( 'name' ),
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'hero_title', array(
'label' => esc_html__( 'Hero Title', 'peptide-starter' ),
'section' => 'peptide_starter_hero',
'type' => 'text',
) );
// Hero Subtitle.
$wp_customize->add_setting( 'hero_subtitle', array(
'default' => esc_html__( 'A scientific peptide reference database', 'peptide-starter' ),
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'hero_subtitle', array(
'label' => esc_html__( 'Hero Subtitle', 'peptide-starter' ),
'section' => 'peptide_starter_hero',
'type' => 'textarea',
) );
// Hero Search Placeholder.
$wp_customize->add_setting( 'hero_search_placeholder', array(
'default' => esc_html__( 'Search peptides, sequences, or research...', 'peptide-starter' ),
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'hero_search_placeholder', array(
'label' => esc_html__( 'Search Placeholder', 'peptide-starter' ),
'section' => 'peptide_starter_hero',
'type' => 'text',
) );
// Footer section.
$wp_customize->add_section(
'peptide_starter_footer',
array(
'title' => esc_html__( 'Footer', 'peptide-starter' ),
'priority' => 50,
)
);
// Footer Copyright.
$wp_customize->add_setting( 'footer_copyright', array(
'default' => esc_html__( 'Copyright © 2026 Peptide Repo. All rights reserved.', 'peptide-starter' ),
'transport' => 'postMessage',
'sanitize_callback' => 'wp_kses_post',
) );
$wp_customize->add_control( 'footer_copyright', array(
'label' => esc_html__( 'Copyright Text', 'peptide-starter' ),
'section' => 'peptide_starter_footer',
'type' => 'textarea',
) );
// Dark mode section.
$wp_customize->add_section(
'peptide_starter_theme_mode',
array(
'title' => esc_html__( 'Theme Mode', 'peptide-starter' ),
'priority' => 60,
)
);
// Dark mode default.
$wp_customize->add_setting( 'dark_mode_default', array(
'default' => false,
'transport' => 'refresh',
'sanitize_callback' => 'peptide_starter_sanitize_checkbox',
) );
$wp_customize->add_control( 'dark_mode_default', array(
'label' => esc_html__( 'Enable Dark Mode by Default', 'peptide-starter' ),
'section' => 'peptide_starter_theme_mode',
'type' => 'checkbox',
) );
}
add_action( 'customize_register', 'peptide_starter_customize_register' );
/**
* Sanitize checkbox values for the Customizer.
*
* @param mixed $checked The raw value.
* @return bool True if checked, false otherwise.
*/
function peptide_starter_sanitize_checkbox( $checked ) {
return ( isset( $checked ) && true === $checked ) ? true : false;
}
/**
* Add dark mode body class if enabled.
*
* @param array $classes Existing body classes.
* @return array Modified body classes.
*/
function peptide_starter_dark_mode_body_class( $classes ) {
if ( get_theme_mod( 'dark_mode_default', false ) ) {
$classes[] = 'dark-mode-default';
}
return $classes;
}
add_filter( 'body_class', 'peptide_starter_dark_mode_body_class' );