123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- /**
- * Lodestar Theme Customizer.
- *
- * @package Lodestar
- */
- /**
- * Add postMessage support for site title and description for the Theme Customizer.
- *
- * @param WP_Customize_Manager $wp_customize Theme Customizer object.
- */
- function lodestar_customize_register( $wp_customize ) {
- $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
- $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
- $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
- /**
- * Add the Theme Options section
- */
- $wp_customize->add_panel( 'lodestar_options_panel', array(
- 'title' => esc_html__( 'Theme Options', 'lodestar' ),
- 'description' => esc_html__( 'Configure your theme settings', 'lodestar' ),
- ) );
- // Top of site content
- $wp_customize->add_section( 'lodestar_top_of_site', array(
- 'title' => esc_html__( 'Header Top Text', 'lodestar' ),
- 'panel' => 'lodestar_options_panel',
- 'description' => esc_html__( 'Add a short bit of content to the top of your website.', 'lodestar' ),
- ) );
- $wp_customize->add_setting( 'lodestar_header_top_text_1', array(
- 'sanitize_callback' => 'wp_kses_post',
- ) );
- $wp_customize->add_control( 'lodestar_header_top_text_1', array(
- 'section' => 'lodestar_top_of_site',
- 'type' => 'textarea',
- 'priority' => 1,
- 'label' => esc_html__( 'Header Top Text 1', 'lodestar' ),
- ) );
- $wp_customize->add_setting( 'lodestar_header_top_text_2', array(
- 'sanitize_callback' => 'wp_kses_post',
- ) );
- $wp_customize->add_control( 'lodestar_header_top_text_2', array(
- 'section' => 'lodestar_top_of_site',
- 'type' => 'textarea',
- 'priority' => 1,
- 'label' => esc_html__( 'Header Top Text 2', 'lodestar' ),
- ) );
- // Panel 1
- $wp_customize->add_section( 'lodestar_panel1', array(
- 'title' => esc_html__( 'Panel 1', 'lodestar' ),
- 'active_callback' => 'is_front_page',
- 'panel' => 'lodestar_options_panel',
- 'description' => esc_html__( 'Add an image to your panel by setting a featured image in the page editor. If you don’t select a page, this panel will not be displayed.', 'lodestar' ),
- ) );
- $wp_customize->add_setting( 'lodestar_panel1', array(
- 'default' => false,
- 'sanitize_callback' => 'lodestar_sanitize_numeric_value',
- ) );
- $wp_customize->add_control( 'lodestar_panel1', array(
- 'label' => esc_html__( 'Panel Content', 'lodestar' ),
- 'section' => 'lodestar_panel1',
- 'type' => 'dropdown-pages',
- ) );
- $wp_customize->add_setting( 'lodestar_panel1_layout', array(
- 'default' => 'one-column',
- 'sanitize_callback' => 'lodestar_sanitize_layout',
- ) );
- $wp_customize->add_control( 'lodestar_panel1_layout', array(
- 'label' => esc_html__( 'Panel Layout', 'lodestar' ),
- 'section' => 'lodestar_panel1',
- 'type' => 'radio',
- 'choices' => array(
- 'one-column' => esc_html__( 'One Column', 'lodestar' ),
- 'two-column' => esc_html__( 'Two Column', 'lodestar' ),
- ),
- ) );
- // Panel 2
- $wp_customize->add_section( 'lodestar_panel2', array(
- 'title' => esc_html__( 'Panel 2', 'lodestar' ),
- 'active_callback' => 'is_front_page',
- 'panel' => 'lodestar_options_panel',
- 'description' => esc_html__( 'Add an image to your panel by setting a featured image in the page editor. If you don’t select a page, this panel will not be displayed.', 'lodestar' ),
- ) );
- $wp_customize->add_setting( 'lodestar_panel2', array(
- 'default' => false,
- 'sanitize_callback' => 'lodestar_sanitize_numeric_value',
- ) );
- $wp_customize->add_control( 'lodestar_panel2', array(
- 'label' => esc_html__( 'Panel Content', 'lodestar' ),
- 'section' => 'lodestar_panel2',
- 'type' => 'dropdown-pages',
- ) );
- $wp_customize->add_setting( 'lodestar_panel2_layout', array(
- 'default' => 'one-column',
- 'sanitize_callback' => 'lodestar_sanitize_layout',
- ) );
- $wp_customize->add_control( 'lodestar_panel2_layout', array(
- 'label' => esc_html__( 'Panel Layout', 'lodestar' ),
- 'section' => 'lodestar_panel2',
- 'type' => 'radio',
- 'choices' => array(
- 'one-column' => esc_html__( 'One Column', 'lodestar' ),
- 'two-column' => esc_html__( 'Two Column', 'lodestar' ),
- ),
- ) );
- // Panel 3
- $wp_customize->add_section( 'lodestar_panel3', array(
- 'title' => esc_html__( 'Panel 3', 'lodestar' ),
- 'active_callback' => 'is_front_page',
- 'panel' => 'lodestar_options_panel',
- 'description' => esc_html__( 'Add an image to your panel by setting a featured image in the page editor. If you don’t select a page, this panel will not be displayed.', 'lodestar' ),
- ) );
- $wp_customize->add_setting( 'lodestar_panel3', array(
- 'default' => false,
- 'sanitize_callback' => 'lodestar_sanitize_numeric_value',
- ) );
- $wp_customize->add_control( 'lodestar_panel3', array(
- 'label' => esc_html__( 'Panel Content', 'lodestar' ),
- 'section' => 'lodestar_panel3',
- 'type' => 'dropdown-pages',
- ) );
- $wp_customize->add_setting( 'lodestar_panel3_layout', array(
- 'default' => 'one-column',
- 'sanitize_callback' => 'lodestar_sanitize_layout',
- ) );
- $wp_customize->add_control( 'lodestar_panel3_layout', array(
- 'label' => esc_html__( 'Panel Layout', 'lodestar' ),
- 'section' => 'lodestar_panel3',
- 'type' => 'radio',
- 'choices' => array(
- 'one-column' => esc_html__( 'One Column', 'lodestar' ),
- 'two-column' => esc_html__( 'Two Column', 'lodestar' ),
- ),
- ) );
- // Panel 4
- $wp_customize->add_section( 'lodestar_panel4', array(
- 'title' => esc_html__( 'Panel 4', 'lodestar' ),
- 'active_callback' => 'is_front_page',
- 'panel' => 'lodestar_options_panel',
- 'description' => esc_html__( 'Add an image to your panel by setting a featured image in the page editor. If you don’t select a page, this panel will not be displayed.', 'lodestar' ),
- ) );
- $wp_customize->add_setting( 'lodestar_panel4', array(
- 'default' => false,
- 'sanitize_callback' => 'lodestar_sanitize_numeric_value',
- ) );
- $wp_customize->add_control( 'lodestar_panel4', array(
- 'label' => esc_html__( 'Panel Content', 'lodestar' ),
- 'section' => 'lodestar_panel4',
- 'type' => 'dropdown-pages',
- ) );
- $wp_customize->add_setting( 'lodestar_panel4_layout', array(
- 'default' => 'one-column',
- 'sanitize_callback' => 'lodestar_sanitize_layout',
- ) );
- $wp_customize->add_control( 'lodestar_panel4_layout', array(
- 'label' => esc_html__( 'Panel Layout', 'lodestar' ),
- 'section' => 'lodestar_panel4',
- 'type' => 'radio',
- 'choices' => array(
- 'one-column' => esc_html__( 'One Column', 'lodestar' ),
- 'two-column' => esc_html__( 'Two Column', 'lodestar' ),
- ),
- ) );
- // Footer Image
- $wp_customize->add_section( 'lodestar_footer_settings', array(
- 'title' => esc_html__( 'Footer Image', 'lodestar' ),
- 'panel' => 'lodestar_options_panel',
- 'default' => '',
- ) );
- $wp_customize->add_setting('lodestar_footer_image', array(
- 'transport' => 'refresh',
- 'sanitize_callback' => 'esc_url_raw',
- ) );
- $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize,
- 'lodestar_footer_image', array(
- 'label' => esc_html__( 'Footer Image', 'lodestar' ),
- 'section' => 'lodestar_footer_settings',
- 'description' => esc_html__( 'Add an image to be displayed at the bottom of the Front Page template, above the footer.', 'lodestar' ),
- ) ) );
- }
- add_action( 'customize_register', 'lodestar_customize_register' );
- /**
- * Sanitize a numeric value
- */
- function lodestar_sanitize_numeric_value( $input ) {
- if ( is_numeric( $input ) ) {
- return intval( $input );
- } else {
- return 0;
- }
- }
- /**
- * Sanitize a radio button
- */
- function lodestar_sanitize_layout( $input ) {
- $valid = array(
- 'one-column' => esc_html__( 'One Column', 'lodestar' ),
- 'two-column' => esc_html__( 'Two Column', 'lodestar' ),
- );
- if ( array_key_exists( $input, $valid ) ) {
- return $input;
- } else {
- return '';
- }
- }
- /**
- * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
- */
- function lodestar_customize_preview_js() {
- wp_enqueue_script( 'lodestar_customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20151215', true );
- }
- add_action( 'customize_preview_init', 'lodestar_customize_preview_js' );
- /**
- * Some extra JavaScript to improve the user experience in the Customizer for this theme.
- */
- function lodestar_panels_js() {
- wp_enqueue_script( 'lodestar_extra_js', get_template_directory_uri() . '/assets/js/panel-customizer.js', array(), '20151116', true );
- }
- add_action( 'customize_controls_enqueue_scripts', 'lodestar_panels_js' );
|