<?php
/**
 * Custom Functions.
 *
 * @package Modern Art Gallery
 */

if( !function_exists( 'modern_art_gallery_fonts_url' ) ) :

    //Google Fonts URL
    function modern_art_gallery_fonts_url(){

        $modern_art_gallery_font_families = array(
            'DM+Serif+Display',
            'Work+Sans:ital,wght@0,100..900;1,100..900',
        );

        $modern_art_gallery_fonts_url = add_query_arg( array(
            'family' => implode( '&family=', $modern_art_gallery_font_families ),
            'display' => 'swap',
        ), 'https://fonts.googleapis.com/css2' );

        return esc_url_raw($modern_art_gallery_fonts_url);
    }

endif;

if ( ! function_exists( 'modern_art_gallery_sub_menu_toggle_button' ) ) :

    function modern_art_gallery_sub_menu_toggle_button( $modern_art_gallery_args, $modern_art_gallery_item, $depth ) {

        // Add sub menu toggles to the main menu with toggles
        if ( $modern_art_gallery_args->theme_location == 'modern-art-gallery-primary-menu' && isset( $modern_art_gallery_args->show_toggles ) ) {
            
            // Wrap the menu item link contents in a div, used for positioning
            $modern_art_gallery_args->before = '<div class="submenu-wrapper">';
            $modern_art_gallery_args->after  = '';

            // Add a toggle to items with children
            if ( in_array( 'menu-item-has-children', $modern_art_gallery_item->classes ) ) {

                $toggle_target_string = '.menu-item.menu-item-' . $modern_art_gallery_item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $modern_art_gallery_args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="250" aria-expanded="false"><span class="btn__content" tabindex="-1"><span class="screen-reader-text">' . esc_html__( 'Show sub menu', 'modern-art-gallery' ) . '</span>' . modern_art_gallery_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

            // Close the wrapper
            $modern_art_gallery_args->after .= '</div><!-- .submenu-wrapper -->';
            // Add sub menu icons to the main menu without toggles (the fallback menu)

        }elseif( $modern_art_gallery_args->theme_location == 'modern-art-gallery-primary-menu' ) {

            if ( in_array( 'menu-item-has-children', $modern_art_gallery_item->classes ) ) {

                $modern_art_gallery_args->before = '<div class="link-icon-wrapper">';
                $modern_art_gallery_args->after  = modern_art_gallery_get_theme_svg( 'chevron-down' ) . '</div>';

            } else {

                $modern_art_gallery_args->before = '';
                $modern_art_gallery_args->after  = '';

            }

        }

        return $modern_art_gallery_args;

    }

endif;

add_filter( 'nav_menu_item_args', 'modern_art_gallery_sub_menu_toggle_button', 10, 3 );

if ( ! function_exists( 'modern_art_gallery_the_theme_svg' ) ):
    
    function modern_art_gallery_the_theme_svg( $modern_art_gallery_svg_name, $modern_art_gallery_return = false ) {

        if( $modern_art_gallery_return ){

            return modern_art_gallery_get_theme_svg( $modern_art_gallery_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in modern_art_gallery_get_theme_svg();.

        }else{

            echo modern_art_gallery_get_theme_svg( $modern_art_gallery_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in modern_art_gallery_get_theme_svg();.

        }
    }

endif;

if ( ! function_exists( 'modern_art_gallery_get_theme_svg' ) ):

    function modern_art_gallery_get_theme_svg( $modern_art_gallery_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $modern_art_gallery_svg = wp_kses(
            modern_art_gallery_SVG_Icons::get_svg( $modern_art_gallery_svg_name ),
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
                'polyline' => array(
                    'fill'      => true,
                    'points'    => true,
                ),
                'line' => array(
                    'fill'      => true,
                    'x1'      => true,
                    'x2' => true,
                    'y1'    => true,
                    'y2' => true,
                ),
            )
        );
        if ( ! $modern_art_gallery_svg ) {
            return false;
        }
        return $modern_art_gallery_svg;

    }

endif;

if( !function_exists( 'modern_art_gallery_post_category_list' ) ) :

    // Post Category List.
    function modern_art_gallery_post_category_list( $modern_art_gallery_select_cat = true ){

        $modern_art_gallery_post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );

        $modern_art_gallery_post_cat_cat_array = array();
        if( $modern_art_gallery_select_cat ){

            $modern_art_gallery_post_cat_cat_array[''] = esc_html__( '-- Select Category --','modern-art-gallery' );

        }

        foreach ( $modern_art_gallery_post_cat_lists as $modern_art_gallery_post_cat_list ) {

            $modern_art_gallery_post_cat_cat_array[$modern_art_gallery_post_cat_list->slug] = $modern_art_gallery_post_cat_list->name;

        }

        return $modern_art_gallery_post_cat_cat_array;
    }

endif;

if( !function_exists('modern_art_gallery_single_post_navigation') ):

    function modern_art_gallery_single_post_navigation(){

        $modern_art_gallery_default = modern_art_gallery_get_default_theme_options();
        $modern_art_gallery_twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'twp_disable_ajax_load_next_post', true ) );
        $modern_art_gallery_current_id = '';
        $article_wrap_class = '';
        global $post;
        $modern_art_gallery_current_id = $post->ID;
        if( $modern_art_gallery_twp_navigation_type == '' || $modern_art_gallery_twp_navigation_type == 'global-layout' ){
            $modern_art_gallery_twp_navigation_type = get_theme_mod('twp_navigation_type', $modern_art_gallery_default['twp_navigation_type']);
        }

        if( $modern_art_gallery_twp_navigation_type != 'no-navigation' && 'post' === get_post_type() ){

            if( $modern_art_gallery_twp_navigation_type == 'theme-normal-navigation' ){ ?>

                <div class="navigation-wrapper">
                    <?php
                    // Previous/next post navigation.
                    the_post_navigation(array(
                        'prev_text' => '<span class="arrow" aria-hidden="true">' . modern_art_gallery_the_theme_svg('arrow-left',$modern_art_gallery_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'modern-art-gallery') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . modern_art_gallery_the_theme_svg('arrow-right',$modern_art_gallery_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'modern-art-gallery') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

                $modern_art_gallery_next_post = get_next_post();
                if( isset( $modern_art_gallery_next_post->ID ) ){

                    $modern_art_gallery_next_post_id = $modern_art_gallery_next_post->ID;
                    echo '<div loop-count="1" next-post="' . absint( $modern_art_gallery_next_post_id ) . '" class="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'modern_art_gallery_navigation_action','modern_art_gallery_single_post_navigation',30 );

if( !function_exists('modern_art_gallery_content_offcanvas') ):

    // Offcanvas Contents
    function modern_art_gallery_content_offcanvas(){ ?>

        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">
                <div class="close-offcanvas-menu">
                    <div class="offcanvas-close">
                        <a href="javascript:void(0)" class="skip-link-menu-start"></a>
                        <button type="button" class="button-offcanvas-close">
                            <span class="offcanvas-close-label">
                                <?php echo esc_html__('Close', 'modern-art-gallery'); ?>
                            </span>
                        </button>
                    </div>
                </div>
                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'modern-art-gallery'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('modern-art-gallery-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'modern-art-gallery-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            }else{

                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_sub_menu_icons' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new Modern_Art_Gallery_Walker_Page(),
                                    )
                                );
                            }
                            ?>
                        </ul>
                    </nav><!-- .primary-menu-wrapper -->
                </div>
                <a href="javascript:void(0)" class="skip-link-menu-end"></a>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'modern_art_gallery_before_footer_content_action','modern_art_gallery_content_offcanvas',30 );

if( !function_exists('modern_art_gallery_footer_content_widget') ):

    function modern_art_gallery_footer_content_widget(){
        
        $modern_art_gallery_default = modern_art_gallery_get_default_theme_options();
        
        $modern_art_gallery_footer_column_layout = absint(get_theme_mod('modern_art_gallery_footer_column_layout', $modern_art_gallery_default['modern_art_gallery_footer_column_layout']));
        $modern_art_gallery_footer_sidebar_class = 12;
        
        if($modern_art_gallery_footer_column_layout == 2) {
            $modern_art_gallery_footer_sidebar_class = 6;
        }
        
        if($modern_art_gallery_footer_column_layout == 3) {
            $modern_art_gallery_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('modern_art_gallery_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $modern_art_gallery_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($modern_art_gallery_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'modern-art-gallery-footer-widget-' . $i ) ) : 

                                    if ($i === 0) : ?>
                                        <div id="media_image-3" class="widget widget_media_image">
                                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/logo.png'); ?>" alt="Footer Image" style="max-width: 100%; height: auto;">
                                        </div>
                                        <div id="text-3" class="widget widget_text">
                                            <div class="textwidget">
                                                <p class="widget-title">
                                                    <?php esc_html_e('The Modern Art Gallery WordPress Theme is a sleek, visually striking, and feature-rich theme designed for artists, art galleries, and creative professionals looking to establish a powerful online presence. Perfect for showcasing fine art, digital illustrations, photography, or contemporary artwork, this artistic WordPress theme offers a clean and elegant layout that enhances the presentation of any visual medium. Built specifically for online art galleries, painter portfolios, and creative exhibition platforms, the theme includes beautifully structured grid layouts, fullscreen art showcases, and interactive gallery blocks.', 'modern-art-gallery'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'modern-art-gallery'); ?></h2>
                                            <?php get_calendar(); ?>
                                        </div>

                                    <?php elseif ($i === 2) : ?>
                                        <div id="search-2" class="widget widget_search">
                                            <h2 class="widget-title"><?php esc_html_e('Enter Keywords Here', 'modern-art-gallery'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('modern-art-gallery-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

                    </div>
                </div>
            </div>
        <?php endif; ?> 

    <?php
    }

endif;

add_action( 'modern_art_gallery_footer_content_action', 'modern_art_gallery_footer_content_widget', 10 );

if( !function_exists('modern_art_gallery_footer_content_info') ):

    /**
     * Footer Copyright Area
    **/
    function modern_art_gallery_footer_content_info(){

        $modern_art_gallery_default = modern_art_gallery_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <div class="column-row">

                    <div class="column column-9">
                        <div class="footer-credits">

                            <div class="footer-copyright">

                                <?php
                                $modern_art_gallery_footer_copyright_text = wp_kses_post( get_theme_mod( 'modern_art_gallery_footer_copyright_text', $modern_art_gallery_default['modern_art_gallery_footer_copyright_text'] ) );
                                    echo esc_html( $modern_art_gallery_footer_copyright_text );
                                    echo '<br>';

                                    echo esc_html__('Theme: ', 'modern-art-gallery') . '<a href="' . esc_url('https://www.omegathemes.com/products/modern-art-gallery') . '" title="' . esc_attr__('Modern Art Gallery', 'modern-art-gallery') . '" target="_blank"><span>' . esc_html__('Modern Art Gallery ', 'modern-art-gallery') . '</span></a>' . esc_html__(' By ', 'modern-art-gallery') . '  <span>' . esc_html__('OMEGA ', 'modern-art-gallery') . '</span>';

                                    echo esc_html__('Powered by ', 'modern-art-gallery') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'modern-art-gallery') . '" target="_blank"><span>' . esc_html__('WordPress.', 'modern-art-gallery') . '</span></a>';
                                 ?>

                            </div>
                        </div>
                    </div>


                    <div class="column column-3 align-text-right">
                        <a class="to-the-top" href="#site-header">
                            <span class="to-the-top-long">
                                <?php if ( get_theme_mod('modern_art_gallery_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $modern_art_gallery_to_the_top_text = get_theme_mod( 'modern_art_gallery_to_the_top_text', __( 'To the Top', 'modern-art-gallery' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $modern_art_gallery_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>

                    </div>
                </div>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'modern_art_gallery_footer_content_action','modern_art_gallery_footer_content_info',20 );


if( !function_exists( 'modern_art_gallery_main_slider' ) ) :

    function modern_art_gallery_main_slider(){

        $modern_art_gallery_defaults = modern_art_gallery_get_default_theme_options();
        $modern_art_gallery_header_banner = get_theme_mod( 'modern_art_gallery_header_banner', $modern_art_gallery_defaults['modern_art_gallery_header_banner'] );
        $modern_art_gallery_header_banner_cat = get_theme_mod( 'modern_art_gallery_header_banner_cat' );

        if( $modern_art_gallery_header_banner ){

            $modern_art_gallery_rtl = '';
            if( is_rtl() ){
                $modern_art_gallery_rtl = 'dir="rtl"';
            }

            $modern_art_gallery_banner_query = new WP_Query( array('post_type' => 'post', 'posts_per_page' => 4,'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html( $modern_art_gallery_header_banner_cat ) ) );
            $modern_art_gallery_slider_section_short_title = get_theme_mod( 'modern_art_gallery_slider_section_short_title', 
            $modern_art_gallery_defaults['modern_art_gallery_slider_section_short_title'] );

            $modern_art_gallery_slider_section_extra_content = get_theme_mod( 'modern_art_gallery_slider_section_extra_content', 
            $modern_art_gallery_defaults['modern_art_gallery_slider_section_extra_content'] );

          if( $modern_art_gallery_banner_query->have_posts() ): ?>

            <div class="theme-custom-block theme-banner-block">
                <div class="slider-box">
                    <div class="wrapper">
                        <div class="swiper-container theme-main-carousel swiper-container" <?php echo $modern_art_gallery_rtl; ?>>
                            <div class="swiper-wrapper">
                              <?php
                              while( $modern_art_gallery_banner_query->have_posts() ):
                                $modern_art_gallery_banner_query->the_post();
                                $modern_art_gallery_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                                $modern_art_gallery_default_image = get_template_directory_uri() . '/assets/images/banner.png'; // Replace with the actual path to your default image
                                $modern_art_gallery_featured_image = isset( $modern_art_gallery_featured_image[0] ) ? $modern_art_gallery_featured_image[0] : $modern_art_gallery_default_image;?>
                                <div class="swiper-slide main-carousel-item">
                                    <div class="theme-article-post">
                                        <div class="main-carousel-caption">
                                            <div class="post-content ">
                                                <header class="entry-header">
                                                    <h2 class="entry-title entry-title-big">
                                                        <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php the_title(); ?></span></a>
                                                    </h2>
                                                </header>
                                                <div class="entry-content">
                                                    <?php
                                                        if (has_excerpt()) {

                                                            the_excerpt();

                                                        } else {

                                                        echo esc_html(wp_trim_words(get_the_content(), 25, '...'));

                                                    } ?>
                                                </div>
                                                <div class="slide-btn">
                                                    <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary">
                                                        <?php echo esc_html__( 'Know More', 'modern-art-gallery' ); ?>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="entry-thumbnail">
                                            <div class="data-bg data-bg-medium" data-background="<?php echo esc_url($modern_art_gallery_featured_image); ?>">
                                                <a href="<?php the_permalink(); ?>" class="theme-image-responsive" tabindex="0"></a>
                                            </div>
                                          <?php modern_art_gallery_post_format_icon(); ?>
                                        </div>
                                    </div>
                                </div>
                              <?php endwhile; ?>
                            </div>
                            <div class="swiper-pagination"></div>                  
                        </div>
                        <h6 class="extra-title">
                            <?php echo esc_html( $modern_art_gallery_slider_section_short_title ); ?>
                        </h6>
                        <p class="extra-content">
                            <?php echo esc_html( $modern_art_gallery_slider_section_extra_content ); ?>
                        </p>
                    </div>
                </div>
                <?php $modern_art_gallery_total_slides = $modern_art_gallery_banner_query->post_count; ?>
                <div class="custom-navigation">
                    <div class="swiper-button-prev custom-prev">
                        <span class="arrow"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M257.5 445.1l-22.2 22.2c-9.4 9.4-24.6 9.4-33.9 0L7 273c-9.4-9.4-9.4-24.6 0-33.9L201.4 44.7c9.4-9.4 24.6-9.4 33.9 0l22.2 22.2c9.5 9.5 9.3 25-.4 34.3L136.6 216H424c13.3 0 24 10.7 24 24v32c0 13.3-10.7 24-24 24H136.6l120.5 114.8c9.8 9.3 10 24.8 .4 34.3z"/></svg></span>
                        <span class="text"><?php esc_html_e('Prev','modern-art-gallery'); ?></span>
                    </div>
                    <div class="custom-pagination">
                        <span class="current"><?php esc_html_e('1','modern-art-gallery'); ?></span> / <span class="total"><?php echo esc_html($modern_art_gallery_total_slides); ?></span>
                    </div>
                    <div class="swiper-button-next custom-next">
                        <span class="arrow"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z"/></svg></span>
                        <span class="text"><?php esc_html_e('Next','modern-art-gallery'); ?></span>
                        
                    </div>
                </div>
            </div>


          <?php
          wp_reset_postdata();
          endif;

        }

    }

endif;

if (!function_exists('modern_art_gallery_post_format_icon')):

    // Post Format Icon.
    function modern_art_gallery_post_format_icon() {

        $modern_art_gallery_format = get_post_format(get_the_ID()) ?: 'standard';
        $modern_art_gallery_icon = '';
        $modern_art_gallery_title = '';
        if( $modern_art_gallery_format == 'video' ){
            $modern_art_gallery_icon = modern_art_gallery_get_theme_svg( 'video' );
            $modern_art_gallery_title = esc_html__('Video','modern-art-gallery');
        }elseif( $modern_art_gallery_format == 'audio' ){
            $modern_art_gallery_icon = modern_art_gallery_get_theme_svg( 'audio' );
            $modern_art_gallery_title = esc_html__('Audio','modern-art-gallery');
        }elseif( $modern_art_gallery_format == 'gallery' ){
            $modern_art_gallery_icon = modern_art_gallery_get_theme_svg( 'gallery' );
            $modern_art_gallery_title = esc_html__('Gallery','modern-art-gallery');
        }elseif( $modern_art_gallery_format == 'quote' ){
            $modern_art_gallery_icon = modern_art_gallery_get_theme_svg( 'quote' );
            $modern_art_gallery_title = esc_html__('Quote','modern-art-gallery');
        }elseif( $modern_art_gallery_format == 'image' ){
            $modern_art_gallery_icon = modern_art_gallery_get_theme_svg( 'image' );
            $modern_art_gallery_title = esc_html__('Image','modern-art-gallery');
        }
        
        if (!empty($modern_art_gallery_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo modern_art_gallery_svg_escape($modern_art_gallery_icon); ?></span>
                <?php if( $modern_art_gallery_title ){ echo '<span class="post-format-label">'.esc_html( $modern_art_gallery_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'modern_art_gallery_svg_escape' ) ):

    /**
     * Get information about the SVG icon.
     *
     * @param string $modern_art_gallery_svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function modern_art_gallery_svg_escape( $modern_art_gallery_input ) {

        // Make sure that only our allowed tags and attributes are included.
        $modern_art_gallery_svg = wp_kses(
            $modern_art_gallery_input,
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
            )
        );

        if ( ! $modern_art_gallery_svg ) {
            return false;
        }

        return $modern_art_gallery_svg;

    }

endif;

if( !function_exists( 'modern_art_gallery_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function modern_art_gallery_sanitize_sidebar_option_meta( $modern_art_gallery_input ){

        $modern_art_gallery_metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $modern_art_gallery_input,$modern_art_gallery_metabox_options ) ){

            return $modern_art_gallery_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'modern_art_gallery_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function modern_art_gallery_sanitize_pagination_meta( $modern_art_gallery_input ){

        $modern_art_gallery_metabox_options = array( 'Center','Right','Left');
        if( in_array( $modern_art_gallery_input,$modern_art_gallery_metabox_options ) ){

            return $modern_art_gallery_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'modern_art_gallery_aboutus_slider' ) ) :

    function modern_art_gallery_aboutus_slider(){

        $modern_art_gallery_defaults = modern_art_gallery_get_default_theme_options();
        $modern_art_gallery_services = get_theme_mod( 'modern_art_gallery_services', $modern_art_gallery_defaults['modern_art_gallery_services'] );

        $modern_art_gallery_our_team_section_title = get_theme_mod( 'modern_art_gallery_our_team_section_title', 
        $modern_art_gallery_defaults['modern_art_gallery_our_team_section_title'] );

        $modern_art_gallery_our_team_section_short_title = get_theme_mod( 'modern_art_gallery_our_team_section_short_title', 
        $modern_art_gallery_defaults['modern_art_gallery_our_team_section_short_title'] );
        
        if( $modern_art_gallery_services ){ ?>
        <div class="theme-product-block">
            <div class="wrapper">
                <div class="team-left-content">
                    <?php if( $modern_art_gallery_our_team_section_short_title ){ ?>
                        <h6><?php echo esc_html( $modern_art_gallery_our_team_section_short_title ); ?></h6>
                    <?php } ?>
                    <?php if( $modern_art_gallery_our_team_section_title ){ ?>
                        <h2><?php echo esc_html( $modern_art_gallery_our_team_section_title ); ?></h2>
                    <?php } ?>
                </div>
                <div class="tab-box">
                    <!-- Tab Header -->
                    <div class="tab-header">
                        <?php
                        for ($i = 1; $i <= 4; $i++) {
                            $modern_art_gallery_tab_title = get_theme_mod('modern_art_gallery_price_list_tab_title' . $i);
                            if ($modern_art_gallery_tab_title) {
                                echo '<div class="tab-item ' . (($i == 1) ? 'active' : '') . '" onclick="modern_art_gallery_showTabContent(' . $i . ')">' . esc_html($modern_art_gallery_tab_title) . '</div>';
                            }
                        }
                        ?>
                    </div>
                    <!-- Tab Content -->
                    <?php if( get_theme_mod('modern_art_gallery_category_tab1')  || get_theme_mod('modern_art_gallery_category_tab2') || get_theme_mod('modern_art_gallery_category_tab3') || get_theme_mod('modern_art_gallery_category_tab4') ) { ?>
                    <div class="tabcontent">
                        <?php

                        // Separate post query outside the tab content loop
                        $modern_art_gallery_header_pricing_plans_cats = array(
                            get_theme_mod('modern_art_gallery_category_tab1'),
                            get_theme_mod('modern_art_gallery_category_tab2'),
                            get_theme_mod('modern_art_gallery_category_tab3'),
                            get_theme_mod('modern_art_gallery_category_tab4')
                        );

                        for ($i = 1; $i <= 4; $i++) {
                            $category_slug = esc_html($modern_art_gallery_header_pricing_plans_cats[$i - 1]);

                            $modern_art_gallery_tab_banner_query = new WP_Query(array(
                                'post_type' => 'post',
                                'posts_per_page' => 6,
                                'post__not_in' => get_option("sticky_posts"),
                                'category_name' => $category_slug
                            ));

                            if ($modern_art_gallery_tab_banner_query->have_posts()) :
                                echo '<div class="tab-content" id="tab-content-' . $i . '">'; ?>
                                <div class="post-main-content owl-carousel"> 
                                    <?php
                                    $s=1;
                                    while( $modern_art_gallery_tab_banner_query->have_posts() ):
                                    $modern_art_gallery_tab_banner_query->the_post();
                                    $modern_art_gallery_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                                    $modern_art_gallery_featured_image = isset( $modern_art_gallery_featured_image[0] ) ? $modern_art_gallery_featured_image[0] : ''; 

                                    $modern_art_gallery_team_section_designation = esc_html( get_theme_mod( 'modern_art_gallery_team_section_designation'.$s ) );

                                    ?> 
                                                          
                                    <div class="theme-article-post slider-post-content ">
                                        <div class="entry-thumbnail">
                                            <div class="data-bg featured-img" data-background="<?php echo esc_url($modern_art_gallery_featured_image ? $modern_art_gallery_featured_image : get_template_directory_uri() . '/assets/images/default.png'); ?>">
                                            </div>
                                            <?php modern_art_gallery_post_format_icon(); ?>
                                        </div>
                                        <div class="main-owl-caption">
                                            <div class=" post-content-location">
                                                <header class="entry-header">
                                                    <h2 class="entry-title entry-title-big">
                                                        <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php the_title(); ?></span></a>
                                                    </h2> 
                                                    <a class="banner-btn" href="<?php the_permalink(); ?>"><?php echo esc_html('Read More','modern-art-gallery'); ?></a>
                                                </header>
                                            </div>
                                        </div>
                                    </div>
                                    <?php $s++; endwhile; 
                                                echo '</div>';
                                                echo '</div>';
                                                wp_reset_postdata();
                                            endif;
                                        } ?>
                                </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
        <?php } ?>
            
    <?php }


endif;

if( !function_exists( 'modern_art_gallery_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function modern_art_gallery_sanitize_menu_transform( $modern_art_gallery_input ){

        $modern_art_gallery_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $modern_art_gallery_input,$modern_art_gallery_metabox_options ) ){

            return $modern_art_gallery_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'modern_art_gallery_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function modern_art_gallery_sanitize_page_content_alignment( $modern_art_gallery_input ){

        $modern_art_gallery_metabox_options = array( 'left','center','right');
        if( in_array( $modern_art_gallery_input,$modern_art_gallery_metabox_options ) ){

            return $modern_art_gallery_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'modern_art_gallery_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function modern_art_gallery_sanitize_footer_widget_title_alignment( $modern_art_gallery_input ){

        $modern_art_gallery_metabox_options = array( 'left','center','right');
        if( in_array( $modern_art_gallery_input,$modern_art_gallery_metabox_options ) ){

            return $modern_art_gallery_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'modern_art_gallery_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $modern_art_gallery_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function modern_art_gallery_sanitize_pagination_type( $modern_art_gallery_input ) {
        // Define valid options for the pagination type.
        $modern_art_gallery_valid_options = array( 'numeric', 'newer_older' ); // Update valid options to include 'newer_older'

        // If the input is one of the valid options, return it. Otherwise, return the default option ('numeric').
        if ( in_array( $modern_art_gallery_input, $modern_art_gallery_valid_options, true ) ) {
            return $modern_art_gallery_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;

// Sanitize the enable/disable setting for pagination
if( !function_exists('modern_art_gallery_sanitize_enable_pagination') ) :
    function modern_art_gallery_sanitize_enable_pagination( $modern_art_gallery_input ) {
        return (bool) $modern_art_gallery_input;
    }
endif;

if( !function_exists( 'modern_art_gallery_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function modern_art_gallery_sanitize_copyright_alignment_meta( $modern_art_gallery_input ){

        $modern_art_gallery_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $modern_art_gallery_input,$modern_art_gallery_metabox_options ) ){

            return $modern_art_gallery_input;

        }else{

            return '';

        }
    }

endif;

/**
 * Sidebar Layout Function
 */
function modern_art_gallery_get_final_sidebar_layout() {
	$modern_art_gallery_defaults       = modern_art_gallery_get_default_theme_options();
	$modern_art_gallery_global_layout  = get_theme_mod('modern_art_gallery_global_sidebar_layout', $modern_art_gallery_defaults['modern_art_gallery_global_sidebar_layout']);
	$modern_art_gallery_page_layout    = get_theme_mod('modern_art_gallery_page_sidebar_layout', $modern_art_gallery_global_layout);
	$modern_art_gallery_post_layout    = get_theme_mod('modern_art_gallery_post_sidebar_layout', $modern_art_gallery_global_layout);
	$modern_art_gallery_meta_layout    = get_post_meta(get_the_ID(), 'modern_art_gallery_post_sidebar_option', true);

	if (!empty($modern_art_gallery_meta_layout) && $modern_art_gallery_meta_layout !== 'default') {
		return $modern_art_gallery_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $modern_art_gallery_page_layout;
	}
	if (is_single()) {
		return $modern_art_gallery_post_layout;
	}
	return $modern_art_gallery_global_layout;
}