<?php
add_filter('widget_nav_menu_args', 'add_custom_nav_class_and_walker', 10, 4);
function add_custom_nav_class_and_walker($args, $nav_menu, $args_input, $instance) {
	// Check if this is the specific sidebar/widget you want to modify
	if (is_active_sidebar('top-nav')) {
		$args['container'] = false;
		$args['menu_class'] = '';
		$args['fallback_cb'] = '__return_false';
		$args['items_wrap'] = '<ul id="wpstream_theme-navbar" class="navbar-nav %2$s">%3$s</ul>';
		$args['depth'] = 3;
		$args['walker'] = new WpStream_Bootstrap_5_Wp_Nav_Menu_Walker();
	}
	return $args;
}

/*
*
* Extetend main query for arhive to include all post types
*
*/

function wpstream_extend_category_archive_query( $query ) {

	if ( ! is_admin() && $query->is_main_query() ) {
		// Check if it's a category archive

		if ( $query->is_category() || $query->is_archive() || $query->is_taxonomy() ) {

			// Include an array of post types in category archive
			$post_type_array = apply_filters( 'wpstream_extend_category_archive_query_filter', array( 'post' ) );
			$query->set( 'post_type', $post_type_array );
		}
	}
}
add_action( 'pre_get_posts', 'wpstream_extend_category_archive_query', 99 );

if ( ! function_exists( 'wpstream_create_archive_lists' ) ) {
	/**
	 * Generate archive lists for a specific taxonomy and term.
	 *
	 * This function generates archive lists for a specific taxonomy and term,
	 * displaying posts for each associated post type.
	 *
	 * @param string $taxonomy The taxonomy name.
	 * @param string $term     The term slug.
	 * @return string HTML content for the archive lists.
	 */
	function wpstream_create_archive_lists( $taxonomy, $term, $selected_item_post_type ) {
		$tax_array = wpstream_return_taxonomy_array();
		$nav_items = '';
		$nav_tabs  = '';
		$is_active = 'active';
		$is_show   = 'show';
		$is_true   = 'true';

		if ( $selected_item_post_type !== '' ) {
			$is_active = '';
			$is_show   = '';
			$is_true   = '';

		}

		$taxonomy_labels = apply_filters( 'wpstream_archives_lists_taxonomy_labels', array(
			'post' => esc_html__( 'Blog Posts', 'hello-wpstream' ),
		) );

		foreach ( $tax_array[ $taxonomy ] as $key => $item_post_type ) :
			$posts_per_page = get_option( 'posts_per_page' );
			$paged          = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

			$tax_array = array(
				'taxonomy' => $taxonomy,
				'field'    => 'slug',
				'terms'    => $term,
			);

			$args = array(
				'post_type'      => $item_post_type,
				'post_status'    => 'publish',
				'paged'          => $paged,
				'posts_per_page' => $posts_per_page,
				'tax_query'      => array(//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
					$tax_array,
				),
                's'              => '',
			);

			if ( $selected_item_post_type === $item_post_type ) {
				$is_active = 'active';
				$is_show   = 'show';
				$is_true   = 'true';
			}

			$use_transient = wpstream_theme_return_use_transient();
			$transient_key = 'wpstream_archive_' . $taxonomy . '_' . $term;

			$query = wpstream_theme_custom_query( $args, $transient_key, false );
			$wpstream_archive_items_per_row        = intval( get_theme_mod( 'wpstream_archive_items_per_row', 3 ) );
			$overwrite_wpstream_cols_name 			= wpstream_blog_column_class( $wpstream_archive_items_per_row );
	
		
			$card_grid_class_overwrite = wpstream_blog_column_class( $wpstream_archive_items_per_row );

			if ( $query->found_posts > 0 ) {
				$nav_items .= '<li class="nav-item" role="presentation">
				<button class="nav-link ' . esc_attr( $is_active ) . '" id="pills-' . esc_attr( $item_post_type ) . '-tab" data-bs-toggle="pill" data-bs-target="#pills-' . esc_attr( $item_post_type ) . '" type="button" role="tab" aria-controls="pills-' . esc_attr( $item_post_type ) . '" aria-selected="' . esc_attr( $is_true ) . '">' . $taxonomy_labels[ $item_post_type ] . '</button>
				</li>';

				ob_start();
				?>


				<div class="row">
					<?php

					while ( $query->have_posts() ) :
						$query->the_post();
						if ( $item_post_type === 'post' ) {
							$blog_unit_card_type = wpstream_blog_post_card_selector( );
							include locate_template( $blog_unit_card_type );
						} else {
							if ( class_exists( 'Wpstream_Player' ) ) {
								$unit_card_type = wpstream_video_item_card_selector();
								include locate_template($unit_card_type);
							}
						}

						endwhile;
					?>

				</div>
				
				<footer class="entry-footer">
					<?php wpstream_theme_pagination_for_taxonmies( $query->found_posts, $item_post_type ); ?>
				</footer>


				<?php
				$content = ob_get_contents();

				ob_end_clean();

				$nav_tabs .= ' <div class="tab-pane fade  ' . esc_attr( $is_show ) . '  ' . esc_attr( $is_active ) . '" id="pills-' . esc_attr( $item_post_type ) . '" role="tabpanel" aria-labelledby="pills-' . esc_attr( $item_post_type ) . '-tab">' . $content . '</div>';
				$is_active = '';
				$is_show   = '';
				$is_true   = 'false';
			}

			wp_reset_postdata();
			wp_reset_query();

		endforeach;

		$return_string  = '<ul class="nav nav-pills mb-3" id="wpstream-pills-tab-archive" role="tablist">' . $nav_items . '</ul>';
		$return_string .= '<div class="tab-content" id="wpstream-pills-tab-archiveContent">' . $nav_tabs . '</div>';

		return $return_string;
	}
}




