add_section( 'archive_news_banner_section', array( 'title' => esc_html__( 'Banner Section', 'archive-news' ), 'panel' => 'archive_news_frontpage_panel', ) ); // Banner enable setting. $wp_customize->add_setting( 'archive_news_banner_section_enable', array( 'default' => false, 'sanitize_callback' => 'archive_news_sanitize_checkbox', ) ); $wp_customize->add_control( new Archive_News_Toggle_Checkbox_Custom_control( $wp_customize, 'archive_news_banner_section_enable', array( 'label' => esc_html__( 'Enable Banner Section', 'archive-news' ), 'type' => 'checkbox', 'settings' => 'archive_news_banner_section_enable', 'section' => 'archive_news_banner_section', ) ) ); // Main News Sub Heading. $wp_customize->add_setting( 'archive_news_banner_main_news_sub_heading', array( 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( new Archive_News_Sub_Section_Heading_Custom_Control( $wp_customize, 'archive_news_banner_main_news_sub_heading', array( 'label' => esc_html__( 'Main News Section', 'archive-news' ), 'settings' => 'archive_news_banner_main_news_sub_heading', 'section' => 'archive_news_banner_section', 'active_callback' => 'archive_news_if_banner_enabled', ) ) ); // Main News title settings. $wp_customize->add_setting( 'archive_news_banner_main_news_title', array( 'default' => __( 'Main News', 'archive-news' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'archive_news_banner_main_news_title', array( 'label' => esc_html__( 'Title', 'archive-news' ), 'section' => 'archive_news_banner_section', 'active_callback' => 'archive_news_if_banner_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'archive_news_banner_main_news_title', array( 'selector' => '.main-banner-section .main-news-outer .widget-title', 'settings' => 'archive_news_banner_main_news_title', 'container_inclusive' => false, 'fallback_refresh' => true, ) ); } // banner main news content type settings. $wp_customize->add_setting( 'archive_news_banner_main_news_content_type', array( 'default' => 'post', 'sanitize_callback' => 'archive_news_sanitize_select', ) ); $wp_customize->add_control( 'archive_news_banner_main_news_content_type', array( 'label' => esc_html__( 'Main News Content type:', 'archive-news' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'archive-news' ), 'section' => 'archive_news_banner_section', 'settings' => 'archive_news_banner_main_news_content_type', 'type' => 'select', 'active_callback' => 'archive_news_if_banner_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'archive-news' ), 'category' => esc_html__( 'Category', 'archive-news' ), ), ) ); for ( $i = 1; $i <= 3; $i++ ) { // Main News post setting. $wp_customize->add_setting( 'archive_news_banner_main_news_post_' . $i, array( 'sanitize_callback' => 'archive_news_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'archive_news_banner_main_news_post_' . $i, array( 'label' => sprintf( esc_html__( 'Post %d', 'archive-news' ), $i ), 'section' => 'archive_news_banner_section', 'type' => 'select', 'choices' => archive_news_get_post_choices(), 'active_callback' => 'archive_news_banner_main_news_content_type_post_enabled', ) ); } // Main News category setting. $wp_customize->add_setting( 'archive_news_banner_main_news_category', array( 'sanitize_callback' => 'archive_news_sanitize_select', ) ); $wp_customize->add_control( 'archive_news_banner_main_news_category', array( 'label' => esc_html__( 'Category', 'archive-news' ), 'section' => 'archive_news_banner_section', 'type' => 'select', 'choices' => archive_news_get_post_cat_choices(), 'active_callback' => 'archive_news_banner_main_news_content_type_category_enabled', ) ); // Editor Pick Sub Heading. $wp_customize->add_setting( 'archive_news_banner_editor_pick_sub_heading', array( 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( new Archive_News_Sub_Section_Heading_Custom_Control( $wp_customize, 'archive_news_banner_editor_pick_sub_heading', array( 'label' => esc_html__( 'Editor Pick Section', 'archive-news' ), 'settings' => 'archive_news_banner_editor_pick_sub_heading', 'section' => 'archive_news_banner_section', 'active_callback' => 'archive_news_if_banner_enabled', ) ) ); // Editor Pick title settings. $wp_customize->add_setting( 'archive_news_banner_editor_pick_title', array( 'default' => __( 'Editor Pick', 'archive-news' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'archive_news_banner_editor_pick_title', array( 'label' => esc_html__( 'Title', 'archive-news' ), 'section' => 'archive_news_banner_section', 'active_callback' => 'archive_news_if_banner_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'archive_news_banner_editor_pick_title', array( 'selector' => '.main-banner-section .editor-pick-outer .widget-title', 'settings' => 'archive_news_banner_editor_pick_title', 'container_inclusive' => false, 'fallback_refresh' => true, ) ); } // banner main news content type settings. $wp_customize->add_setting( 'archive_news_banner_editor_pick_content_type', array( 'default' => 'post', 'sanitize_callback' => 'archive_news_sanitize_select', ) ); $wp_customize->add_control( 'archive_news_banner_editor_pick_content_type', array( 'label' => esc_html__( 'Editor Pick Content type:', 'archive-news' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'archive-news' ), 'section' => 'archive_news_banner_section', 'settings' => 'archive_news_banner_editor_pick_content_type', 'type' => 'select', 'active_callback' => 'archive_news_if_banner_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'archive-news' ), 'category' => esc_html__( 'Category', 'archive-news' ), ), ) ); for ( $i = 1; $i <= 3; $i++ ) { // Editor Pick post setting. $wp_customize->add_setting( 'archive_news_banner_editor_pick_post_' . $i, array( 'sanitize_callback' => 'archive_news_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'archive_news_banner_editor_pick_post_' . $i, array( 'label' => sprintf( esc_html__( 'Post %d', 'archive-news' ), $i ), 'section' => 'archive_news_banner_section', 'type' => 'select', 'choices' => archive_news_get_post_choices(), 'active_callback' => 'archive_news_banner_editor_pick_content_type_post_enabled', ) ); } // Editor Pick category setting. $wp_customize->add_setting( 'archive_news_banner_editor_pick_category', array( 'sanitize_callback' => 'archive_news_sanitize_select', ) ); $wp_customize->add_control( 'archive_news_banner_editor_pick_category', array( 'label' => esc_html__( 'Category', 'archive-news' ), 'section' => 'archive_news_banner_section', 'type' => 'select', 'choices' => archive_news_get_post_cat_choices(), 'active_callback' => 'archive_news_banner_editor_pick_content_type_category_enabled', ) ); // Featured Posts Sub Heading. $wp_customize->add_setting( 'archive_news_banner_featured_posts_sub_heading', array( 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( new Archive_News_Sub_Section_Heading_Custom_Control( $wp_customize, 'archive_news_banner_featured_posts_sub_heading', array( 'label' => esc_html__( 'Featured Posts Section', 'archive-news' ), 'settings' => 'archive_news_banner_featured_posts_sub_heading', 'section' => 'archive_news_banner_section', 'active_callback' => 'archive_news_if_banner_enabled', ) ) ); // Featured Posts title settings. $wp_customize->add_setting( 'archive_news_banner_featured_posts_title', array( 'default' => __( 'Featured Posts', 'archive-news' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'archive_news_banner_featured_posts_title', array( 'label' => esc_html__( 'Title', 'archive-news' ), 'section' => 'archive_news_banner_section', 'active_callback' => 'archive_news_if_banner_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'archive_news_banner_featured_posts_title', array( 'selector' => '.main-banner-section .featured-posts-outer .widget-title', 'settings' => 'archive_news_banner_featured_posts_title', 'container_inclusive' => false, 'fallback_refresh' => true, ) ); } // banner featured posts content type settings. $wp_customize->add_setting( 'archive_news_banner_featured_posts_content_type', array( 'default' => 'post', 'sanitize_callback' => 'archive_news_sanitize_select', ) ); $wp_customize->add_control( 'archive_news_banner_featured_posts_content_type', array( 'label' => esc_html__( 'Featured Posts Content type:', 'archive-news' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'archive-news' ), 'section' => 'archive_news_banner_section', 'settings' => 'archive_news_banner_featured_posts_content_type', 'type' => 'select', 'active_callback' => 'archive_news_if_banner_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'archive-news' ), 'category' => esc_html__( 'Category', 'archive-news' ), ), ) ); for ( $i = 1; $i <= 4; $i++ ) { // Featured Posts post setting. $wp_customize->add_setting( 'archive_news_banner_featured_posts_post_' . $i, array( 'sanitize_callback' => 'archive_news_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'archive_news_banner_featured_posts_post_' . $i, array( 'label' => sprintf( esc_html__( 'Post %d', 'archive-news' ), $i ), 'section' => 'archive_news_banner_section', 'type' => 'select', 'choices' => archive_news_get_post_choices(), 'active_callback' => 'archive_news_banner_featured_posts_content_type_post_enabled', ) ); } // Featured Posts category setting. $wp_customize->add_setting( 'archive_news_banner_featured_posts_category', array( 'sanitize_callback' => 'archive_news_sanitize_select', ) ); $wp_customize->add_control( 'archive_news_banner_featured_posts_category', array( 'label' => esc_html__( 'Category', 'archive-news' ), 'section' => 'archive_news_banner_section', 'type' => 'select', 'choices' => archive_news_get_post_cat_choices(), 'active_callback' => 'archive_news_banner_featured_posts_content_type_category_enabled', ) ); /*========================Active Callback==============================*/ function archive_news_if_banner_enabled( $control ) { return $control->manager->get_setting( 'archive_news_banner_section_enable' )->value(); } // Banner Main News function archive_news_banner_main_news_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'archive_news_banner_main_news_content_type' )->value(); return archive_news_if_banner_enabled( $control ) && ( 'post' === $content_type ); } function archive_news_banner_main_news_content_type_category_enabled( $control ) { $content_type = $control->manager->get_setting( 'archive_news_banner_main_news_content_type' )->value(); return archive_news_if_banner_enabled( $control ) && ( 'category' === $content_type ); } // Banner Editor Pick function archive_news_banner_editor_pick_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'archive_news_banner_editor_pick_content_type' )->value(); return archive_news_if_banner_enabled( $control ) && ( 'post' === $content_type ); } function archive_news_banner_editor_pick_content_type_category_enabled( $control ) { $content_type = $control->manager->get_setting( 'archive_news_banner_editor_pick_content_type' )->value(); return archive_news_if_banner_enabled( $control ) && ( 'category' === $content_type ); } // Banner Featured Posts function archive_news_banner_featured_posts_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'archive_news_banner_featured_posts_content_type' )->value(); return archive_news_if_banner_enabled( $control ) && ( 'post' === $content_type ); } function archive_news_banner_featured_posts_content_type_category_enabled( $control ) { $content_type = $control->manager->get_setting( 'archive_news_banner_featured_posts_content_type' )->value(); return archive_news_if_banner_enabled( $control ) && ( 'category' === $content_type ); }