add_section( 'benpress_section_featured', array( 'title' => esc_html__( 'Featured Posts', 'benpress' ), 'priority' => 60, 'panel' => 'benpress_options_panel', ) ); // Add settings and controls for Featured Posts. $wp_customize->add_control( new benpress_Customize_Header_Control( $wp_customize, 'benpress_theme_options[activate_featured_posts]', array( 'label' => esc_html__( 'Activate Featured Posts', 'benpress' ), 'section' => 'benpress_section_featured', 'settings' => array(), 'priority' => 10, ) ) ); $wp_customize->add_setting( 'benpress_theme_options[featured_posts]', array( 'default' => false, 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'benpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'benpress_theme_options[featured_posts]', array( 'label' => esc_html__( 'Show Featured Posts on home page', 'benpress' ), 'section' => 'benpress_section_featured', 'settings' => 'benpress_theme_options[featured_posts]', 'type' => 'checkbox', 'priority' => 20, ) ); // Add Setting and Control for Featured Posts Category. $wp_customize->add_setting( 'benpress_theme_options[featured_category]', array( 'default' => 0, 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( new benpress_Customize_Category_Dropdown_Control( $wp_customize, 'benpress_theme_options[featured_category]', array( 'label' => esc_html__( 'Featured Posts Category', 'benpress' ), 'section' => 'benpress_section_featured', 'settings' => 'benpress_theme_options[featured_category]', 'priority' => 30, ) ) ); // Add Partial for Featured Post Settings. $wp_customize->selective_refresh->add_partial( 'benpress_featured_content_partial', array( 'selector' => '.site #featured-content', 'settings' => array( 'benpress_theme_options[featured_posts]', 'benpress_theme_options[featured_category]', ), 'render_callback' => 'benpress_customize_partial_featured_posts', 'fallback_refresh' => false, ) ); } add_action( 'customize_register', 'benpress_customize_register_featured_settings' ); /** * Render the featured posts for the selective refresh partial. */ function benpress_customize_partial_featured_posts() { if ( true === benpress_get_option( 'featured_posts' ) && is_front_page() ) : get_template_part( 'template-parts/featured/featured-content' ); endif; }