get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; get_template_part('inc/customizer-button/upsell-section'); if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => 'blog_sphere_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'blog_sphere_customize_partial_blogdescription', ) ); } $wp_customize->register_section_type( 'Blog_Sphere_Customize_Upsell_Section' ); // Register section. $wp_customize->add_section( new Blog_Sphere_Customize_Upsell_Section( $wp_customize, 'theme_upsell', array( 'title' => esc_html__( 'Blog Sphere Pro', 'blog-sphere' ), 'pro_text' => esc_html__( 'Upgrade To Pro', 'blog-sphere' ), 'pro_url' => 'https://cawpthemes.com/blog-sphere-premium-wordpress-theme/', 'priority' => 1, ) ) ); } add_action( 'customize_register', 'blog_sphere_customize_register_btn' ); /** * Render the site title for the selective refresh partial. * * @return void */ function blog_sphere_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. * * @return void */ function blog_sphere_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function blog_sphere_customize_preview_js() { wp_enqueue_script( 'blog-sphere-customizer', get_template_directory_uri() . '/inc/customizer-button/customizer.js', array( 'customize-preview' ), '20151215', true ); } add_action( 'customize_preview_init', 'blog_sphere_customize_preview_js' ); /** * Customizer control scripts and styles. * * @since 1.0.0 */ function blog_sphere_customizer_control_scripts() { wp_enqueue_style( 'blog-sphere-customize-controls', get_template_directory_uri() . '/inc/customizer-button/customize-controls.css', '', '1.0.0' ); wp_enqueue_script( 'blog-sphere-customize-controls', get_template_directory_uri() . '/inc/customizer-button/customize-controls.js', array( 'customize-controls' ), '1.0.0', true ); } add_action( 'customize_controls_enqueue_scripts', 'blog_sphere_customizer_control_scripts', 0 ); //-----Code to add the Upgrade to Pro button in the Customizer End---------- //------------------Theme Information-------------------- function blog_sphere_customize_register( $wp_customize ) { // Add a custom setting for the Site Identity color $wp_customize->add_setting( 'blog_sphere_site_identity_color', array( 'default' => '#000', 'sanitize_callback' => 'sanitize_hex_color', ) ); // Add a custom control for the primary color $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'blog_sphere_site_identity_color', array( 'label' => __( 'Site Identity Color', 'blog-sphere' ), 'section' => 'title_tagline', 'settings' => 'blog_sphere_site_identity_color', ) ) ); // Add a custom setting for the Site Identity color $wp_customize->add_setting( 'blog_sphere_site_identity_tagline_color', array( 'default' => '#000', 'sanitize_callback' => 'sanitize_hex_color', ) ); // Add a custom control for the primary color $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'blog_sphere_site_identity_tagline_color', array( 'label' => __( 'Tagline Color', 'blog-sphere' ), 'section' => 'title_tagline', 'settings' => 'blog_sphere_site_identity_tagline_color', ) ) ); //------------------Site Identity Ends--------------------- // Add a custom setting for the primary color $wp_customize->add_setting( 'blog_sphere_primary_color', array( 'default' => '#000', 'sanitize_callback' => 'sanitize_hex_color', ) ); // Add a custom control for the primary color $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'blog_sphere_primary_color', array( 'label' => __( 'Primary Color', 'blog-sphere' ), 'section' => 'colors', 'settings' => 'blog_sphere_primary_color', ) ) ); //---------------Home Front Page--------------- $wp_customize->add_panel( 'blog_sphere_panel', array( 'title' => __( 'Front Page Settings', 'blog-sphere' ), 'priority' => 6, ) ); //--------Single------------------------------------------ $wp_customize->add_section( 'blog_sphere_section_single', array( 'title' => __( 'Single Post', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); //-----------------Enable Option Section One------------- $wp_customize->add_setting('blog_sphere_section_single_enable',array( 'default' => 'Enable', 'sanitize_callback' => 'blog_sphere_sanitize_choices' )); $wp_customize->add_control('blog_sphere_section_single_enable',array( 'type' => 'radio', 'label' => __('Do you want this section', 'blog-sphere'), 'section' => 'blog_sphere_section_single', 'choices' => array( 'Enable' => __('Enable', 'blog-sphere'), 'Disable' => __('Disable', 'blog-sphere') ))); $wp_customize->add_setting('blog_sphere_single_title',array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_control('blog_sphere_single_title',array( 'label' => __('Welcome Title','blog-sphere'), 'section' => 'blog_sphere_section_single', 'setting' => 'blog_sphere_single_title', 'type' => 'text' ) ); // ----------- Posts ------------ $posts = get_posts(array( 'numberposts' => -1, 'post_type' => 'post', 'post_status' => 'publish', )); $post_choices = array(); $i = 0; foreach($posts as $post){ if($i == 0){ $default_post = $post->ID; $i++; } $post_choices[$post->ID] = $post->post_title; } $wp_customize->add_setting('blog_sphere_section_single_post', array( 'default' => $default_post, 'sanitize_callback' => 'absint', // Sanitize as an integer since we're dealing with post IDs )); $wp_customize->add_control('blog_sphere_section_single_post', array( 'type' => 'select', 'choices' => $post_choices, 'label' => __('Select Post to Display', 'blog-sphere'), 'section' => 'blog_sphere_section_single', )); //--------Latest-------------------- $wp_customize->add_section( 'blog_sphere_section_latest', array( 'title' => __( 'Latest Post', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); //-----------------Enable Option Section One------------- $wp_customize->add_setting('blog_sphere_section_latest_enable',array( 'default' => 'Enable', 'sanitize_callback' => 'blog_sphere_sanitize_choices' )); $wp_customize->add_control('blog_sphere_section_latest_enable',array( 'type' => 'radio', 'label' => __('Do you want this section', 'blog-sphere'), 'section' => 'blog_sphere_section_latest', 'choices' => array( 'Enable' => __('Enable', 'blog-sphere'), 'Disable' => __('Disable', 'blog-sphere') ))); $wp_customize->add_setting('blog_sphere_latest_title',array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_control('blog_sphere_latest_title',array( 'label' => __('Welcome Title','blog-sphere'), 'section' => 'blog_sphere_section_latest', 'setting' => 'blog_sphere_latest_title', 'type' => 'text' ) ); //-----------Category------------ $categories = get_categories(); $cats = array(); $i = 0; foreach($categories as $category){ if($i==0){ $default = $category->name; $i++; } $cats[$category->name] = $category->name; } $wp_customize->add_setting('blog_sphere_section_latest_category',array( 'sanitize_callback' => 'sanitize_text_field', )); $wp_customize->add_control('blog_sphere_section_latest_category',array( 'type' => 'select', 'choices' => $cats, 'label' => __('Select Category to Display Post','blog-sphere'), 'section' => 'blog_sphere_section_latest', 'sanitize_callback' => 'sanitize_text_field', )); //--------Section One (Featured Post)------------------------------------------ $wp_customize->add_section( 'blog_sphere_section1', array( 'title' => __( 'Featured Post', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); //-----------------Enable Option Section One------------- $wp_customize->add_setting('blog_sphere_section1_enable',array( 'default' => 'Enable', 'sanitize_callback' => 'blog_sphere_sanitize_choices' )); $wp_customize->add_control('blog_sphere_section1_enable',array( 'type' => 'radio', 'label' => __('Do you want this section', 'blog-sphere'), 'section' => 'blog_sphere_section1', 'choices' => array( 'Enable' => __('Enable', 'blog-sphere'), 'Disable' => __('Disable', 'blog-sphere') ))); //-----------Category------------ $categories = get_categories(); $cats = array(); $i = 0; foreach($categories as $category){ if($i==0){ $default = $category->name; $i++; } $cats[$category->name] = $category->name; } $wp_customize->add_setting('blog_sphere_section1_category',array( 'sanitize_callback' => 'sanitize_text_field', )); $wp_customize->add_control('blog_sphere_section1_category',array( 'type' => 'select', 'choices' => $cats, 'label' => __('Select Category to Display Post','blog-sphere'), 'section' => 'blog_sphere_section1', 'sanitize_callback' => 'sanitize_text_field', )); //------------------------Blog Page Settings-------------------------- $wp_customize->add_section( 'blog_sphere_blogpage_settings', array( 'title' => __( 'Blog Page Settings', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); //--------------Section One Title----------------------- $wp_customize->add_setting('blog_sphere_blogpage_title',array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_control('blog_sphere_blogpage_title',array( 'label' => __('Blog Page Title','blog-sphere'), 'section' => 'blog_sphere_blogpage_settings', 'setting' => 'blog_sphere_blogpage_title', 'type' => 'text' ) ); //-----------Category------------ $categories = get_categories(); $cats = array(); $i = 0; foreach($categories as $category){ if($i==0){ $default = $category->name; $i++; } $cats[$category->name] = $category->name; } $wp_customize->add_setting('blog_sphere_blogpage_category',array( 'sanitize_callback' => 'sanitize_text_field', )); $wp_customize->add_control('blog_sphere_blogpage_category',array( 'type' => 'select', 'choices' => $cats, 'label' => __('Select Category to Display Post on Blog Page','blog-sphere'), 'section' => 'blog_sphere_blogpage_settings', 'sanitize_callback' => 'sanitize_text_field', )); $wp_customize->add_setting('blog_sphereblog_page_category_number_of_posts_setting',array( 'default' => '18', 'sanitize_callback' => 'sanitize_text_field' )); $wp_customize->add_control('blog_sphereblog_page_category_number_of_posts_setting',array( 'label' => __('Number of Posts','blog-sphere'), 'section' => 'blog_sphere_blogpage_settings', 'setting' => 'blog_sphereblog_page_category_number_of_posts_setting', 'type' => 'number' )); //-------------------------Footer Settings-------------- $wp_customize->add_section( 'blog_sphere_footer', array( 'title' => __( 'Footer Settings', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); // Add a custom setting for the footer text $wp_customize->add_setting( 'blog_sphere_footer_text', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', ) ); // Add a custom control for the footer text $wp_customize->add_control( 'blog_sphere_footer_text', array( 'label' => __( 'Footer Text', 'blog-sphere' ), 'section' => 'blog_sphere_footer', 'type' => 'text', ) ); //-------------------404 Page----------- $wp_customize->add_section( 'blog_sphere_404page', array( 'title' => __( '404 Page Settings', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); // Add a custom setting for the footer text $wp_customize->add_setting( 'blog_sphere_404page_title', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', ) ); // Add a custom control for the footer text $wp_customize->add_control( 'blog_sphere_404page_title', array( 'label' => __( 'Page Not Found Title', 'blog-sphere' ), 'section' => 'blog_sphere_404page', 'type' => 'text', ) ); // Add a custom setting for the footer text $wp_customize->add_setting( 'blog_sphere_404page_text', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', ) ); // Add a custom control for the footer text $wp_customize->add_control( 'blog_sphere_404page_text', array( 'label' => __( 'Page Not Found Text', 'blog-sphere' ), 'section' => 'blog_sphere_404page', 'type' => 'text', ) ); //-------General Settings----------------------------- $wp_customize->add_section( 'blog_sphere_general', array( 'title' => __( 'General Settings', 'blog-sphere' ), 'panel' => 'blog_sphere_panel', ) ); $wp_customize->add_setting( 'blog_sphere_post_meta_toggle_switch_control', array( 'default' => true, 'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs 'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'blog_sphere_post_meta_toggle_switch_control', array( 'label' => __( 'Display Time/Author', 'blog-sphere' ), 'section' => 'blog_sphere_general', 'settings' => 'blog_sphere_post_meta_toggle_switch_control', 'type' => 'checkbox', ) ) ); $wp_customize->add_setting( 'blog_sphere_post_readmore_toggle_switch_control', array( 'default' => true, 'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs 'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'blog_sphere_post_readmore_toggle_switch_control', array( 'label' => __( 'Display Readmore Link', 'blog-sphere' ), 'section' => 'blog_sphere_general', 'settings' => 'blog_sphere_post_readmore_toggle_switch_control', 'type' => 'checkbox', ) ) ); } add_action( 'customize_register', 'blog_sphere_customize_register' );