get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; // General Settings $wp_customize->add_section( 'general_settings', array( 'title' => __( 'General Settings', 'realistic' ), 'priority' => 10, ) ); //Add "Switcher" support to the theme customizer class Realistic_Customizer_Switcher_Control extends WP_Customize_Control { public $type = 'switcher'; public function render_content() { ?> add_setting( 'footer_left', array( 'default' => 'Proudly powered by WordPress', 'sanitize_callback' => 'realistic_sanitize_text', ) ); $wp_customize->add_control( 'footer_left', array( 'label' => __( 'Copyright Text', 'realistic' ), 'section' => 'general_settings', 'settings' => 'footer_left', 'type' => 'textarea', ) ); // Site Title & Tagline //logo upload $wp_customize->add_setting( 'logo_image' , array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', )); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'logo_image', array( 'label' => __( 'Logo Image', 'realistic' ), 'section' => 'title_tagline', 'settings' => 'logo_image', ) ) ); // Archives Settings $wp_customize->add_section( 'archives_settings', array( 'title' => __( 'Archives Settings', 'realistic' ), 'priority' => 20 ) ); // Add Radio-Image control support to the theme customizer class Realistic_Customizer_Radio_Image_Control extends WP_Customize_Control { public $type = 'radio-image'; public function enqueue() { wp_enqueue_script( 'jquery-ui-button' ); } // Markup for the field's title public function title() { echo ''; $this->label(); $this->description(); echo ''; } // The markup for the label. public function label() { // The label has already been sanitized in the Fields class, no need to re-sanitize it. echo $this->label; } // Markup for the field's description public function description() { if ( ! empty( $this->description ) ) { // The description has already been sanitized in the Fields class, no need to re-sanitize it. echo '' . $this->description . ''; } } public function render_content() { if ( empty( $this->choices ) ) { return; } $name = '_customize-radio-' . $this->id; ?> title(); ?>
choices as $value => $label ) : ?> link(); checked( $this->value(), $value ); ?>>
add_setting( 'archives_post_meta' , array( 'default' => '1', 'sanitize_callback' => 'realistic_sanitize_checkbox', ) ); $wp_customize->add_control( new Realistic_Customizer_Switcher_Control( $wp_customize, 'archives_post_meta', array( 'label' => __( 'Archives Meta', 'realistic' ), 'section' => 'archives_settings', ) ) ); //Add input[type=number] support to the theme customizer class Realistic_Customizer_Number_Control extends WP_Customize_Control { public $type = 'number'; public function render_content() { ?> add_setting( 'excerpt_length', array( 'default' => '40', 'sanitize_callback' => 'realistic_sanitize_integer', ) ); $wp_customize->add_control( new Realistic_Customizer_Number_Control( $wp_customize, 'excerpt_length', array( 'label' => __( 'Excerpt Length', 'realistic' ), 'section' => 'archives_settings', 'settings' => 'excerpt_length', ) ) ); // Article Settings $wp_customize->add_section( 'article_settings', array( 'title' => __( 'Article Settings', 'realistic' ), 'priority' => 30 ) ); //Post Meta $wp_customize->add_setting( 'post_meta' , array( 'default' => '1', 'sanitize_callback' => 'realistic_sanitize_checkbox', ) ); $wp_customize->add_control( new Realistic_Customizer_Switcher_Control( $wp_customize, 'post_meta', array( 'label' => __( 'Post Meta', 'realistic' ), 'section' => 'article_settings', ) ) ); //Related Posts $wp_customize->add_setting( 'related_posts' , array( 'default' => '1', 'sanitize_callback' => 'realistic_sanitize_checkbox', ) ); $wp_customize->add_control( new Realistic_Customizer_Switcher_Control( $wp_customize, 'related_posts', array( 'label' => __( 'Related Posts', 'realistic' ), 'section' => 'article_settings', ) ) ); //Related Posts Number $wp_customize->add_setting( 'related_posts_number', array( 'default' => '4', 'sanitize_callback' => 'realistic_sanitize_integer', ) ); $wp_customize->add_control( 'related_posts_number', array( 'label' => __( 'Related Posts Number', 'realistic' ), 'section' => 'article_settings', 'settings' => 'related_posts_number', 'type' => 'number' ) ); //Related Posts Query type $wp_customize->add_setting( 'related_posts_query', array( 'default' => 'tags', 'sanitize_callback' => 'realistic_sanitize_related_posts_query', ) ); $wp_customize->add_control( 'related_posts_query', array( 'type' => 'radio', 'label' => __( 'Related Posts Query', 'realistic' ), 'section' => 'article_settings', 'choices' => array( 'tags' => __( 'Tags', 'realistic' ), 'categories' => __( 'Categories', 'realistic' ), ), ) ); //Next/Prev Article $wp_customize->add_setting( 'next_prev_post' , array( 'default' => '1', 'sanitize_callback' => 'realistic_sanitize_checkbox', ) ); $wp_customize->add_control( new Realistic_Customizer_Switcher_Control( $wp_customize, 'next_prev_post', array( 'label' => __( 'Next/Prev Article', 'realistic' ), 'section' => 'article_settings', ) ) ); //Post Author Box $wp_customize->add_setting( 'author_box' , array( 'default' => '1', 'sanitize_callback' => 'realistic_sanitize_checkbox', ) ); $wp_customize->add_control( new Realistic_Customizer_Switcher_Control( $wp_customize, 'author_box', array( 'label' => __( 'Post Author Box', 'realistic' ), 'section' => 'article_settings', ) ) ); // Design & Layout $wp_customize->add_section( 'design_layout', array( 'title' => __( 'Design & Layout', 'realistic' ), 'priority' => 40 ) ); // Sidebar Settings $wp_customize->add_setting( 'sidebar_settings', array( 'default' => 'right_sidebar', 'sanitize_callback' => 'realistic_sanitize_sidebar_settings', ) ); $wp_customize->add_control( new Realistic_Customizer_Radio_Image_Control( $wp_customize, 'sidebar_settings', array( 'label' => __( 'Sidebar Settings', 'realistic' ), 'section' => 'design_layout', 'choices' => array( 'right_sidebar' => get_template_directory_uri() .'/images/customizer/right.jpg', 'left_sidebar' => get_template_directory_uri() .'/images/customizer/left.jpg', ), ) ) ); // color scheme $wp_customize->add_setting( 'theme_color', array( 'default' => 'indigo-pink', 'sanitize_callback' => 'realistic_sanitize_color_scheme', ) ); $wp_customize->add_control( new Realistic_Customizer_Radio_Image_Control( $wp_customize, 'theme_color', array( 'label' => __( 'Color Scheme', 'realistic' ), 'section' => 'design_layout', 'choices' => array( 'indigo-pink' => get_template_directory_uri() .'/images/customizer/indigo-pink.png', 'blue-indigo' => get_template_directory_uri() .'/images/customizer/blue-indigo.png', 'bluegrey-teal' => get_template_directory_uri() .'/images/customizer/bluegrey-teal.png', 'red-deeporange' => get_template_directory_uri() .'/images/customizer/red-deeporange.png', 'purple-blue' => get_template_directory_uri() .'/images/customizer/purple-blue.png', 'green-lightgreen' => get_template_directory_uri() .'/images/customizer/green-lightgreen.png', ), ) ) ); // Background Settings $wp_customize->add_setting( 'background_settings', array( 'default' => 'color', 'sanitize_callback' => 'realistic_sanitize_background_settings', ) ); $wp_customize->add_control( 'background_settings', array( 'type' => 'radio', 'label' => __( 'Background settings', 'realistic' ), 'section' => 'design_layout', 'choices' => array( 'color' => __( 'Color', 'realistic' ), 'pattern' => __( 'Pattern', 'realistic' ), 'custom_image' => __( 'Custom image', 'realistic' ), ), ) ); // Background color $wp_customize->add_setting( 'bg_color', array( 'default' => '#f7f7f7', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'bg_color', array( 'label' => __( 'Background color', 'realistic' ), 'section' => 'design_layout', 'settings' => 'bg_color', ) ) ); // Background pattern $wp_customize->add_setting( 'background_pattern', array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', ) ); $wp_customize->add_control( new Realistic_Customizer_Radio_Image_Control( $wp_customize, 'background_pattern', array( 'label' => __( 'Background pattern', 'realistic' ), 'section' => 'design_layout', 'choices' => array( get_template_directory_uri() .'/images/patterns/21.gif' => get_template_directory_uri() .'/images/patterns/21.gif', get_template_directory_uri() .'/images/patterns/22.gif' => get_template_directory_uri() .'/images/patterns/22.gif', get_template_directory_uri() .'/images/patterns/23.gif' => get_template_directory_uri() .'/images/patterns/23.gif', get_template_directory_uri() .'/images/patterns/24.gif' => get_template_directory_uri() .'/images/patterns/24.gif', get_template_directory_uri() .'/images/patterns/25.gif' => get_template_directory_uri() .'/images/patterns/25.gif', get_template_directory_uri() .'/images/patterns/26.gif' => get_template_directory_uri() .'/images/patterns/26.gif', get_template_directory_uri() .'/images/patterns/27.gif' => get_template_directory_uri() .'/images/patterns/27.gif', get_template_directory_uri() .'/images/patterns/28.gif' => get_template_directory_uri() .'/images/patterns/28.gif', get_template_directory_uri() .'/images/patterns/29.gif' => get_template_directory_uri() .'/images/patterns/29.gif', get_template_directory_uri() .'/images/patterns/30.gif' => get_template_directory_uri() .'/images/patterns/30.gif', get_template_directory_uri() .'/images/patterns/31.gif' => get_template_directory_uri() .'/images/patterns/31.gif', get_template_directory_uri() .'/images/patterns/32.gif' => get_template_directory_uri() .'/images/patterns/32.gif', get_template_directory_uri() .'/images/patterns/33.gif' => get_template_directory_uri() .'/images/patterns/33.gif', get_template_directory_uri() .'/images/patterns/34.gif' => get_template_directory_uri() .'/images/patterns/34.gif', get_template_directory_uri() .'/images/patterns/35.gif' => get_template_directory_uri() .'/images/patterns/35.gif', get_template_directory_uri() .'/images/patterns/36.gif' => get_template_directory_uri() .'/images/patterns/36.gif', get_template_directory_uri() .'/images/patterns/37.gif' => get_template_directory_uri() .'/images/patterns/37.gif', get_template_directory_uri() .'/images/patterns/38.gif' => get_template_directory_uri() .'/images/patterns/38.gif', get_template_directory_uri() .'/images/patterns/39.gif' => get_template_directory_uri() .'/images/patterns/39.gif', get_template_directory_uri() .'/images/patterns/40.gif' => get_template_directory_uri() .'/images/patterns/40.gif', get_template_directory_uri() .'/images/patterns/1.jpg' => get_template_directory_uri() .'/images/patterns/1.jpg', get_template_directory_uri() .'/images/patterns/2.jpg' => get_template_directory_uri() .'/images/patterns/2.jpg', get_template_directory_uri() .'/images/patterns/3.jpg' => get_template_directory_uri() .'/images/patterns/3.jpg', get_template_directory_uri() .'/images/patterns/4.jpg' => get_template_directory_uri() .'/images/patterns/4.jpg', get_template_directory_uri() .'/images/patterns/5.jpg' => get_template_directory_uri() .'/images/patterns/5.jpg', get_template_directory_uri() .'/images/patterns/6.jpg' => get_template_directory_uri() .'/images/patterns/6.jpg', get_template_directory_uri() .'/images/patterns/7.jpg' => get_template_directory_uri() .'/images/patterns/7.jpg', get_template_directory_uri() .'/images/patterns/8.jpg' => get_template_directory_uri() .'/images/patterns/8.jpg', get_template_directory_uri() .'/images/patterns/9.jpg' => get_template_directory_uri() .'/images/patterns/9.jpg', get_template_directory_uri() .'/images/patterns/10.jpg' => get_template_directory_uri() .'/images/patterns/10.jpg', get_template_directory_uri() .'/images/patterns/11.jpg' => get_template_directory_uri() .'/images/patterns/11.jpg', get_template_directory_uri() .'/images/patterns/12.jpg' => get_template_directory_uri() .'/images/patterns/12.jpg', get_template_directory_uri() .'/images/patterns/13.jpg' => get_template_directory_uri() .'/images/patterns/13.jpg', get_template_directory_uri() .'/images/patterns/14.jpg' => get_template_directory_uri() .'/images/patterns/14.jpg', get_template_directory_uri() .'/images/patterns/15.jpg' => get_template_directory_uri() .'/images/patterns/15.jpg', get_template_directory_uri() .'/images/patterns/16.jpg' => get_template_directory_uri() .'/images/patterns/16.jpg', get_template_directory_uri() .'/images/patterns/17.jpg' => get_template_directory_uri() .'/images/patterns/17.jpg', get_template_directory_uri() .'/images/patterns/18.jpg' => get_template_directory_uri() .'/images/patterns/18.jpg', get_template_directory_uri() .'/images/patterns/19.jpg' => get_template_directory_uri() .'/images/patterns/19.jpg', get_template_directory_uri() .'/images/patterns/20.jpg' => get_template_directory_uri() .'/images/patterns/20.jpg', ), ) ) ); //Background image uploader $wp_customize->add_setting( 'background_image' , array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', )); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'background_image', array( 'label' => __( 'Custom background image', 'realistic' ), 'section' => 'design_layout', 'settings' => 'background_image', ) ) ); //Background image repeat $wp_customize->add_setting( 'background_image_repeat' , array( 'default' => 'repeat', 'sanitize_callback' => 'realistic_sanitize_background_image_repeat', )); $wp_customize->add_control( 'background_image_repeat', array( 'type' => 'select', 'label' => __( 'Repeat', 'realistic' ), 'section' => 'design_layout', 'choices' => array( 'repeat' => __( 'Repeat', 'realistic' ), 'repeat-x' => __( 'Repeat-x', 'realistic' ), 'repeat-y' => __( 'Repeat-y', 'realistic' ), 'no-repeat' => __( 'No-repeat', 'realistic' ), ), ) ); //Background image attachment $wp_customize->add_setting( 'background_image_attachment' , array( 'default' => 'scroll', 'sanitize_callback' => 'realistic_sanitize_background_image_attachment', )); $wp_customize->add_control( 'background_image_attachment', array( 'type' => 'select', 'label' => __( 'Attachment', 'realistic' ), 'section' => 'design_layout', 'choices' => array( 'scroll' => __( 'Scroll', 'realistic' ), 'fixed' => __( 'Fixed', 'realistic' ), ), ) ); //Background image position $wp_customize->add_setting( 'background_image_position' , array( 'default' => 'left top', 'sanitize_callback' => 'realistic_sanitize_background_image_position', )); $wp_customize->add_control( 'background_image_position', array( 'type' => 'select', 'label' => __( 'Position', 'realistic' ), 'section' => 'design_layout', 'choices' => array( 'left top' => __( 'Left top', 'realistic' ), 'left center' => __( 'Left center', 'realistic' ), 'left bottom' => __( 'Left bottom', 'realistic' ), 'right top' => __( 'Right top', 'realistic' ), 'right center' => __( 'Right center', 'realistic' ), 'right bottom' => __( 'Right bottom', 'realistic' ), 'center top' => __( 'Center top', 'realistic' ), 'center center' => __( 'Center center', 'realistic' ), 'center bottom' => __( 'Center bottom', 'realistic' ), ), ) ); // Custom CSS $wp_customize->add_setting( 'custom_css', array( 'default' => '', 'sanitize_callback' => 'realistic_sanitize_css', ) ); $wp_customize->add_control( 'custom_css', array( 'label' => __( 'Custom CSS', 'realistic' ), 'section' => 'design_layout', 'settings' => 'custom_css', 'type' => 'textarea', ) ); } add_action( 'customize_register', 'realistic_options_theme_customizer_register' ); /*-----------------------------------------------------------------------------------*/ /* CUSTOM DATA SANITIZATION /*-----------------------------------------------------------------------------------*/ // Sanitize text function realistic_sanitize_text( $input ) { return strip_tags( $input,'' ); } // Sanitize checkbox function realistic_sanitize_checkbox( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } } // Sanitize integer function realistic_sanitize_integer( $input ) { return absint( $input ); } // Sanitize sidebar settings function realistic_sanitize_sidebar_settings( $input ) { $valid = array( 'right_sidebar' => get_template_directory_uri() .'/images/customizer/right.jpg', 'left_sidebar' => get_template_directory_uri() .'/images/customizer/left.jpg', ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize color scheme function realistic_sanitize_color_scheme( $input ) { $valid = array( 'indigo-pink' => get_template_directory_uri() .'/images/customizer/indigo-pink.png', 'blue-indigo' => get_template_directory_uri() .'/images/customizer/blue-indigo.png', 'bluegrey-teal' => get_template_directory_uri() .'/images/customizer/bluegrey-teal.png', 'red-deeporange' => get_template_directory_uri() .'/images/customizer/red-deeporange.png', 'purple-blue' => get_template_directory_uri() .'/images/customizer/purple-blue.png', 'green-lightgreen' => get_template_directory_uri() .'/images/customizer/green-lightgreen.png', ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize background settings function realistic_sanitize_background_settings( $input ) { $valid = array( 'color' => 'Color', 'pattern' => 'Pattern', 'custom_image' => 'Custom image', ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize background image repeat function realistic_sanitize_background_image_repeat( $input ) { $valid = array( 'repeat' => __( 'Repeat', 'realistic' ), 'repeat-x' => __( 'Repeat-x', 'realistic' ), 'repeat-y' => __( 'Repeat-y', 'realistic' ), 'no-repeat' => __( 'No-repeat', 'realistic' ), ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize background image attachment function realistic_sanitize_background_image_attachment( $input ) { $valid = array( 'scroll' => __( 'Scroll', 'realistic' ), 'fixed' => __( 'Fixed', 'realistic' ), ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize background image position function realistic_sanitize_background_image_position( $input ) { $valid = array( 'left top' => __( 'Left top', 'realistic' ), 'left center' => __( 'Left center', 'realistic' ), 'left bottom' => __( 'Left bottom', 'realistic' ), 'right top' => __( 'Right top', 'realistic' ), 'right center' => __( 'Right center', 'realistic' ), 'right bottom' => __( 'Right bottom', 'realistic' ), 'center top' => __( 'Center top', 'realistic' ), 'center center' => __( 'Center center', 'realistic' ), 'center bottom' => __( 'Center bottom', 'realistic' ), ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize Related Posts Query function realistic_sanitize_related_posts_query( $input ) { $valid = array( 'tags' => 'Tags', 'categories' => 'Categories', ); if ( array_key_exists( $input, $valid ) ) { return $input; } else { return ''; } } // Sanitize CSS (Taken from Jetpack CSS module) function realistic_sanitize_css( $input ) { $css = preg_replace( '/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $input ); $css = str_replace( '<=', '<=', $css ); $css = wp_kses_split( $css, array(), array() ); $css = str_replace( '>', '>', $css ); $css = strip_tags( $css ); return $css; } /*-----------------------------------------------------------------------------------*/ /* Customizer Styles & Scripts /*-----------------------------------------------------------------------------------*/ // Style settings output. function realistic_add_style_settings() { $sidebar_settings = get_theme_mod( 'sidebar_settings' ); if ( $sidebar_settings && $sidebar_settings == 'left_sidebar' ) { $layout_style = ' .content-area { float: right !important;} '; } else { $layout_style = ''; } $custom_css = get_theme_mod( 'custom_css' ); $background_settings = get_theme_mod( 'background_settings', 'color' ); if ( $background_settings && $background_settings == 'color') { $bg_color = get_theme_mod( 'bg_color', '#f7f7f7' ); $background = ' body { background: ' . $bg_color . ';}'; } elseif ( $background_settings && $background_settings == 'pattern') { $background_pattern = get_theme_mod( 'background_pattern' ); $background = ' body { background: url(' . $background_pattern . ') repeat left bottom;}'; } else { $background_image = get_theme_mod( 'background_image' ); $background_image_repeat = get_theme_mod( 'background_image_repeat' ); $background_image_attachment = get_theme_mod( 'background_image_attachment' ); $background_image_position = get_theme_mod( 'background_image_position' ); if ( $background_image ) { $background = ' body { background: url(' . $background_image . ') '. $background_image_repeat .' '. $background_image_attachment .' '. $background_image_position .';}'; } } ?>