ID ] = $page->post_title;
}
return $pages;
}
/**
* Get page object
*
* @since 1.0
*
* @return {Object} $page_got_by_title
*/
function alpus_get_page_by_title( $title ) {
$query = new WP_Query(
array(
'post_type' => 'page',
'title' => $title,
'post_status' => 'all',
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'orderby' => 'post_date ID',
'order' => 'ASC',
)
);
if ( ! empty( $query->post ) ) {
$page_got_by_title = $query->post;
} else {
$page_got_by_title = null;
}
return $page_got_by_title;
}
/**
* Get social shares.
*
* @since 1.0
*/
function alpus_get_social_shares() {
return apply_filters(
'alpus_social_links',
array(
'facebook' => array(
'title' => esc_html__( 'Facebook', 'alpus' ),
'icon' => 'fab fa-facebook-f',
'link' => 'https://www.facebook.com/sharer.php?u=$permalink',
),
'twitter' => array(
'title' => esc_html__( 'Twitter', 'alpus' ),
'icon' => 'fab fa-twitter',
'link' => 'https://twitter.com/intent/tweet?text=$title&url=$permalink',
),
'linkedin' => array(
'title' => esc_html__( 'Linkedin', 'alpus' ),
'icon' => 'fab fa-linkedin-in',
'link' => 'https://www.linkedin.com/shareArticle?mini=true&url=$permalink&title=$title',
),
'email' => array(
'title' => esc_html__( 'Email', 'alpus' ),
'icon' => 'far fa-envelope',
'link' => 'mailto:?subject=$title&body=$permalink',
),
'pinterest' => array(
'title' => esc_html__( 'Pinterest', 'alpus' ),
'icon' => 'fab fa-pinterest-p',
'link' => 'https://pinterest.com/pin/create/button/?url=$permalink&media=$image',
),
'reddit' => array(
'title' => esc_html__( 'Reddit', 'alpus' ),
'icon' => 'fab fa-reddit-alien',
'link' => 'http://www.reddit.com/submit?url=$permalink&title=$title',
),
'tumblr' => array(
'title' => esc_html__( 'Tumblr', 'alpus' ),
'icon' => 'fab fa-tumblr',
'link' => 'http://www.tumblr.com/share/link?url=$permalink&name=$title&description=$excerpt',
),
'vk' => array(
'title' => esc_html__( 'VK', 'alpus' ),
'icon' => 'fab fa-vk',
'link' => 'https://vk.com/share.php?url=$permalink&title=$title&image=$image&noparse=true',
),
'whatsapp' => array(
'title' => esc_html__( 'WhatsApp', 'alpus' ),
'icon' => 'fab fa-whatsapp',
'link' => 'whatsapp://send?text=$title-$permalink',
),
'xing' => array(
'title' => esc_html__( 'Xing', 'alpus' ),
'icon' => 'fab fa-xing',
'https://www.xing-share.com/app/user?op=share;sc_p=xing-share;url=$permalink',
),
'instagram' => array(
'title' => esc_html__( 'Instagram', 'alpus' ),
'icon' => 'fab fa-instagram',
'link' => '',
),
)
);
}
/**
* Load google font
*
* @since 1.0
*/
function alpus_load_google_font() {
/**
* Filters google fonts.
*
* @since 1.0
*/
$typos = apply_filters( 'alpus_google_fonts', array( 'typo_default', 'typo_heading', 'typo_custom1', 'typo_custom2', 'typo_custom3', 'typo_ptb_title', 'typo_ptb_subtitle', 'typo_ptb_breadcrumb' ) );
$weights = array();
$fonts = array();
$google_fonts = class_exists( 'Kirki_Fonts' ) ? Kirki_Fonts::get_google_fonts() : array();
foreach ( $typos as $typo ) {
$t = alpus_get_option( $typo );
$family = empty( $t['font-family'] ) ? '' : $t['font-family'];
if ( 'inherit' == $family || 'initial' == $family || '' == $family ) {
continue;
}
if ( ! isset( $t['variant'] ) ) {
$weight = '400';
} elseif ( 'normal' == $t['variant'] || 'regular' == $t['variant'] ) {
$weight = '400';
} elseif ( 'italic' == $t['variant'] ) {
$weight = '400italic';
} else {
$weight = $t['variant'];
}
if ( ! array_key_exists( $family, $weights ) ) {
$weights[ $family ] = array( '300', '400', '500', '600', '700' );
}
if ( ! in_array( $weight, $weights[ $family ] ) ) {
$weights[ $family ][] = $weight;
}
}
global $alpus_layout;
if ( ! empty( $alpus_layout['used_blocks'] ) ) {
foreach ( $alpus_layout['used_blocks'] as $block_id => $block_content ) {
$block_fonts = json_decode( rawurldecode( get_post_meta( $block_id, 'alpus_vc_google_fonts', true ) ), true );
if ( ! empty( $block_fonts ) ) {
$weights = array_merge_recursive( $weights, $block_fonts );
}
}
}
if ( is_singular() ) {
$page_id = get_the_ID();
$page_fonts = json_decode( rawurldecode( get_post_meta( $page_id, 'alpus_vc_google_fonts', true ) ), true );
if ( ! empty( $page_fonts ) ) {
$weights = array_merge_recursive( $weights, $page_fonts );
}
}
foreach ( $weights as $family => $weight ) {
$weight = array_unique( $weight );
$fonts[] = str_replace( ' ', '+', $family ) . ( ! empty( $google_fonts ) && isset( $google_fonts[ $family ] ) && 1 >= count( $google_fonts[ $family ]['variants'] ) ? '' : ':' . implode( ',', $weight ) );
}
if ( $fonts ) {
if ( is_admin() || alpus_get_option( 'google_webfont' ) ) {
$fonts_str = implode( "','", $fonts );
if ( alpus_get_option( 'font_face_display' ) ) {
$fonts_str .= '&display=swap';
}
?>
' .
$native_name .
' (' .
$translated_name .
')';
} else {
$ret = '' . esc_html( $native_name ) . '';
}
} elseif ( $native_name ) {
$ret = $native_name;
} elseif ( $translated_name ) {
$ret = $translated_name;
}
return $ret;
}
/**
* Get responsive cols
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_responsive_cols' ) ) {
function alpus_get_responsive_cols( $cols, $type = 'product' ) {
$result = array();
$base = ! empty( $cols['xlg'] ) ? $cols['xlg'] : 4;
if ( 6 < $base ) { // 7, 8
$result = array(
'xlg' => $base,
'xl' => $base,
'lg' => 6,
'md' => 4,
'sm' => 3,
'min' => 2,
);
} elseif ( 4 < $base ) { // 5, 6
$result = array(
'xlg' => $base,
'xl' => $base,
'lg' => 4,
'md' => 4,
'sm' => 3,
'min' => 2,
);
} elseif ( 2 < $base ) { // 3, 4
$result = array(
'xlg' => $base,
'xl' => $base,
'lg' => $base,
'md' => 3,
'sm' => 2,
'min' => 2,
);
if ( 'post' == $type ) {
$result['min'] = 1;
}
} else { // 1, 2
$result = array(
'xlg' => $base,
'xl' => $base,
'lg' => $base,
'md' => $base,
'sm' => 1,
'min' => 1,
);
}
foreach ( $cols as $w => $c ) {
if ( 'xlg' != $w && $c > 0 ) {
$result[ $w ] = $c;
}
}
/**
* Filters responsive columns.
*
* @since 1.0
*/
return apply_filters( 'alpus_filter_reponsive_cols', $result, $cols );
}
}
if ( ! function_exists( 'alpus_get_grid_space' ) ) {
/**
* Get columns' gutter size value from size string
*
* @since 1.0
*
* @param string $col_sp Columns gutter size string
*
* @return int Gutter size value
*/
function alpus_get_grid_space( $col_sp ) {
if ( 'no' == $col_sp ) {
return 0;
} elseif ( 'sm' == $col_sp ) {
return 10;
} elseif ( 'lg' == $col_sp ) {
return 30;
} elseif ( 'xs' == $col_sp ) {
return 2;
} else {
return 20;
}
}
}
/**
* Get overlay class
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_overlay_class' ) ) {
function alpus_get_overlay_class( $overlay ) {
if ( 'light' === $overlay ) {
return 'overlay-light';
}
if ( 'dark' === $overlay ) {
return 'overlay-dark';
}
if ( 'zoom' === $overlay ) {
return 'overlay-zoom';
}
if ( 'zoom_light' === $overlay ) {
return 'overlay-zoom overlay-light';
}
if ( 'zoom_dark' === $overlay ) {
return 'overlay-zoom overlay-dark';
}
if ( 0 == strncmp( $overlay, 'effect-', 7 ) ) {
return 'overlay-' . $overlay;
}
return '';
}
}
/**
* Loadmore attributes
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_loadmore_attributes' ) ) {
function alpus_loadmore_attributes( $cpt, $props, $args, $loadmore_type, $max_num_pages, $is_filter_cat = false ) {
if ( empty( $args ) ) {
$args = array();
}
$args['cpt'] = $cpt;
return 'data-load="' . esc_attr(
json_encode(
array(
'props' => $props,
'args' => $args,
'max' => $max_num_pages,
)
)
) . '"';
}
}
/**
* Loadmore html
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_loadmore_html' ) ) {
function alpus_loadmore_html( $query, $loadmore_type, $loadmore_label, $loadmore_btn_style = '', $name_prefix = '' ) {
if ( 'button' == $loadmore_type ) {
$class = 'btn btn-load ';
if ( $loadmore_btn_style ) {
$class .= function_exists( 'alpus_widget_button_get_class' ) ? implode( ' ', alpus_widget_button_get_class( $loadmore_btn_style, $name_prefix ) ) : '';
} else {
$class .= 'btn-primary';
}
$label = empty( $loadmore_label ) ? esc_html__( 'Load More', 'alpus' ) : esc_html( $loadmore_label );
echo '';
} elseif ( 'page' == $loadmore_type || ! $loadmore_type ) {
echo alpus_get_pagination( $query, 'pagination-load' );
}
}
}
/**
* Get pagination html
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_pagination_html' ) ) {
function alpus_get_pagination_html( $paged, $total, $class = '' ) {
$classes = array( 'pagination' );
// Set up paginated links.
$args = apply_filters(
'alpus_filter_pagination_args',
array(
'current' => $paged,
'total' => $total,
'end_size' => 1,
'mid_size' => 2,
'prev_text' => ' ' . esc_html__( 'Prev', 'alpus' ),
'next_text' => esc_html__( 'Next', 'alpus' ) . ' ',
)
);
$links = paginate_links( $args );
if ( $class ) {
$classes[] = esc_attr( $class );
}
if ( $links ) {
if ( 1 == $paged ) {
$links = sprintf(
'%s',
$args['prev_text']
) . $links;
} elseif ( $paged == $total ) {
$links .= sprintf(
'%s',
$args['next_text']
);
}
$links = '
' . preg_replace( '/^\s+|\n|\r|\s+$/m', '', $links ) . '
';
}
return $links;
}
}
/**
* Get page links html
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_page_links_html' ) ) :
function alpus_get_page_links_html() {
if ( ! is_singular() ) {
return;
}
global $page, $numpages, $multipage;
if ( $multipage ) {
global $wp_rewrite;
$post = get_post();
$query_args = array();
$prev_link = '';
$next_link = '';
if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
if ( $page + 1 <= $numpages ) {
$next_link = add_query_arg( 'page', $page + 1, get_permalink() );
}
if ( $page > 1 ) {
$prev_link = add_query_arg( 'page', $page - 1, get_permalink() );
}
} elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
if ( $page + 1 <= $numpages ) {
$next_link = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . ( $page + 1 ), 'single_paged' );
}
if ( $page > 1 ) {
$prev_link = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . ( $page - 1 ), 'single_paged' );
}
} else {
if ( $page + 1 <= $numpages ) {
$next_link = trailingslashit( get_permalink() ) . user_trailingslashit( $page + 1, 'single_paged' );
}
if ( $page > 1 ) {
$prev_link = trailingslashit( get_permalink() ) . user_trailingslashit( $page - 1, 'single_paged' );
}
}
if ( $prev_link ) {
$prev_html_escaped = ' ' . esc_html__( 'Prev', 'alpus' ) . '';
} else {
$prev_html_escaped = ' ' . esc_html__( 'Prev', 'alpus' ) . '';
}
if ( $next_link ) {
$next_html_escaped = '' . esc_html__( 'Next', 'alpus' ) . ' ';
} else {
$next_html_escaped = '' . esc_html__( 'Next', 'alpus' ) . ' ';
}
wp_link_pages(
array(
'before' => '',
)
);
}
}
endif;
/**
* Get pagination
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_pagination' ) ) {
function alpus_get_pagination( $query = '', $class = '' ) {
if ( ! $query ) {
global $wp_query;
$query = $wp_query;
}
$paged = $query->get( 'paged' ) ? $query->get( 'paged' ) : ( $query->get( 'page' ) ? $query->get( 'page' ) : 1 );
$total = $query->max_num_pages;
return alpus_get_pagination_html( $paged, $total, $class );
}
}
/**
* Pagination
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_pagination' ) ) {
function alpus_pagination( $query = '', $class = '' ) {
echo alpus_get_pagination( $query, $class );
}
}
/**
* Get excerpt
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_excerpt' ) ) {
function alpus_get_excerpt( $post, $excerpt_length = 45, $excerpt_type = 'words', $readmore_btn = '' ) {
if ( has_excerpt( $post ) ) {
echo alpus_trim_description( alpus_strip_script_tags( get_the_excerpt( $post ) ), $excerpt_length, $excerpt_type ) . alpus_escaped( $readmore_btn );
} elseif ( strpos( $post->post_content, '' ) ) {
$content = apply_filters( 'the_content', get_the_content() );
if ( $content ) {
echo alpus_escaped( $content . $readmore_btn );
}
} else {
$content = alpus_trim_description( $post->post_content, $excerpt_length, $excerpt_type );
if ( $content ) {
echo alpus_escaped( $content . $readmore_btn );
}
}
}
}
/**
* Get excerpt.
*
* @since 1.0
*
* @param string $text Whole excerpt content
* @param int $limit Excerpt length
* @param string $unit Excerpt unit
* @return string Returns exctracted excerpt
*/
function alpus_trim_description( $text = '', $limit = 45, $unit = 'words' ) {
$content = wp_strip_all_tags( $text );
$content = strip_shortcodes( $content );
if ( ! $limit ) {
$limit = 45;
}
if ( ! $unit ) {
$unit = 'words';
}
if ( 'words' == $unit ) {
$content = wp_trim_words( $content, $limit );
} else { // by characters
$affix = ( strlen( $content ) < $limit ? '' : ' ...' );
$content = mb_substr( $content, 0, $limit ) . $affix;
}
if ( $content ) {
$content = '' . wp_strip_all_tags( $content ) . '
';
}
/**
* Filters trim description.
*
* @since 1.0
*/
return apply_filters( 'alpus_filter_trim_description', $content );
}
/**
* The post comment
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_post_comment' ) ) {
function alpus_post_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
?>
id="comment-">
comment_type || 'trackback' == $comment->comment_type ) { ?>
'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second',
);
foreach ( $tokens as $unit => $text ) {
if ( $time < $unit ) {
continue;
}
$number_of_units = floor( $time / $unit );
return $number_of_units . ' ' . $text . ( ( $number_of_units > 1 ) ? 's' : '' );
}
}
/**
* Minify css
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_minify_css' ) ) {
function alpus_minify_css( $style ) {
if ( ! $style ) {
return;
}
// Change ::before, ::after to :before, :after
$style = str_replace( array( '::before', '::after' ), array( ':before', ':after' ), $style );
$style = preg_replace( '/\s+/', ' ', $style );
$style = preg_replace( '/;(?=\s*})/', '', $style );
$style = preg_replace( '/(,|:|;|\{|}|\*\/|>) /', '$1', $style );
$style = preg_replace( '/ (,|;|\{|})/', '$1', $style );
$style = preg_replace( '/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $style );
$style = preg_replace( '/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $style );
$style = preg_replace( '/\/\*[^\/]*\*\//', '', $style );
$style = str_replace( array( '}100%{', ',100%{', ' !important', ' >' ), array( '}to{', ',to{', '!important', '>' ), $style );
// Trim
$style = trim( $style );
return $style;
}
}
if ( ! function_exists( 'alpus_get_page_layout' ) ) {
/**
* Get current page's layout name.
*
* @since 1.0
* @return {string}
*/
function alpus_get_page_layout() {
/**
* Check global variable first
*
* @since 1.2.0
*/
global $alpus_page_layout;
if ( $alpus_page_layout ) {
return $alpus_page_layout;
}
/**
* Filters current page layout.
*
* @since 1.0
*/
$layout = apply_filters( 'alpus_get_page_layout', '' );
if ( $layout ) {
return $layout;
}
if ( is_404() ) {
return 'error';
}
if ( class_exists( 'WooCommerce' ) && is_cart() ) {
return 'cart';
}
if ( class_exists( 'WooCommerce' ) && is_checkout() ) {
return 'checkout';
}
if ( alpus_is_shop() ) { // product archive
return 'archive_product';
}
$type = get_post_type();
if ( ! $type ) {
$type = get_query_var( 'post_type' );
if ( ! $type ) {
$type = 'post';
}
}
if ( is_home() || is_archive() || is_search() ) {
$taxonomy = get_query_var( 'taxonomy' );
if ( $taxonomy ) {
$taxonomy = get_taxonomy( $taxonomy );
if ( ! empty( $taxonomy->object_type ) ) {
$type = $taxonomy->object_type[0];
}
}
if ( 'post' == $type || 'attachment' == $type || is_search() && 'any' == get_query_var( 'post_type' ) ) {
return 'archive_post';
}
return 'archive_' . $type; // custom post type archive
}
if ( is_page() || ALPUS_NAME . '_template' == $type ) { // single page
return 'single_page';
}
if ( alpus_is_product() ) { // product single
return 'single_product';
}
if ( is_single() ) {
if ( 'post' == $type || 'attachment' == $type ) {
return 'single_post';
}
return 'single_' . $type; // custom post type single page
}
return '';
}
}
if ( ! function_exists( 'alpus_breadcrumb' ) ) {
/**
* Display breadcrumb using WooCommerce.
*
* @since 1.0
*/
function alpus_breadcrumb() {
global $alpus_layout;
$wrap_class = 'breadcrumb-container';
if ( isset( $alpus_layout['breadcrumb_wrap'] ) && 'full' != $alpus_layout['breadcrumb_wrap'] ) {
$wrap_class .= 'container-fluid' == $alpus_layout['breadcrumb_wrap'] ? ' container-fluid' : ' container';
}
echo '';
if ( function_exists( 'rank_math_the_breadcrumbs' ) && ( RankMath\Helper::get_settings( 'general.breadcrumbs' ) ) ) {
echo '
';
rank_math_the_breadcrumbs();
echo '
';
} else {
/**
* Fires after run breadcrumb functions.
*
* @since 1.0
*/
do_action( 'alpus_breadcrumb' );
}
echo '
';
}
}
/**
* Is shop
*
* @since 1.0
*/
function alpus_is_shop() {
if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_category() || is_product_tag() || ( is_search() && isset( $_POST['post_type'] ) && 'product' == $_POST['post_type'] ) ) ) { // Shop Page
/**
* Filters page is shop page or not.
*
* @since 1.0
*/
return apply_filters( 'alpus_is_shop', true );
} else {
$term = get_queried_object();
if ( class_exists( 'WooCommerce' ) && $term && isset( $term->taxonomy ) &&
in_array(
$term->taxonomy,
get_taxonomies(
array(
'object_type' => array( 'product' ),
),
'names',
'and'
)
) ) {
return apply_filters( 'alpus_is_shop', true );
}
}
return apply_filters( 'alpus_is_shop', false );
}
/**
* Is product
*
* @since 1.0
*/
function alpus_is_product() {
if ( class_exists( 'WooCommerce' ) && is_product() ) {
return true;
}
/**
* Filters page is product page or not.
*
* @since 1.0
*/
return apply_filters( 'alpus_is_product', false );
}
/**
* Set loop prop for woocommerce
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_wc_set_loop_prop' ) ) {
function alpus_wc_set_loop_prop() {
// Category Props //////////////////////////////////////////////////////////////////////////////
wc_set_loop_prop( 'category_type', 'default' );
// Product Props ///////////////////////////////////////////////////////////////////////////////
wc_set_loop_prop( 'product_type', 'default' );
if ( alpus_is_shop() || alpus_is_product() ) {
wc_set_loop_prop( 'show_labels', array( 'hot', 'sale', 'new', 'stock' ) );
}
}
}
if ( ! function_exists( 'alpus_wc_get_loop_prop' ) ) {
/**
* Gets a property from the woocommerce_loop global.
*
* @since 1.0
* @param string $prop Prop to get.
* @param string $default Default if the prop does not exist.
* @return mixed
*/
function alpus_wc_get_loop_prop( $prop, $default = '' ) {
if ( empty( $GLOBALS['woocommerce_loop'] ) ) {
wc_setup_loop(); // Ensure shop loop is setup.
}
return isset( $GLOBALS['woocommerce_loop'], $GLOBALS['woocommerce_loop'][ $prop ] ) ? $GLOBALS['woocommerce_loop'][ $prop ] : $default;
}
}
if ( ! function_exists( 'alpus_print_mobile_bar' ) ) {
/**
* Print alpus mobile navigation bar
*
* @since 1.0
*
*/
function alpus_print_mobile_bar() {
$mobile_bar = alpus_get_option( 'mobile_bar_icons' );
$result = '';
$cnt = 0;
if ( ! $mobile_bar ) {
return;
}
foreach ( $mobile_bar as $item ) {
$icon = alpus_get_option( 'mobile_bar_' . $item . '_icon' );
$label = alpus_get_option( 'mobile_bar_' . $item . '_label' );
if ( 'menu' == $item ) {
if ( alpus_get_option( 'mobile_menu_items' ) ) {
$result .= '';
++ $cnt;
}
} elseif ( 'home' == $item ) {
$result .= '' . $label . '';
++ $cnt;
} elseif ( 'shop' == $item && class_exists( 'WooCommerce' ) ) {
$item_class = 'mobile-item mobile-item-categories';
$mobile_menus = alpus_get_option( 'mobile_menu_items' );
if ( ! empty( $mobile_menus ) && count( $mobile_menus ) ) {
foreach ( $mobile_menus as $menu ) {
if ( 'categories' == $menu ) {
$item_class .= ' show-categories-menu';
break;
}
}
}
$result .= '' . $label . '';
++ $cnt;
} elseif ( 'wishlist' == $item && class_exists( 'WooCommerce' ) && defined( 'YITH_WCWL' ) ) {
$result .= '' . $label . '';
++ $cnt;
} elseif ( 'compare' == $item && class_exists( 'WooCommerce' ) ) {
$result .= '' . esc_html__( 'Compare', 'alpus' ) . '';
$cnt ++;
} elseif ( 'account' == $item && class_exists( 'WooCommerce' ) ) {
$result .= '' . $label . '';
++ $cnt;
} elseif ( 'cart' == $item && class_exists( 'WooCommerce' ) ) {
ob_start();
?>
' . $label . '';
++ $cnt;
} else {
$result .= '' . $label . '';
++ $cnt;
}
}
if ( $result ) {
echo '' . $result . '
';
}
}
}
/**
* Print Alpus Block
*
* @param string $block_name The block name to print.
* @param bool $is_menu Determines whether block is menu or not.
* @since 1.0
*/
if ( ! function_exists( 'alpus_print_template' ) ) :
function alpus_print_template( $block_name, $is_menu = false ) {
if ( $block_name && defined( 'ALPUS_CORE_FRAMEWORK_PATH' ) ) {
$atts = array(
'name' => $block_name,
'is_menu' => $is_menu,
);
require alpus_core_framework_path( ALPUS_CORE_FRAMEWORK_PATH . '/widgets/block/render-block.php' );
}
}
endif;
/**
* Check Used Blocks
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_get_page_blocks' ) ) :
function alpus_get_page_blocks() {
global $alpus_layout;
$used_blocks = array();
if ( empty( $alpus_layout ) || ! isset( $alpus_layout['header'] ) ) {
return array();
}
if ( ! empty( $alpus_layout['used_blocks'] ) ) {
return $alpus_layout['used_blocks'];
}
// blocks set from layout builder
$fields = array( 'header', 'footer', 'ptb', 'top_block', 'inner_top_block', 'inner_bottom_block', 'bottom_block', 'top_bar', 'popup', 'error_block' );
foreach ( $fields as $field ) {
if ( ! empty( $alpus_layout[ $field ] ) && 'hide' != $alpus_layout[ $field ] ) {
$used_blocks[] = $alpus_layout[ $field ];
}
}
// Sidebar blocks
$widgets = array();
$sidebar_widgets = get_option( 'sidebars_widgets' );
if ( isset( $alpus_layout['top_sidebar'] ) && isset( $sidebar_widgets[ $alpus_layout['top_sidebar'] ] ) ) {
$widgets = array_merge( $widgets, $sidebar_widgets[ $alpus_layout['top_sidebar'] ] );
}
if ( isset( $alpus_layout['left_sidebar'] ) && isset( $sidebar_widgets[ $alpus_layout['left_sidebar'] ] ) ) {
$widgets = array_merge( $widgets, $sidebar_widgets[ $alpus_layout['left_sidebar'] ] );
}
if ( isset( $alpus_layout['right_sidebar'] ) && isset( $sidebar_widgets[ $alpus_layout['right_sidebar'] ] ) ) {
$widgets = array_merge( $widgets, $sidebar_widgets[ $alpus_layout['right_sidebar'] ] );
}
if ( ! empty( $widgets ) ) {
global $wp_registered_widgets;
foreach ( $widgets as $key ) {
if ( isset( $wp_registered_widgets[ $key ] ) && isset( $wp_registered_widgets[ $key ]['callback'] ) ) {
$widget_obj = $wp_registered_widgets[ $key ]['callback'][0];
if ( ! empty( $widget_obj ) && 'block-widget' == $widget_obj->id_base ) {
$args = get_option( $widget_obj->option_name );
if ( ! empty( $args[ $widget_obj->number ] ) ) {
$used_blocks[] = $args[ $widget_obj->number ]['id'];
}
}
}
}
}
// single product layout builder
if ( alpus_is_product() && ! empty( $alpus_layout['single_product_block'] ) ) {
$used_blocks[] = $alpus_layout['single_product_block'];
}
// shop builder
if ( function_exists( 'alpus_is_shop' ) && alpus_is_shop() &&
! empty( $alpus_layout['shop_block'] ) ) {
$used_blocks[] = $alpus_layout['shop_block'];
}
// Archive builder
if ( ( is_home() || is_archive() ) && ! empty( $alpus_layout['archive_block'] ) ) {
$used_blocks[] = $alpus_layout['archive_block'];
}
// Single builder
if ( is_single() && ! empty( $alpus_layout['single_block'] ) ) {
$used_blocks[] = $alpus_layout['single_block'];
}
// blocks in page-content
if ( is_singular() ) {
$page_blocks = get_post_meta( get_the_ID(), '_alpus_vc_blocks_content', true );
if ( ! empty( $page_blocks ) && is_array( $page_blocks ) ) {
$used_blocks = array_merge( $used_blocks, $page_blocks );
}
}
return array_fill_keys(
array_unique( $used_blocks, SORT_NUMERIC ),
array(
'css' => false,
'js' => false,
)
);
}
endif;
/**
* Print popup template
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_print_popup_template' ) ) {
function alpus_print_popup_template( $popup_id, $popup_delay ) {
if ( alpus_get_feature( 'fs_pb_elementor' ) && defined( 'ELEMENTOR_VERSION' ) && ! empty( get_post_meta( $popup_id, '_elementor_data', true ) ) ) {
$settings = get_post_meta( $popup_id, '_elementor_page_settings', true );
}
echo '';
}
}
/**
* Clear alpus transient
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_clear_transient' ) ) {
function alpus_clear_transient() {
global $wpdb;
$cache_key = 'alpus-clear-brand-transient';
$brand_transients = wp_cache_get( $cache_key, 'alpus-transient' );
$results = array();
if ( false == $brand_transients ) {
$brand_transients = $wpdb->get_results(
"SELECT
AVG(rating) AS rating,
term_taxonomy_id,
term_id,
COUNT(temp1.post_id) AS review_count
FROM
(SELECT
post_id,
meta_value AS rating
FROM
$wpdb->postmeta AS pm
INNER JOIN $wpdb->posts AS wpp
ON pm.post_id = wpp.ID
WHERE wpp.post_type = 'product'
AND pm.meta_key = '_wc_average_rating'
GROUP BY post_id) AS temp1
LEFT JOIN
(SELECT
wptt.term_taxonomy_id,
term_id,
wtr.object_id AS post_id
FROM
$wpdb->term_taxonomy AS wptt
INNER JOIN $wpdb->term_relationships AS wtr
ON wptt.term_taxonomy_id = wtr.term_taxonomy_id
WHERE wptt.taxonomy = 'product_brand'
GROUP BY post_id) AS temp2
ON temp1.post_id = temp2.post_id
WHERE term_id IS NOT NULL
GROUP BY term_id"
);
wp_cache_set( $cache_key, $brand_transients, 'alpus-transient', 3600 * 6 );
}
if ( is_array( $brand_transients ) && count( $brand_transients ) > 0 ) {
foreach ( $brand_transients as $transient ) {
update_term_meta( $transient->term_id, 'review_count', absint( $transient->review_count ) );
update_term_meta( $transient->term_id, 'rating', abs( round( $transient->rating, 2 ) ) );
}
}
if ( class_exists( 'Alpus_Product_Brand' ) ) {
delete_transient( 'wc_layered_nav_counts_product_brand' );
}
}
}
/**
* Get list of templates and sidebars
*
* @since 1.0
*/
function alpus_get_global_templates_sidebars() {
global $wp_registered_sidebars;
$alpus_templates = array();
$template_types = array();
if ( alpus_get_feature( 'fs_builder_block' ) ) {
$template_types[] = 'block';
}
if ( alpus_get_feature( 'fs_builder_header' ) ) {
$template_types[] = 'header';
}
if ( alpus_get_feature( 'fs_builder_footer' ) ) {
$template_types[] = 'footer';
}
if ( alpus_get_feature( 'fs_builder_popup' ) ) {
$template_types[] = 'popup';
}
if ( class_exists( 'WooCommerce' ) && alpus_get_feature( 'fs_plugin_woocommerce' ) && alpus_get_feature( 'fs_builder_singleproduct' ) ) {
$template_types[] = 'product_layout';
}
if ( class_exists( 'WooCommerce' ) && alpus_get_feature( 'fs_plugin_woocommerce' ) && alpus_get_feature( 'fs_builder_shop' ) ) {
$template_types[] = 'shop_layout';
}
if ( class_exists( 'WooCommerce' ) && alpus_get_feature( 'fs_plugin_woocommerce' ) && alpus_get_feature( 'fs_builder_cart' ) ) {
$template_types[] = 'cart';
}
if ( alpus_get_feature( 'fs_builder_sidebar' ) ) {
$template_types[] = 'sidebar';
}
if ( alpus_get_feature( 'fs_builder_single' ) ) {
$template_types[] = 'single';
}
if ( alpus_get_feature( 'fs_builder_archive' ) ) {
$template_types[] = 'archive';
}
if ( class_exists( 'WooCommerce' ) && alpus_get_feature( 'fs_plugin_woocommerce' ) && alpus_get_feature( 'fs_builder_checkout' ) ) {
$template_types[] = 'checkout';
}
// Get Templates
foreach ( $template_types as $template_type ) {
$posts = get_posts(
array(
'post_type' => ALPUS_NAME . '_template',
'meta_key' => ALPUS_NAME . '_template_type',
'meta_value' => $template_type,
'numberposts' => -1,
)
);
sort( $posts );
foreach ( $posts as $post ) {
$alpus_templates[ $template_type ][ $post->ID ] = $post->post_title;
}
}
// Get Sidebars
$alpus_templates['sidebar'] = array();
foreach ( $wp_registered_sidebars as $id => $sidebar ) {
$alpus_templates['sidebar'][ $id ] = $sidebar['name'];
}
return $alpus_templates;
}
/**
* Check file write permission
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_check_file_write_permission' ) ) {
function alpus_check_file_write_permission( $filename ) {
if ( is_writable( dirname( $filename ) ) == false ) {
@chmod( dirname( $filename ), 0755 );
}
if ( file_exists( $filename ) ) {
if ( is_writable( $filename ) == false ) {
@chmod( $filename, 0755 );
}
@unlink( $filename );
}
}
}
/**
* Get search form
*
* @since 1.0
*/
if ( ! function_exists( 'alpus_search_form' ) ) {
function alpus_search_form( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'type' => 'classic',
'toggle_type' => 'overlap',
'search_align' => 'start',
'show_categories' => false,
'where' => '',
'live_search' => (bool) alpus_get_option( 'live_search' ),
'search_post_type' => alpus_get_option( 'search_post_type' ),
'label' => '',
'placeholder' => '',
)
);
extract( $args );
ob_start();
$class = '';
if ( 'toggle' == $type ) {
$class .= ' hs-toggle hs-' . $toggle_type;
}
if ( $show_categories ) {
$class .= ' hs-expanded';
} else {
$class .= ' hs-simple';
}
if ( 'toggle' == $type && 'dropdown' == $toggle_type ) {
$class .= ' hs-' . $search_align;
}
?>
', '' ); ?>