$default_background_color, ) ) ); } add_action( 'after_setup_theme', 'bradbury_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 bradbury_customize_register( $wp_customize ) { $color_scheme = bradbury_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', 'bradbury' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'footer_featured_background_color', array( 'default' => $color_scheme[2], 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_featured_background_color', array( 'label' => __( 'Featured Posts (Footer) Background', 'bradbury' ), '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', 'bradbury' ), 'section' => 'colors', ) ) ); // 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', 'bradbury' ), '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', 'bradbury' ), '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', 'bradbury' ), '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', 'bradbury' ), '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', 'bradbury' ), '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', 'bradbury' ), 'section' => 'colors', ) ) ); $wp_customize->add_panel( 'bradbury_panel', array( 'priority' => 130, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => esc_html__( 'Theme Options', 'bradbury' ), 'description' => esc_html__( 'Bradbury Theme Options', 'bradbury' ), ) ); $wp_customize->add_section( 'bradbury_header_options', array( 'title' => esc_html__( 'Header', 'bradbury' ), 'panel' => 'bradbury_panel', ) ); $wp_customize->add_setting( 'bradbury_header_display_tagline', array( 'default' => 1, 'sanitize_callback' => 'bradbury_sanitize_checkbox', ) ); $wp_customize->add_control( 'bradbury_header_display_tagline', array( 'label' => esc_html__( 'Display site title and tagline in the header.', 'bradbury' ), 'section' => 'bradbury_header_options', 'type' => 'checkbox', ) ); $wp_customize->add_section( 'bradbury_front_page', array( 'title' => esc_html__( 'Featured Content Blocks', 'bradbury' ), 'panel' => 'bradbury_panel', ) ); // Featured Posts checkbox $wp_customize->add_setting( 'bradbury_front_exclusive_posts', array( 'default' => 1, 'sanitize_callback' => 'bradbury_sanitize_checkbox', ) ); // Featured Posts checkbox $wp_customize->add_setting( 'bradbury_front_featured_posts', array( 'default' => 1, 'sanitize_callback' => 'bradbury_sanitize_checkbox', ) ); $wp_customize->add_control( 'bradbury_front_featured_posts', array( 'label' => esc_html__( 'Display Featured Posts at the top of the Front Page', 'bradbury' ), 'section' => 'bradbury_front_page', 'type' => 'checkbox', ) ); // Featured Posts Options $wp_customize->add_setting( 'bradbury_featured_term_1', array( 'default' => 'featured', 'sanitize_callback' => 'bradbury_sanitize_terms', ) ); $wp_customize->add_control( 'bradbury_featured_term_1', array( 'label' => esc_html__( 'Front Page: Featured Tag', 'bradbury' ), 'description' => sprintf( wp_kses( __( 'This list is populated with Post Tags.', 'bradbury' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( 'edit-tags.php?taxonomy=post_tag' ) ) ), 'section' => 'bradbury_front_page', 'type' => 'select', 'choices' => bradbury_get_terms(), ) ); return $wp_customize; } add_action( 'customize_register', 'bradbury_customize_register' ); if ( ! function_exists( 'bradbury_get_terms' ) ) : /** * Return an array of tag names and slugs * * @since 1.0.0. * * @return array The list of terms. */ function bradbury_get_terms() { $choices = array( 0 ); // Default $choices = array( 'none' => esc_html__( 'None', 'bradbury' ) ); // 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( 'bradbury_get_terms', $choices ); } endif; if ( ! function_exists( 'bradbury_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 bradbury_sanitize_terms( $value ) { $choices = bradbury_get_terms(); $valid = array_keys( $choices ); if ( ! in_array( $value, $valid ) ) { $value = 'none'; } return $value; } endif; if ( ! function_exists( 'bradbury_get_categories' ) ) : /** * Return an array of tag names and slugs * * @since 1.0.0. * * @return array The list of terms. */ function bradbury_get_categories() { $choices = array( 0 ); // Default $choices = array( 'none' => esc_html__( 'None', 'bradbury' ) ); // 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( 'bradbury_get_categories', $choices ); } endif; if ( ! function_exists( 'bradbury_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 bradbury_sanitize_categories( $value ) { $choices = bradbury_get_categories(); $valid = array_keys( $choices ); if ( ! in_array( $value, $valid ) ) { $value = 'none'; } return $value; } endif; if ( ! function_exists( 'bradbury_sanitize_checkbox' ) ) : /** * Sanitize the checkbox. * * @param mixed $input. * @return boolean (true|false). */ function bradbury_sanitize_checkbox( $input ) { if ( 1 == $input ) { return true; } else { return false; } } endif; if ( ! function_exists( 'bradbury_sanitize_widget_layout' ) ) : /** * Sanitize the Featured Posts layout. * * @param boolean $input. * @return boolean (true|false). */ function bradbury_sanitize_widget_layout( $input ) { $choices = array( 'default', 'large' ); if ( ! in_array( $input, $choices ) ) { $input = 'default'; } return $input; } endif; /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function bradbury_customize_preview_js() { wp_enqueue_script( 'bradbury_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20160513', true ); } add_action( 'customize_preview_init', 'bradbury_customize_preview_js' ); /** * Registers color schemes for Bradbury. * * Can be filtered with {@see 'bradbury_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 Bradbury 1.0 * * @return array An associative array of color scheme options. */ function bradbury_get_color_schemes() { /** * Filter the color schemes registered for use with Bradbury. * * The default schemes include 'default', 'dark', 'gray', 'red', and 'yellow'. * * @since Bradbury 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( 'bradbury_color_schemes', array( 'default' => array( 'label' => __( 'Default', 'bradbury' ), 'colors' => array( '#f2f1ed', // [0] background color '#ffffff', // [1] content container background color '#262626', // [2] footer featured content background color '#3F88C5', // [3] link color '#e3713d', // [4] link :hover color '#333333', // [5] main text color '#888888', // [6] secondary text color '#131313', // [7] footer background color '#131313', // [8] main menu background color '#3F88C5', // [9] highlight background color ), ), ) ); } if ( ! function_exists( 'bradbury_get_color_scheme' ) ) : /** * Retrieves the current Bradbury color scheme. * * Create your own bradbury_get_color_scheme() function to override in a child theme. * * @since Bradbury 1.0 * * @return array An associative array of either the current or default color scheme HEX values. */ function bradbury_get_color_scheme() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); $color_schemes = bradbury_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; // bradbury_get_color_scheme if ( ! function_exists( 'bradbury_get_color_scheme_choices' ) ) : /** * Retrieves an array of color scheme choices registered for Bradbury. * * Create your own bradbury_get_color_scheme_choices() function to override * in a child theme. * * @since Bradbury 1.0 * * @return array Array of color schemes. */ function bradbury_get_color_scheme_choices() { $color_schemes = bradbury_get_color_schemes(); $color_scheme_control_options = array(); foreach ( $color_schemes as $color_scheme => $value ) { $color_scheme_control_options[ $color_scheme ] = $value['label']; } return $color_scheme_control_options; } endif; // bradbury_get_color_scheme_choices if ( ! function_exists( 'bradbury_sanitize_color_scheme' ) ) : /** * Handles sanitization for Bradbury color schemes. * * Create your own bradbury_sanitize_color_scheme() function to override * in a child theme. * * @since Bradbury 1.0 * * @param string $value Color scheme name value. * @return string Color scheme name. */ function bradbury_sanitize_color_scheme( $value ) { $color_schemes = bradbury_get_color_scheme_choices(); if ( ! array_key_exists( $value, $color_schemes ) ) { return 'default'; } return $value; } endif; // bradbury_sanitize_color_scheme /** * Enqueues front-end CSS for color scheme. * * @since Bradbury 1.0 * * @see wp_add_inline_style() */ function bradbury_color_scheme_css() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); // Don't do anything if the default color scheme is selected. if ( 'default' === $color_scheme_option ) { return; } $color_scheme = bradbury_get_color_scheme(); // If we get this far, we have a custom color scheme. $colors = array( 'background_color' => $color_scheme[0], 'page_background_color' => $color_scheme[1], 'footer_featured_background_color' => $color_scheme[2], 'link_color' => $color_scheme[3], 'link_color_hover' => $color_scheme[4], 'main_text_color' => $color_scheme[5], 'secondary_text_color' => $color_scheme[6], 'footer_background_color' => $color_scheme[7], 'main_menu_background_color' => $color_scheme[8], 'highlight_background_color' => $color_scheme[9], ); $color_scheme_css = bradbury_get_color_scheme_css( $colors ); wp_add_inline_style( 'bradbury-style', $color_scheme_css ); } add_action( 'wp_enqueue_scripts', 'bradbury_color_scheme_css' ); /** * Returns CSS for the color schemes. * * @since Bradbury 1.0 * * @param array $colors Color scheme colors. * @return string Color scheme CSS. */ function bradbury_get_color_scheme_css( $colors ) { $colors = wp_parse_args( $colors, array( 'background_color' => '', 'page_background_color' => '', 'footer_featured_background_color' => '', 'link_color' => '', 'link_color_hover' => '', 'main_text_color' => '', 'secondary_text_color' => '', 'footer_background_color' => '', 'main_menu_background_color' => '', 'highlight_background_color' => '', ) ); return <<