Current File : /home/kelaby89/muzza.fit/wp-content/themes/deadlift/inc/conditional-functions.php
<?php
/**
 * Deadlift conditional functions
 *
 * @package WordPress
 * @subpackage Deadlift
 * @version 1.8.2
 */

defined( 'ABSPATH' ) || exit;

/**
 * Check if we can display the sidepanel
 */
function deadlift_can_display_sidepanel() {
	$menu_panel_mod  = deadlift_get_theme_mod( 'side_panel_position' );
	$menu_panel_meta = get_post_meta( deadlift_get_inherit_post_id(), '_post_side_panel_position', true );

	/**
	 * Exclude side panel when certain menu layout are selected
	 *
	 * @since Deadlift 1.0.0
	 */
	$excluded_menu_layout = apply_filters( 'deadlift_excluded_side_panel_menu_layout', array( 'offcanvas', 'lateral', 'overlay' ) );

	$bool = true;

	if ( ! is_active_sidebar( 'sidebar-side-panel' ) ) {
		$bool = false;
	}

	if ( deadlift_get_inherit_mod( 'sidepanel_content_block_id' ) && 'none' !== deadlift_get_inherit_mod( 'sidepanel_content_block_id' ) ) {
		$bool = true;
	}

	if ( ( 'none' === $menu_panel_mod || ! $menu_panel_mod ) && ! $menu_panel_meta ) {
		$bool = false;
	}

	/* Be sure to not display the side panel if metabox option is set to none */
	if ( 'none' === $menu_panel_meta ) {
		$bool = false;
	}

	if ( in_array( deadlift_get_inherit_mod( 'menu_layout' ), $excluded_menu_layout, true ) ) {
		$bool = false;
	}

	/**
	 * Filters side panel display condition
	 *
	 * @since Deadlift 1.0.0
	 */
	return apply_filters( 'deadlift_display_sidepanel', $bool );
}

/**
 * Check if we should display the search menu item
 */
function deadlift_display_shop_search_menu_item() {
	return deadlift_get_theme_mod( 'shop_search_menu_item' );
}

/**
 * Check if we should display the cart menu item
 */
function deadlift_display_cart_menu_item() {
	return deadlift_is_woocommerce() && deadlift_get_theme_mod( 'cart_menu_item' );
}

/**
 * Check if we should display the account menu item
 */
function deadlift_display_account_menu_item() {
	return deadlift_is_woocommerce() && deadlift_get_theme_mod( 'account_menu_item' );
}

/**
 * Check if we should display the wishlist menu item
 */
function deadlift_display_wishlist_menu_item() {
	return deadlift_is_wishlist() && deadlift_get_theme_mod( 'wishlist_menu_item' );
}

/**
 * Check if there is a main menu to display
 *
 * @return bool
 */
function deadlift_is_main_menu() {
	$has_menu = has_nav_menu( 'primary' );
	$has_logo = deadlift_get_theme_mod( 'logo_svg' ) || deadlift_get_theme_mod( 'logo_light' ) || deadlift_get_theme_mod( 'logo_dark' );
	return $has_menu || $has_logo;
}

/**
 * Is Woocommerce activated?
 *
 * @return bool
 */
function deadlift_is_woocommerce() {
	return ( class_exists( 'WooCommerce' ) );
}

/**
 * Is Wolf Woocommerce Wishlist activated?
 *
 * @return bool
 */
function deadlift_is_wishlist() {
	return ( class_exists( 'Wolf_WooCommerce_Wishlist' ) && class_exists( 'WooCommerce' ) );
}

/**
 * Check if we are on a woocommerce page
 *
 * @return bool
 */
function deadlift_is_woocommerce_page() {

	if ( class_exists( 'WooCommerce' ) ) {

		if ( is_woocommerce() ) {
			return true;
		}

		if ( is_shop() ) {
			return true;
		}

		if ( is_checkout() || is_order_received_page() ) {
			return true;
		}

		if ( is_cart() ) {
			return true;
		}

		if ( is_account_page() ) {
			return true;
		}

		if ( function_exists( 'wolf_wishlist_get_page_id' ) && is_page( wolf_wishlist_get_page_id() ) ) {
			return true;
		}
	}
}