if ( ! function_exists( 'wpstream_create_author_archive_lists' ) ) {
	/**
	 * Generate archive lists for a specific taxonomy and term.
	 *
	 * This function generates archive lists for a specific taxonomy and term,
	 * displaying posts for each associated post type.
	 *
	 * @param string $taxonomy The taxonomy name.
	 * @param string $term     The term slug.
	 * @return string HTML content for the archive lists.
	 */
	function wpstream_create_author_archive_lists(
            $author_id,
            $taxonomy,
            $term,
            $selected_item_post_type
    ) {
		$tax_array = wpstream_return_taxonomy_array();

		$nav_items = '';
		$nav_tabs  = '';
		$is_active = 'active';
		$is_show   = 'show';
		$is_true   = 'true';

		if ( $selected_item_post_type !== '' ) {
			$is_active = '';
			$is_show   = '';
			$is_true   = '';
		}

		$taxonomy_labels = apply_filters( 'wpstream_author_archive_list_taxonomy_labels', array(
			'post' => esc_html__( 'Blog Posts', 'hello-wpstream' ),
		) );

		foreach ( $tax_array[ 'category' ] as $key => $item_post_type ) :
			$posts_per_page = get_option( 'posts_per_page' );
			$paged          = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

			$tax_array = array(
				'taxonomy' => $taxonomy,
				'field'    => 'slug',
				'terms'    => $term,
			);

			$args = array(
				'post_type'      => $item_post_type,
				'author'		 => $author_id,
				'post_status'    => 'publish',
				'paged'          => $paged,
				'posts_per_page' => $posts_per_page,
                's'              => '',
			);

			if ( $selected_item_post_type === $item_post_type ) {
				$is_active = 'active';
				$is_show   = 'show';
				$is_true   = 'true';
			}

			$use_transient = wpstream_theme_return_use_transient();
			$transient_key = 'wpstream_author_'.$author_id .'_' . $taxonomy . '_' . $term;

            $query = wpstream_theme_custom_query( $args, $transient_key, false );

			$wpstream_archive_items_per_row        = intval( get_theme_mod( 'wpstream_archive_items_per_row', 3 ) );
			$overwrite_wpstream_cols_name 			= wpstream_blog_column_class( $wpstream_archive_items_per_row );

			
			$card_grid_class_overwrite = wpstream_blog_column_class( $wpstream_archive_items_per_row );

			if ( $query->found_posts > 0 ) {
				if ( $item_post_type === 'post' || ( $item_post_type !== 'post' && class_exists( 'Wpstream_Player' ) ) ) {
                    $nav_items .= '<li class="nav-item" role="presentation">
                    <button class="nav-link ' . esc_attr( $is_active ) . '" id="pills-' . esc_attr( $item_post_type ) . '-tab" data-bs-toggle="pill" data-bs-target="#pills-' . esc_attr( $item_post_type ) . '" type="button" role="tab" aria-controls="pills-' . esc_attr( $item_post_type ) . '" aria-selected="' . esc_attr( $is_true ) . '">' . $taxonomy_labels[ $item_post_type ] . '</button>
                    </li>';
				}

				ob_start();
				?>


				<div class="row">
					<?php

					while ( $query->have_posts() ) :
						$query->the_post();

						if ( $item_post_type === 'post' ) {
							$blog_unit_card_type = wpstream_blog_post_card_selector( );
							include locate_template( $blog_unit_card_type );
						} else {
							if ( class_exists( 'Wpstream_Player' ) ) {
								$unit_card_type = wpstream_video_item_card_selector();
								include locate_template($unit_card_type);
							}
						}

						endwhile;
					?>

				</div>

				<footer class="entry-footer">
					<?php wpstream_theme_pagination_for_taxonmies( $query->found_posts, $item_post_type ); ?>
				</footer>


				<?php
				$content = ob_get_contents();

				ob_end_clean();

				$nav_tabs .= ' <div class="tab-pane fade  ' . esc_attr( $is_show ) . '  ' . esc_attr( $is_active ) . '" id="pills-' . esc_attr( $item_post_type ) . '" role="tabpanel" aria-labelledby="pills-' . esc_attr( $item_post_type ) . '-tab">' . $content . '</div>';
				$is_active = '';
				$is_show   = '';
				$is_true   = 'false';
			}

			wp_reset_postdata();
			wp_reset_query();

		endforeach;

		$return_string  = '<ul class="nav nav-pills mb-3" id="wpstream-pills-tab-archive" role="tablist">' . $nav_items . '</ul>';
		$return_string .= '<div class="tab-content" id="wpstream-pills-tab-archiveContent">' . $nav_tabs . '</div>';

		return $return_string;
	}
}



/*
*
* Taxonomy array
*
*/

if ( ! function_exists( 'wpstream_return_taxonomy_array' ) ) {
	/**
	 * Return taxonomy array.
	 *
	 * @return array Taxonomy array.
	 */
	function wpstream_return_taxonomy_array() {
		$taxonomy_array = array(
			'category'  => array(
				'post',
				'product',
			),

			'post_tag'  => array(
				'post',
				'product',
			),
			'date'      => array(
				'post',
			),
		);

		return $taxonomy_array;
	}
}

if ( ! function_exists( 'wpstream_return_taxonomy_labels' ) ) {
	/**
	 * Return taxonomy labels.
	 *
	 * @return array Taxonomy labels.
	 */
	function wpstream_return_taxonomy_labels() {
		$taxonomy_array = array(
			'category'              => esc_html__( 'Category', 'hello-wpstream' ),
			'post_tag'              => esc_html__( 'Tags', 'hello-wpstream' ),
		);

		return $taxonomy_array;
	}
}

/**
 * Show add to cart button forVideo Collection
 */
add_action(
	'woocommerce_wpstream_bundle_add_to_cart',
	function () {
		do_action( 'woocommerce_simple_add_to_cart' );
	}
);

if ( ! function_exists( 'wpstream_display_bundle_items' ) ) {
	/**
	 * Display bundle items.
	 *
	 * @param int    $post_id   The post ID.
	 * @param string $post_type The post type.
	 * @return string           HTML string for bundle items.
	 */
	function wpstream_display_bundle_items( $post_id, $post_type = 'product' ) {
		$return_string             = '';
		$custom_field_values       = get_post_meta( $post_id, 'wpstream_bundle_selection', true );
		$custom_field_values_array = explode( ',', $custom_field_values );

		$args = array(
			'posts_per_page' => -1,
			'post__in'       => $custom_field_values_array,
			'post_type'      => $post_type,
		);

		$query = new WP_Query( $args );

		// Set Episode section is true or false.

		$is_episodes_vars = true;

		ob_start();

		include locate_template( 'template-parts/single/video-loop-content.php' );

		$return_string .= ob_get_contents();

		ob_end_clean();

		return $return_string;
	}
}

