t( $blog_layout, $size ) {
$post_format = get_post_format();
$post_format = $post_format ? $post_format : 'image';
$css_class = 'format-' . $post_format;
$html = '';
if ( $blog_layout == 'list' ) {
switch ( get_post_format() ) {
case 'gallery':
$html = martfury_post_format_gallery( $size );
break;
case 'audio':
$html = martfury_post_format_audio();
break;
case 'video':
$html = martfury_post_format_video();
break;
case 'link':
$html = martfury_post_format_link();
break;
case 'quote':
$html = martfury_post_format_quote();
break;
default:
$html = martfury_post_format_image( $size );
break;
}
} elseif ( $blog_layout == 'small-thumb' ) {
switch ( get_post_format() ) {
case 'audio':
$html = martfury_post_format_audio();
break;
case 'link':
$html = martfury_post_format_link();
break;
case 'quote':
$html = martfury_post_format_quote();
break;
default:
$html = martfury_post_format_image( $size );
break;
}
} else {
$html = martfury_post_format_image( $size );
}
if ( $html ) {
echo "
$html
";
}
}
endif;
/**
* Get post format quote
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_post_format_quote' ) ) :
function martfury_post_format_quote() {
$quote = get_post_meta( get_the_ID(), 'quote', true );
$author = get_post_meta( get_the_ID(), 'quote_author', true );
$author_url = get_post_meta( get_the_ID(), 'author_url', true );
if ( ! $quote ) {
return;
}
return sprintf(
'%s%s
',
esc_html( $quote ),
empty( $author_url ) ? $author : '' . $author . ''
);
}
endif;
/**
* Get post format link
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_post_format_link' ) ) :
function martfury_post_format_link() {
$desc = get_post_meta( get_the_ID(), 'desc', true );
$link = get_post_meta( get_the_ID(), 'url', true );
$text = get_post_meta( get_the_ID(), 'url_text', true );
if ( ! $link ) {
return;
}
if ( $desc ) {
$desc = sprintf( '%s
', $desc );
}
return sprintf( '%s%s', $desc, esc_url( $link ), $text ? $text : $link );
}
endif;
/**
* Get post format gallery
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_post_format_gallery' ) ) :
function martfury_post_format_gallery( $size ) {
$image_ids = get_post_meta( get_the_ID(), 'images', false );
if ( empty( $image_ids ) ) {
$post_thumbnail_id = get_post_thumbnail_id( get_the_ID() );
return '' . martfury_get_image_html( $post_thumbnail_id, $size ) . '';
} else {
$gallery = array();
foreach ( $image_ids as $id ) {
$image = martfury_get_image_html( $id, $size );
if ( $image ) {
$gallery[] = '' . $image . '';
}
}
return '' . implode( '', $gallery ) . '
';
}
}
endif;
/**
* Get post format video
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_post_format_video' ) ) :
function martfury_post_format_video() {
$video = get_post_meta( get_the_ID(), 'video', true );
if ( ! $video ) {
return;
}
$video_html = '';
// If URL: show oEmbed HTML
if ( filter_var( $video, FILTER_VALIDATE_URL ) ) {
if ( $oembed = @wp_oembed_get( $video, array( 'width' => 1170 ) ) ) {
$video_html = $oembed;
} else {
$atts = array(
'src' => $video,
'width' => 1170,
);
if ( has_post_thumbnail() ) {
$atts['poster'] = get_the_post_thumbnail_url( get_the_ID(), 'full' );
}
$video_html = wp_video_shortcode( $atts );
}
} // If embed code: just display
else {
$video_html = $video;
}
return $video_html;
}
endif;
/**
* Get post format audio
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_post_format_audio' ) ) :
function martfury_post_format_audio() {
$audio = get_post_meta( get_the_ID(), 'audio', true );
if ( ! $audio ) {
return;
}
$html = '';
// If URL: show oEmbed HTML or jPlayer
if ( filter_var( $audio, FILTER_VALIDATE_URL ) ) {
// Try oEmbed first
if ( $oembed = @wp_oembed_get( $audio ) ) {
$html .= $oembed;
} // Use audio shortcode
else {
$html .= '' . wp_audio_shortcode( array( 'src' => $audio ) ) . '
';
}
} // If embed code: just display
else {
$html .= $audio;
}
return $html;
}
endif;
/**
* Get post format image
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_post_format_image' ) ) :
function martfury_post_format_image( $size ) {
$post_thumbnail_id = get_post_thumbnail_id( get_the_ID() );
if ( martfury_get_option( 'blog_layout' ) == 'masonry' ) {
$thumb = wp_get_attachment_image( $post_thumbnail_id, $size );
} else {
$thumb = martfury_get_image_html( $post_thumbnail_id, $size );
}
if ( empty( $thumb ) ) {
return;
}
return '' . $thumb . '';
}
endif;
/**
* show categories filter
*
* @return string
*/
if ( ! function_exists( 'martfury_taxs_list' ) ) :
function martfury_taxs_list( $taxonomy = 'category' ) {
if ( $taxonomy == 'category' ) {
if ( ! intval( martfury_get_option( 'show_blog_cats' ) ) ) {
return '';
}
}
$cats = '';
$output = array();
$number = apply_filters( 'blog_cats_number', 6 );
$args = array(
'number' => $number,
'orderby' => 'count',
'order' => 'DESC',
);
$term_id = 0;
if ( is_tax( $taxonomy ) || is_category() ) {
$queried_object = get_queried_object();
if ( $queried_object ) {
$term_id = $queried_object->term_id;
}
}
$found = false;
$custom_slug = intval( martfury_get_option( 'custom_blog_cats' ) );
if ( $custom_slug ) {
$cats_slug = martfury_get_option( 'blog_cats_slug' );
foreach ( $cats_slug as $slug ) {
$cat = get_term_by( 'slug', $slug, $taxonomy );
if ( $cat ) {
$css_class = '';
if ( $cat->term_id == $term_id ) {
$css_class = 'selected';
$found = true;
}
$cats .= sprintf( '%s', esc_attr( $css_class ), esc_url( get_term_link( $cat ) ), esc_html( $cat->name ) );
}
}
} else {
$categories = get_terms( $taxonomy, $args );
if ( ! is_wp_error( $categories ) && $categories ) {
foreach ( $categories as $cat ) {
$cat_selected = '';
if ( $cat->term_id == $term_id ) {
$cat_selected = 'selected';
$found = true;
}
$cats .= sprintf( '%s', esc_url( get_term_link( $cat ) ), esc_attr( $cat_selected ), esc_html( $cat->name ) );
}
}
}
$cat_selected = $found ? '' : 'selected';
if ( $cats ) {
$blog_url = get_page_link( get_option( 'page_for_posts' ) );
if ( 'posts' == get_option( 'show_on_front' ) ) {
$blog_url = home_url();
}
$output[] = sprintf(
'',
esc_url( $blog_url ),
esc_attr( $cat_selected ),
esc_html__( 'All', 'martfury' ),
$cats
);
}
if ( $output ) {
echo '' . implode( "\n", $output ) . '
';
}
}
endif;
/**
* Retrieves related product terms
*
* @param string $term
*
* @return array
*/
function martfury_get_related_terms( $term, $post_id = null ) {
$post_id = $post_id ? $post_id : get_the_ID();
$terms_array = array( 0 );
$terms = wp_get_post_terms( $post_id, $term );
foreach ( $terms as $term ) {
$terms_array[] = $term->term_id;
}
return array_map( 'absint', $terms_array );
}
/**
* Get product image use lazyload
*
* @since 1.0
*
* @return string
*/
function martfury_get_image_html( $post_thumbnail_id, $image_size, $css_class = '', $attributes = false ) {
$output = '';
if ( intval( martfury_get_option( 'lazyload' ) ) ) {
$alt = trim( strip_tags( get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ) ) );
$image = wp_get_attachment_image_src( $post_thumbnail_id, $image_size );
if ( $image ) {
$image_trans = get_template_directory_uri() . '/images/transparent.png';
$image_trans = apply_filters( 'martfury_image_transparent', $image_trans );
if ( $attributes ) {
$full_size_image = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );
$output = sprintf(
'',
esc_url( $image_trans ),
esc_url( $image[0] ),
esc_attr( $alt ),
esc_attr( $css_class ),
esc_attr( $full_size_image[0] ),
esc_attr( $full_size_image[0] ),
esc_attr( $attributes['data-large_image_width'] ),
esc_attr( $attributes['data-large_image_height'] )
);
} else {
$output = sprintf(
'',
esc_url( $image_trans ),
esc_url( $image[0] ),
esc_attr( $alt ),
esc_attr( $css_class ),
esc_attr( $image[1] ),
esc_attr( $image[2] )
);
}
}
} else {
$attributes['class'] = $css_class;
$output = wp_get_attachment_image( $post_thumbnail_id, $image_size, false, $attributes );
}
return $output;
}
/**
* Get current page URL for layered nav items.
* @return string
*/
if ( ! function_exists( 'martfury_get_page_base_url' ) ) :
function martfury_get_page_base_url() {
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$link = get_post_type_archive_link( 'product' );
} elseif ( is_product_category() ) {
$link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
} elseif ( is_product_tag() ) {
$link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
} else {
$queried_object = get_queried_object();
if ( $queried_object ) {
$link = get_term_link( $queried_object->slug, $queried_object->taxonomy );
}
}
return apply_filters( 'martfury_get_page_base_url', $link );
}
endif;
/**
* Get catalog layout
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_catalog_layout' ) ) :
function
martfury_get_catalog_layout() {
$layout = '10';
if ( martfury_is_vendor_page() ) {
$layout = '12';
} elseif ( is_search() ) {
$layout = '10';
} elseif ( function_exists( 'is_shop' ) && is_shop() ) {
$layout = martfury_get_option( 'shop_layout' );
} elseif ( function_exists( 'is_product_category' ) && is_product_category() && martfury_get_product_category_level() == 0 ) {
$layout = martfury_get_option( 'products_cat_level_1_layout' );
if ( function_exists( 'get_term_meta' ) ) {
$queried_object = get_queried_object();
$cat_layout = get_term_meta( $queried_object->term_id, 'mf_cat_layout', true );
$layout = $cat_layout ? $cat_layout : $layout;
}
}
return apply_filters( 'martfury_get_catalog_layout', $layout );
}
endif;
/**
* Get catalog layout
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_catalog_full_width' ) ) :
function martfury_get_catalog_full_width() {
if ( ! martfury_is_catalog() && ! martfury_is_vendor_page() ) {
return false;
}
$catalog_layout = martfury_get_catalog_layout();
if ( $catalog_layout == '1' && intval( martfury_get_option( 'catalog_full_width_1' ) ) ) {
return true;
} elseif ( $catalog_layout == '3' && intval( martfury_get_option( 'catalog_full_width_3' ) ) ) {
return true;
} elseif ( $catalog_layout == '10' ) {
if ( is_search() ) {
if ( intval( martfury_get_option( 'search_full_width' ) ) ) {
return true;
}
} else {
if ( intval( martfury_get_option( 'catalog_full_width_10' ) ) ) {
return true;
}
}
} elseif ( $catalog_layout == '12' && intval( martfury_get_option( 'catalog_full_width_12' ) ) ) {
return true;
}
return false;
}
endif;
/**
* Get category level
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_product_category_level' ) ) :
function martfury_get_product_category_level() {
global $wp_query;
$current_cat = $wp_query->get_queried_object();
if ( empty( $current_cat ) ) {
return 0;
}
$term_id = $current_cat->term_id;
return count( get_ancestors( $term_id, 'product_cat' ) );
}
endif;
/**
* Get catalog layout
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_filtered_term_product_counts' ) ) :
function martfury_get_filtered_term_product_counts( $term_ids, $taxonomy = false, $query_type = false ) {
global $wpdb;
if ( ! class_exists( 'WC_Query' ) ) {
return false;
}
$tax_query = WC_Query::get_main_tax_query();
$meta_query = WC_Query::get_main_meta_query();
if ( 'or' === $query_type ) {
foreach ( $tax_query as $key => $query ) {
if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) {
unset( $tax_query[ $key ] );
}
}
}
if ( 'product_brand' === $taxonomy ) {
foreach ( $tax_query as $key => $query ) {
if ( is_array( $query ) ) {
if ( $query['taxonomy'] === 'product_brand' ) {
unset( $tax_query[ $key ] );
if ( preg_match( '/pa_/', $query['taxonomy'] ) ) {
unset( $tax_query[ $key ] );
}
}
}
}
}
$meta_query = new WP_Meta_Query( $meta_query );
$tax_query = new WP_Tax_Query( $tax_query );
$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
$tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
// Generate query
$query = array();
$query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, terms.term_id as term_count_id";
$query['from'] = "FROM {$wpdb->posts}";
$query['join'] = "
INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
INNER JOIN {$wpdb->terms} AS terms USING( term_id )
" . $tax_query_sql['join'] . $meta_query_sql['join'];
$query['where'] = "
WHERE {$wpdb->posts}.post_type IN ( 'product' )
AND {$wpdb->posts}.post_status = 'publish'
" . $tax_query_sql['where'] . $meta_query_sql['where'] . "
AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
";
if ( $search = WC_Query::get_main_search_query_sql() ) {
$query['where'] .= ' AND ' . $search;
}
$query['group_by'] = "GROUP BY terms.term_id";
$query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query );
$query = implode( ' ', $query );
// We have a query - let's see if cached results of this query already exist.
$query_hash = md5( $query );
$cache = apply_filters( 'woocommerce_layered_nav_count_maybe_cache', true );
if ( true === $cache ) {
$cached_counts = (array) get_transient( 'wc_layered_nav_counts_' . sanitize_title( $taxonomy ) );
} else {
$cached_counts = array();
}
if ( ! isset( $cached_counts[ $query_hash ] ) ) {
$results = $wpdb->get_results( $query, ARRAY_A );
$counts = array_map( 'absint', wp_list_pluck( $results, 'term_count', 'term_count_id' ) );
$cached_counts[ $query_hash ] = $counts;
set_transient( 'wc_layered_nav_counts_' . sanitize_title( $taxonomy ), $cached_counts, DAY_IN_SECONDS );
}
return array_map( 'absint', (array) $cached_counts[ $query_hash ] );
}
endif;
/**
* Get socials
*
* @since 1.0.0
*
*
* @return string
*/
if ( ! function_exists( 'martfury_get_socials' ) ) :
function martfury_get_socials() {
$socials = array(
'facebook' => esc_html__( 'Facebook', 'martfury' ),
'twitter' => esc_html__( 'Twitter', 'martfury' ),
'google' => esc_html__( 'Google', 'martfury' ),
'tumblr' => esc_html__( 'Tumblr', 'martfury' ),
'flickr' => esc_html__( 'Flickr', 'martfury' ),
'vimeo' => esc_html__( 'Vimeo', 'martfury' ),
'youtube' => esc_html__( 'Youtube', 'martfury' ),
'linkedin' => esc_html__( 'LinkedIn', 'martfury' ),
'pinterest' => esc_html__( 'Pinterest', 'martfury' ),
'dribbble' => esc_html__( 'Dribbble', 'martfury' ),
'spotify' => esc_html__( 'Spotify', 'martfury' ),
'instagram' => esc_html__( 'Instagram', 'martfury' ),
'tumbleupon' => esc_html__( 'Tumbleupon', 'martfury' ),
'wordpress' => esc_html__( 'WordPress', 'martfury' ),
'rss' => esc_html__( 'Rss', 'martfury' ),
'deviantart' => esc_html__( 'Deviantart', 'martfury' ),
'share' => esc_html__( 'Share', 'martfury' ),
'skype' => esc_html__( 'Skype', 'martfury' ),
'behance' => esc_html__( 'Behance', 'martfury' ),
'apple' => esc_html__( 'Apple', 'martfury' ),
'yelp' => esc_html__( 'Yelp', 'martfury' ),
);
return apply_filters( 'martfury_header_socials', $socials );
}
endif;
/**
* Get page header layout
*
* @return array
*/
if ( ! function_exists( 'martfury_get_page_header' ) ) :
function martfury_get_page_header() {
if ( is_404() || is_page_template( 'template-homepage.php' ) || is_page_template( 'template-home-full-width.php' ) || is_page_template( 'template-coming-soon-page.php' ) ) {
return false;
}
$page_header = array( 'title', 'breadcrumb' );
if ( martfury_is_blog() ) {
if ( ! intval( martfury_get_option( 'page_header_blog' ) ) ) {
return false;
}
$page_header = martfury_get_option( 'page_header_blog_els' );
} elseif ( is_page() ) {
if ( ! intval( martfury_get_option( 'page_header_page' ) ) ) {
return false;
}
$custom_layout = get_post_meta( get_the_ID(), 'custom_page_header', true );
if ( $custom_layout ) {
$hide_page_header = get_post_meta( get_the_ID(), 'hide_page_header', true );
if ( $hide_page_header ) {
return false;
}
if ( get_post_meta( get_the_ID(), 'hide_breadcrumb', true ) ) {
$key = array_search( 'breadcrumb', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
if ( get_post_meta( get_the_ID(), 'hide_title', true ) ) {
$key = array_search( 'title', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
} else {
$page_header = martfury_get_option( 'page_header_pages_els' );
}
} elseif ( is_search() ) {
$page_header = array( 'title', 'breadcrumb' );
} elseif ( function_exists( 'is_shop' ) && is_shop() ) {
$shop_id = get_option( 'woocommerce_shop_page_id' );
$custom_layout = get_post_meta( $shop_id, 'custom_page_header', true );
if ( $custom_layout ) {
$hide_page_header = get_post_meta( $shop_id, 'hide_page_header', true );
if ( $hide_page_header ) {
return false;
}
if ( get_post_meta( $shop_id, 'hide_breadcrumb', true ) ) {
$key = array_search( 'breadcrumb', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
if ( get_post_meta( $shop_id, 'hide_title', true ) ) {
$key = array_search( 'title', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
}
}
if ( martfury_is_vendor_page() ) {
$page_header = martfury_get_option( 'page_header_vendor_els' );
}
return apply_filters( 'martfury_get_page_header', $page_header );
}
endif;
/**
* Get recently viewed products
*
* @return string
*/
if ( ! function_exists( 'martfury_recently_viewed_products' ) ) :
function martfury_recently_viewed_products( $atts ) {
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array();
$viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
$output = array();
$thumbnail_size = 'thumbnail';
if ( function_exists( 'wc_get_image_size' ) ) {
$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );
$thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', array(
$gallery_thumbnail['width'],
$gallery_thumbnail['height']
) );
}
$output[] = '';
if ( empty( $viewed_products ) ) {
$output[] = sprintf(
'',
esc_html__( 'Recently Viewed Products is a function which helps you keep track of your recent viewing history.', 'martfury' ),
esc_url( get_permalink( get_option( 'woocommerce_shop_page_id' ) ) ),
esc_html__( 'Shop Now', 'martfury' )
);
} else {
if ( ! function_exists( 'wc_get_product' ) ) {
$output[] = sprintf(
'',
esc_html__( 'Recently Viewed Products is a function which helps you keep track of your recent viewing history.', 'martfury' ),
esc_url( get_permalink( get_option( 'woocommerce_shop_page_id' ) ) ),
esc_html__( 'Shop Now', 'martfury' )
);
}
$output[] = '';
$number = intval( $atts['numbers'] );
$index = 1;
foreach ( $viewed_products as $product_id ) {
if ( $index > $number ) {
break;
}
$index ++;
$product = wc_get_product( $product_id );
if ( empty( $product ) ) {
continue;
}
$output[] = sprintf(
'- ' .
'%s' .
''.
'
',
esc_url( $product->get_permalink() ),
$product->get_image( $thumbnail_size ),
$product->get_title(),
$product->get_price_html()
);
}
$output[] = '
';
}
return sprintf( '%s
', implode( ' ', $output ) );
}
endif;
/**
* Print HTML of currency switcher
* It requires plugin WooCommerce Currency Switcher installed
*/
if ( ! function_exists( 'martfury_currency_switcher' ) ) :
function martfury_currency_switcher( $show_desc = false ) {
$currency_dd = '';
if ( class_exists( 'WOOCS' ) ) {
global $WOOCS;
$key_cur = 'name';
if ( $show_desc ) {
$key_cur = 'description';
}
$currencies = $WOOCS->get_currencies();
$currency_list = array();
foreach ( $currencies as $key => $currency ) {
$currency_value = empty($currency[ $key_cur ]) ? $currency['name'] : $currency[ $key_cur ];
if ( $WOOCS->current_currency == $key ) {
array_unshift(
$currency_list, sprintf(
'%s',
esc_attr( $currency['name'] ),
esc_html( $currency_value )
)
);
} else {
$currency_list[] = sprintf(
'%s',
esc_attr( $currency['name'] ),
esc_html( $currency_value )
);
}
}
$currency_value = empty($currencies[ $WOOCS->current_currency ][ $key_cur ]) ? $currencies[ $WOOCS->current_currency ][ 'name' ] : $currencies[ $WOOCS->current_currency ][ $key_cur ];
$currency_dd = sprintf(
'%s' .
'',
$currency_value,
implode( "\n\t", $currency_list )
);
} elseif ( class_exists( 'Alg_WC_Currency_Switcher' ) ) {
$function_currencies = alg_get_enabled_currencies();
$currencies = get_woocommerce_currencies();
$selected_currency = alg_get_current_currency_code();
$selected_currency_name = '';
$currency_list = array();
$first_link = '';
foreach ( $function_currencies as $currency_code ) {
if ( isset( $currencies[ $currency_code ] ) ) {
$the_text = function_exists('alg_format_currency_switcher') ? alg_format_currency_switcher( $currencies[ $currency_code ], $currency_code, false ) : '';
$the_link = '' . $the_text . '';
if ( $currency_code != $selected_currency ) {
$currency_list[] = $the_link;
} else {
$first_link = $the_link;
$selected_currency_name = $the_text;
}
}
}
if ( '' != $first_link ) {
$currency_list = array_merge( array( $first_link ), $currency_list );
}
if ( ! empty( $currency_list ) && ! empty( $selected_currency_name ) ) {
$currency_dd = sprintf(
'%s' .
'',
$selected_currency_name,
implode( "\n\t", $currency_list )
);
}
}
return $currency_dd;
}
endif;
if ( ! function_exists( 'martfury_product_video' ) ) :
function martfury_product_video() {
global $product;
$video_image = get_post_meta( $product->get_id(), 'video_thumbnail', true );
$video_url = get_post_meta( $product->get_id(), 'video_url', true );
$video_first = get_post_meta( $product->get_id(), 'video_position', true );
$video_width = 1024;
$video_height = 768;
$video_html = '';
if ( $video_image ) {
$video_thumb = wp_get_attachment_image_src( $video_image, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
$video_thumb = $video_thumb[0];
// If URL: show oEmbed HTML
if ( filter_var( $video_url, FILTER_VALIDATE_URL ) ) {
$atts = array(
'width' => $video_width,
'height' => $video_height
);
if ( $oembed = @wp_oembed_get( $video_url, $atts ) ) {
$video_html = $oembed;
} else {
$atts = array(
'src' => $video_url,
'width' => $video_width,
'height' => $video_height
);
$video_html = wp_video_shortcode( $atts );
}
}
if ( $video_html ) {
$vid_html = '' . $video_html . '
';
if ( $video_first == '2' ) {
$vid_html .= '';
}
$video_wrapper = sprintf( '%s
', $vid_html );
$video_html = '' . $video_wrapper . '
';
}
}
return $video_html;
}
endif;
/**
* Wrapper function to deal with backwards compatibility.
*/
if ( ! function_exists( 'martfury_body_open' ) ) {
function martfury_body_open() {
if ( function_exists( 'wp_body_open' ) ) {
wp_body_open();
} else {
do_action( 'wp_body_open' );
}
}
}
if ( ! function_exists( 'martfury_cartflows_template' ) ) {
function martfury_cartflows_template() {
if ( ! class_exists( 'Cartflows_Loader' ) || ! function_exists('_get_wcf_step_id')) {
return false;
}
$page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
if( !$page_template || $page_template == 'default' ) {
return false;
}
return true;
}
}
/**
* Sanitize SVG code.
*
* @since 1.0.0
*
* @param string $svg SVG code.
*
* @return string
*/
function martfury_sanitize_svg( $svg ) {
$allowed = array();
$whitelist = array(
'a' => array(
'class',
'clip-path',
'clip-rule',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'id',
'mask',
'opacity',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
'href',
'xlink:href',
'xlink:title',
),
'circle' => array(
'class',
'clip-path',
'clip-rule',
'cx',
'cy',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'id',
'mask',
'opacity',
'r',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
),
'clipPath' => array( 'class', 'clipPathUnits', 'id' ),
'defs' => array(),
'style' => array( 'type' ),
'desc' => array(),
'ellipse' => array(
'class',
'clip-path',
'clip-rule',
'cx',
'cy',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'id',
'mask',
'opacity',
'requiredFeatures',
'rx',
'ry',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
),
'feGaussianBlur' => array(
'class',
'color-interpolation-filters',
'id',
'requiredFeatures',
'stdDeviation'
),
'filter' => array(
'class',
'color-interpolation-filters',
'filterRes',
'filterUnits',
'height',
'id',
'primitiveUnits',
'requiredFeatures',
'width',
'x',
'xlink:href',
'y',
),
'foreignObject' => array(
'class',
'font-size',
'height',
'id',
'opacity',
'requiredFeatures',
'style',
'transform',
'width',
'x',
'y',
),
'g' => array(
'class',
'clip-path',
'clip-rule',
'id',
'display',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'mask',
'opacity',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
'font-family',
'font-size',
'font-style',
'font-weight',
'text-anchor',
),
'image' => array(
'class',
'clip-path',
'clip-rule',
'filter',
'height',
'id',
'mask',
'opacity',
'requiredFeatures',
'style',
'systemLanguage',
'transform',
'width',
'x',
'xlink:href',
'xlink:title',
'y',
),
'line' => array(
'class',
'clip-path',
'clip-rule',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'id',
'marker-end',
'marker-mid',
'marker-start',
'mask',
'opacity',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
'x1',
'x2',
'y1',
'y2',
),
'linearGradient' => array(
'class',
'id',
'gradientTransform',
'gradientUnits',
'requiredFeatures',
'spreadMethod',
'systemLanguage',
'x1',
'x2',
'xlink:href',
'y1',
'y2',
),
'marker' => array(
'id',
'class',
'markerHeight',
'markerUnits',
'markerWidth',
'orient',
'preserveAspectRatio',
'refX',
'refY',
'systemLanguage',
'viewBox',
),
'mask' => array(
'class',
'height',
'id',
'maskContentUnits',
'maskUnits',
'width',
'x',
'y'
),
'metadata' => array( 'class', 'id' ),
'path' => array(
'class',
'clip-path',
'clip-rule',
'd',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'id',
'marker-end',
'marker-mid',
'marker-start',
'mask',
'opacity',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
),
'pattern' => array(
'class',
'height',
'id',
'patternContentUnits',
'patternTransform',
'patternUnits',
'requiredFeatures',
'style',
'systemLanguage',
'viewBox',
'width',
'x',
'xlink:href',
'y',
),
'polygon' => array(
'class',
'clip-path',
'clip-rule',
'id',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'id',
'class',
'marker-end',
'marker-mid',
'marker-start',
'mask',
'opacity',
'points',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
),
'polyline' => array(
'class',
'clip-path',
'clip-rule',
'id',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'marker-end',
'marker-mid',
'marker-start',
'mask',
'opacity',
'points',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
),
'radialGradient' => array(
'class',
'cx',
'cy',
'fx',
'fy',
'gradientTransform',
'gradientUnits',
'id',
'r',
'requiredFeatures',
'spreadMethod',
'systemLanguage',
'xlink:href',
),
'rect' => array(
'class',
'clip-path',
'clip-rule',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'height',
'id',
'mask',
'opacity',
'requiredFeatures',
'rx',
'ry',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
'width',
'x',
'y',
),
'stop' => array(
'class',
'id',
'offset',
'requiredFeatures',
'stop-color',
'stop-opacity',
'style',
'systemLanguage',
),
'svg' => array(
'class',
'clip-path',
'clip-rule',
'filter',
'id',
'mask',
'preserveaspectRatio',
'requiredfeatures',
'style',
'systemlanguage',
'viewbox',
'fill',
'fill-opacity',
'fill-rule',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'width',
'height',
'xmlns',
'xmlns:se',
'xmlns:xlink',
'x',
'y',
'enable-background',
),
'switch' => array( 'class', 'id', 'requiredFeatures', 'systemLanguage' ),
'symbol' => array(
'class',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'font-family',
'font-size',
'font-style',
'font-weight',
'id',
'opacity',
'preserveAspectRatio',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'transform',
'viewBox',
),
'text' => array(
'class',
'clip-path',
'clip-rule',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'font-family',
'font-size',
'font-style',
'font-weight',
'id',
'mask',
'opacity',
'requiredFeatures',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'text-anchor',
'transform',
'x',
'xml:space',
'y',
),
'textPath' => array(
'class',
'id',
'method',
'requiredFeatures',
'spacing',
'startOffset',
'style',
'systemLanguage',
'transform',
'xlink:href',
),
'title' => array(),
'tspan' => array(
'class',
'clip-path',
'clip-rule',
'dx',
'dy',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'font-family',
'font-size',
'font-style',
'font-weight',
'id',
'mask',
'opacity',
'requiredFeatures',
'rotate',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'systemLanguage',
'text-anchor',
'textLength',
'transform',
'x',
'xml:space',
'y',
),
'use' => array(
'class',
'clip-path',
'clip-rule',
'fill',
'fill-opacity',
'fill-rule',
'filter',
'height',
'id',
'mask',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'style',
'transform',
'width',
'x',
'xlink:href',
'y',
),
);
foreach ( $whitelist as $tag => $attributes ) {
$allowed[ $tag ] = array();
foreach ( $attributes as $attribute ) {
$allowed[ $tag ][ $attribute ] = true;
}
}
return wp_kses( $svg, $allowed );
}