$default_background_color, ) ) ); } add_action( 'after_setup_theme', 'bizpress_custom_header_and_background' ); /** * Add postMessage support for site title and description for the Theme Customizer. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function bizpress_customize_register( $wp_customize ) { $color_scheme = bizpress_get_color_scheme(); $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // Add page background color setting and control. $wp_customize->add_setting( 'page_background_color', array( 'default' => $color_scheme[1], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_background_color', array( 'label' => __( 'Page Background Color', 'bizpress' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'header_background_color', array( 'default' => $color_scheme[2], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_background_color', array( 'label' => __( 'Header Background Color', 'bizpress' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'footer_background_color', array( 'default' => $color_scheme[7], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_background_color', array( 'label' => __( 'Footer Background Color', 'bizpress' ), 'section' => 'colors', ) ) ); // Remove the core header textcolor control, as it shares the main text color. $wp_customize->remove_control( 'header_textcolor' ); // Add link color setting and control. $wp_customize->add_setting( 'link_color', array( 'default' => $color_scheme[3], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( 'label' => __( 'Link Color', 'bizpress' ), 'section' => 'colors', ) ) ); // Add link color setting and control. $wp_customize->add_setting( 'link_color_hover', array( 'default' => $color_scheme[4], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color_hover', array( 'label' => __( 'Link Color :hover', 'bizpress' ), 'section' => 'colors', ) ) ); // Add main text color setting and control. $wp_customize->add_setting( 'main_text_color', array( 'default' => $color_scheme[5], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_text_color', array( 'label' => __( 'Main Text Color', 'bizpress' ), 'section' => 'colors', ) ) ); // Add secondary text color setting and control. $wp_customize->add_setting( 'secondary_text_color', array( 'default' => $color_scheme[6], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_text_color', array( 'label' => __( 'Secondary Text Color', 'bizpress' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'main_menu_background_color', array( 'default' => $color_scheme[8], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_menu_background_color', array( 'label' => __( 'Main Menu Background Color', 'bizpress' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'secondary_menu_background_color', array( 'default' => $color_scheme[10], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_menu_background_color', array( 'label' => __( 'Secondary Menu Background Color', 'bizpress' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'highlight_background_color', array( 'default' => $color_scheme[9], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'highlight_background_color', array( 'label' => __( 'Highlight Background Color', 'bizpress' ), 'section' => 'colors', ) ) ); $wp_customize->add_panel( 'bizpress_panel', array( 'priority' => 130, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => esc_html__( 'Theme Options', 'bizpress' ), 'description' => esc_html__( 'Bizpress Theme Options', 'bizpress' ), ) ); $wp_customize->add_section( 'bizpress_header_options', array( 'title' => esc_html__( 'Header', 'bizpress' ), 'panel' => 'bizpress_panel', ) ); // Featured Categories checkbox $wp_customize->add_setting( 'bizpress_header_display_tagline', array( 'default' => 1, 'sanitize_callback' => 'bizpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'bizpress_header_display_tagline', array( 'label' => esc_html__( 'Display site title and tagline in the header.', 'bizpress' ), 'section' => 'bizpress_header_options', 'type' => 'checkbox', ) ); $wp_customize->add_section( 'bizpress_front_page', array( 'title' => esc_html__( 'Featured Content Blocks', 'bizpress' ), 'panel' => 'bizpress_panel', ) ); // Featured Posts checkbox $wp_customize->add_setting( 'bizpress_front_featured_posts', array( 'default' => 1, 'sanitize_callback' => 'bizpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'bizpress_front_featured_posts', array( 'label' => esc_html__( 'Show Featured Posts Section on the Front Page', 'bizpress' ), 'section' => 'bizpress_front_page', 'type' => 'checkbox', ) ); $wp_customize->add_setting( 'bizpress_front_featured_posts_num', array( 'default' => 3, 'sanitize_callback' => 'bizpress_sanitize_widget_num' ) ); $wp_customize->add_control( 'bizpress_front_featured_posts_num', array( 'label' => esc_html__( 'Featured Posts Amount', 'bizpress' ), 'section' => 'bizpress_front_page', 'type' => 'select', 'description' => esc_html__( 'Set the amount of posts to be displayed.', 'bizpress' ), 'choices' => array( '1' => esc_html_x( '1', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '2' => esc_html_x( '2', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '3' => esc_html_x( '3', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '4' => esc_html_x( '4', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '5' => esc_html_x( '5', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '6' => esc_html_x( '6', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '7' => esc_html_x( '7', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '8' => esc_html_x( '8', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '9' => esc_html_x( '9', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), '10' => esc_html_x( '10', 'This sets the amount of posts to be displayed on the homepage in the Featured Section', 'bizpress' ), ), ) ); $wp_customize->add_setting( 'bizpress_front_featured_posts_title', array( 'default' => 0, 'sanitize_callback' => 'bizpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'bizpress_front_featured_posts_title', array( 'label' => esc_html__( 'Show the post titles for the Featured Posts', 'bizpress' ), 'section' => 'bizpress_front_page', 'type' => 'checkbox', ) ); $wp_customize->add_setting( 'bizpress_featured_term_1', array( 'default' => 'featured', 'sanitize_callback' => 'bizpress_sanitize_terms', ) ); $wp_customize->add_control( 'bizpress_featured_term_1', array( 'label' => esc_html__( 'Front Page: Featured Tag', 'bizpress' ), 'description' => sprintf( wp_kses( __( 'This list is populated with Post Tags.', 'bizpress' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( 'edit-tags.php?taxonomy=post_tag' ) ) ), 'section' => 'bizpress_front_page', 'type' => 'select', 'choices' => bizpress_get_terms(), ) ); $wp_customize->add_section( 'bizpress_other_options', array( 'title' => esc_html__( 'Other Options', 'bizpress' ), 'panel' => 'bizpress_panel', ) ); $wp_customize->add_setting( 'bizpress_single_featured_image', array( 'default' => 1, 'sanitize_callback' => 'bizpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'bizpress_single_featured_image', array( 'label' => esc_html__( 'Display Featured Image on Post Pages', 'bizpress' ), 'section' => 'bizpress_other_options', 'description' => esc_html__( 'The recommended width of featured images is 1220px.', 'bizpress' ), 'type' => 'checkbox', ) ); $wp_customize->add_setting( 'bizpress_single_gravatar', array( 'default' => 1, 'sanitize_callback' => 'bizpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'bizpress_single_gravatar', array( 'label' => esc_html__( 'Display Author Gravatar on Post Pages', 'bizpress' ), 'section' => 'bizpress_other_options', 'type' => 'checkbox', ) ); return $wp_customize; } add_action( 'customize_register', 'bizpress_customize_register' ); if ( ! function_exists( 'bizpress_get_terms' ) ) : /** * Return an array of tag names and slugs * * @since 1.0.0. * * @return array The list of terms. */ function bizpress_get_terms() { $choices = array( 0 ); // Default $choices = array( 'none' => esc_html__( 'None', 'bizpress' ) ); // Post Tags $type_terms = get_terms( 'post_tag' ); if ( ! empty( $type_terms ) ) { $type_slugs = wp_list_pluck( $type_terms, 'slug' ); $type_names = wp_list_pluck( $type_terms, 'name' ); $type_list = array_combine( $type_slugs, $type_names ); $choices = array_merge( $choices, $type_list ); } return apply_filters( 'bizpress_get_terms', $choices ); } endif; if ( ! function_exists( 'bizpress_sanitize_terms' ) ) : /** * Sanitize a value from a list of allowed values. * * @since 1.0.0. * * @param mixed $value The value to sanitize. * @return mixed The sanitized value. */ function bizpress_sanitize_terms( $value ) { $choices = bizpress_get_terms(); $valid = array_keys( $choices ); if ( ! in_array( $value, $valid ) ) { $value = 'none'; } return $value; } endif; if ( ! function_exists( 'bizpress_get_categories' ) ) : /** * Return an array of tag names and slugs * * @since 1.0.0. * * @return array The list of terms. */ function bizpress_get_categories() { $choices = array( 0 ); // Default $choices = array( 'none' => esc_html__( 'None', 'bizpress' ) ); // Categories $type_terms = get_terms( 'category' ); if ( ! empty( $type_terms ) ) { $type_names = wp_list_pluck( $type_terms, 'name', 'term_id' ); $choices = $choices + $type_names; } return apply_filters( 'bizpress_get_categories', $choices ); } endif; if ( ! function_exists( 'bizpress_sanitize_categories' ) ) : /** * Sanitize a value from a list of allowed values. * * @since 1.0.0. * * @param mixed $value The value to sanitize. * @return mixed The sanitized value. */ function bizpress_sanitize_categories( $value ) { $choices = bizpress_get_categories(); $valid = array_keys( $choices ); if ( ! in_array( $value, $valid ) ) { $value = 'none'; } return $value; } endif; if ( ! function_exists( 'bizpress_sanitize_checkbox' ) ) : /** * Sanitize the checkbox. * * @param mixed $input. * @return boolean (true|false). */ function bizpress_sanitize_checkbox( $input ) { if ( 1 == $input ) { return true; } else { return false; } } endif; if ( ! function_exists( 'bizpress_sanitize_widget_num' ) ) : /** * Sanitize the Featured Category posts number. * * @param boolean $input. * @return boolean (true|false). */ function bizpress_sanitize_widget_num( $input ) { $choices = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ); if ( ! in_array( $input, $choices ) ) { $input = '3'; } return $input; } endif; /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function bizpress_customize_preview_js() { wp_enqueue_script( 'bizpress_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20160513', true ); } add_action( 'customize_preview_init', 'bizpress_customize_preview_js' ); /** * Registers color schemes for Bizpress. * * Can be filtered with {@see 'bizpress_color_schemes'}. * * The order of colors in a colors array: * 1. Main Background Color. * 2. Page Background Color. * 3. Link Color. * 4. Main Text Color. * 5. Secondary Text Color. * * @since Bizpress 1.0 * * @return array An associative array of color scheme options. */ function bizpress_get_color_schemes() { /** * Filter the color schemes registered for use with Bizpress. * * The default schemes include 'default', 'dark', 'gray', 'red', and 'yellow'. * * @since Bizpress 1.0 * * @param array $schemes { * Associative array of color schemes data. * * @type array $slug { * Associative array of information for setting up the color scheme. * * @type string $label Color scheme label. * @type array $colors HEX codes for default colors prepended with a hash symbol ('#'). * Colors are defined in the following order: Main background, page * background, link, main text, secondary text. * } * } */ return apply_filters( 'bizpress_color_schemes', array( 'default' => array( 'label' => __( 'Default', 'bizpress' ), 'colors' => array( '#dddddd', // [0] background color '#ffffff', // [1] content container background color '#b21b34', // [2] header background color '#3fa0cd', // [3] link color '#ab1133', // [4] link :hover color '#414141', // [5] main text color '#888888', // [6] secondary text color '#dddddd', // [7] footer background color '#202020', // [8] main menu background color '#b21b34', // [9] highlight background color '#303030', // [10] secondary menu background color ), ), ) ); } if ( ! function_exists( 'bizpress_get_color_scheme' ) ) : /** * Retrieves the current Bizpress color scheme. * * Create your own bizpress_get_color_scheme() function to override in a child theme. * * @since Bizpress 1.0 * * @return array An associative array of either the current or default color scheme HEX values. */ function bizpress_get_color_scheme() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); $color_schemes = bizpress_get_color_schemes(); if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { return $color_schemes[ $color_scheme_option ]['colors']; } return $color_schemes['default']['colors']; } endif; // bizpress_get_color_scheme /** * Enqueues front-end CSS for the page background color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_page_background_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[1]; $page_background_color = get_theme_mod( 'page_background_color', $default_color ); // Don't do anything if the current color is the default. if ( $page_background_color === $default_color ) { return; } $css = ' /* Custom Page Background Color */ .wrapper-frame { background-color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $page_background_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_page_background_color_css', 11 ); /** * Enqueues front-end CSS for the header background color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_header_background_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[1]; $header_background_color = get_theme_mod( 'header_background_color', $default_color ); // Don't do anything if the current color is the default. if ( $header_background_color === $default_color ) { return; } $css = ' /* Custom Header Background Color */ #site-header-main { background-color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $header_background_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_header_background_color_css', 11 ); /** * Enqueues front-end CSS for the footer background color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_footer_background_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[1]; $footer_background_color = get_theme_mod( 'footer_background_color', $default_color ); // Don't do anything if the current color is the default. if ( $footer_background_color === $default_color ) { return; } $css = ' /* Custom Footer Background Color */ .site-footer { background-color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $footer_background_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_footer_background_color_css', 11 ); /** * Enqueues front-end CSS for the Main Menu background color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_main_menu_background_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[8]; $menu_background_color = get_theme_mod( 'main_menu_background_color', $default_color ); // Don't do anything if the current color is the default. if ( $menu_background_color === $default_color ) { return; } $css = ' /* Custom Main Menu Background Color */ #site-header-navigation { background-color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $menu_background_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_main_menu_background_color_css', 11 ); /** * Enqueues front-end CSS for the Secondary Menu background color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_secondary_menu_background_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[10]; $secmenu_background_color = get_theme_mod( 'secondary_menu_background_color', $default_color ); // Don't do anything if the current color is the default. if ( $secmenu_background_color === $default_color ) { return; } $css = ' /* Custom Secondary Menu Background Color */ #site-header-navigation-secondary { background-color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $secmenu_background_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_secondary_menu_background_color_css', 11 ); /** * Enqueues front-end CSS for the Highlights background color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_highlight_background_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[9]; $highlight_background_color = get_theme_mod( 'highlight_background_color', $default_color ); // Don't do anything if the current color is the default. if ( $highlight_background_color === $default_color ) { return; } $css = ' /* Custom Highlight Background Color */ .infinite-scroll #infinite-handle span, .post-navigation .nav-previous:hover, .post-navigation .nav-previous:focus, .post-navigation .nav-next:hover, .post-navigation .nav-next:focus, .posts-navigation .nav-previous:hover, .posts-navigation .nav-previous:focus, .posts-navigation .nav-next:hover, .posts-navigation .nav-next:focus { background-color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $highlight_background_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_highlight_background_color_css', 11 ); /** * Enqueues front-end CSS for the link color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_link_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[2]; $link_color = get_theme_mod( 'link_color', $default_color ); // Don't do anything if the current color is the default. if ( $link_color === $default_color ) { return; } $css = ' /* Custom Link Color */ a { color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $link_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_link_color_css', 11 ); /** * Enqueues front-end CSS for the link :hover color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_link_color_hover_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[3]; $link_color = get_theme_mod( 'link_color_hover', $default_color ); // Don't do anything if the current color is the default. if ( $link_color === $default_color ) { return; } $css = ' /* Custom Link:hover Color */ a:hover, a:focus, .ilovewp-post .post-meta .entry-date a:hover, .ilovewp-post .post-meta .entry-date a:focus, h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover, h1 a:focus, h2 a:focus, h3 a:focus, h4 a:focus, h5 a:focus, h6 a:focus, .ilovewp-posts-archive .title-post a:hover, .ilovewp-posts-archive .title-post a:focus, .ilovewp-posts-archive .post-meta a:hover, .ilovewp-posts-archive .post-meta a:focus, .ilovewp-post .post-meta .entry-date a:hover, .ilovewp-post .post-meta .entry-date a:focus { color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $link_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_link_color_hover_css', 11 ); /** * Enqueues front-end CSS for the main text color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_main_text_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[4]; $main_text_color = get_theme_mod( 'main_text_color', $default_color ); // Don't do anything if the current color is the default. if ( $main_text_color === $default_color ) { return; } $css = ' /* Custom Main Text Color */ body { color: %1$s } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $main_text_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_main_text_color_css', 11 ); /** * Enqueues front-end CSS for the secondary text color. * * @since Bizpress 1.0 * * @see wp_add_inline_style() */ function bizpress_secondary_text_color_css() { $color_scheme = bizpress_get_color_scheme(); $default_color = $color_scheme[4]; $secondary_text_color = get_theme_mod( 'secondary_text_color', $default_color ); // Don't do anything if the current color is the default. if ( $secondary_text_color === $default_color ) { return; } $css = ' /* Custom Secondary Text Color */ body:not(.search-results) .entry-summary { color: %1$s; } .post-meta, .ilovewp-post .post-meta { color: %1$s; } '; wp_add_inline_style( 'bizpress-style', sprintf( $css, esc_attr( $secondary_text_color ) ) ); } add_action( 'wp_enqueue_scripts', 'bizpress_secondary_text_color_css', 11 );