if ( ! function_exists( 'wpstream_theme_featured_image_simple' ) ) {
	/**
	 * Display the featured image for a post or page in a simple format.
	 *
	 * @param int    $post_id The ID of the post or page.
	 * @param string $size    Optional. The image size to retrieve. Default is 'full'.
	 * @param string $context Optional. The context in which the function is being used. Default is 'unit_card'.
	 * @return string         The HTML markup for the featured image.
	 */
	function wpstream_theme_featured_image_simple( $post_id, $size = 'full', $context = 'unit_card' ) {

		$featured_image_src = wpstream_theme_default_card_no_image_url( $size );

		// Check if a featured image is set for the current post or page.
		if ( has_post_thumbnail( $post_id ) ) {
			$featured_image_src = get_the_post_thumbnail_url( $post_id, $size );
		}

		$return_string = '<div class="post-thumbnail wpstream_featured_image">';

		$return_string .= '<img src="' . esc_url( $featured_image_src ) . '" class="wpstream_featured_unit_cards rounded mb-3" />';

		if ( 'unit_card' === $context ) {
			$views          = intval( get_post_meta( $post_id, 'post_view_count', true ) );
			$return_string .= '<div class="wpstream_featured_image_views">' . $views . ' ' . esc_html__( 'views', 'hello-wpstream' ) . '</div>';
		}

		$return_string .= '</div><!-- .post-thumbnail -->';

		return $return_string;
	}
}

if ( !function_exists( 'wpstream_blog_cards_column_class' ) ) {
	/**
	 * Determine the column classes for blog cards based on the number of columns per row.
	 *
	 * @param int $per_row The number of columns per row.
	 * @return string The string of column classes.
	 */
	function wpstream_blog_cards_column_class( $per_row ) {
		$per_row = intval( $per_row );
		$return = 'col-12 col-sm-6 col-md-4 col-lg-4';

		if ( 4 === $per_row ) {
			$return = 'col-12 col-sm-6 col-md-4 col-lg-3';
		}else if ( 2 === $per_row ) {
			$return = 'col-12 col-sm-6 col-md-6 col-lg-6';
		}else if ( 6 === $per_row ) {
			$return = 'col-12 col-sm-6 col-md-4 col-lg-3 col-xl-2';
		}else if ( 5 === $per_row ) {
			$return = 'col-12 col-sm-6 col-md-4 col-2-4';
		}
		return $return;
	}
}

if ( ! function_exists( 'wpstream_theme_featured_image' ) ) {
	/**
	 * Display the featured image for a post or page with additional functionality.
	 *
	 * @param int    $post_id The ID of the post or page.
	 * @param string $size    Optional. The image size to retrieve. Default is 'full'.
	 * @param string $context Optional. The context in which the function is being used. Default is 'unit_card'.
	 * @param bool   $link        Optional. Link to post.
	 * @param bool   $show_badge        Optional. Show badge.
	 * @return string         The HTML markup for the featured image.
	 */
	function wpstream_theme_featured_image( $post_id, $size = 'full', $context = 'unit_card', $link = false, $show_badge = false ) {
		$featured_image_src = wpstream_theme_default_card_no_image_url( $size );
		$featured_image_id  = get_post_thumbnail_id( $post_id );
		$featured_image_alt = get_post_meta( $featured_image_id, '_wp_attachment_image_alt', true );

		// Check if a featured image is set for the current post or page.

		if ( has_post_thumbnail( $post_id ) ) {
			$featured_image_src = get_the_post_thumbnail_url( $post_id, $size );
		}

		$video_attachment_id = get_post_meta( $post_id, 'video_preview', true );

		$return_string = '<div class="post-thumbnail wpstream_featured_image">';

		if ( $link ) {
			$return_string .= '<a class="d-block w-100 h-100" href="' . esc_url( get_permalink( $post_id ) ) . '">';
		}

		if ( ('unit_card' === $context || 'video_preview' === $context ) && '' !== $video_attachment_id ) {
			$video_id = 'wpstream_unit_video_preview_' . wp_rand( 0, 99999999 );

			$video_attachment_id = get_post_meta( $post_id, 'video_preview', true );

			$video_src = wp_get_attachment_url( $video_attachment_id );
			$play_button = $context === 'video_preview' ? '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('play_icon_white.svg') . '</div>' : "";

			if ($context === 'video_preview' && get_post_type($post_id) === 'post'){
				$play_button =  '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('bloghover.svg') . '</div>';
			}



			$return_string .= '<div class="wpstream_video_unit_video_wrapper wpstream_video_unit_video_wrapper_trigger" 
					data-video-id="'. esc_attr( $video_id ).'">'

				. $play_button 
				.'<div class="wpstream_video_unit_overlay"></div>'
				.'<video id="' . esc_attr( $video_id ) . '" class="wpstream_video_unit_video" preload="none" poster="' . esc_url( $featured_image_src ) . '" muted>
					<source src="' . esc_url( $video_src ) . '" type="video/mp4">
					Your browser does not support the video tag.
				</video>

			</div>';
		} else {
			if( get_post_type($post_id) === 'post' || !wpstream_is_woo_video_product( $post_id ) ){
				$play_button =  '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('bloghover.svg') . '</div>';
			}else{
				$play_button =  '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('play_icon_white.svg') . '</div>';
			}
		

			$return_string .= '<div class="wpstream_video_unit_overlay"></div>'. $play_button .'<img src="' . esc_url( $featured_image_src ) . '" alt="' . esc_attr( ! empty( $featured_image_alt ) ? $featured_image_alt : get_the_title( $post_id ) ) . '" class="wpstream_featured_unit_cards" />';
		}

		if ( $link ) {
			$return_string .= '</a>';
		}

		if ( 'unit_card' === $context || $show_badge ) {
			$views       = intval( get_post_meta( $post_id, 'post_view_count', true ) );
			$views_label = __( 'reads', 'hello-wpstream' );
			$return_string .= '<div class="wpstream_featured_image_views">' . $views . ' ' . esc_html( $views_label ) . '</div>';
		}

		if ( class_exists( 'Wpstream_Player' ) ) {
			$return_string .= wpstream_get_live_tag_html( $post_id );
        }

		$return_string .= '</div><!-- .post-thumbnail -->';

		return $return_string;
	}
}











