add_section( 'blog_point_editor_choice_section', array( 'title' => esc_html__( 'Editor Choice Section', 'blog-point' ), 'panel' => 'blog_point_frontpage_panel', ) ); // Editor Choice section enable settings. $wp_customize->add_setting( 'blog_point_editor_choice_section_enable', array( 'default' => false, 'sanitize_callback' => 'blog_point_sanitize_checkbox', ) ); $wp_customize->add_control( new Blog_Point_Toggle_Checkbox_Custom_control( $wp_customize, 'blog_point_editor_choice_section_enable', array( 'label' => esc_html__( 'Enable Editor Choice Section', 'blog-point' ), 'type' => 'checkbox', 'settings' => 'blog_point_editor_choice_section_enable', 'section' => 'blog_point_editor_choice_section', ) ) ); // Editor Choice title settings. $wp_customize->add_setting( 'blog_point_editor_choice_title', array( 'default' => __( 'Editor Choice', 'blog-point' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'blog_point_editor_choice_title', array( 'label' => esc_html__( 'Section Title', 'blog-point' ), 'section' => 'blog_point_editor_choice_section', 'active_callback' => 'blog_point_if_editor_choice_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blog_point_editor_choice_title', array( 'selector' => '.blog-editors-choice h3.section-title', 'settings' => 'blog_point_editor_choice_title', 'container_inclusive' => false, 'fallback_refresh' => true, ) ); } // Editor Choice subtitle settings. $wp_customize->add_setting( 'blog_point_editor_choice_subtitle', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'blog_point_editor_choice_subtitle', array( 'label' => esc_html__( 'Section Subtitle', 'blog-point' ), 'section' => 'blog_point_editor_choice_section', 'active_callback' => 'blog_point_if_editor_choice_enabled', ) ); // editor_choice content type settings. $wp_customize->add_setting( 'blog_point_editor_choice_content_type', array( 'default' => 'post', 'sanitize_callback' => 'blog_point_sanitize_select', ) ); $wp_customize->add_control( 'blog_point_editor_choice_content_type', array( 'label' => esc_html__( 'Content type:', 'blog-point' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'blog-point' ), 'section' => 'blog_point_editor_choice_section', 'type' => 'select', 'active_callback' => 'blog_point_if_editor_choice_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'blog-point' ), 'category' => esc_html__( 'Category', 'blog-point' ), ), ) ); for ( $i = 1; $i <= 3; $i++ ) { // editor_choice post setting. $wp_customize->add_setting( 'blog_point_editor_choice_post_' . $i, array( 'sanitize_callback' => 'blog_point_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'blog_point_editor_choice_post_' . $i, array( 'label' => sprintf( esc_html__( 'Post %d', 'blog-point' ), $i ), 'section' => 'blog_point_editor_choice_section', 'type' => 'select', 'choices' => blog_point_get_post_choices(), 'active_callback' => 'blog_point_editor_choice_section_content_type_post_enabled', ) ); } // editor_choice category setting. $wp_customize->add_setting( 'blog_point_editor_choice_category', array( 'sanitize_callback' => 'blog_point_sanitize_select', ) ); $wp_customize->add_control( 'blog_point_editor_choice_category', array( 'label' => esc_html__( 'Category', 'blog-point' ), 'section' => 'blog_point_editor_choice_section', 'type' => 'select', 'choices' => blog_point_get_post_cat_choices(), 'active_callback' => 'blog_point_editor_choice_section_content_type_category_enabled', ) ); /*========================Active Callback==============================*/ function blog_point_if_editor_choice_enabled( $control ) { return $control->manager->get_setting( 'blog_point_editor_choice_section_enable' )->value(); } function blog_point_editor_choice_section_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'blog_point_editor_choice_content_type' )->value(); return blog_point_if_editor_choice_enabled( $control ) && ( 'post' === $content_type ); } function blog_point_editor_choice_section_content_type_category_enabled( $control ) { $content_type = $control->manager->get_setting( 'blog_point_editor_choice_content_type' )->value(); return blog_point_if_editor_choice_enabled( $control ) && ( 'category' === $content_type ); } /*========================Partial Refresh==============================*/ if ( ! function_exists( 'blog_point_editor_choice_title_text_partial' ) ) : // Title. function blog_point_editor_choice_title_text_partial() { return esc_html( get_theme_mod( 'blog_point_editor_choice_title' ) ); } endif;