add_section( 'actual_news_recent_posts_section', array( 'title' => esc_html__( 'Recent Posts Section', 'actual-news' ), 'panel' => 'news_articles_frontpage_panel', 'priority' => 25, ) ); // Recent Posts section enable settings. $wp_customize->add_setting( 'actual_news_recent_posts_section_enable', array( 'default' => false, 'sanitize_callback' => 'news_articles_sanitize_checkbox', ) ); $wp_customize->add_control( new Actual_News_Toggle_Checkbox_Custom_control( $wp_customize, 'actual_news_recent_posts_section_enable', array( 'label' => esc_html__( 'Enable Recent Posts Section', 'actual-news' ), 'type' => 'checkbox', 'settings' => 'actual_news_recent_posts_section_enable', 'section' => 'actual_news_recent_posts_section', ) ) ); // Recent Posts title settings. $wp_customize->add_setting( 'actual_news_recent_posts_title', array( 'default' => __( 'Recent Articles', 'actual-news' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'actual_news_recent_posts_title', array( 'label' => esc_html__( 'Title', 'actual-news' ), 'section' => 'actual_news_recent_posts_section', 'active_callback' => 'actual_news_if_recent_posts_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'actual_news_recent_posts_title', array( 'selector' => '.recentpost h3.widget-title', 'settings' => 'actual_news_recent_posts_title', 'container_inclusive' => false, 'fallback_refresh' => true, 'render_callback' => 'actual_news_recent_posts_title_text_partial', ) ); } // View All button label setting. $wp_customize->add_setting( 'actual_news_recent_posts_view_all_button_label', array( 'default' => __( 'View All', 'actual-news' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'actual_news_recent_posts_view_all_button_label', array( 'label' => esc_html__( 'View All Button Label', 'actual-news' ), 'section' => 'actual_news_recent_posts_section', 'settings' => 'actual_news_recent_posts_view_all_button_label', 'type' => 'text', 'active_callback' => 'actual_news_if_recent_posts_enabled', ) ); // Abort if selective refresh is not available. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'actual_news_recent_posts_view_all_button_label', array( 'selector' => '.recentpost .adore-view-all', 'settings' => 'actual_news_recent_posts_view_all_button_label', 'container_inclusive' => false, 'fallback_refresh' => true, 'render_callback' => 'actual_news_recent_posts_view_all_btn_partial', ) ); } // View All button URL setting. $wp_customize->add_setting( 'actual_news_recent_posts_view_all_button_url', array( 'default' => '#', 'sanitize_callback' => 'esc_url_raw', ) ); $wp_customize->add_control( 'actual_news_recent_posts_view_all_button_url', array( 'label' => esc_html__( 'View All Button Link', 'actual-news' ), 'section' => 'actual_news_recent_posts_section', 'settings' => 'actual_news_recent_posts_view_all_button_url', 'type' => 'url', 'active_callback' => 'actual_news_if_recent_posts_enabled', ) ); // recent_posts content type settings. $wp_customize->add_setting( 'actual_news_recent_posts_content_type', array( 'default' => 'post', 'sanitize_callback' => 'news_articles_sanitize_select', ) ); $wp_customize->add_control( 'actual_news_recent_posts_content_type', array( 'label' => esc_html__( 'Content type:', 'actual-news' ), 'description' => esc_html__( 'Choose where you want to render the content from.', 'actual-news' ), 'section' => 'actual_news_recent_posts_section', 'type' => 'select', 'active_callback' => 'actual_news_if_recent_posts_enabled', 'choices' => array( 'post' => esc_html__( 'Post', 'actual-news' ), 'recent' => esc_html__( 'Recent', 'actual-news' ), ), ) ); for ( $actual_news_i = 1; $actual_news_i <= 3; $actual_news_i++ ) { // recent_posts post setting. $wp_customize->add_setting( 'actual_news_recent_posts_post_' . $actual_news_i, array( 'sanitize_callback' => 'news_articles_sanitize_dropdown_pages', ) ); $wp_customize->add_control( 'actual_news_recent_posts_post_' . $actual_news_i, array( 'label' => sprintf( esc_html__( 'Post %d', 'actual-news' ), $actual_news_i ), 'section' => 'actual_news_recent_posts_section', 'type' => 'select', 'choices' => news_articles_get_post_choices(), 'active_callback' => 'actual_news_recent_posts_section_content_type_post_enabled', ) ); } /*========================Active Callback==============================*/ function actual_news_if_recent_posts_enabled( $control ) { return $control->manager->get_setting( 'actual_news_recent_posts_section_enable' )->value(); } function actual_news_recent_posts_section_content_type_post_enabled( $control ) { $content_type = $control->manager->get_setting( 'actual_news_recent_posts_content_type' )->value(); return actual_news_if_recent_posts_enabled( $control ) && ( 'post' === $content_type ); } /*========================Partial Refresh==============================*/ if ( ! function_exists( 'actual_news_recent_posts_title_text_partial' ) ) : // Title. function actual_news_recent_posts_title_text_partial() { return esc_html( get_theme_mod( 'actual_news_recent_posts_title' ) ); } endif; if ( ! function_exists( 'actual_news_recent_posts_view_all_btn_partial' ) ) : // View All Btn. function actual_news_recent_posts_view_all_btn_partial() { return esc_html( get_theme_mod( 'actual_news_recent_posts_view_all_button_label' ) ); } endif;