/**
 * Check if we're on a post archive page
 *
 * Used for pagination to know if you can use the standard pagination links
 *
 * @param string $post_type The post type to check.
 * @return bool
 */
function deadlift_is_post_type_archive( $post_type = null ) {

	$is_blog      = deadlift_is_blog();
	$is_portfolio = deadlift_is_portfolio();
	$is_shop      = ( function_exists( 'is_shop' ) ) ? is_shop() : false;

	return $is_blog || $is_portfolio || $is_shop;
}

/**
 * Check if WPBakery Page Builder Extension is used on this page
 *
 * @return bool
 */
function deadlift_is_vc() {

	if ( function_exists( 'wvc_is_vc' ) ) {
		return wvc_is_vc();
	}
}

/**
 * Check if any page builder is used on this page
 *
 * @return bool
 */
function deadlift_is_page_builder_page() {

	$wolf_core_is_page_builder_page = function_exists( 'wolf_core_is_page_builder_page' ) && wolf_core_is_page_builder_page();

	return $wolf_core_is_page_builder_page || deadlift_is_vc();
}

/**
 * Check if we are in the customizer previes
 *
 * @return bool
 */
function deadlift_is_customizer() {

	global $wp_customize;
	if ( isset( $wp_customize ) ) {
		return true;
	}
}

/**
 * Check if a hero background is set
 *
 * @return bool
 */
function deadlift_has_hero() {

	$bool = false;

	if ( function_exists( 'is_product_category' ) && is_product_category() && get_term_meta( get_queried_object()->term_id, 'thumbnail_id', true ) ) {
		$bool = true;
	}

	$post_type    = get_post_type();
	$hero_bg_type = deadlift_get_inherit_mod( 'hero_background_type', 'featured-image' );

	/**
	 * Filters post types when the hero header should not be displayed
	 *
	 * @since Deadlift 1.0.0
	 */
	$no_hero_post_types = apply_filters( 'deadlift_no_header_post_types', array( 'product', 'release', 'event', 'proof_gallery', 'attachment' ) );

	if ( is_single() && in_array( $post_type, $no_hero_post_types, true ) ) {
		$bool = false;

	} elseif ( deadlift_is_home_as_blog() && get_header_image() ) {

		$bool = true;

	} elseif ( deadlift_get_hero_background() ) {

		$bool = true;
	}

	if ( 'transparent' === deadlift_get_inherit_mod( 'menu_style' ) && 'none' === deadlift_get_inherit_mod( 'hero_layout' ) ) {
		$bool = true;
	}

	/**
	 * Filters has_hero condition
	 *
	 * @since Deadlift 1.0.0
	 */
	return apply_filters( 'deadlift_has_hero', $bool );
}

/**
 * Check if we're on a portfolio page
 *
 * @return bool
 */
function deadlift_is_portfolio() {

	return function_exists( 'wolf_portfolio_get_page_id' ) && is_page( wolf_portfolio_get_page_id() ) || is_tax( 'work_type' );
}

/**
 * Check if we're on a jobs page
 *
 * @return bool
 */
function deadlift_is_jobs() {

	return function_exists( 'wolf_jobs_get_page_id' ) && is_page( wolf_jobs_get_page_id() ) || is_tax( 'work_type' );
}

/**
 * Check if we're on a albums page
 *
 * @return bool
 */
function deadlift_is_albums() {

	return function_exists( 'wolf_albums_get_page_id' ) && is_page( wolf_albums_get_page_id() ) || is_tax( 'gallery_type' );
}

/**
 * Check if we're on a photos page
 *
 * @return bool
 */
function deadlift_is_photos() {

	if ( function_exists( 'deadlift_is_photos_page' ) ) {
		return deadlift_is_photos_page();
	}
}

/**
 * Check if we're on a videos page
 *
 * @return bool
 */
function deadlift_is_videos() {

	return function_exists( 'wolf_videos_get_page_id' ) && is_page( wolf_videos_get_page_id() ) || is_tax( 'video_type' ) || is_tax( 'video_tag' );
}

/**
 * Check if we're on a events page
 *
 * @return bool
 */
