get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; //$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title', 'render_callback' => 'abedul_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'abedul_customize_partial_blogdescription', ) ); $blog_navigation_array = array( 'navigation' => __('Navigation', 'abedul'), 'pagination' => __('Pagination', 'abedul'), ); $related_posts_array = array( 'by_tag' => __('By tag', 'abedul'), 'by_category' => __('By category', 'abedul'), 'no_show' => __('Do not show', 'abedul'), ); $google_fonts_headings = array( 'Delius' => 'Delius', 'Delius Swash Caps' => 'Delius Swash Caps', 'Bitter' => 'Bitter', 'Lato' => 'Lato', 'Source Sans Pro' => 'Source Sans Pro', ); $google_fonts_text = array( 'Bitter' => 'Bitter', 'Lato' => 'Lato', 'Source Sans Pro' => 'Source Sans Pro', ); /** * Removes the control for displaying or not the header text and adds the posibility of displaying the site title and tagline separately. **/ // =============================== $wp_customize->remove_control('display_header_text'); //=============================== $wp_customize->add_setting('abedul_theme_options[show_site_title]', array( 'default' => 1, //'transport' => 'postMessage', 'sanitize_callback' => 'absint', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( 'show_site_title', array( 'label' => __('Display Site Title', 'abedul'), 'section' => 'title_tagline', 'settings' => 'abedul_theme_options[show_site_title]', 'type' => 'checkbox', )); //=============================== $wp_customize->add_setting( 'abedul_theme_options[show_site_description]', array( 'default' => 1, //'transport' => 'postMessage', 'sanitize_callback' => 'absint', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control('show_site_description', array( 'label' => __('Display Tagline', 'abedul'), 'section' => 'title_tagline', 'settings' => 'abedul_theme_options[show_site_description]', 'type' => 'checkbox', )); // ============================== // == Colors Section == // ============================== $wp_customize->add_setting( 'abedul_theme_options[site_description_color]', array( 'default' => '#111111', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'site_description_color', array( 'label' => __('Site Description Color', 'abedul'), 'section' => 'colors', 'settings' => 'abedul_theme_options[site_description_color]', ))); // ============================= // == Front Page Section == // ============================= $wp_customize->add_setting('abedul_theme_options[show_sidebar]', array( 'default' => 1, 'sanitize_callback' => 'absint', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( 'show_sidebar', array( 'label' => __('Show the Sidebar in the Front Page.', 'abedul'), 'description' => __('(It only works if you select a static page and there are widgets in the sidebar widget areas)', 'abedul'), 'active_callback' => 'abedul_show_sidebar_control', 'section' => 'static_front_page', 'settings' => 'abedul_theme_options[show_sidebar]', 'type' => 'checkbox', )); // ============================= // == Theme Settings == // ============================= $wp_customize->add_panel( 'theme_settings', array( 'title' => __('Theme Settings', 'abedul'), 'description' => __('Here you can find several options to customize your site.', 'abedul'), 'priority' => 112, ) ); // ============================= // == Typography Section == // ============================= $wp_customize->add_section( 'typography', array( 'title' => __( 'Typography', 'abedul' ), 'description' => __( 'In this section you can change the font of the headings, the tagline and the main text. Select the fonts with the dropdown menus.', 'abedul'), 'panel' => 'theme_settings', ) ); //=============================== $wp_customize->add_setting( 'abedul_theme_options[headings_font]', array( 'sanitize_callback' => 'abedul_sanitize_font_style', 'type' => 'option', 'capability' => 'edit_theme_options', 'default' => 'Lato', ) ); $wp_customize->add_control( 'headings_font', array( 'settings' => 'abedul_theme_options[headings_font]', 'label' => __('Choose the headings font', 'abedul'), 'section' => 'typography', 'type' => 'select', 'choices' => $google_fonts_headings, )); //=============================== $wp_customize->add_setting( 'abedul_theme_options[site_description_font]', array( 'sanitize_callback' => 'abedul_sanitize_font_style', 'type' => 'option', 'capability' => 'edit_theme_options', 'default' => 'Lato', ) ); $wp_customize->add_control( 'site_description_font', array( 'settings' => 'abedul_theme_options[site_description_font]', 'label' => __('Choose the tagline font', 'abedul'), 'section' => 'typography', 'type' => 'select', 'choices' => $google_fonts_text, )); // =============================== $wp_customize->add_setting( 'abedul_theme_options[text_font]', array( 'sanitize_callback' => 'abedul_sanitize_font_style', 'type' => 'option', 'capability' => 'edit_theme_options', 'default' => 'Source Sans Pro', )); $wp_customize->add_control( 'text_font', array( 'settings' => 'abedul_theme_options[text_font]', 'label' => __( 'Choose the text font','abedul' ), 'section' => 'typography', 'type' => 'select', 'choices' => $google_fonts_text, )); // ============================= // == Special Pages Section == // ============================= $wp_customize->add_section( 'special_pages', array( 'title' => __( 'Special Pages', 'abedul' ), 'description' => __( 'This section saves the pages made with the special page templates, so they can be used across the theme. Select the pages with the dropdown selector.', 'abedul'), 'panel' => 'theme_settings', ) ); //=============================== $wp_customize->add_setting( 'abedul_theme_options[contributors_page]', array( 'default' => '', 'sanitize_callback' => 'absint', 'type' => 'option', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( 'contributors_page', array( 'label' => __('Your Contributors Page', 'abedul'), 'section' => 'special_pages', 'settings' => 'abedul_theme_options[contributors_page]', 'type' => 'dropdown-pages', 'allow_addition' => true, )); //=============================== $wp_customize->add_setting( 'abedul_theme_options[featured_articles_page]', array( 'default' => '', 'sanitize_callback' => 'absint', 'type' => 'option', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( 'featured_articles_page', array( 'label' => __('Your Featured Articles Page', 'abedul'), 'section' => 'special_pages', 'settings' => 'abedul_theme_options[featured_articles_page]', 'type' => 'dropdown-pages', 'allow_addition' => true, )); // ============================= // == Posts Section == // ============================= $wp_customize->add_section( 'post_settings', array( 'title' => __( 'Post Settings', 'abedul' ), 'description' => __( 'This section adds several options to the posts in single view.', 'abedul'), 'panel' => 'theme_settings', ) ); //=============================== $wp_customize->add_setting('abedul_theme_options[show_excerpt]', array( 'default' => 1, 'sanitize_callback' => 'absint', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( 'show_excerpt', array( 'label' => __('Show the excerpt as the article lead in standard posts.', 'abedul'), 'section' => 'post_settings', 'settings' => 'abedul_theme_options[show_excerpt]', 'type' => 'checkbox', )); //=============================== $wp_customize->add_setting('abedul_theme_options[show_related_posts]', array( 'default' => 'by_tag', 'sanitize_callback' => 'abedul_sanitize_related_posts', 'capability' => 'manage_options', 'type' => 'option', )); $wp_customize->add_control( 'show_related_posts', array( 'label' => __('Show related posts by tag or by category','abedul'), 'section' => 'post_settings', 'settings' => 'abedul_theme_options[show_related_posts]', 'type' => 'radio', 'choices' => $related_posts_array, )); //=============================== $wp_customize->add_setting('abedul_theme_options[show_author_info]', array( 'default' => 1, 'sanitize_callback' => 'absint', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( 'show_author_info', array( 'label' => __('Show author information in posts.', 'abedul'), 'section' => 'post_settings', 'settings' => 'abedul_theme_options[show_author_info]', 'type' => 'checkbox', )); // ============================= // == Navigation Section == // ============================= $wp_customize->add_section( 'navigation', array( 'title' => __( 'Navigation Settings', 'abedul' ), 'description' => __( 'This section adds the possibility of choosing between navigation or pagination in multiple view pages.', 'abedul'), 'panel' => 'theme_settings', ) ); //=============================== $wp_customize->add_setting('abedul_theme_options[blog_navigation]', array( 'default' => 'navigation', 'sanitize_callback' => 'abedul_sanitize_blog_nav', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( 'blog_navigation', array( 'label' => __('Choose your preferred mode of navigating between old and new articles','abedul'), 'section' => 'navigation', 'settings' => 'abedul_theme_options[blog_navigation]', 'type' => 'radio', 'choices' => $blog_navigation_array, )); } add_action( 'customize_register', 'abedul_customize_register' ); /** * Theme's Custom Styling */ function abedul_theme_custom_styling() { $abedul_theme_options = abedul_get_options( 'abedul_theme_options' ); $headings_font = $abedul_theme_options['headings_font']; $site_description_font = $abedul_theme_options['site_description_font']; $text_font = $abedul_theme_options['text_font']; $css = ''; if ( $headings_font ) : $css .= '.site-title, .entry-title, .post-title, .archive-title, .category-title, .widget-title, .nav-links { font-family: ' . $headings_font . '}' . "\n"; endif; if ( $site_description_font ) : $css .= ' .site-description { font-family: ' . $site_description_font . '}' . "\n"; endif; if ( $text_font ) : $css .= ' body { font-family: ' . $text_font . '}' . "\n"; endif; // CSS styles if ( isset( $css ) && $css !== '' ) : $css = strip_tags( $css ); $css = "\n\n"; echo $css; endif; } add_action( 'wp_head','abedul_theme_custom_styling' ); /** * Sanitization of the font style choices. * * @since Abedul 1.0.9 * * @param string $value Value of the font style. * @return string Sanitised value of the font style choice. */ function abedul_sanitize_font_style( $value ) { $recognized = abedul_font_styles(); if ( array_key_exists( $value, $recognized ) ) { return $value; } return apply_filters( 'abedul_font_style', current( $recognized ) ); } /** * Array of font family options. * * @since Abedul 1.0.9 */ function abedul_font_styles() { $default = array( 'Delius' => 'Delius', 'Delius Swash Caps' => 'Delius Swash Caps', 'Bitter' => 'Bitter', 'Lato' => 'Lato', 'Source Sans Pro' => 'Source Sans Pro', ); return apply_filters( 'abedul_font_styles', $default ); } /** * Sanitization for navigation choice */ function abedul_sanitize_blog_nav( $value ) { $recognized = abedul_blog_nav(); if ( array_key_exists( $value, $recognized ) ) { return $value; } return apply_filters( 'abedul_blog_nav', current( $recognized ) ); } function abedul_blog_nav() { $default = array( 'navigation' => 'navigation', 'pagination' => 'pagination', ); return apply_filters( 'abedul_blog_nav', $default ); } /** * Sanitization for related posts choice */ function abedul_sanitize_related_posts( $value ) { $recognized = abedul_related_posts(); if ( array_key_exists( $value, $recognized ) ) { return $value; } return apply_filters( 'abedul_related_posts', current( $recognized ) ); } function abedul_related_posts() { $default = array( 'no_show' => 'no_show', 'by_tag' => 'by_tag', 'by_category' => 'by_category', ); return apply_filters( 'abedul_related_posts', $default ); } function abedul_get_option_defaults() { $defaults = array( 'show_site_title' => 1, 'show_site_description' => 1, 'site_description_color' => '#111111', 'headings_font' => 'Lato', 'site_description_font' => 'Lato', 'text_font' => 'Source Sans Pro', 'contributors_page' => '', 'featured_articles_page' => '', 'show_sidebar' => 1, 'show_excerpt' => 1, 'show_related_posts' => 'by_tag', 'show_author_info' => 1, 'blog_navigation' => 'navigation', ); return apply_filters( 'abedul_get_option_defaults', $defaults ); } function abedul_get_options() { // Options API return wp_parse_args( get_option( 'abedul_theme_options', array() ), abedul_get_option_defaults() ); } /** * Render the site title for the selective refresh partial. * * @since Abedul 1.0.7 * @see abedul_customize_register() * * @return void */ function abedul_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. * * @since Abedul 1.0.7 * @see abedul_customize_register() * * @return void */ function abedul_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Callback function for the show sidebar control. */ function abedul_show_sidebar_control() { if ( get_option('show_on_front') === 'page') { return true; } } /** * Bind JS handlers to instantly live-preview changes. */ function abedul_customize_preview_js() { wp_enqueue_script( 'abedul-customize-preview', get_template_directory_uri( '/js/customize-preview.js' ), array( 'customize-preview' ), '1.0', true ); } add_action( 'customize_preview_init', 'abedul_customize_preview_js' );