get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => 'ananya_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'ananya_customize_partial_blogdescription', ) ); } // ======================================================================= // = Accent color setting = // ======================================================================= $wp_customize->add_setting( 'ananya_accent_color', array( 'default' => '#0047a5', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'ananya_accent_color', array( 'label' => __( 'Accent Color', 'ananya' ), 'section' => 'colors', 'settings' => 'ananya_accent_color', 'description' => __( 'Applied to some of the elements.', 'ananya' ), ) ) ); // ======================================================================= // = Add theme other options panel = // ======================================================================= $wp_customize->add_panel( 'ananya_options_panel', array( 'priority' => 180, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Theme Other Options', 'ananya' ), 'description' => '', ) ); // ======================================================================= // = Blog Page Layout Section = // ======================================================================= $wp_customize->add_section( 'ananya_blog_page_options_section', array( 'title' => __( 'Blog Page Settings', 'ananya' ), 'priority' => 1, 'capability' => 'edit_theme_options', 'panel' => 'ananya_options_panel', ) ); // ======================================================================= // = Post content display option: Post Excerpt/Full Post = // ======================================================================= $wp_customize->add_setting( 'ananya_post_display_type_option', array( 'default' => 'post-excerpt', 'sanitize_callback' => 'ananya_sanitize_post_display_option', 'transport' => 'refresh', )); $wp_customize->add_control( 'ananya_post_display_type_option', array( 'label' => __( 'How would you like to dispaly post content on Blog posts index page?', 'ananya' ), 'section' => 'ananya_blog_page_options_section', 'settings' => 'ananya_post_display_type_option', 'type' => 'radio', 'choices' => array( 'post-excerpt' => __( 'Post Excerpt', 'ananya' ), 'full-post' => __( 'Full Post', 'ananya' ), ), )); // ======================================================================= // = Disable/Hide footer on blog page = // ======================================================================= $wp_customize->add_setting( 'ananya_hide_blog_page_post_footer_option', array( 'default' => false, 'sanitize_callback' => 'ananya_sanitize_checkbox', 'transport' => 'refresh', )); $wp_customize->add_control( 'ananya_hide_blog_page_post_footer_option', array( 'label' => __( 'Hide footer of a post on Blog posts index page.', 'ananya' ), 'description' => __( 'If you select this option the blog post footer which has post\'s Categoryand Social Media Sharing buttons will be removed.', 'ananya'), 'section' => 'ananya_blog_page_options_section', 'settings' => 'ananya_hide_blog_page_post_footer_option', 'type' => 'checkbox', )); // ======================================================================= // = Single Post Option: Section = // ======================================================================= $wp_customize->add_section( 'ananya_single_post_settings_section', array( 'title' => __( 'Single Post Settings', 'ananya' ), 'priority' => 3, 'capability' => 'edit_theme_options', 'panel' => 'ananya_options_panel', ) ); // ======================================================================= // = Disable/Hide default social media icons on a single page = // ======================================================================= $wp_customize->add_setting( 'ananya_hide_single_post_share_option', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'ananya_sanitize_checkbox', )); $wp_customize->add_control( 'ananya_hide_single_post_share_option', array( 'label' => __( 'Hide social media sharing icons on a single post.', 'ananya' ), 'section' => 'ananya_single_post_settings_section', 'settings' => 'ananya_hide_single_post_share_option', 'type' => 'checkbox', )); // ==================================================================== // = Social Media Options: Select any four social media services to display on home page = // ==================================================================== $wp_customize->add_section( 'ananya_social_media_settings_section', array( 'title' => __( 'Social Menu Section', 'ananya' ), 'priority' => 4, 'capability' => 'edit_theme_options', 'panel' => 'ananya_options_panel', ) ); $wp_customize->add_setting( 'ananya_social_media_menu_enable', array( 'capability' => 'edit_theme_options', 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'ananya_sanitize_checkbox', ) ); $wp_customize->add_control( 'ananya_social_media_menu_enable', array( 'type' => 'checkbox', 'priority' => 1, 'section' => 'ananya_social_media_settings_section', 'label' => __( 'Enable Social Media Icons in top Navigation.', 'ananya' ), 'settings' => 'ananya_social_media_menu_enable', ) ); // Social Icons Array $social_media_names = array( 'facebook-f' => 'Facebook', 'facebook-square' => 'Facebook Square', 'twitter' => 'Twitter', 'twitter-square' => 'Twitter Square', 'google' => 'Google', 'linkedin-square' => 'Linkedin Square', 'linkedin' => 'Linkedin In', 'pinterest' => 'Pinterest', 'pinterest-square' => 'Pinterest Square', 'behance' => 'Behance', 'behance-square' => 'Behance Square', 'tumblr' => 'Tumblr', 'tumblr-square' => 'Tumblr Square', 'reddit' => 'Reddit', 'reddit-square' => 'Reddit Square', 'dribbble' => 'Dribbble', 'vk' => 'vKontakte', 'skype' => 'Skype', 'film' => 'Film', 'youtube-play' => 'Youtube 1', 'youtube' => 'Youtube 2', 'youtube-square' => 'Youtube 3', 'vimeo-square' => 'Vimeo 1', 'soundcloud' => 'Soundcloud', 'instagram' => 'Instagram', 'info' => 'Info 1', 'info-circle' => 'Info 2', 'flickr' => 'Flickr', 'rss' => 'RSS 1', 'rss-square' => 'RSS 2', 'heart' => 'Heart 1', 'heart-o' => 'Heart 2', 'github' => 'Github 1', 'github-alt' => 'Github 2', 'github-square' => 'Github 3', 'stack-overflow' => 'Stack Overflow', 'qq' => 'QQ', 'weibo' => 'Weibo', 'weixin' => 'Weixin', 'xing' => 'Xing 1', 'xing-square' => 'Xing 2', 'gamepad' => 'Gamepad', 'medium' => 'Medium', 'map-marker' => 'Map Marker', 'envelope' => 'Envelope 1', 'envelope-o' => 'Envelope 2', 'envelope-square ' => 'Envelope 3', 'spotify' => 'Spotify', 'shopping-cart' => 'Cart', 'cc-paypal' => 'PayPal', 'credit-card' => 'Credit Card', ); for( $count=1; $count<=4; $count++ ) { $wp_customize->add_setting( 'ananya_social_media_icon_'.$count, array( 'default' => 'facebook-f', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'ananya_sanitize_select' ) ); $wp_customize->add_control( 'ananya_social_media_icon_'.$count, array( 'label' => __( 'Social Media Name', 'ananya' ), 'settings' => 'ananya_social_media_icon_'.$count, 'section' => 'ananya_social_media_settings_section', 'type' => 'select', 'choices' => $social_media_names, 'priority' => $count+1, ) ); $wp_customize->add_setting( 'ananya_social_media_url_'.$count, array( 'default' => '', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url' ) ); $wp_customize->add_control( 'ananya_social_media_url_'.$count, array( 'label' => __( 'Social Media URL', 'ananya' ), 'settings' => 'ananya_social_media_url_'.$count, 'section' => 'ananya_social_media_settings_section', 'type' => 'text', 'priority' => $count+1, ) ); } // ======================================================================= // = Searchbox Section = // ======================================================================= $wp_customize->add_section( 'ananya_searchbox_section', array( 'title' => __( 'Search Box', 'ananya' ), 'panel' => 'ananya_options_panel', 'priority' => 5, ) ); //Add setting for diplaying search box to primary navigation menu. $wp_customize->add_setting( 'ananya_searchbox_display_setting', array( 'default' => true, 'transport' => 'refresh', 'sanitize_callback' => 'ananya_sanitize_checkbox', ) ); $wp_customize->add_control( 'ananya_searchbox_display_setting', array( 'type' => 'checkbox', 'label' => __( 'Add Search button to the Top Navigation.', 'ananya' ), 'priority' => 1, 'settings' => 'ananya_searchbox_display_setting', 'section' => 'ananya_searchbox_section', ) ); // ======================================================================= // = Typography Section = // ======================================================================= $wp_customize->add_section( 'ananya_font_family_section', array( 'title' => __( 'Typography', 'ananya' ), 'priority' => 1, 'capability' => 'edit_theme_options', 'priority' => 42, ) ); //Set recomended fonts array for body and heading $font_family = array( 'Lato' => 'Lato', 'Lora' => 'Lora', 'Libre Franklin' => 'Libre Franklin', 'Open Sans' => 'Open Sans', 'Playfair Display' => 'Playfair Display', 'Pacifico' => 'Pacifico', ); // ======================================================================= // = Heading Font Settings = // ======================================================================= $wp_customize->add_setting( 'ananya_heading_font_select', array( 'default' => 'Playfair Display', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'ananya_sanitize_select' ) ); $wp_customize->add_control( 'ananya_heading_font_select', array( 'type' => 'select', 'label' => __( 'Heading Font', 'ananya' ), 'description' => '', 'section' => 'ananya_font_family_section', 'settings' => 'ananya_heading_font_select', 'choices' => $font_family, ) ); // ======================================================================= // = Body Font Settings = // ======================================================================= $wp_customize->add_setting( 'ananya_body_font_select', array( 'default' => 'Open Sans', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'ananya_sanitize_select' ) ); $wp_customize->add_control( 'ananya_body_font_select', array( 'type' => 'select', 'label' => __( 'Body Font Family', 'ananya' ), 'description' => '', 'section' => 'ananya_font_family_section', 'settings' => 'ananya_body_font_select', 'choices' => $font_family, ) ); } add_action( 'customize_register', 'ananya_customize_register' ); /** * Render the site title for the selective refresh partial. * * @return void */ function ananya_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. * * @return void */ function ananya_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function ananya_customize_preview_js() { wp_enqueue_script( 'ananya-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), false, true ); } add_action( 'customize_preview_init', 'ananya_customize_preview_js' ); /** * This will output the custom WordPress settings to the live theme's WP head. * * Used by hook: 'wp_head' * * @see add_action('wp_head',$func) * @since 1.0 */ function ananya_header_output() { $accent_color = get_theme_mod( 'ananya_accent_color', '#044e92' ); $accent_color = esc_attr( $accent_color ); $body_font = get_theme_mod( 'ananya_body_font_select', 'Open Sans' ); $heading_font = get_theme_mod( 'ananya_heading_font_select', 'Playfair Display' ); ?> manager->get_control( $setting->id )->choices; //return input if valid or return default option return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } /** * Sanitize Checkbox Control Setting * @since 1.0.0 */ function ananya_sanitize_checkbox( $input ){ // Boolean check. return ( ( isset( $input ) && true === $input ) ? true : false ); } /** * Sanitize Text Control Setting * @since 1.0.0 */ function ananya_sanitize_text( $input ) { /** * @var array[] $allowedtags Array of KSES allowed HTML elements. * @since 1.0.0 */ $allowedtags = array( 'a' => array( 'href' => true, 'title' => true, ), 'abbr' => array( 'title' => true, ), 'acronym' => array( 'title' => true, ), 'b' => array(), 'blockquote' => array( 'cite' => true, ), 'br' => array(), 'button' => array( 'disabled' => true, 'name' => true, 'type' => true, 'value' => true, ), 'cite' => array(), 'code' => array(), 'del' => array( 'datetime' => true, ), 'em' => array(), 'i' => array(), 'q' => array( 'cite' => true, ), 's' => array(), 'strike' => array(), 'strong' => array(), ); return wp_kses( force_balance_tags( $input ), $allowedtags ); } /** * Sanitize Select Control Setting * @since 1.0.0 */ function ananya_sanitize_select( $input, $setting ) { // get all select options $options = $setting->manager->get_control( $setting->id )->choices; // return default if not valid return ( array_key_exists( $input, $options ) ? $input : $setting->default ); } /** * Returns true if header media type is image. * @since 1.0.0 */ function ananya_is_header_media_image( $control ) { if ( 'image' === $control->manager->get_setting( 'ananya_frontpage_header_type' )->value() ) { return true; } else { return false; } } if ( ! function_exists( 'ananya_sanitize_post_display_option' ) ) : /** * Sanitization callback for post display option. * * * @param string $value post display style. * @return string $value post display style. * @since 1.0 */ function ananya_sanitize_post_display_option( $value ) { if ( ! in_array( $value, array( 'post-excerpt', 'full-post' ) ) ) { $value = 'post-excerpt'; } return $value; } endif; // ananya_sanitize_post_display_option /** * Convert HEX to RGB. * * @since Ananyapro 1.0 * * @param string $color The original color, in 3- or 6-digit hexadecimal form. * @return array Array containing RGB (red, green, and blue) values for the given * HEX code, empty array otherwise. */ function ananya_hex2rgb( $color ) { $color = trim( $color, '#' ); if ( strlen( $color ) == 3 ) { $r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) ); $g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) ); $b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) ); } elseif ( strlen( $color ) == 6 ) { $r = hexdec( substr( $color, 0, 2 ) ); $g = hexdec( substr( $color, 2, 2 ) ); $b = hexdec( substr( $color, 4, 2 ) ); } else { return array(); } return array( 'red' => $r, 'green' => $g, 'blue' => $b, ); }