if ( ! function_exists( 'wpstream_theme_return_gallery' ) ) {
	/**
	 * Return the gallery markup for a post or product.
	 *
	 * @param int    $post_id    The ID of the post or product.
	 * @param string $full_size  Optional. The image size for the full-size images. Default is 'full'.
	 * @param string $thumb_size Optional. The image size for the thumbnail images. Default is 'thumbnail'.
	 * @return string            The HTML markup for the gallery.
	 */
	function wpstream_theme_return_gallery( $post_id, $full_size = 'full', $thumb_size = 'thumbnail' ) {
		$post_type = get_post_type( $post_id );

		if ( 'product' === $post_type ) {
			$gallery_images_source = get_post_meta( $post_id, '_product_image_gallery', true );
			$gallery_images        = explode( ',', $gallery_images_source );
		} else {
			$gallery_images=null;
			if(function_exists('rwmb_meta')){
				$gallery_images = rwmb_meta( 'wpstream_theme_gallery', array(), $post_id );
				$gallery_images = array_keys( $gallery_images );
			}
		}

		return  wpstream_gallery_generate_slick_slider( $gallery_images, $full_size, $thumb_size );
	}
}

if ( ! function_exists( 'wpstream_gallery_generate_slick_slider' ) ) {
	/**
	 * Generate a slick slider gallery markup for given image IDs.
	 *
	 * @param array  $image_ids  Array of image IDs.
	 * @param string $full_size  Optional. The image size for the full-size images. Default is 'full'.
	 * @param string $thumb_size Optional. The image size for the thumbnail images. Default is 'thumbnail'.
	 * @return string            The HTML markup for the slick slider gallery.
	 */
	function wpstream_gallery_generate_slick_slider( $image_ids, $full_size = 'full', $thumb_size = 'thumbnail' ) {

		if ( empty( $image_ids ) ) {
			return;
		}

		$output  = '<div class="wpstream-gallery-slider-wrapper" >';
		$output .= '<div class="wpstream-gallery-slick-carousel" data-auto="0" >';

		// Generate carousel slides with images.
		foreach ( $image_ids as $image_id ) {
			$image_src = wp_get_attachment_image_src( $image_id, $full_size );
			$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
			$output   .= '<div class="slick-slide">';
			$output   .= '<img src="' . $image_src[0] . '" alt="' . $image_alt . '">';
			$output   .= '</div>';

		}

		$output .= '</div>'; // end slick carousel.
		$output .= '<div class="wpstream-slick-thumbnails">';

		// Generate thumbnails.
		foreach ( $image_ids as $image_id ) {
			$image_thumb = wp_get_attachment_image_src( $image_id, $thumb_size );
			$image_alt   = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
			$output     .= '<div class="wpstream-slick-thumbnail">';
			$output     .= '<img src="' . $image_thumb[0] . '" alt="' . $image_alt . '">';
			$output     .= '</div>';
		}

		$output .= '</div>'; // end slick thumbnails.
		$output .= '</div>'; // end wpstream-gallery-slider.
		$output .= '<script type="text/javascript">

		//<![CDATA[
		jQuery(document).ready(function(){
			wpstream_enable_gallery_slider();
		});
		//]]>

	</script>';

		return $output;
	}
}

if ( ! function_exists( 'wpstream_theme_show_social_share_page' ) ) {
	/**
	 * Display social share buttons for a given post.
	 *
	 * @param int    $post_id   The ID of the post.
	 * @param string $size      Optional. The size of the post image. Default is 'full'.
	 * @param int    $is_single Optional. Whether the post is single or not. Default is 1 (true).
	 * @return string           The HTML markup for the social share buttons.
	 */
	function wpstream_theme_show_social_share_page( $post_id, $size = 'full', $is_single = 1 ) {
		$return_string  = '<div class="wpstream-social-share-wrapper">';
		$return_string .= wpstream_share_unit_desing( $post_id, $size, $is_single );
		$return_string .= '</div>';

		return $return_string;
	}
}

