get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; $wp_customize->get_section( 'background_image' )->panel = 'arouse_styling'; $wp_customize->get_section( 'colors' )->panel = 'arouse_styling'; // Logo image $wp_customize->add_setting( 'site_logo', array( 'sanitize_callback' => 'arouse_sanitize_image' ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'site_logo', array( 'label' => __( 'Site Logo', 'arouse' ), 'section' => 'title_tagline', 'settings' => 'site_logo', 'description' => __( 'Upload a logo for your website. Recommended height for your logo is 135px.', 'arouse' ), ) ) ); // Logo, title and description chooser $wp_customize->add_setting( 'site_title_option', array ( 'default' => 'text-only', 'sanitize_callback' => 'arouse_sanitize_select', 'transport' => 'refresh' ) ); $wp_customize->add_control( 'site_title_option', array( 'label' => __( 'Display site title / logo.', 'arouse' ), 'section' => 'title_tagline', 'type' => 'radio', 'description' => __( 'Choose your preferred option.', 'arouse' ), 'choices' => array ( 'text-only' => __( 'Display site title and description only.', 'arouse' ), 'logo-only' => __( 'Display site logo image only.', 'arouse' ), 'text-logo' => __( 'Display both site title and logo image.', 'arouse' ), 'display-none' => __( 'Display none', 'arouse' ) ) ) ); /** * Slider Settings section. */ $wp_customize->add_section( 'arouse_slider', array( 'title' => __( 'Slider', 'arouse' ), 'description' => __( 'Use this section to setup the homepage slider.', 'arouse' ), 'priority' => 30, ) ); // Display slider? $wp_customize->add_setting( 'display_slider', array( 'default' => true, 'sanitize_callback' => 'arouse_sanitize_checkbox' ) ); $wp_customize->add_control( 'display_slider', array( 'settings' => 'display_slider', 'section' => 'arouse_slider', 'type' => 'checkbox', 'label' => __( 'Display slider on homepage ?', 'arouse' ) ) ); $wp_customize->add_setting( 'slider_category', array( 'default' => '', 'sanitize_callback' => 'arouse_sanitize_category_dropdown' ) ); $wp_customize->add_control( new WP_Customize_Category_Control( $wp_customize, 'slider_category', array( 'label' => __( 'Select the category for slider.', 'arouse' ), 'description' => __( 'Featured images of the posts from selected category will be displayed in the slider', 'arouse' ), 'section' => 'arouse_slider', 'settings' => 'slider_category', ) ) ); /** * Home Settings section. */ $wp_customize->add_panel( 'arouse_home_settings', array( 'title' => __( 'Front Page Settings', 'arouse' ), 'description' => __( 'Use this panel to set your home page settings', 'arouse' ), 'priority' => 31, ) ); $wp_customize->add_section( 'arouse_featured_section', array( 'title' => __( 'Featured Pages', 'arouse' ), 'description' => __( 'Use this section to setup the featured pages that are just below the slider.', 'arouse' ), 'panel' => 'arouse_home_settings' ) ); $wp_customize->add_setting( 'display_featured_section', array( 'default' => true, 'sanitize_callback' => 'arouse_sanitize_checkbox' ) ); $wp_customize->add_control( 'display_featured_section', array( 'section' => 'arouse_featured_section', 'type' => 'checkbox', 'label' => __( 'Display featured pages section?', 'arouse' ) ) ); $wp_customize->add_setting( 'display_page_titles', array( 'default' => true, 'sanitize_callback' => 'arouse_sanitize_checkbox' ) ); $wp_customize->add_control( 'display_page_titles', array( 'section' => 'arouse_featured_section', 'type' => 'checkbox', 'label' => __( 'Display page titles?', 'arouse' ) ) ); for( $i = 1; $i <= 3; $i++ ) { $wp_customize->add_setting( 'featured_article_' . $i, array( 'default' => '', 'sanitize_callback' => 'absint' ) ); $wp_customize->add_control( 'featured_article_' . $i, array( 'label' => sprintf( __( 'Select page %d.', 'arouse' ), $i ), 'section' => 'arouse_featured_section', 'type' => 'dropdown-pages' ) ); } /* Theme Options */ $wp_customize->add_section( 'arouse_theme_options', array( 'title' => __( 'Theme Options', 'arouse' ), 'priority' => 32, ) ); // Blog listing layout. $wp_customize->add_setting( 'archive_listing_layout', array ( 'default' => 'grid', 'sanitize_callback' => 'arouse_sanitize_select', 'transport' => 'refresh' ) ); $wp_customize->add_control( 'archive_listing_layout', array( 'label' => __( 'Blog posts listing layout', 'arouse' ), 'section' => 'arouse_theme_options', 'type' => 'radio', 'description' => __( 'Select the main layout for blog posts listing.', 'arouse' ), 'choices' => array ( 'grid' => __( 'Grid Layout.', 'arouse' ), 'list' => __( 'List Layout.', 'arouse' ), ) ) ); $wp_customize->add_setting( 'show_article_featured_image', array( 'default' => true, 'sanitize_callback' => 'arouse_sanitize_checkbox' ) ); $wp_customize->add_control( 'show_article_featured_image', array( 'settings' => 'show_article_featured_image', 'section' => 'arouse_theme_options', 'type' => 'checkbox', 'label' => __( 'Display featured image on single post article ?', 'arouse' ) ) ); /** * Styling Options. */ $wp_customize->add_panel( 'arouse_styling', array( 'title' => __( 'Site Styling', 'arouse' ), 'description' => __( 'Use this section to setup the homepage slider and featured posts.', 'arouse' ), 'priority' => 33, ) ); /** * Custom CSS section */ $wp_customize->add_section( 'arouse_custom_css', array( 'title' => __( 'Custom CSS', 'arouse' ), 'panel' => 'arouse_styling', 'priority' => 50 ) ); $wp_customize->add_setting( 'custom_css', array( 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'arouse_sanitize_css' ) ); $wp_customize->add_control( 'custom_css', array( 'settings' => 'custom_css', 'section' => 'arouse_custom_css', 'type' => 'textarea', 'label' => __( 'Custom CSS', 'arouse' ), 'description' => __( 'Define custom CSS be used for your site. Do not enclose in script tags.', 'arouse' ), ) ); } add_action( 'customize_register', 'arouse_customize_register' ); /** * Image sanitization. * * @see wp_check_filetype() https://developer.wordpress.org/reference/functions/wp_check_filetype/ * * @param string $image Image filename. * @param WP_Customize_Setting $setting Setting instance. * @return string The image filename if the extension is allowed; otherwise, the setting default. */ function arouse_sanitize_image( $image, $setting ) { /* * Array of valid image file types. * * The array includes image mime types that are included in wp_get_mime_types() */ $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff', 'ico' => 'image/x-icon' ); // Return an array with file extension and mime_type. $file = wp_check_filetype( $image, $mimes ); // If $image has a valid mime_type, return it; otherwise, return the default. return ( $file['ext'] ? $image : $setting->default ); } /** * Checkbox sanitization. * * 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 arouse_sanitize_checkbox( $checked ) { // Boolean check. return ( ( isset( $checked ) && true == $checked ) ? true : false ); } /** * HTML sanitization * * @see wp_filter_post_kses() https://developer.wordpress.org/reference/functions/wp_filter_post_kses/ * * @param string $html HTML to sanitize. * @return string Sanitized HTML. */ function arouse_sanitize_html( $html ) { return wp_filter_post_kses( $html ); } /** * CSS sanitization. * * @see wp_strip_all_tags() https://developer.wordpress.org/reference/functions/wp_strip_all_tags/ * * @param string $css CSS to sanitize. * @return string Sanitized CSS. */ function arouse_sanitize_css( $css ) { return wp_strip_all_tags( $css ); } /** * URL sanitization. * * @see esc_url_raw() https://developer.wordpress.org/reference/functions/esc_url_raw/ * * @param string $url URL to sanitize. * @return string Sanitized URL. */ function arouse_sanitize_url( $url ) { return esc_url_raw( $url ); } /** * Category dropdown sanitization. * * @param int $catid to sanitize. * @return int $cat_id. */ function arouse_sanitize_category_dropdown( $catid ) { // Ensure $catid is an absolute integer. return $cat_id = absint( $catid ); } /** * Select sanitization. * * - Sanitization: select * - Control: select, radio * * @param string $input Slug to sanitize. * @param WP_Customize_Setting $setting Setting instance. * @return string Sanitized slug if it is a valid choice; otherwise, the setting default. */ function arouse_sanitize_select( $input, $setting ) { // Ensure input is a slug. $input = sanitize_key( $input ); // Get list of choices from the control associated with the setting. $choices = $setting->manager->get_control( $setting->id )->choices; // If the input is a valid key, return it; otherwise, return the default. return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function arouse_customize_preview_js() { wp_enqueue_script( 'arouse_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true ); } add_action( 'customize_preview_init', 'arouse_customize_preview_js' );