get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->add_section( 'titan_theme_options', array( 'title' => __( 'Theme', 'titan' ), 'priority' => 110, ) ); /* * Theme-specific settings. */ $wp_customize->add_setting( 'T_twitter', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_twitter_username', ) ); $wp_customize->add_control( 'T_twitter', array( 'label' => __( 'Twitter Username', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_twitter', 'type' => 'text', 'priority' => 10, ) ); $wp_customize->add_setting( 'T_twitter_toggle', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_boolean', ) ); $wp_customize->add_control( 'T_twitter_toggle', array( 'label' => __( 'Disable Twitter link', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_twitter_toggle', 'type' => 'checkbox', 'priority' => 20, ) ); $wp_customize->add_setting( 'T_notice_content', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_textarea', ) ); $wp_customize->add_control( new Titan_Customize_Textarea_Control( $wp_customize, 'T_notice_content', array( 'label' => __( 'Custom notice', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_notice_content', 'type' => 'checkbox', 'priority' => 30, ) ) ); $wp_customize->add_setting( 'T_custom_notice', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_boolean', ) ); $wp_customize->add_control( 'T_custom_notice', array( 'label' => __( 'Enable custom notice', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_custom_notice', 'type' => 'checkbox', 'priority' => 30, ) ); /* * The following options are provided for backward compatibility. * They will not be shown to users if they are using a custom menu * or if they have not previously set a value for one of them. */ if ( titan_show_navigation_options() ) { $wp_customize->add_setting( 'T_pages_to_exclude', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_comma_separated_list', ) ); $wp_customize->add_control( 'T_pages_to_exclude', array( 'label' => __( 'Page ids to exclude from menu', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_pages_to_exclude', 'type' => 'text', 'priority' => 100, ) ); $wp_customize->add_setting( 'T_categories_to_exclude', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_comma_separated_list', ) ); $wp_customize->add_control( 'T_categories_to_exclude', array( 'label' => __( 'Category ids to exclude from menu', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_categories_to_exclude', 'type' => 'text', 'priority' => 110, ) ); $wp_customize->add_setting( 'T_hide_pages', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_boolean', ) ); $wp_customize->add_control( 'T_hide_pages', array( 'label' => __( 'Hide all pages in menu', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_hide_pages', 'type' => 'checkbox', 'priority' => 120, ) ); $wp_customize->add_setting( 'T_hide_cats', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_boolean', ) ); $wp_customize->add_control( 'T_hide_cats', array( 'label' => __( 'Hide all categories in the menu', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_hide_cats', 'type' => 'checkbox', 'priority' => 130, ) ); $wp_customize->add_setting( 'T_hide_home', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'titan_sanitize_boolean', ) ); $wp_customize->add_control( 'T_hide_home', array( 'label' => __( 'Hide homepage link in menu', 'titan' ), 'section' => 'titan_theme_options', 'settings' => 'T_hide_home', 'type' => 'checkbox', 'priority' => 140, ) ); } } add_action( 'customize_register', 'titan_customize_register' ); /** * Sanitize Twitter Username. * @see https://support.twitter.com/articles/101299-why-can-t-i-register-certain-usernames */ function titan_sanitize_twitter_username( $username ) { $clean = ''; $username = trim( $username ); if ( 1 === preg_match( '/^[a-zA-Z0-9_]{1,15}$/', $username ) ) $clean = $username; return $clean; } function titan_sanitize_boolean( $value ) { if ( ! empty( $value ) ) return 'true'; return ''; } /** * Should we display navigation options in the Customizer? * * This will always return false if the Primary Menu location * has been assigned a custom menu * * If a user has set navigation values in the old UI, a set * of options will be displayed in the Customizer. If they * Have never set these options, the options will be hidden. * * @return bool */ function titan_show_navigation_options() { global $titan; if ( has_nav_menu( 'primary' ) ) return false; $navigation_options = array( (bool) $titan->hidePages(), (bool) $titan->hideCategories(), (bool) $titan->hideHome(), (bool) $titan->excludedCategories(), (bool) $titan->excludedPages(), ); if ( 0 == array_sum( array_map( 'intval', $navigation_options ) ) ) return false; return true; } /** * Sanitize a comma-separated list of integers */ function titan_sanitize_comma_separated_list( $list ) { $parts = explode( ',', $list ); $clean = array_filter( array_map( 'absint', $parts ) ); return implode( ', ', $clean ); } function titan_sanitize_textarea( $text ) { return wp_kses_post( $text ); } /** * Enqueue script for the customizer. */ function titan_customize_preview_js() { wp_enqueue_script( 'titan-customizer', get_template_directory_uri() . '/javascripts/customizer.js', array( 'customize-preview' ), '20130509', true ); } add_action( 'customize_preview_init', 'titan_customize_preview_js' );