if ( ! function_exists( 'wpstream_share_unit_desing' ) ) {
	/**
	 * Generate social share buttons HTML for a post.
	 *
	 * @param int    $post_id   The ID of the post.
	 * @param string $size      Optional. The size of the post image. Default is 'full'.
	 * @param int    $is_single Optional. Whether the post is single or not. Default is 0 (false).
	 * @return string           The HTML markup for the social share buttons.
	 */
	function wpstream_share_unit_desing( $post_id, $size = 'full', $is_single = 0 ) {
		$protocol       = is_ssl() ? 'https' : 'http';
		$pinterest      = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
		$link           = esc_url( get_permalink( $post_id ) );
		$title          = get_the_title( $post_id );
		$twitter_status = rawurlencode( $title . ' ' . $link );
		$email_link     = 'subject=' . rawurlencode( $title ) . '&body=' . rawurlencode( esc_url( $link ) );

		ob_start();

		$facebook_label  = '';
		$twitter_label   = '';
		$pinterest_label = '';
		$whatsup_label   = '';
		$email_label     = '';

		if ( intval( $is_single ) === 1 ) {
			$facebook_label  = esc_html__( 'Facebook', 'hello-wpstream' );
			$twitter_label   = esc_html__( 'Twitter', 'hello-wpstream' );
			$pinterest_label = esc_html__( 'Pinterest', 'hello-wpstream' );
			$whatsup_label   = esc_html__( 'WhatsApp', 'hello-wpstream' );
			$email_label     = esc_html__( 'Email', 'hello-wpstream' );
		}

		$text_whats = get_the_title( $post_id ) . ' ' . esc_url( get_permalink( $post_id ) );

		$whatsup_link = 'https://wa.me/?text=' . ( $text_whats );

		?>

		<div class="share_unit">
			<a href="<?php echo esc_url( $protocol . '://www.facebook.com/sharer.php?u=' . $link . '&amp;t=' . rawurlencode( get_the_title() ) ); ?>"
				target="_blank" rel="noreferrer noopener nofollow" class="social_facebook d-flex align-items-center">

				<?php echo wpstream_theme_get_svg_icon( 'facebook.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

				<?php echo esc_html( $facebook_label ); ?>

			</a>
			<a href="<?php echo esc_url( $protocol . '://twitter.com/intent/tweet?text=' . $twitter_status ); ?>"
				class="social_twitter d-flex align-items-center" rel="noreferrer noopener nofollow" target="_blank">

				<?php echo wpstream_theme_get_svg_icon( 'x_twitter.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

				<?php echo esc_html( $twitter_label ); ?>

			</a>
			<a href="<?php echo esc_url( $protocol . '://pinterest.com/pin/create/button/?url=' . $link . '&amp;media=' .
								( isset( $pinterest[0] ) ? esc_url( $pinterest[0] ) : '' ) .
					'&amp;description=' . rawurlencode( get_the_title() ) ); ?>" target="_blank"
				rel="noreferrer noopener nofollow" class="social_pinterest d-flex align-items-center">

				<?php echo wpstream_theme_get_svg_icon( 'pinterest.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

				<?php echo esc_html( $pinterest_label ); ?>

			</a>
			<a href="<?php echo esc_url( $whatsup_link ); ?>" class="social_whatsapp d-flex align-items-center"
				rel="noreferrer noopener nofollow" target="_blank">

				<?php echo wpstream_theme_get_svg_icon( 'whatsapp.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

				<?php echo esc_html( $whatsup_label ); ?>

			</a>
			<a href="mailto:email@email.com?<?php echo esc_attr( trim( $email_link ) ); ?>" data-action="share email"
				class="social_email d-flex align-items-center" rel="noreferrer noopener nofollow">

				<?php echo wpstream_theme_get_svg_icon( 'email.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

				<?php echo esc_html( $email_label ); ?>

			</a>
		</div>
		<?php

		return ob_get_clean();
	}
}

if ( ! function_exists( 'wpstream_theme_show_like_dislike' ) ) {
	/**
	 * Display the like and dislike icons for a given post.
	 *
	 * @param int $post_id The ID of the post.
	 * @return string HTML markup for displaying like and dislike icons.
	 */
	function wpstream_theme_show_like_dislike( $post_id ) {
		$return_string  = '<div class="wpstream-show-like-dislike-wrapper">';
		$return_string .= wpstream_theme_show_like_dislike_icons( $post_id );
		$return_string .= '</div>';

		return $return_string;
	}
}

if ( ! function_exists( 'wpstream_return_all_categories_array' ) ) {
	/**
	 * Return an array of all categories.
	 *
	 * @return array Array containing labels and taxonomies for all categories.
	 */
	function wpstream_return_all_categories_array() {
		return array(
			array(
				'label'    => esc_html__( 'Category', 'hello-wpstream' ),
				'taxonomy' => 'category',
			),

			array(
				'label'    => esc_html__( 'Tags', 'hello-wpstream' ),
				'taxonomy' => 'post_tag',
			),

			array(
				'label'    => esc_html__( 'Actors', 'hello-wpstream' ),
				'taxonomy' => 'wpstream_actors',
			),

			array(
				'label'    => esc_html__( 'Media Category', 'hello-wpstream' ),
				'taxonomy' => 'wpstream_category',

			),

			array(
				'label'    => esc_html__( 'Viwer Ratings', 'hello-wpstream' ),
				'taxonomy' => 'wpstream_movie_rating',
			),

			array(
				'label'    => esc_html__( 'Product Category', 'hello-wpstream' ),
				'taxonomy' => 'product_cat',
			),

			array(
				'label'    => esc_html__( 'Product Tags', 'hello-wpstream' ),
				'taxonomy' => 'product_tag',
			),

		);
	}
}

if ( ! function_exists( 'wpstream_theme_show_item_categories' ) ) {
	/**
	 * Display item categories.
	 *
	 * @param int $post_id The ID of the post.
	 * @return string HTML markup for displaying item categories.
	 */
	function wpstream_theme_show_item_categories( $post_id ) {

		$taxonomy_array = wpstream_return_all_categories_array();
		$return_string  = '';

		foreach ( $taxonomy_array as $key => $tax ) {

			$details = wpstream_theme_show_item_categories_list( $post_id, $tax['taxonomy'] );

			if ( trim( $details ) ) :
				$return_string .= '<div class="wpstream-vod-terms-content flex-md-nowrap flex-wrap">';
				$return_string .= '<div class="wpstream-vod-terms-title fw-700 w-100">';
				$return_string .= esc_html( $tax['label'] );
				$return_string .= '</div>';
				$return_string .= '<div class="wpstream-vod-terms-list">';
				$return_string .= $details;
				$return_string .= '</div>';
				$return_string .= '</div>';

			endif;

		}

		return $return_string;
	}
}

if ( ! function_exists( 'wpstream_theme_show_item_categories_list' ) ) {
	/**
	 * Display item categories list.
	 *
	 * @param int    $post_id  The ID of the post.
	 * @param string $taxonomy The taxonomy name.
	 * @return string HTML markup for displaying item categories list.
	 */
	function wpstream_theme_show_item_categories_list( $post_id, $taxonomy ) {
		$terms   = wp_get_post_terms( $post_id, $taxonomy );
		$display = '';

		if ( is_array( $terms ) ) :
			foreach ( $terms as $term ) {
				$display .= '<a  class="wpstream-theme-taxonomy-link tax-meta-style" href="' . esc_url( get_category_link( $term->term_id ) ) . '">' . esc_html( $term->name ) . '</a>';
			}
		endif;

		return rtrim( $display, '  ' );
	}
}

if ( ! function_exists( 'wpstream_theme_show_like_dislike_icons' ) ) {
	/**
	 * Display like and dislike icons for the given post.
	 *
	 * @param int $post_id The ID of the post.
	 * @return string HTML markup for displaying like and dislike icons.
	 */
	function wpstream_theme_show_like_dislike_icons( $post_id ) {
		$user_id          = get_current_user_id();
		$user_liked_items = get_user_meta( $user_id, 'wpstream_user_liked_items', true );
		$item_likes       = intval( get_post_meta( $post_id, 'wpstream_like_items', true ) );
		$extra_class      = '';

		if ( is_array( $user_liked_items ) ) {
			if ( in_array( $post_id, $user_liked_items, true ) ) {
				$extra_class = 'wpstream_already_liked';
			}
		}

		$user_disliked_items = get_user_meta( $user_id, 'wpstream_user_disliked_items', true );
		$item_dislikes       = intval( get_post_meta( $post_id, 'wpstream_dislike_items', true ) );
		$extra_class_dislike = '';

		if ( is_array( $user_disliked_items ) ) {
			if ( in_array( $post_id, $user_disliked_items, true ) ) {
				$extra_class_dislike = 'wpstream_already_disliked';
			}
		}

		if ( is_user_logged_in() ) {
			$return_string = '<div class="wpstream-like-action btn-hover-white meta-style ' . esc_attr( $extra_class ) . '" '
				. 'data-toggle="tooltip" data-bs-placement="bottom" data-bs-original-title="' . esc_html__( 'I like this', 'hello-wpstream' ) . '" '
				. 'data-postID="' . esc_attr( $post_id ) . '">'
				. wpstream_theme_get_svg_icon( 'like.svg' )
				. '<div class="wpstream_likes_wrapper">' . $item_likes . '</div>'
				. '</div>';

			$return_string .= '<div class="wpstream-dislike-action btn-hover-white meta-style ' . esc_attr( $extra_class_dislike ) . '" '
				. 'data-toggle="tooltip" data-bs-placement="bottom" data-bs-original-title="' . esc_html__( 'I dislike this', 'hello-wpstream' ) . '" '
				. 'data-postID="' . esc_attr( $post_id ) . '">'
				. wpstream_theme_get_svg_icon( 'dislike.svg' )
				. '<div class="wpstream_dislikes_wrapper">' . intval( $item_dislikes ) . '</div>'
				. '</div>';
		} else {
			$return_string = '<div tabindex="0"  class="wpstream-like-action btn-hover-white wpstream_no_action "  '
				. 'data-toggle="tooltip" data-bs-placement="bottom" '
				. 'data-bs-original-title="' . esc_html__( 'Sign in to make your opinion count.', 'hello-wpstream' ) . '"  '
				. 'data-postID="' . esc_attr( $post_id ) . '">'
				. wpstream_theme_get_svg_icon( 'like.svg' )
				. '<div class="wpstream_likes_wrapper">' . $item_likes . '</div>'
				. '</div>';

			$return_string .= '<div tabindex="0" class="wpstream-dislike-action btn-hover-white wpstream_no_action " '
				. 'data-toggle="tooltip" data-bs-placement="bottom" '
				. 'data-bs-original-title="' . esc_html__( 'Sign in to make your opinion count.', 'hello-wpstream' ) . '"  '
				. 'data-postID="' . esc_attr( $post_id ) . '">'
				. wpstream_theme_get_svg_icon( 'dislike.svg' )
				. '<div class="wpstream_dislikes_wrapper">' . intval( $item_dislikes ) . '</div>'
				. '</div>';
		}

		return $return_string;
	}
}

add_action( 'wp_ajax_wpstream_handle_like_item_ajax', 'wpstream_handle_like_item_ajax' );

/**
 * Handles the AJAX request for liking or disliking an item.
 */
function wpstream_handle_like_item_ajax() {
	// Verify nonce.
	if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'like_nonce_ajax_action' ) ) {
		wp_send_json_error( 'Nonce verification failed.', 403 );
	}

	if ( is_user_logged_in() ) {
		$user_id       = get_current_user_id();
		$post_id       = isset( $_POST['postID'] ) ? intval( $_POST['postID'] ) : 0;
		$action_answer = wpstream_handle_like_item_action( $post_id, $user_id, 'like' );

		$answer = array(
			'success'       => true,
			'class'         => $action_answer['class'],
			'item_likes'    => $action_answer['likes'],
			'item_dislikes' => $action_answer['dislikes'],
		);

	} else {
		// User is not logged in.
		$answer = array(
			'success' => false,
			'message' => 'Please log in to access this content.',
		);
	}

	wp_send_json( $answer );
}

add_action( 'wp_ajax_wpstream_handle_dislike_item_ajax', 'wpstream_handle_dislike_item_ajax' );

/**
 * Handles the AJAX request for disliking an item.
 */
function wpstream_handle_dislike_item_ajax() {
	// Verify nonce.
	if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'dislike_nonce_ajax_action' ) ) {
		wp_send_json_error( 'Nonce verification failed.', 403 );
	}

	// Check if 'postID' is set in $_POST.
	if ( isset( $_POST['postID'] ) ) {
		$post_id = intval( $_POST['postID'] );
	} else {
		wp_send_json_error( 'Missing postID parameter.', 400 );
	}

	if ( is_user_logged_in() ) {
		$user_id       = get_current_user_id();
		$post_id       = intval( $_POST['postID'] );
		$action_answer = wpstream_handle_like_item_action( $post_id, $user_id, 'dislike' );

		$answer = array(
			'success'       => true,
			'class'         => $action_answer['class'],
			'item_likes'    => $action_answer['likes'],
			'item_dislikes' => $action_answer['dislikes'],
		);
	} else {
		// User is not logged in.
		$answer = array(
			'success' => false,
			'message' => 'Please log in to access this content.',
		);
	}

	print wp_json_encode( $answer );

	wp_die();
}

