config->get_customizer_panels() ); if ( is_array( $panels ) ) { foreach ( $panels as $key => $panel ) { Kirki::add_panel( $key, $panel ); } } } /** * Add Kirki Sections */ public function add_sections() { $sections = apply_filters( 'rocksite_kit_filter_customizer_sections', $this->config->get_customizer_sections() ); if ( is_array( $sections ) ) { foreach ( $sections as $key => $section ) { Kirki::add_section( $key, $section ); } } } /** * Add Kirki Fields */ public function add_fields() { $fields = apply_filters( 'rocksite_kit_filter_customizer_fields', $this->config->get_customizer_fields() ); foreach ( $fields as $field_name => $field_args ) { Kirki::add_field( ROCKSITE_THEME_SETTINGS, $this->add_default_values_to_field( $field_name, $field_args ) ); } } /** * Ads default value from the configuration file into single field configuration * * @param $field_name * @param array $field_configuration * * @return array */ private function add_default_values_to_field( $field_name, array $field_configuration ) { $default_settings = $this->config->default_settings(); if ( ! isset ( $field_configuration['default'] ) ) { if ( isset( $default_settings[ $field_name ] ) ) { $field_configuration['default'] = $default_settings[ $field_name ]; } } return $field_configuration; } /** * Add Basic Settings without installing any plugin * * @param $wp_customize */ public function add_basic_fields( $wp_customize ) { // remove unused controls $wp_customize->remove_control( "header_textcolor" ); // Footer copyright $wp_customize->add_setting( 'footer_copyright_text', array( 'sanitize_callback' => 'sanitize_text_field', 'default' => __( 'Rocksite Copyright', 'canvi' ) ) ); $wp_customize->add_control( 'footer_copyright_text', array( 'label' => __( 'Footer copyright text', 'canvi' ), 'section' => 'title_tagline' ) ); $wp_customize->selective_refresh->add_partial( 'footer_copyright_text', array( 'selector' => '.powered-by', 'render_callback' => 'rocksite_copyright', ) ); // Footer Description $wp_customize->add_setting( 'footer_description_text', array( 'sanitize_callback' => 'sanitize_text_field', 'default' => __( 'Footer Description Text', 'canvi' ) ) ); $wp_customize->add_control( 'footer_description_text', array( 'label' => __( 'Footer Description text', 'canvi' ), 'section' => 'title_tagline' ) ); $wp_customize->selective_refresh->add_partial( 'footer_description_text', array( 'selector' => '.footer-description', 'render_callback' => 'rocksite_footer_description', ) ); // Header Section $wp_customize->add_setting( 'header_image_title', array( 'sanitize_callback' => 'sanitize_text_field', 'default' => __( 'Default Website Title', 'canvi' ) ) ); $wp_customize->add_control( 'header_image_title', array( 'label' => __( 'Header Title', 'canvi' ), 'section' => 'header_image' ) ); $wp_customize->add_setting( 'header_image_description', array( 'sanitize_callback' => 'sanitize_text_field', 'default' => __( 'Short description below the title. You can change it in the customizer', 'canvi' ) ) ); $wp_customize->add_control( 'header_image_description', array( 'label' => __( 'Header Description', 'canvi' ), 'section' => 'header_image' ) ); /** * Global Colors */ // Text Color $wp_customize->add_setting( 'global--color-text-base', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-text-base' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-text-base', array( 'label' => __( 'Text Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Third Color Lighten $wp_customize->add_setting( 'global--color-text-lighten', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-text-lighten' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-text-lighten', array( 'label' => __( 'Text Color Lighten', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Primary Base Color $wp_customize->add_setting( 'global--color-primary-base', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-primary-base' ), ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-primary-base', array( 'label' => __( 'Primary Base Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Primary Lighten Color $wp_customize->add_setting( 'global--color-primary-lighten', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-primary-lighten' ), ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-primary-lighten', array( 'label' => __( 'Primary Lighten Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Sectondary Base Color $wp_customize->add_setting( 'global--color-secondary', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-secondary' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-secondary', array( 'label' => __( 'Secondary Base Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Sectondary Lighten Color $wp_customize->add_setting( 'global--color-secondary-lighten', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-secondary-lighten' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-secondary-lighten', array( 'label' => __( 'Secondary Lighten Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Third Base Color $wp_customize->add_setting( 'global--color-third-base', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-third-base' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-third-base', array( 'label' => __( 'Third Base Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Third Lighten Color $wp_customize->add_setting( 'global--color-third-lighten', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-third-lighten' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-third-lighten', array( 'label' => __( 'Third Lighten Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Gray Base Color $wp_customize->add_setting( 'global--color-gray-base', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-gray-base' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-gray-base', array( 'label' => __( 'Gray Base Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Gray Darken Color $wp_customize->add_setting( 'global--color-gray-darken', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-gray-darken' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-gray-darken', array( 'label' => __( 'Gray Darken Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Gray Darken Color $wp_customize->add_setting( 'global--color-gray-lighten', array( 'sanitize_callback' => 'sanitize_hex_color', 'default' => $this->config->get_project_variables( 'global--color-gray-lighten' ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'global--color-gray-lighten', array( 'label' => __( 'Gray Lighten Color', 'canvi' ), 'section' => 'colors', // Add a default or your own section ) ) ); // Navigation Bar $wp_customize->add_section( 'navbar_section', array( 'title' => __( 'Navigation Bar Section', 'canvi' ), 'priority' => 24, ) ); $wp_customize->add_setting( 'main_menu_search_display', array( 'capability' => 'edit_theme_options', 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), 'default' => TRUE ) ); $wp_customize->add_control( 'main_menu_search_display', array( 'type' => 'checkbox', 'section' => 'navbar_section', // Add a default or your own section 'label' => esc_html__( 'Display Search Bar', 'canvi' ), ) ); $wp_customize->add_setting( 'navbar_fixed', array( 'capability' => 'edit_theme_options', 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), 'default' => TRUE ) ); // Blog Settings $wp_customize->add_section( 'blog_section', array( 'title' => __( 'Blog Settings', 'canvi' ), 'priority' => 24, ) ); $wp_customize->add_setting( 'infinite_scroll_on', array( 'capability' => 'edit_theme_options', 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), 'default' => TRUE ) ); $wp_customize->add_control( 'infinite_scroll_on', array( 'type' => 'checkbox', 'section' => 'blog_section', // Add a default or your own section 'label' => esc_html__( 'Switch on infintie scroll on archive pages', 'canvi' ), ) ); /* Display full content or excerpts on the blog and archives --------- */ $wp_customize->add_setting( 'display_excerpt_or_full_post', array( 'capability' => 'edit_theme_options', 'default' => 'full', 'sanitize_callback' => array( $this, 'sanitize_select' ), ) ); $wp_customize->add_control( 'display_excerpt_or_full_post', array( 'type' => 'radio', 'section' => 'blog_section', 'priority' => 10, 'label' => __( 'On archive pages, posts show:', 'canvi' ), 'choices' => array( 'full' => __( 'Full text', 'canvi' ), 'excerpt' => __( 'Summary', 'canvi' ), ), ) ); /* Show author bio ---------------------------------------------------- */ $wp_customize->add_setting( 'show_author_bio', array( 'capability' => 'edit_theme_options', 'default' => TRUE, 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), ) ); $wp_customize->add_control( 'show_author_bio', array( 'type' => 'checkbox', 'section' => 'blog_section', 'priority' => 10, 'label' => __( 'Show author bio', 'canvi' ), ) ); // Add partial for blogdescription. $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => array( $this, 'partial_blogdescription' ), ) ); // Add "display_title_and_tagline" setting for displaying the site-title & tagline. $wp_customize->add_setting( 'display_title_and_tagline', array( 'capability' => 'edit_theme_options', 'default' => TRUE, 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), ) ); // Add control for the "display_title_and_tagline" setting. $wp_customize->add_control( 'display_title_and_tagline', array( 'type' => 'checkbox', 'section' => 'title_tagline', 'label' => esc_html__( 'Display Site Title & Tagline', 'canvi' ), ) ); } public function custom_font_fields( $wp_customize ) { $wp_customize->add_section( 'fonts_section', array( 'title' => __( 'Theme Typography', 'canvi' ), 'priority' => 24, ) ); $wp_customize->add_setting( 'global--font-primary', array( 'default' => '{"font":"Spartan","regularweight":"600","italicweight":"italic","boldweight":"700","category":"serif"}', 'sanitize_callback' => 'skyrocket_google_font_sanitization', ) ); $wp_customize->add_control( new Skyrocket_Google_Font_Select_Custom_Control( $wp_customize, 'global--font-primary', array( 'label' => esc_attr__( 'Heading Font Family', 'canvi' ), 'description' => esc_attr__( 'Choose heading font for your site', 'canvi' ), 'section' => 'fonts_section', 'input_attrs' => array( 'font_count' => 'all', 'orderby' => 'alpha', ), ) ) ); $wp_customize->add_setting( 'global--font-secondary', array( 'default' => '{"font":"Mulish","regularweight":"regular","italicweight":"italic","boldweight":"700","category":"serif"}', 'sanitize_callback' => 'skyrocket_google_font_sanitization', ) ); $wp_customize->add_control( new Skyrocket_Google_Font_Select_Custom_Control( $wp_customize, 'global--font-secondary', array( 'label' => esc_attr__( 'General Font Family', 'canvi' ), 'description' => esc_attr__( 'Choose font for regular text', 'canvi' ), 'section' => 'fonts_section', 'input_attrs' => array( 'font_count' => 'all', 'orderby' => 'alpha', ), ) ) ); // Button font family $wp_customize->add_setting( 'button--font-family', array( 'default' => '{"font":"Spartan","regularweight":"600","italicweight":"italic","boldweight":"700","category":"serif"}', 'sanitize_callback' => 'skyrocket_google_font_sanitization', ) ); $wp_customize->add_control( new Skyrocket_Google_Font_Select_Custom_Control( $wp_customize, 'button--font-family', array( 'label' => esc_attr__( 'Button Font Family', 'canvi' ), 'description' => esc_attr__( 'Choose font for buttons on your site', 'canvi' ), 'section' => 'fonts_section', 'input_attrs' => array( 'font_count' => 'all', 'orderby' => 'alpha', ), ) ) ); // Button line height $wp_customize->add_setting( 'button--line-height', array( 'sanitize_callback' => 'absint', //converts value to a non-negative integer 'default' => $this->config->get_project_variables( 'button--line-height' ), ) ); $wp_customize->add_control( 'button--line-height', array( 'label' => esc_html__( 'Button line height', 'canvi' ), 'section' => 'fonts_section', 'type' => 'number' ) ); } /** * Select Sanitization * * @param $input * @param $setting * * @return string */ function sanitize_select( $input, $setting ) { //input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only $input = sanitize_key( $input ); //get the list of possible select options $choices = $setting->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 * * @param $checked * * @return bool */ function sanitize_checkbox( $checked ) { // Boolean check. return ( ( isset( $checked ) && TRUE == $checked ) ? TRUE : FALSE ); } } }