add_section( 'blog_talk_popular_posts_section', array( 'title' => esc_html__( 'Popular Posts Section', 'blog-talk' ), 'panel' => 'blog_talk_frontpage_panel', ) ); // Popular Posts section enable settings. $wp_customize->add_setting( 'blog_talk_popular_posts_section_enable', array( 'default' => false, 'sanitize_callback' => 'blog_talk_sanitize_checkbox', ) ); $wp_customize->add_control( new Blog_Talk_Toggle_Checkbox_Custom_control( $wp_customize, 'blog_talk_popular_posts_section_enable', array( 'label' => esc_html__( 'Enable Popular Posts Section', 'blog-talk' ), 'type' => 'checkbox', 'settings' => 'blog_talk_popular_posts_section_enable', 'section' => 'blog_talk_popular_posts_section', ) ) ); // Popular Posts title settings. $wp_customize->add_setting( 'blog_talk_popular_posts_title', array( 'default' => __( 'Popular Posts', 'blog-talk' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'blog_talk_popular_posts_title', array( 'label' => esc_html__( 'Section Title', 'blog-talk' ), 'section' => 'blog_talk_popular_posts_section', 'active_callback' => 'blog_talk_if_popular_posts_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blog_talk_popular_posts_title', array( 'selector' => '.popularpost h3.section-title', 'settings' => 'blog_talk_popular_posts_title', 'container_inclusive' => false, 'fallback_refresh' => true, 'render_callback' => 'blog_talk_popular_posts_title_text_partial', ) ); } // Popular Posts subtitle settings. $wp_customize->add_setting( 'blog_talk_popular_posts_subtitle', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'blog_talk_popular_posts_subtitle', array( 'label' => esc_html__( 'Section Subtitle', 'blog-talk' ), 'section' => 'blog_talk_popular_posts_section', 'active_callback' => 'blog_talk_if_popular_posts_enabled', ) ); // popular_posts content type settings. $wp_customize->add_setting( 'blog_talk_popular_posts_content_type', array( 'default' => 'post', 'sanitize_callback' => 'blog_talk_sanitize_select', ) ); $wp_customize->add_control( 'blog_talk_popular_posts_content_type', array( 'label' => esc_html__( 'Content type:', 'blog-talk' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'blog-talk' ), 'section' => 'blog_talk_popular_posts_section', 'type' => 'select', 'active_callback' => 'blog_talk_if_popular_posts_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'blog-talk' ), 'category' => esc_html__( 'Category', 'blog-talk' ), ), ) ); for ( $i = 1; $i <= 5; $i++ ) { // popular_posts post setting. $wp_customize->add_setting( 'blog_talk_popular_posts_post_' . $i, array( 'sanitize_callback' => 'blog_talk_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'blog_talk_popular_posts_post_' . $i, array( 'label' => sprintf( esc_html__( 'Post %d', 'blog-talk' ), $i ), 'section' => 'blog_talk_popular_posts_section', 'type' => 'select', 'choices' => blog_talk_get_post_choices(), 'active_callback' => 'blog_talk_popular_posts_section_content_type_post_enabled', ) ); } // popular_posts category setting. $wp_customize->add_setting( 'blog_talk_popular_posts_category', array( 'sanitize_callback' => 'blog_talk_sanitize_select', ) ); $wp_customize->add_control( 'blog_talk_popular_posts_category', array( 'label' => esc_html__( 'Category', 'blog-talk' ), 'section' => 'blog_talk_popular_posts_section', 'type' => 'select', 'choices' => blog_talk_get_post_cat_choices(), 'active_callback' => 'blog_talk_popular_posts_section_content_type_category_enabled', ) ); // Popular Posts button label setting. $wp_customize->add_setting( 'blog_talk_popular_posts_button_label', array( 'default' => __( 'Read More', 'blog-talk' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'blog_talk_popular_posts_button_label', array( 'label' => esc_html__( 'Button Label', 'blog-talk' ), 'section' => 'blog_talk_popular_posts_section', 'type' => 'text', 'active_callback' => 'blog_talk_if_popular_posts_enabled', ) ); /*========================Active Callback==============================*/ function blog_talk_if_popular_posts_enabled( $control ) { return $control->manager->get_setting( 'blog_talk_popular_posts_section_enable' )->value(); } function blog_talk_popular_posts_section_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'blog_talk_popular_posts_content_type' )->value(); return blog_talk_if_popular_posts_enabled( $control ) && ( 'post' === $content_type ); } function blog_talk_popular_posts_section_content_type_category_enabled( $control ) { $content_type = $control->manager->get_setting( 'blog_talk_popular_posts_content_type' )->value(); return blog_talk_if_popular_posts_enabled( $control ) && ( 'category' === $content_type ); } /*========================Partial Refresh==============================*/ if ( ! function_exists( 'blog_talk_popular_posts_title_text_partial' ) ) : // Title. function blog_talk_popular_posts_title_text_partial() { return esc_html( get_theme_mod( 'blog_talk_popular_posts_title' ) ); } endif;