function deadlift_is_events() {

	return function_exists( 'wolf_events_get_page_id' ) && is_page( wolf_events_get_page_id() ) || is_tax( 'we_artist' ) || is_tax( 'we_type' );
}

/**
 * Check if we're on a artists page
 *
 * @return bool
 */
function deadlift_is_artists() {

	return function_exists( 'wolf_artists_get_page_id' ) && is_page( wolf_artists_get_page_id() ) || is_tax( 'artist_genre' );
}


/**
 * Check if we're on a plugins page
 *
 * @return bool
 */
function deadlift_is_plugins() {

	return function_exists( 'wolf_plugins_get_page_id' ) && is_page( wolf_plugins_get_page_id() ) || is_tax( 'plugin_cat' ) || is_tax( 'plugin_tag' );
}

/**
 * Check if we're on a themes page
 *
 * @return bool
 */
function deadlift_is_themes() {

	return function_exists( 'wolf_themes_get_page_id' ) && is_page( wolf_themes_get_page_id() ) || is_tax( 'themes_cat' ) || is_tax( 'themes_tag' );
}

/**
 * Check if we're on a discography page
 *
 * @return bool
 */
function deadlift_is_discography() {

	return function_exists( 'wolf_discography_get_page_id' ) && is_page( wolf_discography_get_page_id() ) || is_tax( 'label' ) || is_tax( 'band' ) || is_tax( 'release_genre' );
}

/**
 * Do masonry
 *
 * @return bool
 */
function deadlift_do_masonry() {

	$blog_masonry_display      = array( 'masonry', 'metro', 'metro_modern' );
	$portfolio_masonry_display = array( 'masonry', 'metro' );

	$return = false;

	if ( deadlift_is_blog() ) {

		$return = in_array( deadlift_get_theme_mod( 'post_display' ), $blog_masonry_display, true );

	} elseif ( deadlift_is_portfolio() ) {

		$return = in_array( deadlift_get_theme_mod( 'work_display' ), $portfolio_masonry_display, true );
	}

	return $return;
}

/**
 * Do packery (metro layout)
 *
 * @return bool
 */
function deadlift_do_packery() {

	if ( deadlift_is_blog() ) {

		return 'metro' === deadlift_get_theme_mod( 'post_display' ) || 'metro_modern' === deadlift_get_theme_mod( 'post_display' );

	} elseif ( deadlift_is_portfolio() ) {

		return 'metro' === deadlift_get_theme_mod( 'work_display' );

	} elseif ( deadlift_is_albums() ) {

		return 'metro' === deadlift_get_theme_mod( 'gallery_display' );
	}
}

/**
 * Is AJAX navigation enabled?
 *
 * @return bool
 */
function deadlift_do_ajax_nav() {

	$ajax_mod = deadlift_get_theme_mod( 'ajax_nav' );

	/**
	 * Filters AJAX navigation condition
	 *
	 * @since Deadlift 1.0.0
	 */
	return apply_filters( 'deadlift_do_ajax_nav', $ajax_mod );
}

/**
 * Check if post format is status, aside, quote or link
 *
 * @return bool
 */
function deadlift_is_short_post_format() {

	$short_format = array( 'aside', 'status', 'quote', 'link' );

	return in_array( get_post_format(), $short_format, true );
}

/**
 * Check if we need to display the sidebar depending on context
 *
 * @return bool
 */
