add_section( 'admire_blog_flash_posts_section', array( 'title' => esc_html__( 'Flash Posts Section', 'admire-blog' ), 'panel' => 'admire_blog_frontpage_panel', ) ); // Flash Posts section enable settings. $wp_customize->add_setting( 'admire_blog_flash_posts_section_enable', array( 'default' => false, 'sanitize_callback' => 'admire_blog_sanitize_checkbox', ) ); $wp_customize->add_control( new Admire_Blog_Toggle_Checkbox_Custom_control( $wp_customize, 'admire_blog_flash_posts_section_enable', array( 'label' => esc_html__( 'Enable Flash Posts Section', 'admire-blog' ), 'type' => 'checkbox', 'settings' => 'admire_blog_flash_posts_section_enable', 'section' => 'admire_blog_flash_posts_section', ) ) ); // flash_posts content type settings. $wp_customize->add_setting( 'admire_blog_flash_posts_content_type', array( 'default' => 'post', 'sanitize_callback' => 'admire_blog_sanitize_select', ) ); $wp_customize->add_control( 'admire_blog_flash_posts_content_type', array( 'label' => esc_html__( 'Content type:', 'admire-blog' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'admire-blog' ), 'section' => 'admire_blog_flash_posts_section', 'type' => 'select', 'active_callback' => 'admire_blog_if_flash_posts_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'admire-blog' ), 'category' => esc_html__( 'Category', 'admire-blog' ), ), ) ); for ( $i = 1; $i <= 5; $i++ ) { // flash_posts post setting. $wp_customize->add_setting( 'admire_blog_flash_posts_post_' . $i, array( 'sanitize_callback' => 'admire_blog_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'admire_blog_flash_posts_post_' . $i, array( 'label' => sprintf( esc_html__( 'Post %d', 'admire-blog' ), $i ), 'section' => 'admire_blog_flash_posts_section', 'type' => 'select', 'choices' => admire_blog_get_post_choices(), 'active_callback' => 'admire_blog_flash_posts_section_content_type_post_enabled', ) ); } // flash_posts category setting. $wp_customize->add_setting( 'admire_blog_flash_posts_category', array( 'sanitize_callback' => 'admire_blog_sanitize_select', ) ); $wp_customize->add_control( 'admire_blog_flash_posts_category', array( 'label' => esc_html__( 'Category', 'admire-blog' ), 'section' => 'admire_blog_flash_posts_section', 'type' => 'select', 'choices' => admire_blog_get_post_cat_choices(), 'active_callback' => 'admire_blog_flash_posts_section_content_type_category_enabled', ) ); /*========================Active Callback==============================*/ function admire_blog_if_flash_posts_enabled( $control ) { return $control->manager->get_setting( 'admire_blog_flash_posts_section_enable' )->value(); } function admire_blog_flash_posts_section_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'admire_blog_flash_posts_content_type' )->value(); return admire_blog_if_flash_posts_enabled( $control ) && ( 'post' === $content_type ); } function admire_blog_flash_posts_section_content_type_category_enabled( $control ) { $content_type = $control->manager->get_setting( 'admire_blog_flash_posts_content_type' )->value(); return admire_blog_if_flash_posts_enabled( $control ) && ( 'category' === $content_type ); }