/**
 * Get the count of likes for a specific post.
 *
 * @param int $post_id The ID of the post.
 * @return int The count of likes for the post.
 */
if ( ! function_exists( 'wpstream_get_count_like_post' ) ) {
	function wpstream_get_count_like_post($post_id)	{
		return intval(get_post_meta($post_id, 'wpstream_like_items', true));
	}
}


/**
 * Handle like or dislike action for a specific post.
 *
 * @param int    $post_id  The ID of the post.
 * @param int    $user_id  The ID of the user.
 * @param string $action   The action to perform ('like' or 'dislike').
 * @return array An array containing the updated like and dislike counts, and class to be added.
 */
function wpstream_handle_like_item_action( $post_id, $user_id, $action = 'like' ) {
	$user_liked_items = (array) get_user_meta( $user_id, 'wpstream_user_liked_items', true );
	$item_likes       = intval( get_post_meta( $post_id, 'wpstream_like_items', true ) );

	if ( '' === $user_liked_items ) {
		$user_liked_items = array();
	}

	$item_dis_likes       = intval( get_post_meta( $post_id, 'wpstream_dislike_items', true ) );
	$user_dis_liked_items = (array) get_user_meta( $user_id, 'wpstream_user_disliked_items', true );

	if ( '' === $user_dis_liked_items ) {
		$user_dis_liked_items = array();
	}

	if ( ! is_array( $user_liked_items ) ) {
		$user_liked_items = array();
	}

	$class_to_be_added = '';

	if ( 'like' === $action ) {
		if ( in_array( $post_id, $user_liked_items, true ) ) {
			$item_likes       = max( 0, $item_likes - 1 );
			$user_liked_items = array_diff( $user_liked_items, array( $post_id ) );
		} else {
			++$item_likes;
			$user_liked_items[] = $post_id;
			$class_to_be_added  = 'add_like_class';

			if ( in_array( $post_id, $user_dis_liked_items, true ) ) {
				$item_dis_likes       = max( 0, $item_dis_likes - 1 );
				$user_dis_liked_items = array_diff( $user_dis_liked_items, array( $post_id ) );
			}
		}
	} elseif ( in_array( $post_id, $user_dis_liked_items, true ) ) {
		$item_dis_likes       = max( 0, $item_dis_likes - 1 );
		$user_dis_liked_items = array_diff( $user_dis_liked_items, array( $post_id ) );
	} else {
		++$item_dis_likes;
		$user_dis_liked_items[] = $post_id;
		$class_to_be_added      = 'add_dislike_class';

		if ( in_array( $post_id, $user_liked_items, true ) ) {
			$item_likes       = max( 0, $item_likes - 1 );
			$user_liked_items = array_diff( $user_liked_items, array( $post_id ) );
		}
	}

	// Update like data.
	update_user_meta( $user_id, 'wpstream_user_liked_items', $user_liked_items );
	update_post_meta( $post_id, 'wpstream_like_items', $item_likes );
	update_user_meta( $user_id, 'wpstream_user_disliked_items', $user_dis_liked_items );
	update_post_meta( $post_id, 'wpstream_dislike_items', $item_dis_likes );

	return array(
		'likes'    => $item_likes,
		'dislikes' => $item_dis_likes,
		'class'    => $class_to_be_added,
	);
}

