add_section( 'tdt_one_theme_settings', array( 'title' => __('Theme Settings', 'tdt-one'), ) ); } add_action('customize_register', 'tdt_one_customize_theme_settings_section'); /** * We will handle the live preview */ function tdt_one_customize_blogname_live_preview( $customize ) { $customize->get_setting('blogname')->transport = 'postMessage'; $customize->get_setting('blogdescription')->transport = 'postMessage'; $customize->get_setting('header_textcolor')->transport = 'postMessage'; } add_action('customize_register', 'tdt_one_customize_blogname_live_preview'); function tdt_one_customize_social_links( $customize ) { $customize->add_section('tdt_one_social_links', array( 'title' => __('Social Links', 'tdt-one'), 'priority' => 60 )); // DRY $link_settings = array( 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage' ); // facebook link $customize->add_setting('tdt_one_social_link_facebook', $link_settings ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_social_link_facebook', array( 'label' => __('Facebook Link', 'tdt-one'), 'section' => 'tdt_one_social_links' ) ) ); // twitter link $customize->add_setting('tdt_one_social_link_twitter', $link_settings ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_social_link_twitter', array( 'label' => __('Twitter Link', 'tdt-one'), 'section' => 'tdt_one_social_links' ) ) ); // instagram link $customize->add_setting('tdt_one_social_link_instagram', $link_settings ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_social_link_instagram', array( 'label' => __('Instagram Link', 'tdt-one'), 'section' => 'tdt_one_social_links' ) ) ); // linkedin link $customize->add_setting('tdt_one_social_link_linkedin', $link_settings ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_social_link_linkedin', array( 'label' => __('LinkedIn Link', 'tdt-one'), 'section' => 'tdt_one_social_links' ) ) ); // github link $customize->add_setting('tdt_one_social_link_github', $link_settings ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_social_link_github', array( 'label' => __('Github Link', 'tdt-one'), 'section' => 'tdt_one_social_links' ) ) ); // pinterest link $customize->add_setting('tdt_one_social_link_pinterest', $link_settings ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_social_link_pinterest', array( 'label' => __('Pinterest Link', 'tdt-one'), 'section' => 'tdt_one_social_links' ) ) ); } add_action('customize_register', 'tdt_one_customize_social_links'); /** * The copyright text * * @since 1.1.7 */ function tdt_one_customize_copyright( $customize ) { $customize->add_section( 'tdt_one_copyright', array( 'title' => __('Copyright Text', 'tdt-one'), 'priority' => 60 ) ); $customize->add_setting( 'tdt_one_copyright_text', array( 'default' => '2018 © All Rights Reserved.', 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_copyright_text', array( 'label' => __( 'Copyright Text', 'tdt-one' ), 'section' => 'tdt_one_copyright', ) ) ); } add_action( 'customize_register', 'tdt_one_customize_copyright' ); $tdt_one_primary_color = '#ff0000'; $tdt_one_primary_backcolor = '#ffd4d4'; $tdt_one_footer_textcolor = '#000'; $tdt_one_footer_backcolor = '#ffabab'; /** * Add some color options */ function tdt_one_customize_colors( $customize ) { global $tdt_one_primary_color, $tdt_one_primary_backcolor, $tdt_one_footer_backcolor, $tdt_one_footer_textcolor; $customize->remove_control('header_textcolor'); $customize->remove_control('background_color'); // DRY $color_settings = array( 'default' => '', 'sanitize_callback' => 'sanitize_hex_color' ); // primary_color $color_settings[ 'default' ] = $tdt_one_primary_color; $customize->add_setting('primary_color', $color_settings ); $customize->add_control( new WP_Customize_Color_Control( $customize, 'primary_color', array( 'label' => __('Primary Color', 'tdt-one'), 'section' => 'colors' ) ) ); // primary_backcolor $color_settings[ 'default' ] = $tdt_one_primary_backcolor; $customize->add_setting('primary_backcolor', $color_settings ); $customize->add_control( new WP_Customize_Color_Control( $customize, 'primary_backcolor', array( 'label' => __('Primary Back Color', 'tdt-one'), 'section' => 'colors' ) ) ); // footer_textcolor $color_settings[ 'default' ] = $tdt_one_footer_textcolor; $customize->add_setting('footer_textcolor', $color_settings ); $customize->add_control( new WP_Customize_Color_Control( $customize, 'footer_textcolor', array( 'label' => __('Footer Text Color', 'tdt-one'), 'section' => 'colors' ) ) ); // footer_backcolor $color_settings[ 'default' ] = $tdt_one_footer_backcolor; $customize->add_setting('footer_backcolor', $color_settings ); $customize->add_control( new WP_Customize_Color_Control( $customize, 'footer_backcolor', array( 'label' => __('Footer Background Color', 'tdt-one'), 'section' => 'colors' ) ) ); } add_action('customize_register', 'tdt_one_customize_colors'); function tdt_one_load_customizerjs() { wp_enqueue_script('tdt-one-customizer', tdt_one_get_uri() . '/js/theme-customizer.js', array( 'jquery', 'customize-preview' ), '1.0', true); } add_action('customize_preview_init', 'tdt_one_load_customizerjs'); function tdt_one_print_theme_colors() { global $tdt_one_primary_color, $tdt_one_primary_backcolor, $tdt_one_footer_backcolor, $tdt_one_footer_textcolor; $primary_color = esc_attr( get_theme_mod('primary_color', $tdt_one_primary_color) ); $primary_backcolor = esc_attr( get_theme_mod('primary_backcolor', $tdt_one_primary_backcolor) ); $footer_textcolor = esc_attr( get_theme_mod('footer_textcolor', $tdt_one_footer_textcolor) ); $footer_backcolor = esc_attr( get_theme_mod('footer_backcolor', $tdt_one_footer_backcolor) ); $css = ""; $css = trim(preg_replace('#\s{2,}#', ' ', $css)); // well, I tried print $css; } add_action('wp_head', 'tdt_one_print_theme_colors'); /** * Setting the site to full width * * @since 1.2.0 */ function tdt_one_customize_full_width( $customize ) { $customize->add_setting( 'tdt_one_is_full_width', array( 'default' => true, 'transport' => 'postMessage', ) ); $customize->add_control( new WP_Customize_Control( $customize, 'tdt_one_is_full_width', array( 'label' => __('Site is Full Width', 'tdt-one'), 'type' => 'checkbox', 'section' => 'tdt_one_theme_settings', ) ) ); } add_action('customize_register', 'tdt_one_customize_full_width'); /** * Adding full-width to the body class * * @since 1.2.0 */ function tdt_one_full_width_class( $classes ) { $is_full_width = (bool) get_theme_mod('tdt_one_is_full_width', false); if($is_full_width) { $classes[] = 'full-width'; } return $classes; } add_filter('body_class', 'tdt_one_full_width_class');