/** * Extend default customizer panel. * * @package Mystery Themes * @subpackage News Portal * @since 1.5.0 * * @see WP_Customize_Panel * @access public */ if ( class_exists( 'WP_Customize_Panel' ) ) { /** * Class News_Portal_Customize_Panel * * @since 1.0.0 */ class News_Portal_Customize_Panel extends WP_Customize_Panel { /** * Panel * * @var string */ public $panel; /** * Control type. * * @var string */ public $type = 'news_portal_panel'; /** * Get section parameters for JS. * * @return array Exported parameters. */ public function json() { $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'type', 'panel', ) ); $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) ); $array['content'] = $this->get_content(); $array['active'] = $this->active(); $array['instanceNumber'] = $this->instance_number; return $array; } } }/** * Add Panels/Sections to the Customizer. * * @package Mystery Themes * @subpackage News Portal * @since 1.5.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'customize_register', 'news_portal_register_customizer_panels_sections' ); if ( ! function_exists( 'news_portal_register_customizer_panels_sections' ) ) : /** * Implement the Theme Customizer for Theme Settings. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function news_portal_register_customizer_panels_sections( $wp_customize ) { /* * Failsafe is safe */ if ( ! isset( $wp_customize ) ) { return; } /*--------------------------- Add Panels -------------------------------------*/ /** * Add Panel for General Settings * * Customize > General Settings * * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/ */ $wp_customize->add_panel( 'news_portal_general_settings_panel', array( 'priority' => 5, 'title' => __( 'General Settings', 'news-portal' ) ) ); /** * Add Panel for Header Settings * * Customize > Header Settings * * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/ */ $wp_customize->add_panel( 'news_portal_header_settings_panel', array( 'priority' => 10, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Header Settings', 'news-portal' ), ) ); /** * Add Panel for Innerpage Settings * * Customize > Innerpage Settings * * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/ */ $wp_customize->add_panel( 'news_portal_design_settings_panel', array( 'priority' => 15, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Innerpage Settings', 'news-portal' ), ) ); /** * Add Panel for Footer Settings * * Customize > Footer Settings * * @uses $wp_customize->add_panel() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_panel/ */ $wp_customize->add_panel( 'news_portal_footer_settings_panel', array( 'priority' => 20, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Footer Settings', 'news-portal' ), ) ); } endif;/** * File to sanitize customizer field * * @package Mystery Themes * @subpackage News Portal * @since 1.0.0 */ if ( ! function_exists( 'news_portal_sanitize_select' ) ) : /** * Sanitize select. * * @param mixed $input The value to sanitize. * @param WP_Customize_Setting $setting WP_Customize_Setting instance. * @return mixed Sanitized value. * * @since 1.0.0 */ function news_portal_sanitize_select( $input, $setting ) { // Ensure input is a slug. $input = sanitize_key( $input ); // Get list of choices from the control associated with the setting. $choices = $setting->manager->get_control( $setting->id )->choices; // If the input is a valid key, return it; otherwise, return the default. return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } endif; if ( ! function_exists( 'news_portal_sanitize_checkbox' ) ) : /** * Sanitize checkbox value * * @param bool $checked Whether the checkbox is checked. * @return bool Whether the checkbox is checked. */ function news_portal_sanitize_checkbox( $input ) { return ( ( isset( $input ) && true === $input ) ? true : false ); } endif; /** * Sanitize repeater value * * @since 1.0.0 */ function news_portal_sanitize_repeater( $input ){ $input_decoded = json_decode( $input, true ); if ( !empty( $input_decoded ) ) { foreach ( $input_decoded as $boxes => $box ){ foreach ( $box as $key => $value ){ $input_decoded[$boxes][$key] = wp_kses_post( $value ); } } return json_encode( $input_decoded ); } return $input; } /** * Sanitize site layout * * @since 1.0.0 */ function news_portal_sanitize_site_layout( $input ) { $valid_keys = array( 'fullwidth_layout' => __( 'Fullwidth Layout', 'news-portal' ), 'boxed_layout' => __( 'Boxed Layout', 'news-portal' ) ); if ( array_key_exists( $input, $valid_keys ) ) { return $input; } else { return ''; } } /** * switch option (show/hide) * * @since 1.0.0 */ function news_portal_sanitize_switch_option( $input ) { $valid_keys = array( 'show' => __( 'Show', 'news-portal' ), 'hide' => __( 'Hide', 'news-portal' ) ); if ( array_key_exists( $input, $valid_keys ) ) { return $input; } else { return ''; } } /*-----------------------------------------------------------------------------------------------------------------------*/ /** * Render the site title for the selective refresh partial. * * @since News Portal 1.0.1 * @see news_portal_customize_register() * * @return void */ function news_portal_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site title for the selective refresh partial. * * @since News Portal 1.0.1 * @see news_portal_customize_register() * * @return void */ function news_portal_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Render the site title for the selective refresh partial. * * @since News Portal 1.0.1 * @see news_portal_footer_settings_register() * * @return void */ function news_portal_customize_partial_copyright() { return get_theme_mod( 'news_portal_copyright_text' ); } /** * Render the site title for the selective refresh partial. * * @since News Portal 1.0.1 * @see news_portal_design_settings_register() * * @return void */ function news_portal_customize_partial_related_title() { return get_theme_mod( 'news_portal_related_posts_title' ); } /** * Render the site title for the selective refresh partial. * * @since News Portal 1.0.1 * @see news_portal_design_settings_register() * * @return void */ function news_portal_customize_partial_archive_more() { return get_theme_mod( 'news_portal_archive_read_more_text' ); } /** * Render the site title for the selective refresh partial. * * @since News Portal 1.0.1 * @see news_portal_header_settings_register() * * @return void */ function news_portal_customize_partial_ticker_caption() { return get_theme_mod( 'news_portal_ticker_caption' ); }/** * Add extended Global and Categories section and it's fields inside Social icons Section. * * @package Mystery Themes * @subpackage News Portal * @since 1.5.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'customize_register', 'news_portal_register_social_icons_options' ); if ( ! function_exists( 'news_portal_register_social_icons_options' ) ) : /** * Register theme options for Social Icons section. * * @param WP_Customize_Manager $wp_customize Object that holds the customizer data. * @since 1.0.0 */ function news_portal_register_social_icons_options( $wp_customize ) { /* * Failsafe is safe */ if ( ! isset( $wp_customize ) ) { return; } /** * Social Icons Section * * @since 1.0.0 */ $wp_customize->add_section( 'news_portal_social_icons_section', array( 'title' => esc_html__( 'Social Icons', 'news-portal' ), 'panel' => 'news_portal_general_settings_panel', 'priority' => 25, ) ); /** * Repeater field for social media icons * * @since 1.0.0 */ $wp_customize->add_setting( 'social_media_icons', array( 'sanitize_callback' => 'news_portal_sanitize_repeater', 'default' => json_encode(array( array( 'social_icon_class' => 'fab fa-facebook-f', 'social_icon_url' => '', ) )) ) ); $wp_customize->add_control( new News_Portal_Repeater_Controler( $wp_customize, 'social_media_icons', array( 'label' => __( 'Social Media Icons', 'news-portal' ), 'section' => 'news_portal_social_icons_section', 'settings' => 'social_media_icons', 'priority' => 5, 'news_portal_box_label' => __( 'Social Media Icon','news-portal' ), 'news_portal_box_add_control' => __( 'Add Icon','news-portal' ) ), array( 'social_icon_class' => array( 'type' => 'social_icon', 'label' => __( 'Social Media Logo', 'news-portal' ), 'description' => __( 'Choose social media icon.', 'news-portal' ) ), 'social_icon_url' => array( 'type' => 'url', 'label' => __( 'Social Icon Url', 'news-portal' ), 'description' => __( 'Enter social media url.', 'news-portal' ) ) ) ) ); /** * Upgrade field for social icons * * @since 1.5.0 */ $wp_customize->add_setting( 'news_preloader_upgrade_social_icons', array( 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_control( new News_Portal_Control_Upgrade( $wp_customize, 'news_preloader_upgrade_social_icons', array( 'priority' => 200, 'section' => 'news_portal_social_icons_section', 'settings' => 'news_preloader_upgrade_social_icons', 'label' => __( 'More Features with News Portal Pro', 'news-portal' ), 'choices' => news_portal_upgrade_choices( 'news_portal_social_icon' ) ) ) ); } endif;/** * Add extended Global and Categories section and it's fields inside Colors Section. * * @package Mystery Themes * @subpackage News Portal * @since 1.5.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'customize_register', 'news_portal_register_template_settings_options' ); if ( ! function_exists( 'news_portal_register_template_settings_options' ) ) : /** * Register theme options for Template Settings section. * * @param WP_Customize_Manager $wp_customize Object that holds the customizer data. * @since 1.0.0 */ function news_portal_register_template_settings_options( $wp_customize ) { /* * Failsafe is safe */ if ( ! isset( $wp_customize ) ) { return; } /** * Templates Settings * * @since 1.0.0 */ $wp_customize->add_section( 'news_portal_templates_settings_section', array( 'title' => __( 'Template Settings', 'news-portal' ), 'description' => __( 'Manage the settings for available templates.', 'news-portal' ), 'priority' => 45, 'panel' => 'news_portal_general_settings_panel', ) ); /** * Toggle option for homepage template content show hide * * @since 1.0.0 */ $wp_customize->add_setting( 'news_portal_home_template_content_option', array( 'default' => news_portal_get_customizer_default( 'news_portal_home_template_content_option' ), 'sanitize_callback' => 'news_portal_sanitize_checkbox' ) ); $wp_customize->add_control( new News_Portal_Control_Toggle( $wp_customize, 'news_portal_home_template_content_option', array( 'priority' => 10, 'section' => 'news_portal_templates_settings_section', 'settings' => 'news_portal_home_template_content_option', 'label' => __( 'Home Page Template', 'news-portal' ), 'description' => __( 'Show/Hide option to display content of the pages that uses home page template.', 'news-portal' ) ) ) ); /** * Toggle option for block base widget editor. * * @since 1.3.0 */ $wp_customize->add_setting( 'np_block_base_widget_editor_option', array( 'default' => news_portal_get_customizer_default( 'np_block_base_widget_editor_option' ), 'sanitize_callback' => 'news_portal_sanitize_checkbox' ) ); $wp_customize->add_control( new News_Portal_Control_Toggle( $wp_customize, 'np_block_base_widget_editor_option', array( 'priority' => 20, 'section' => 'news_portal_templates_settings_section', 'settings' => 'np_block_base_widget_editor_option', 'label' => __( 'Block Widget Editor Option', 'news-portal' ), 'description' => __( 'Enable/disable Block-based Widgets Editor(since WordPress 5.8).', 'news-portal' ) ) ) ); } endif;/** * Add extended Global and Categories section and it's fields inside header top area Section. * * @package Mystery Themes * @subpackage News Portal * @since 1.5.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'customize_register', 'news_portal_register_header_top_area_options' ); if ( ! function_exists( 'news_portal_register_header_top_area_options' ) ) : /** * Register theme options for top header area section. * * @param WP_Customize_Manager $wp_customize Object that holds the customizer data. * @since 1.0.0 */ function news_portal_register_header_top_area_options( $wp_customize ) { /* * Failsafe is safe */ if ( ! isset( $wp_customize ) ) { return; } /** * Top Header Section */ $wp_customize->add_section( 'news_portal_top_header_section', array( 'title' => __( 'Top Header Section', 'news-portal' ), 'priority' => 20, 'panel' => 'news_portal_header_settings_panel' ) ); /** * Toggle option for Top Header * * @since 1.0.0 */ $wp_customize->add_setting( 'news_portal_top_header_option', array( 'default' => news_portal_get_customizer_default( 'news_portal_top_header_option' ), 'sanitize_callback' => 'news_portal_sanitize_checkbox' ) ); $wp_customize->add_control( new News_Portal_Control_Toggle( $wp_customize, 'news_portal_top_header_option', array( 'priority' => 5, 'section' => 'news_portal_top_header_section', 'settings' => 'news_portal_top_header_option', 'label' => __( 'Top Header Section', 'news-portal' ), 'description' => __( 'Show/Hide option for top header section.', 'news-portal' ) ) ) ); /** * Toggle option for Current Date * * @since 1.0.0 */ $wp_customize->add_setting( 'news_portal_top_date_option', array( 'default' => news_portal_get_customizer_default( 'news_portal_top_date_option' ), 'sanitize_callback' => 'news_portal_sanitize_checkbox' ) ); $wp_customize->add_control( new News_Portal_Control_Toggle( $wp_customize, 'news_portal_top_date_option', array( 'priority' => 10, 'section' => 'news_portal_top_header_section', 'settings' => 'news_portal_top_date_option', 'label' => __( 'Current Date', 'news-portal' ), 'description' => __( 'Show/Hide option for current date at top header section.', 'news-portal' ), 'active_callback' => 'news_portal_has_enable_header_top_area' ) ) ); /** * Toggle option for Social Icon * * @since 1.0.0 */ $wp_customize->add_setting( 'news_portal_top_social_option', array( 'default' => news_portal_get_customizer_default( 'news_portal_top_social_option' ), 'sanitize_callback' => 'news_portal_sanitize_checkbox' ) ); $wp_customize->add_control( new News_Portal_Control_Toggle( $wp_customize, 'news_portal_top_social_option', array( 'priority' => 15, 'section' => 'news_portal_top_header_section', 'settings' => 'news_portal_top_social_option', 'label' => __( 'Social Icons', 'news-portal' ), 'description' => __( 'Show/Hide option for social media icons at top header section.', 'news-portal' ), 'active_callback' => 'news_portal_has_enable_header_top_area' ) ) ); } endif;/** * Add extended Global and Categories section and it's fields inside footer main area Section. * * @package Mystery Themes * @subpackage News Portal * @since 1.5.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'customize_register', 'news_portal_register_footer_main_area_options' ); if ( ! function_exists( 'news_portal_register_footer_main_area_options' ) ) : /** * Register theme options for footer main area section. * * @param WP_Customize_Manager $wp_customize Object that holds the customizer data. * @since 1.0.0 */ function news_portal_register_footer_main_area_options( $wp_customize ) { /* * Failsafe is safe */ if ( ! isset( $wp_customize ) ) { return; } /** * Widget Area Section * * @since 1.0.0 */ $wp_customize->add_section( 'news_portal_footer_widget_section', array( 'title' => esc_html__( 'Widget Area', 'news-portal' ), 'panel' => 'news_portal_footer_settings_panel', 'priority' => 5, ) ); /** * Toggle option for footer widget area * * @since 1.0.0 */ $wp_customize->add_setting( 'news_portal_footer_widget_option', array( 'default' => news_portal_get_customizer_default( 'news_portal_footer_widget_option' ), 'sanitize_callback' => 'news_portal_sanitize_checkbox' ) ); $wp_customize->add_control( new News_Portal_Control_Toggle( $wp_customize, 'news_portal_footer_widget_option', array( 'priority' => 5, 'section' => 'news_portal_footer_widget_section', 'settings' => 'news_portal_footer_widget_option', 'label' => __( 'Footer Widget Section', 'news-portal' ), 'description' => __( 'Show/Hide option for footer widget area section.', 'news-portal' ) ) ) ); /** * Image Radio field for widget area column * * @since 1.0.0 */ $wp_customize->add_setting( 'footer_widget_layout', array( 'default' => news_portal_get_customizer_default( 'footer_widget_layout' ), 'sanitize_callback' => 'news_portal_sanitize_select', ) ); $wp_customize->add_control( new News_Portal_Control_Radio_Image( $wp_customize, 'footer_widget_layout', array( 'priority' => 10, 'label' => esc_html__( 'Footer Widget Layout', 'news-portal' ), 'description' => esc_html__( 'Choose layout from available layouts', 'news-portal' ), 'section' => 'news_portal_footer_widget_section', 'choices' => news_portal_footer_widget_layout_choices(), 'active_callback' => 'news_portal_has_enable_footer_widget' ) ) ); /** * Upgrade field for footer main area * * @since 1.5.0 */ $wp_customize->add_setting( 'news_preloader_upgrade_footer_main_area', array( 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_control( new News_Portal_Control_Upgrade( $wp_customize, 'news_preloader_upgrade_footer_main_area', array( 'priority' => 200, 'section' => 'news_portal_footer_widget_section', 'settings' => 'news_preloader_upgrade_footer_main_area', 'label' => __( 'More Features with News Portal Pro', 'news-portal' ), 'choices' => news_portal_upgrade_choices( 'news_portal_footer_area' ) ) ) ); } endif;/** * News Portal custom function and work related to widgets. * * @package Mystery Themes * @subpackage News Portal * @since 1.0.0 */ /*-----------------------------------------------------------------------------------------------------------------------*/ /** * Register widget area. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function news_portal_widgets_init() { /** * Register right sidebar * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Sidebar', 'news-portal' ), 'id' => 'sidebar-1', 'description' => esc_html__( 'Add widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register left sidebar * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Left Sidebar', 'news-portal' ), 'id' => 'news_portal_left_sidebar', 'description' => esc_html__( 'Add widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register header ads area * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Header Ads', 'news-portal' ), 'id' => 'news_portal_header_ads_area', 'description' => esc_html__( 'Add banner widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register home top section area * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Home Top Section', 'news-portal' ), 'id' => 'news_portal_home_top_section_area', 'description' => esc_html__( 'Add widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register home middle section area * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Home Middle Section', 'news-portal' ), 'id' => 'news_portal_home_middle_section_area', 'description' => esc_html__( 'Add widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register home middle aside area * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Home Middle Aside', 'news-portal' ), 'id' => 'news_portal_home_middle_aside_area', 'description' => esc_html__( 'Add widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register home bottom section area * * @since 1.0.0 */ register_sidebar( array( 'name' => esc_html__( 'Home Bottom Section', 'news-portal' ), 'id' => 'news_portal_home_bottom_section_area', 'description' => esc_html__( 'Add widgets here.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); /** * Register 4 different footer area * * @since 1.0.0 */ register_sidebars( 4 , array( 'name' => esc_html__( 'Footer %d', 'news-portal' ), 'id' => 'news_portal_footer_sidebar', 'description' => esc_html__( 'Added widgets are display at Footer Widget Area.', 'news-portal' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'news_portal_widgets_init' ); /*-----------------------------------------------------------------------------------------------------------------------*/ /** * Register different widgets * * @since 1.1.8 */ add_action( 'widgets_init', 'news_portal_register_widgets' ); function news_portal_register_widgets() { // Ads Banner widget register_widget( 'News_Portal_Ads_Banner' ); // Block Posts widget register_widget( 'News_Portal_Block_Posts' ); // Carousel widget register_widget( 'News_Portal_Carousel' ); // Default Tabbed widget register_widget( 'News_Portal_Default_Tabbed' ); // Featured Posts widget register_widget( 'News_Portal_Featured_Posts' ); // Featured Slider widget register_widget( 'News_Portal_Featured_Slider' ); // Recent Posts widget register_widget( 'News_Portal_Recent_Posts' ); // Social Media widget register_widget( 'News_Portal_Social_Media' ); } /*-----------------------------------------------------------------------------------------------------------------------*/ /** * Load widget required files * * @since 1.0.0 */ require get_template_directory() . '/inc/widgets/np-widget-fields.php'; // Widget fields require get_template_directory() . '/inc/widgets/np-ads-banner.php'; // Ads banner widget require get_template_directory() . '/inc/widgets/np-featured-slider.php'; // Featured Slider widget require get_template_directory() . '/inc/widgets/np-featured-posts.php'; // Featured posts widget require get_template_directory() . '/inc/widgets/np-block-posts.php'; // Block posts widget require get_template_directory() . '/inc/widgets/np-carousel.php'; // Carousel widget require get_template_directory() . '/inc/widgets/np-social-media.php'; // Social Media widget require get_template_directory() . '/inc/widgets/np-recent-posts.php'; // Recent Posts widget require get_template_directory() . '/inc/widgets/np-default-tabbed.php'; // Default Tabbed widget