if ( ! function_exists( 'wpstream_display_related_items' ) ) {
	/**
	 * Display related items based on the provided post ID and post type.
	 *
	 * @param int    $post_id   The ID of the current post.
	 * @param string $post_type The type of the current post.
	 * @return string HTML string containing related items.
	 */
	function wpstream_display_related_items( $post_id, $post_type ) {
		$exclude        = $post_id;
		$similar_no     = 3;
		$return_string  = '<div class="wpstream-related-items-wrapper">';
		$return_string .= '<h3>' . wpstream_return_section_label( 'similar_items' ) . '</h3>';
		$return_string .= '<div class="row">';

		$args = array(
			'showposts'           => $similar_no,
			'ignore_sticky_posts' => 0,
			'post_type'           => $post_type,
			'post_status'         => 'publish',
			'post__not_in'        => array( $exclude ),
			'tax_query'           => array( //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
				'relation' => 'AND',
			),
		);

		ob_start();

		$similar_query = new WP_Query( $args );

		if ( $similar_query->have_posts() ) {
			while ( $similar_query->have_posts() ) :
				$similar_query->the_post();
				include locate_template( 'template-parts/item-unit-templates/item-unit-splitter.php' );
			endwhile;
		}

		$content = ob_get_contents();

		ob_end_clean();

		wp_reset_postdata();

		$return_string .= $content;
		$return_string .= '</div>'; // end row.
		$return_string .= '</div>'; // end wstream-related-items-wrapper.

		return $return_string;
	}
}

if ( ! function_exists( 'wpstream_display_vod_attached_to_channel' ) ) {
	/**
	 * Display video-on-demand (VOD) items attached to the provided channel post.
	 *
	 * @param int $post_id The ID of the channel post.
	 * @return string HTML string containing attached VOD items.
	 */
	function wpstream_display_vod_attached_to_channel( $post_id ) {
		$exclude        = $post_id;
		$similar_no     = 3;
		$post_type      = apply_filters( 'wpstream_vod_attached_to_channel', array( 'product' ) );
		$return_string  = '<div class="wpstream-vod-attached-wrapper">';
		$return_string .= '<h3>' . wpstream_return_section_label( 'vod_attached' ) . '</h3>';
		$return_string .= '<div class="row">';

		$args = array(
			'showposts'           => -1,
			'ignore_sticky_posts' => 0,
			'post_type'           => $post_type,
			'post_status'         => 'publish',
			'post__not_in'        => array( $exclude ),
			'meta_query'          => array( //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
				'key'     => 'wpstream_theme_attach_to_channel',
				'value'   => $post_id,
				'compare' => '=',
				'type'    => 'numeric',
			),
		);

		ob_start();

		$similar_query = new WP_Query( $args );

		if ( $similar_query->have_posts() ) {
			while ( $similar_query->have_posts() ) :
				$similar_query->the_post();
				include locate_template( 'template-parts/item-unit-templates/item-unit-splitter.php' );
			endwhile;
		}

		$content = ob_get_contents();

		ob_end_clean();

		wp_reset_postdata();

		$return_string .= $content;
		$return_string .= '</div>'; // end row.
		$return_string .= '</div>'; // end wstream-related-items-wrapper.

		return $return_string;
	}
}

if ( ! function_exists( 'wpstream_return_section_label' ) ) {
	/**
	 * Return the section label based on the provided key.
	 *
	 * @param string $label The key for the label.
	 * @return string The corresponding label.
	 */
	function wpstream_return_section_label( $label ) {
		$label_data = array(
			'similar_items'  => esc_html__( 'Similar Items', 'hello-wpstream' ),
			'bundle_content' => esc_html__( 'Bundle Content', 'hello-wpstream' ),
			'vod_attached'   => esc_html__( 'Recordings Attached to Channel', 'hello-wpstream' ),
		);

		return $label_data[ $label ];
	}
}

if ( ! function_exists( 'wpstream_check_woo_active' ) ) {
	/**
	 * Check if WooCommerce is active.
	 *
	 * @return bool True if WooCommerce is active, false otherwise.
	 */
	function wpstream_check_woo_active() {
		if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
			return true;
		} else {
			return false;
		}
	}
}

if ( ! function_exists( 'wpstream_return_dashboard_page' ) ) {
	/**
	 * Return the URL of the dashboard page.
	 *
	 * @return string The URL of the dashboard page.
	 */
	function wpstream_return_dashboard_page() {
		$url = '';

		if ( wpstream_check_woo_active() ) {
			$url = wc_get_page_permalink( 'myaccount' );
		} else {
			$url = wstream_get_template_link( 'wpstream-theme-dashboard.php' );
		}

		return $url;
	}
}