function deadlift_display_sidebar() {

	global $wp_customize;

	$post_id = deadlift_get_the_id();

	$is_customizer = ( isset( $wp_customize ) ) ? true : false;

	$is_right_post_type = ! is_singular( 'show' );

	$blog_layout = deadlift_is_blog() && ( 'sidebar-left' === deadlift_get_theme_mod( 'post_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'post_layout' ) );

	$shop_layout = ! is_singular( 'product' ) && deadlift_is_woocommerce_page() && ( 'sidebar-left' === deadlift_get_theme_mod( 'product_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'product_layout' ) );

	$product_layout = is_singular( 'product' ) && ( 'sidebar-left' === deadlift_get_inherit_mod( 'single_product_layout' ) || 'sidebar-right' === deadlift_get_inherit_mod( 'single_product_layout' ) );

	$disco_layout = deadlift_is_discography() && ( 'sidebar-left' === deadlift_get_theme_mod( 'release_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'release_layout' ) );

	$videos_layout = deadlift_is_videos() && ( 'sidebar-left' === deadlift_get_theme_mod( 'video_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'video_layout' ) );

	$portfolio_layout = deadlift_is_portfolio() && ( 'sidebar-left' === deadlift_get_theme_mod( 'work_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'work_layout' ) );

	$albums_layout = deadlift_is_albums() && ( 'sidebar-left' === deadlift_get_theme_mod( 'gallery_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'gallery_layout' ) );

	$events_layout = deadlift_is_events() && ( 'sidebar-left' === deadlift_get_theme_mod( 'event_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'event_layout' ) );

	$artists_layout = deadlift_is_artists() && ( 'sidebar-left' === deadlift_get_theme_mod( 'artist_layout' ) || 'sidebar-right' === deadlift_get_theme_mod( 'artist_layout' ) );

	$single_post_layout = deadlift_get_single_post_layout( $post_id );
	$is_single_sidebar  = is_singular( 'post' ) && ( ( 'sidebar-left' === $single_post_layout ) || ( 'sidebar-right' === $single_post_layout ) );

	$single_video_layout     = deadlift_get_single_video_layout( $post_id );
	$is_single_video_sidebar = is_singular( 'video' ) && ( ( 'sidebar-left' === $single_video_layout ) || ( 'sidebar-right' === $single_video_layout ) && ! deadlift_is_page_builder_page() );

	$single_artist_layout     = deadlift_get_single_artist_layout( $post_id );
	$is_single_artist_sidebar = is_singular( 'artist' ) && ( ( 'sidebar-left' === $single_artist_layout ) || ( 'sidebar-right' === $single_artist_layout ) && ! deadlift_is_page_builder_page() );

	$single_mp_event_layout     = deadlift_get_single_mp_event_layout( $post_id );
	$is_single_mp_event_sidebar = is_singular( 'mp-event' ) && ( ( 'sidebar-left' === $single_mp_event_layout ) || ( 'sidebar-right' === $single_mp_event_layout ) );

	$single_mp_column_layout     = deadlift_get_single_mp_column_layout( $post_id );
	$is_single_mp_column_sidebar = is_singular( 'mp-column' ) && ( ( 'sidebar-left' === $single_mp_column_layout ) || ( 'sidebar-right' === $single_mp_column_layout ) );

	if ( $is_right_post_type ) {
		/**
		 * Filters the "display sidebar" condition
		 *
		 * @since 1.0.0
		 */
		return apply_filters( 'deadlift_display_sidebar', $blog_layout || $portfolio_layout || $product_layout || $events_layout || $artists_layout || $shop_layout || $is_customizer || $is_single_sidebar || $is_single_video_sidebar || $is_single_artist_sidebar || $disco_layout || $videos_layout || $albums_layout || $is_single_mp_event_sidebar || $is_single_mp_column_sidebar );
	}
}

/**
 * Check if the default template is used on the current page
 *
 * @return bool
 */
function deadlift_is_default_template() {
	return ( ! deadlift_is_page_builder_page() && 'page.php' === basename( get_page_template() ) );
}

/**
 * Filter is WVC condition
 */
function deadlift_wvc_is_vc_page( $bool ) {

	if ( deadlift_is_blog() || is_search() && ! is_single() ) {
		$bool = false;
	}

	$is_videos_page      = function_exists( 'wolf_videos_get_page_id' ) && is_page( wolf_videos_get_page_id() );
	$is_discography_page = function_exists( 'wolf_discography_get_page_id' ) && is_page( wolf_discography_get_page_id() );
	$is_albums_page      = function_exists( 'wolf_albums_get_page_id' ) && is_page( wolf_albums_get_page_id() );
	$is_events_page      = function_exists( 'wolf_events_get_page_id' ) && is_page( wolf_events_get_page_id() );
	$is_portfolio_page   = function_exists( 'wolf_portfolio_get_page_id' ) && is_page( wolf_portfolio_get_page_id() );

	if ( $is_videos_page || $is_discography_page || $is_albums_page || $is_events_page ) {
		$bool = false;
	}

	return $bool;
}
add_filter( 'wvc_is_vc', 'deadlift_wvc_is_vc_page' );

/**
 * Check if the browser is edge
 *
 * @return bool
 */
function deadlift_is_edge() {
	global $is_edge;

	return $is_edge;
}

/**
 * Check if the browser is iOS
 *
 * @return bool
 */
function deadlift_is_iphone() {
	global $is_iphone;

	return $is_iphone;
}

/**
 * Check if elementor
 */
function deadlift_is_elementor_page( $post_id = null ) {

	if ( defined( 'ELEMENTOR_VERSION' ) ) {
		global $post;

		$post_id = ( $post_id ) ? $post_id : null;

		if ( ! $post_id && is_object( $post ) ) {
			$post_id = $post->ID;
		}

		if ( $post_id ) {
			return \Elementor\Plugin::$instance->documents->get( $post_id )->is_built_with_elementor();
		}
	}
}

/**
 * Check if elementor
 */
function deadlift_is_elementor_editor() {

	if ( defined( 'ELEMENTOR_VERSION' ) ) {
		return ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) || ( isset( $_GET['action'] ) && 'elementor' === $_GET['action'] );
	}
}

/**
 * Check if Elementor fonts are enabled.
 *
 * Disable all font related option if it is.
 */
function deadlift_is_elementor_fonts_enabled() {
	return class_exists( 'Wolf_Core' ) && ! get_option( 'elementor_disable_typography_schemes' );
}

/**
 * Check if Elementor colors are enabled.
 *
 * Disable all colors related option if it is.
 */
function deadlift_is_elementor_colors_enabled() {
	return class_exists( 'Wolf_Core' ) && ! get_option( 'elementor_disable_color_schemes' );
}

/**
 * Check if we must display a "one-^page" menu
 *
 * @return bool
 */
function deadlift_do_onepage_menu() {

	if ( ! is_page() ) {
		return;
	}

	$post_id = get_the_ID();

	$is_page_builder = ( class_exists( 'Wolf_Visual_Composer' ) || class_exists( 'Wolf_Core' ) );
	$meta            = get_post_meta( $post_id, '_post_one_page_menu', true );

	return $is_page_builder && $meta;
}

/**
 * Check if the one-page bullet navigation option it set
 *
 * @return bool
 */
function deadlift_do_onepage_bullet_nav() {

	if ( ! is_page() ) {
		return;
	}

	$post_id = get_the_ID();

	$is_page_builder = ( class_exists( 'Wolf_Visual_Composer' ) || class_exists( 'Wolf_Core' ) );
	$meta            = get_post_meta( $post_id, '_post_scroller', true );

	return $is_page_builder && $meta;
}

/**
 * Check if easy zoom is enabled on product single page
 *
 * @return boo
 */
function deadlift_do_single_product_easyzoom() {

	$bool = deadlift_get_theme_mod( 'product_zoom' );

	if ( get_post_meta( deadlift_get_the_id(), '_post_product_disable_easyzoom', true ) ) {
		$bool = false;
	}

	/* Disable zoom on mobile */
	if ( wp_is_mobile() ) {
		$bool = true;
	}

	/**
	 * Filters single product zoom option condition
	 *
	 * @since Deadlift 1.0.0
	 */
	return apply_filters( 'deadlift_single_product_zoom', $bool );
}

/**
 * Check if post has Instagram embed
 *
 * @return bool
 */
function deadlift_is_instagram_post( $post_id = null ) {

	return preg_match( '/instagr/', deadlift_get_first_url( $post_id ) ) && 'image' === get_post_format( $post_id );
}

/**
 * Check if post has video embed
 *
 * @return bool
 */
function deadlift_is_video_post( $post_id = null ) {
	return deadlift_get_first_video_url( $post_id ) && 'video' === get_post_format( $post_id );
}


/**
 * Post thumbnail
 *
 * @return bool
 */
function deadlift_has_post_thumbnail() {

	return ( deadlift_post_thumbnail( '', false ) ) ? true : false;
}

/**
 * Check if post has Mixcloud, ReverbNation, SoundCloud or Spotify embed player
 *
 * @return bool
 */
function deadlift_is_audio_embed_post( $post_id = null ) {

	return preg_match( '/mixcloud/', deadlift_get_first_url( $post_id ) )
		|| preg_match( '/reverbnation/', deadlift_get_first_url( $post_id ) )
		|| preg_match( '/soundcloud/', deadlift_get_first_url( $post_id ) )
		|| preg_match( '/spotify/', deadlift_get_first_url( $post_id ) );
}

/**
 * Check if single audio player
 *
 * @return bool
 */
function deadlift_is_single_audio_player( $post_id = null ) {
	return deadlift_shortcode_preg_match( 'wolf-audio', $post_id );
}

/**
 * Check if single audio player
 *
 * @return bool
 */
function deadlift_is_playlist_audio_player( $post_id = null ) {
	return deadlift_is_audio_embed_post( $post_id ) || deadlift_shortcode_preg_match( 'wvc_audio_embed' ) || deadlift_shortcode_preg_match( 'wolf_playlist', $post_id ) || deadlift_shortcode_preg_match( 'wvc_playlist' ) || deadlift_shortcode_preg_match( 'playlist', $post_id ) || deadlift_shortcode_preg_match( 'wolf_jplayer_playlist' );
}

/**
 * Is image a gif?
 *
 * @param int $attachment_id The attachment ID.
 * @return bool
 */
function deadlift_is_gif( $attachment_id ) {

	$ext = strtolower( pathinfo( deadlift_get_url_from_attachment_id( $attachment_id ), PATHINFO_EXTENSION ) );

	if ( 'gif' === $ext ) {
		return true;
	}
}

/**
 * Is latest post?
 *
 * @param string $post_type The post type of the post to check.
 * @param int    $post_id The post ID.
 * @return bool
 */
function deadlift_is_latest_post( $post_type = 'post', $post_id = null ) {

	$post_id        = ( $post_id ) ? abdint( $post_id ) : get_the_ID();
	$latest_post_id = null;

	if ( 'post' === $post_type ) {

		$args = array(
			'posts_per_page'      => 1,
			'post_type'           => 'post',
			'post__in'            => get_option( 'sticky_posts' ),
			'ignore_sticky_posts' => 1,
		);

	} else {

		$args = array(
			'numberposts' => 1,
			'post_type'   => $post_type,
		);
	}

	$args['meta_key'] = '_thumbnail_id';

	$recent_posts = wp_get_recent_posts( $args, ARRAY_A );

	if ( is_array( $recent_posts ) && isset( $recent_posts[0] ) ) {
		if ( isset( $recent_posts[0]['ID'] ) ) {
			$latest_post_id = absint( $recent_posts[0]['ID'] );
		}
	}

	return ( $post_id === $latest_post_id );
}

/**
 * Do fullPage?
 */
function deadlift_do_fullpage() {
	return ( function_exists( 'wvc_do_fullpage' ) && wvc_do_fullpage() );
}

/**
 * Maintenance
 */
function deadlift_is_maintenance_page() {

	$wolf_maintenance_settings = get_option( 'wolf_maintenance_settings' );
	$maintenance_page_id       = ( isset( $wolf_maintenance_settings['page_id'] ) ) ? $wolf_maintenance_settings['page_id'] : null;

	if ( is_page( $maintenance_page_id ) ) {
		return true;
	}
}

/**
 * CHeck if gutenberg is used
 */
function deadlift_is_gutenberg_page() {

	if ( ! deadlift_is_woocommerce_page()
		&& is_singular()
		&& function_exists( 'has_blocks' )
		&& has_blocks( deadlift_get_the_id() )
		&& ! class_exists( 'Wolf_Core' )
		&& ! class_exists( 'Wolf_Visual_Composer' )
	) {
		return true;
	}
}

/**
 * Has quick view enabled
 *
 * @return bool
 */
function deadlift_has_quickview() {
	return class_exists( 'Wolf_WooCommerce_Quickview' );
}
Page not found – Hello World !