get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; // refresh customizer support if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.navbar-brand', 'render_callback' => 'blogbaster_customize_partial_blogname', ) ); } // Toggle Switch Hide Site Title $wp_customize->add_setting( 'site_title_hide', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'site_title_hide', array( 'label' => __( 'Show Site Title', 'blogbaster' ), 'section' => 'title_tagline', 'priority' => 20 ) ) ); $wp_customize->add_setting( 'header_image_notice', array( 'default' => false, 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_control( new Blogbaster_Simple_Notice_Custom_Control( $wp_customize, 'header_image_notice', array( 'label' => __( 'Note Please:', 'blogbaster' ), 'description' => __( 'This Control allows you to display an uploaded image in the page header before page main content if you selected Separately mode for Page Header from Theme Options section. If you selected Cover mode for Page Header from Theme Options section and uploaded image you need click to Hide image button located under the Current header field.', 'blogbaster' ), 'section' => 'header_image', 'priority' => 3 ) ) ); /** * * Add settings to Colors section * */ $theme_colors = array(); $theme_colors[] = array( 'slug'=>'site_title_color', 'default' => '#212529', 'label' => esc_html__('Site Title Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'main_color', 'default' => '#212529', 'label' => esc_html__('Body Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'content_color', 'default' => '#212529', 'label' => esc_html__('Content Color', 'blogbaster'), 'transport' => 'refresh' ); $theme_colors[] = array( 'slug'=>'header_bgcolor', 'default' => '#e9ecef', 'label' => esc_html__('Header Background Color', 'blogbaster'), 'description' => esc_html__('It is recommended to use only light colors.','blogbaster'), 'transport' => 'postMessage', 'active_callback' => 'blogbaster_is_overlay_header' ); $theme_colors[] = array( 'slug'=>'title_color', 'default' => '#212529', 'label' => esc_html__('Post/Page Titles Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'wgt_title_color', 'default' => '#212529', 'label' => esc_html__('Widget Title Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'link_color', 'default' => '#1f1f1f', 'label' => esc_html__('Text Link Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'link_hover_color', 'default' => '#454545', 'label' => esc_html__('Text Link Hover Color', 'blogbaster'), 'transport' => 'refresh' ); if ( has_nav_menu( 'social' ) ) : $theme_colors[] = array( 'slug'=>'social_link_bgcolor', 'default' => '#2c2c2c', 'label' => esc_html__('Social Links BG-Color', 'blogbaster'), 'transport' => 'refresh' ); $theme_colors[] = array( 'slug'=>'social_link_color', 'default' => '#ffffff', 'label' => esc_html__('Social Icons Color', 'blogbaster'), 'transport' => 'refresh' ); $theme_colors[] = array( 'slug'=>'social_link_bgcolor_hover', 'default' => '#ffffff', 'label' => esc_html__('Social Links BG-Color: Hover', 'blogbaster'), 'transport' => 'refresh' ); $theme_colors[] = array( 'slug'=>'social_link_color_hover', 'default' => '#2c2c2c', 'label' => esc_html__('Social Icons Color: Hover', 'blogbaster'), 'transport' => 'refresh' ); endif; $theme_colors[] = array( 'slug'=>'meta_color', 'default' => '#212529', 'label' => esc_html__('Body Text Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug' =>'primary_btn_color', 'default' => '#212529', 'label' => esc_html__('Primary Button Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug' =>'primary_btn_hover_color', 'default' => '#000000', 'label' => esc_html__('Primary Button: Hover Color', 'blogbaster'), 'transport' => 'refresh' ); $theme_colors[] = array( 'slug' =>'primary_btn_active_color', 'default' => '#000000', 'label' => esc_html__('Primary Button: Active Color', 'blogbaster'), 'transport' => 'refresh' ); if( has_nav_menu( 'footer' ) || has_nav_menu( 'social' ) ) { $theme_colors[] = array( 'slug' =>'pre_footer_bgcolor', 'default' => '#e9ecef', 'label' => esc_html__('Pre-Footer Background', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug' =>'pre_footer_color', 'default' => '#212529', 'label' => esc_html__('Pre-Footer Menu Color', 'blogbaster'), 'transport' => 'postMessage' ); } $theme_colors[] = array( 'slug' =>'footer_bgcolor', 'default' => '#101010', 'label' => esc_html__('Footer Background', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug' =>'footer_color', 'default' => '#a6a6a6', 'label' => esc_html__('Footer Text Color', 'blogbaster'), 'transport' => 'postMessage' ); foreach( $theme_colors as $color ) { $wp_customize->add_setting( $color['slug'], array( 'default' => $color['default'], 'type' => 'theme_mod', // 'option' 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => $color['transport'] ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 'label' => $color['label'], 'description' => $color['description'], 'section' => 'colors', 'settings' => $color['slug'] ) ) ); } /** * * Add Section * */ $wp_customize->add_section( 'general_options', array( 'title' => __( 'Global Options', 'blogbaster' ), 'capability' => 'edit_theme_options', 'priority' => 160, ) ); $wp_customize->add_setting( 'sidebar_position', array( 'default' => 'right', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_sidebar_position', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'sidebar_position', array( 'label' => __( 'Sidebar Displays', 'blogbaster' ), 'section' => 'general_options', 'settings' => 'sidebar_position', 'type' => 'select', 'choices' => array( 'right' => __( 'Right sidebar', 'blogbaster' ), 'left' => __( 'Left sidebar', 'blogbaster' ), 'none' => __( 'No sidebar', 'blogbaster' ), ), 'priority' => '15', ) ) ); $wp_customize->add_setting( 'single_header_display', array( 'default' => 'standard', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_header_display', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'single_header_display', array( 'label' => __( 'Page Header', 'blogbaster' ), 'description' => __( 'This applies when displaying the title of a single post or page. Note please: If you choose a Cover style then the size of post thumbnails should be at least 1200x860.', 'blogbaster' ), 'section' => 'general_options', 'type' => 'select', 'choices' => array( 'standard' => __( 'Separately', 'blogbaster' ), 'alt' => __( 'Cover', 'blogbaster' ) ), 'priority' => '18', ) ) ); /** * * Add Section * */ $wp_customize->add_section( 'menu_bar_options', array( 'title' => __( 'Navigation Bar', 'blogbaster' ), 'capability' => 'edit_theme_options', 'priority' => 165, ) ); /** * * Settings * */ // Color options $theme_colors = array(); $theme_colors[] = array( 'slug'=>'menu_color', 'default' => '#2c2c2c', 'label' => esc_html__('Menu Color', 'blogbaster'), 'description' => __( 'Note please: This applies when selected Separately Page Header (Theme Options section) or if the page does not have a header image or Featured Image.', 'blogbaster' ), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'menu_hover_color', 'default' => '#000', 'label' => esc_html__('Menu Color: Hover', 'blogbaster'), 'transport' => 'refresh' ); foreach( $theme_colors as $color ) { $wp_customize->add_setting( $color['slug'], array( 'default' => $color['default'], 'type' => 'theme_mod', // 'option' 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => $color['transport'] ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 'label' => $color['label'], 'description' => $color['description'], 'section' => 'menu_bar_options', 'settings' => $color['slug'] ) ) ); } // Toggle Switch Search icon $wp_customize->add_setting( 'show_search_menu_item', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'show_search_menu_item', array( 'label' => __( 'Search button', 'blogbaster' ), 'description' => esc_html__( 'Show the search button on the menu bar.', 'blogbaster' ), 'section' => 'menu_bar_options' ) ) ); // Toggle Switch Cart icon $wp_customize->add_setting( 'show_cart_menu_item', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'show_cart_menu_item', array( 'label' => __( 'Cart button', 'blogbaster' ), 'description' => esc_html__( 'Show the cart button on the menu bar.', 'blogbaster' ), 'section' => 'menu_bar_options' ) ) ); /** * * Posts Page * */ $wp_customize->add_section( 'blog_options', array( 'title' => __( 'Posts Page', 'blogbaster' ), 'capability' => 'edit_theme_options', 'priority' => 170, ) ); // Post preview card style $wp_customize->add_setting( 'card_style', array( 'default' => 'border', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_card_style', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'card_style', array( 'label' => __( 'Post Preview Card Style', 'blogbaster' ), 'section' => 'blog_options', 'settings' => 'card_style', 'type' => 'select', 'choices' => array('border' => esc_html__( 'Border', 'blogbaster' ),'noborder' => esc_html__( 'No border', 'blogbaster' ),'shadow' => esc_html__( 'Shadow', 'blogbaster' )) ) ) ); // Colors $theme_colors = array(); $theme_colors[] = array( 'slug'=>'entry_bgcolor', 'default' => '#ffffff', 'label' => esc_html__('Card Background Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'entry_footer_bgcolor', 'default' => '#ffffff', 'label' => esc_html__('Card Footer Background Color', 'blogbaster'), 'transport' => 'postMessage' ); foreach( $theme_colors as $color ) { $wp_customize->add_setting( $color['slug'], array( 'default' => $color['default'], 'type' => 'theme_mod', // 'option' 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => $color['transport'] ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 'label' => $color['label'], 'description' => $color['description'], 'section' => 'blog_options', 'settings' => $color['slug'] ) ) ); } // Toggle Switch Show Date $wp_customize->add_setting( 'hide_posted_on', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'hide_posted_on', array( 'label' => __( 'Hide Date', 'blogbaster' ), 'section' => 'blog_options' ) ) ); // Toggle Switch Show Author $wp_customize->add_setting( 'hide_posted_by', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'hide_posted_by', array( 'label' => __( 'Hide Author', 'blogbaster' ), 'section' => 'blog_options' ) ) ); $wp_customize->add_setting( 'blog_pagination_mode', array( 'default' => 'standard', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_blog_pagination_mode', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'blog_pagination_mode', array( 'label' => __( 'Pages navigation type', 'blogbaster' ), 'section' => 'blog_options', 'settings' => 'blog_pagination_mode', 'type' => 'select', 'choices' => array( 'standard' => __( 'Standard', 'blogbaster' ), 'numeric' => __( 'Numeric', 'blogbaster' ) ), 'priority' => '20', ) ) ); $wp_customize->add_setting( 'more_link', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'more_link', array( 'label' => __( 'Link to full post', 'blogbaster' ), 'description' => __( 'Enter the button label which is a link to the full post. You can leave this blank if you want to hide the button.', 'blogbaster' ), 'section' => 'blog_options', 'type' => 'text' ) ) ); // Post List helper function. function blogbaster_post_list( $args = array() ) { $args = wp_parse_args( $args, array('numberposts' => '-1') ); $posts = get_posts( $args ); $output = array(); $output[''] = __( '— Select Post —', 'blogbaster' ); foreach( $posts as $post ) { $thetitle = $post->post_title; $getlength = strlen($thetitle); $thelength = 32; $thetitle = substr($thetitle, 0, $thelength); if ($getlength > $thelength){ $thetitle .= '...'; }; $output[$post->ID] = sprintf('%s', esc_html($thetitle) ); } return $output; } $wp_customize->add_setting( 'post_dropdown_setting', array( 'default' => '', 'type' => 'theme_mod', 'sanitize_callback' => 'absint', // $output[$post->ID] 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'post_dropdown_setting', array( 'label' => __( 'Featured Post', 'blogbaster' ), 'section' => 'blog_options', 'settings' => 'post_dropdown_setting', 'type' => 'select', 'choices' => blogbaster_post_list(), 'priority' => '10', ) ) ); $wp_customize->add_setting( 'home_cover_height', array( 'default' => 50, 'transport' => 'postMessage', 'sanitize_callback' => 'blogbaster_range_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Slider_Custom_Control( $wp_customize, 'home_cover_height', array( 'label' => __( 'Cover Height of Featured Post', 'blogbaster' ), 'section' => 'blog_options', 'input_attrs' => array( 'min' => 50, 'max' => 100, 'step' => 1, ), 'active_callback' => 'blogbaster_set_blog_homepage' ) ) ); // Featured Category $wp_customize->add_setting( 'featured_category', array( 'default' => '', 'type' => 'theme_mod', 'sanitize_callback' => 'absint', // because the output is category ID number 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'featured_category', array( 'label' => esc_html__( 'Featured category', 'blogbaster' ), 'section' => 'blog_options', 'settings' => 'featured_category', 'type' => 'select', 'choices' => blogbaster_customizer_category_list() ) ) ); $wp_customize->add_setting( 'blog_layout', array( 'default' => 'standard', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_blog_layout', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'blog_layout', array( 'label' => __( 'Layout mode', 'blogbaster' ), 'section' => 'blog_options', 'settings' => 'blog_layout', 'type' => 'select', 'choices' => array('standard' => esc_html__( 'Standard', 'blogbaster' ),'grid' => esc_html__( 'Grid', 'blogbaster' )), 'priority' => '15' ) ) ); $wp_customize->add_setting( 'blog_grid', array( 'default' => '3cols', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_blog_grid', 'capability' => 'edit_theme_options' ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'blog_grid', array( 'label' => __( 'Number of Columns', 'blogbaster' ), 'section' => 'blog_options', 'type' => 'select', 'choices' => array( '2cols' => esc_html__( '2 columns', 'blogbaster' ), '3cols' => esc_html__( '3 columns', 'blogbaster' ) ), 'priority' => '15' ) ) ); /** * * Single Post Section * */ $wp_customize->add_section( 'single_options', array( 'title' => __( 'Single Post & Page', 'blogbaster' ), 'capability' => 'edit_theme_options', 'priority' => 170, ) ); /* Single Post */ // Toggle Switch Show Date $wp_customize->add_setting( 'hide_single_posted_on', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'hide_single_posted_on', array( 'label' => __( 'Hide Date', 'blogbaster' ), 'section' => 'single_options' ) ) ); // Toggle Switch Show Author $wp_customize->add_setting( 'hide_single_posted_by', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'hide_single_posted_by', array( 'label' => __( 'Hide Author', 'blogbaster' ), 'section' => 'single_options' ) ) ); // Toggle Switch Category meta $wp_customize->add_setting( 'hide_single_posted_in', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'hide_single_posted_in', array( 'label' => __( 'Hide categories', 'blogbaster' ), 'section' => 'single_options' ) ) ); // Toggle Switch Category meta $wp_customize->add_setting( 'hide_single_tagged', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'hide_single_tagged', array( 'label' => __( 'Hide tags', 'blogbaster' ), 'section' => 'single_options' ) ) ); /* Single Post And Page */ // Toggle Switch Content Boxed $wp_customize->add_setting( 'content_boxed', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'blogbaster_switch_sanitization' ) ); $wp_customize->add_control( new Blogbaster_Toggle_Switch_Custom_control( $wp_customize, 'content_boxed', array( 'label' => __( 'Content Boxed', 'blogbaster' ), 'description' => esc_html__( 'When you switch it on, the content is placed in a container with a colored background.', 'blogbaster' ), 'section' => 'single_options' ) ) ); // Border style of content boxed $wp_customize->add_setting( 'single_card_style', array( 'default' => 'border', 'type' => 'theme_mod', 'sanitize_callback' => 'blogbaster_sanitize_card_style', 'capability' => 'edit_theme_options', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'single_card_style', array( 'label' => __( 'Border Style', 'blogbaster' ), 'section' => 'single_options', 'settings' => 'single_card_style', 'type' => 'select', 'choices' => array('border' => esc_html__( 'Border', 'blogbaster' ),'noborder' => esc_html__( 'No border', 'blogbaster' ),'shadow' => esc_html__( 'Shadow', 'blogbaster' )), 'active_callback' => 'blogbaster_set_content_boxed' ) ) ); // Color options $theme_colors = array(); $theme_colors[] = array( 'slug'=>'single_box_bgcolor', 'default' => '#fff', 'label' => esc_html__('Background Color', 'blogbaster'), 'transport' => 'postMessage' ); $theme_colors[] = array( 'slug'=>'single_box_border_color', 'default' => '#eff1f3', 'label' => esc_html__('Border color', 'blogbaster'), 'transport' => 'refresh' ); foreach( $theme_colors as $color ) { $wp_customize->add_setting( $color['slug'], array( 'default' => $color['default'], 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => $color['transport'] ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 'label' => $color['label'], 'description' => $color['description'], 'section' => 'single_options', 'settings' => $color['slug'], 'active_callback' => 'blogbaster_set_content_boxed' ) ) ); } // END Colors Options // END Options } add_action( 'customize_register', 'blogbaster_customize_register' ); /** * Render the site title for the selective refresh partial. * * @return void */ function blogbaster_customize_partial_blogname() { bloginfo( 'name' ); } /** * Sorter sanitization * * @return input Sanitized input or default */ function blogbaster_sanitize_sorter( $input, $setting ) { // Get list of choices from the control associated with the setting. $choices = $setting->manager->get_control( $setting->id )->choices; $input_keys = $input; foreach ( $input_keys as $key => $value ) { if ( ! array_key_exists( $value, $choices ) ) { unset( $input[ $key ] ); } } // If the input is a valid key, return it; // otherwise, return the default. return ( is_array( $input ) ? $input : $setting->default ); } /** * Sanitize the menu bar layout options. * * @param string $input Menu bar layout. */ function blogbaster_sanitize_menubar_mode( $input ) { $valid = array( 'standard' => __( 'Standard', 'blogbaster' ), 'alt' => __( 'Alternative', 'blogbaster' ), ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /** * Sanitize the sidebar position options. * * @param string $input Sidebar position options. */ function blogbaster_sanitize_sidebar_position( $input ) { $valid = array( 'right' => __( 'Right sidebar', 'blogbaster' ), 'left' => __( 'Left sidebar', 'blogbaster' ), 'none' => __( 'No sidebar', 'blogbaster' ), ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /** * Sanitize the single header display options. * * @param string $input Sidebar position options. */ function blogbaster_sanitize_header_display( $input ) { $valid = array( 'standard' => __( 'Standard', 'blogbaster' ), 'alt' => __( 'Alternative', 'blogbaster' ) ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /** * Sanitize the navigation mode options. * * @param string $input navigation mode options. */ function blogbaster_sanitize_blog_pagination_mode( $input ) { $valid = array( 'standard' => __( 'Standard', 'blogbaster' ), 'numeric' => __( 'Numeric', 'blogbaster' ) ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /* * Sanitize the Post Preview Card Style options. * * @param string $input */ function blogbaster_sanitize_card_style( $input ) { $valid = array( 'border' => esc_html__( 'Border', 'blogbaster' ), 'noborder' => esc_html__( 'No border', 'blogbaster' ), 'shadow' => esc_html__( 'Shadow', 'blogbaster' ) ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /* * Sanitize the blog layout options. * * @param string $input blog layout options. */ function blogbaster_sanitize_blog_layout( $input ) { $valid = array( 'grid' => esc_html__( 'Grid', 'blogbaster' ), 'standard' => esc_html__( 'Standard', 'blogbaster' ) ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /* * Sanitize the post grid options. * * @param string $input blog layout options. */ function blogbaster_sanitize_blog_grid( $input ) { $valid = array( '2cols' => esc_html__( '2 columns', 'blogbaster' ), '3cols' => esc_html__( '3 columns', 'blogbaster' ) ); if ( array_key_exists( $input, $valid ) ) { return $input; } return ''; } /** * Checkbox sanitization callback example. * * Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked` * as a boolean value, either TRUE or FALSE. * * @param bool $checked Whether the checkbox is checked. * @return bool Whether the checkbox is checked. */ function blogbaster_sanitize_checkbox( $checked ) { // Boolean check. return ( ( isset( $checked ) && true === $checked ) ? true : false ); } /** * Switch sanitization * * @param string Switch value * @return integer Sanitized value */ if ( ! function_exists( 'blogbaster_switch_sanitization' ) ) { function blogbaster_switch_sanitization( $input ) { if ( true === $input ) { return 1; } else { return 0; } } } /** * Helper function * that only allow values between a certain minimum & maxmium range * * @param number Input to be sanitized * @return number Sanitized input */ function blogbaster_in_range( $input, $min, $max ){ if ( $input < $min ) { $input = $min; } if ( $input > $max ) { $input = $max; } return $input; } /** * Slider sanitization * * @param string Slider value to be sanitized * @return string Sanitized input */ if ( ! function_exists( 'blogbaster_range_sanitization' ) ) { function blogbaster_range_sanitization( $input, $setting ) { $attrs = $setting->manager->get_control( $setting->id )->input_attrs; $min = ( isset( $attrs['min'] ) ? $attrs['min'] : $input ); $max = ( isset( $attrs['max'] ) ? $attrs['max'] : $input ); $step = ( isset( $attrs['step'] ) ? $attrs['step'] : 1 ); $number = floor( $input / $attrs['step'] ) * $attrs['step']; return blogbaster_in_range( $number, $min, $max ); } } /** * * Helper function for Contextual Control * Whether a latest posts is set to a front displays * https://developer.wordpress.org/reference/classes/wp_customize_control/active_callback/ */ function blogbaster_set_blog_homepage(){ if( 'posts' == get_option('show_on_front') ){ return true; } } /** * * Helper function for Contextual Control * Check whether overlay mode is set for the page headers * https://developer.wordpress.org/reference/classes/wp_customize_control/active_callback/ * */ function blogbaster_is_overlay_header(){ if( get_theme_mod('single_header_display') == 'alt' ){ return true; } else { return false; } } /** * * Helper function for Contextual Control * checks whether a single post is contained in a box * https://developer.wordpress.org/reference/classes/wp_customize_control/active_callback/ * */ function blogbaster_set_content_boxed(){ if( get_theme_mod('content_boxed') == 1 ){ return true; } else { return false; } } /** * Helper function * Category List. */ function blogbaster_customizer_category_list( $args = array() ) { $args = wp_parse_args( $args, array( 'hide_empty' => 1 ) ); $cats = get_categories( $args ); $output = array(); $output[''] = esc_html__( '— All —', 'blogbaster' ); foreach( $cats as $cat ) { $output[$cat->term_id] = sprintf('%s (%s)', $cat->name, $cat->count ); } return $output; } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function blogbaster_customize_preview_js() { wp_enqueue_script( 'blogbaster-customizer', get_template_directory_uri() . '/inc/customizer/assets/js/customizer.js', array( 'customize-preview' ), rand(), true ); } add_action( 'customize_preview_init', 'blogbaster_customize_preview_js' ); /** * Live contextual controls for better user experience. */ function blogbaster_customizer_contextual_control() { wp_enqueue_script( 'blogbaster-customizer-contextual', get_template_directory_uri() . '/inc/customizer/assets/js/contextual.js?v=' . rand(), array( 'customize-controls' ), false ); } add_action( 'customize_controls_enqueue_scripts', 'blogbaster_customizer_contextual_control' ); /** * This will generate a line of CSS for use in header output. If the setting * ($mod_name) has no defined value, the CSS will not be output. * * @link https://codex.wordpress.org/Theme_Customization_API#Sample_Theme_Customization_Class * * @uses get_theme_mod() * @param string $selector CSS selector * @param string $style The name of the CSS *property* to modify * @param string $mod_name The name of the 'theme_mod' option to fetch * @param string $prefix Optional. Anything that needs to be output before the CSS property * @param string $postfix Optional. Anything that needs to be output after the CSS property * @param bool $echo Optional. Whether to print directly to the page (default: true). * @return string Returns a single line of CSS with selectors and a property. */ function blogbaster_generate_css( $selector, $style, $mod_name, $prefix='', $postfix='', $echo=true ) { $return = ''; $mod = esc_html( get_theme_mod( $mod_name ) ); if ( ! empty( $mod ) ) { $return = sprintf('%s { %s:%s; }', $selector, $style, $prefix.$mod.$postfix ); if ( $echo ) { echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } return $return; } /** * Output generated a line of CSS from customizer values in header output. * * @link https://codex.wordpress.org/Theme_Customization_API#Sample_Theme_Customization_Class * * Used by hook: 'wp_head' * * @see add_action('wp_head',$func) */ function blogbaster_customizer_css() { ?>