if ( ! function_exists( 'wstream_get_template_link' ) ) {
	/**
	 * Get the permalink of a page using a specific template.
	 *
	 * @param string $template_name The name of the template.
	 * @param int    $bypass        Whether to bypass the transient cache.
	 * @return string The permalink of the page using the template.
	 */
	function wstream_get_template_link( $template_name, $bypass = 0 ) {
		$transient_name = $template_name;

		if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
			$transient_name .= '_' . ICL_LANGUAGE_CODE;
		}

		$template_link = wpstream_request_transient_cache( 'wpstream_get_template_link_' . $transient_name );

		if ( false === $template_link || 1 === $bypass ) {
			$pages = get_pages(
				array(
					'meta_key'   => '_wp_page_template', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
					'meta_value' => $template_name, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
				)
			);

			if ( $pages ) {
				$template_link = esc_url( get_permalink( $pages[0]->ID ) );
			} else {
				$template_link = esc_url( home_url( '/' ) );
			}

			wstream_set_transient_cache( 'wpstream_get_template_link_' . $transient_name, $template_link, 60 * 60 * 24 );
		}

		return esc_url( $template_link );
	}
}

if ( ! function_exists( 'wpstream_request_transient_cache' ) ) {
	/**
	 * Retrieve data from a transient cache if available.
	 *
	 * @param string $transient_name The name of the transient cache.
	 * @return mixed|false The cached data if available, false otherwise.
	 */
	function wpstream_request_transient_cache( $transient_name ) {

		$use_transient = wpstream_theme_return_use_transient();

		if ( $use_transient ) {
			return get_transient( $transient_name );
		} else {
			return false;
		}
	}
}

if ( ! function_exists( 'wstream_set_transient_cache' ) ) {
	/**
	 * Set data into a transient cache if available.
	 *
	 * @param string $transient_name The name of the transient cache.
	 * @param mixed  $value The value to store in the transient cache.
	 * @param int    $time The time in seconds for the transient cache to expire.
	 * @return void
	 */
	function wstream_set_transient_cache( $transient_name, $value, $time ) {
		$use_transient = wpstream_theme_return_use_transient();

		if ( $use_transient ) {
			set_transient( $transient_name, $value, $time );
		}
	}
}

if ( ! function_exists( 'wpstream_theme_default_card_no_image_url' ) ) {
	/**
	 * Returns the default URL for card images if no image is available.
	 *
	 * @param string $size The size of the card image.
	 * @return string The URL of the default image.
	 */
	function wpstream_theme_default_card_no_image_url( $size ) {
		if ( 'wpstream_bundle_unit_cards_image' === $size ) {
			$image_path = '/img/default-cover-big.png';
		} else {
			$image_path = '/img/default-cover.png';
		}

		// Define the default image URL.
		$default_image_url = get_stylesheet_directory_uri() . $image_path;

		// Return the default image URL.
		return esc_url( $default_image_url );
	}
}

if ( ! function_exists( 'wpstream_theme_get_svg_icon' ) ) {
	/**
	 * Get the SVG content from a specified SVG file.
	 *
	 * @param string $icon_path The path to the SVG icon file.
	 * @return string|false The SVG content or false if the file doesn't exist.
	 */
	function wpstream_theme_get_svg_icon( $icon_path ) {
		$icon_path = get_template_directory() . '/img/icons/' . $icon_path;

		// Check if the file exists.
		if ( file_exists( $icon_path ) ) {
			ob_start();
			include $icon_path;

			return ob_get_clean();
		} else {
			return false; // Return false if the icon file doesn't exist.
		}
	}
}

if ( ! function_exists( 'wpstream_is_woo_video_product' ) ) {
    /**
     * Check if the product is a WpStream video product.
     *
     * @param int $product_id The ID of the product.
     * @return bool True if the product is a video product, false otherwise.
     */
    function wpstream_is_woo_video_product( $product_id ) {
        $wpstream_woo_product_types = ['video_on_demand', 'live_stream', 'wpstream_bundle', 'subscription'];

        if ( ! function_exists( 'wc_get_product' ) ) {
            return false;
        }
        $product = wc_get_product( $product_id );

        if ( ! $product ) {
            return false;
        }

        return in_array( $product->get_type(), $wpstream_woo_product_types, true );
    }
}


if ( ! function_exists( 'wpstream_theme_get_svg_icon_menu' ) ) {
	/**
	 * Get the SVG content from a specified SVG file.
	 *
	 * @param string $icon_path The path to the SVG icon file.
	 * @return string|false The SVG content or false if the file doesn't exist.
	 */
	function wpstream_theme_get_svg_icon_menu( $icon_path ) {
		if ( filter_var($icon_path, FILTER_VALIDATE_URL) === FALSE ) {
			return false;
		}

		// Initialize the WP_Filesystem
		global $wp_filesystem;
		if ( empty( $wp_filesystem ) ) {
			require_once ( ABSPATH . '/wp-admin/includes/file.php' );
			WP_Filesystem();
		}

		// Use wp_remote_get() to fetch remote files
		$response = wp_remote_get( $icon_path );

		if ( is_wp_error( $response ) ) {
			return false;
		}

		$icon_content = wp_remote_retrieve_body( $response );

		if ( empty( $icon_content ) ) {
			return false;
		}

		return $icon_content;
	}
}

if ( ! function_exists( 'wpstream_theme_products_tag' ) ) {
    function wpstream_theme_products_tag($product_id,$product){
        if ( get_post_type( $product_id ) === 'product') :

            $product_type = $product->get_type();

            switch ($product_type){
                case "live_stream":
                    ?>
                    <div class="wpstream_featured_image_live_tag wpstream_hide_on_trailer wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'LIVE', 'hello-wpstream' ); ?></div>
                    <?php
                    break;
                case "video_on_demand":
                    ?>
                    <div class="wpstream_featured_image_vod_tag wpstream_hide_on_trailer  wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'VIDEO', 'hello-wpstream' ); ?></div>
                    <?php
                    break;
                case "wpstream_bundle":
                    ?>
                    <div class="wpstream_featured_image_collection_tag wpstream_hide_on_trailer  wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'COLLECTION', 'hello-wpstream' ); ?></div>
                    <?php
                    break;
                case "subscription":
                    ?>
                    <div class="wpstream_featured_image_subscription_tag wpstream_hide_on_trailer  wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'SUBSCRIPTION', 'hello-wpstream' ); ?></div>
                    <?php
                    break;
            }
        endif;
    }
}
