File: /home/globfdxw/diasporameetsafrica.com/wp-content/themes/lavelo/includes/frontend-functions.php
<?php
/*
* All Front-End Helper Functions
* Author & Copyright:Wpoceans
* URL: http://themeforest.net/user/wpoceans
*/
/* Exclude category from blog */
if( ! function_exists( 'lavelo_excludeCat' ) ) {
function lavelo_excludeCat($query) {
if ( $query->is_home ) {
$exclude_cat_ids = cs_get_option('theme_exclude_categories');
if($exclude_cat_ids) {
foreach( $exclude_cat_ids as $exclude_cat_id ) {
$exclude_from_blog[] = '-'. $exclude_cat_id;
}
$query->set('cat', implode(',', $exclude_from_blog));
}
}
return $query;
}
add_filter('pre_get_posts', 'lavelo_excludeCat');
}
/* Excerpt Length */
class LaveloExcerpt {
// Default length (by WordPress)
public static $length = 55;
// Output: lavelo_excerpt('short');
public static $types = array(
'short' => 25,
'regular' => 55,
'long' => 100
);
/**
* Sets the length for the excerpt,
* then it adds the WP filter
* And automatically calls the_excerpt();
*
* @param string $new_length
* @return void
* @author Baylor Rae'
*/
public static function length($new_length = 55) {
LaveloExcerpt::$length = $new_length;
add_filter('excerpt_length', 'LaveloExcerpt::new_length');
LaveloExcerpt::output();
}
// Tells WP the new length
public static function new_length() {
if( isset(LaveloExcerpt::$types[LaveloExcerpt::$length]) )
return LaveloExcerpt::$types[LaveloExcerpt::$length];
else
return LaveloExcerpt::$length;
}
// Echoes out the excerpt
public static function output() {
the_excerpt();
}
}
// Custom Excerpt Length
if( ! function_exists( 'lavelo_excerpt' ) ) {
function lavelo_excerpt($length = 55) {
LaveloExcerpt::length($length);
}
}
if ( ! function_exists( 'lavelo_new_excerpt_more' ) ) {
function lavelo_new_excerpt_more( $more ) {
return ' ';
}
add_filter('excerpt_more', 'lavelo_new_excerpt_more');
}
/* Tag Cloud Widget - Remove Inline Font Size */
if( ! function_exists( 'lavelo_tag_cloud' ) ) {
function lavelo_tag_cloud($tag_string){
return preg_replace("/style='font-size:.+pt;'/", '', $tag_string);
}
add_filter('wp_generate_tag_cloud', 'lavelo_tag_cloud', 10, 3);
}
/* Password Form */
if( ! function_exists( 'lavelo_password_form' ) ) {
function lavelo_password_form( $output ) {
$output = str_replace( 'type="submit"', 'type="submit" class=""', $output );
return $output;
}
add_filter('the_password_form' , 'lavelo_password_form');
}
/* Maintenance Mode */
if( ! function_exists( 'lavelo_maintenance_mode' ) ) {
function lavelo_maintenance_mode(){
$maintenance_mode_page = cs_get_option( 'maintenance_mode_page' ) && cs_get_option( 'enable_maintenance_mode' );
if ( ! empty( $maintenance_mode_page ) && ! is_user_logged_in() ) {
get_template_part('theme-layouts/post/content', 'maintenance');
exit;
}
}
add_action( 'wp', 'lavelo_maintenance_mode', 1 );
}
/* Widget Layouts */
if ( ! function_exists( 'lavelo_footer_widgets' ) ) {
function lavelo_footer_widgets() {
$output = '';
$footer_widget_layout = cs_get_option('footer_widget_layout');
if( $footer_widget_layout ) {
switch ( $footer_widget_layout ) {
case 1: $widget = array('piece' => 1, 'class' => 'col-lg-12'); break;
case 2: $widget = array('piece' => 2, 'class' => 'col-lg-6'); break;
case 3: $widget = array('piece' => 3, 'class' => 'col-lg-4'); break;
case 4: $widget = array('piece' => 4, 'class' => 'col-lg-3 col-md-3 col-sm-6'); break;
case 5: $widget = array('piece' => 3, 'class' => 'col-lg-3', 'layout' => 'col-lg-6', 'queue' => 1); break;
case 6: $widget = array('piece' => 3, 'class' => 'col-lg-3', 'layout' => 'col-lg-6', 'queue' => 2); break;
case 7: $widget = array('piece' => 3, 'class' => 'col-lg-3', 'layout' => 'col-lg-6', 'queue' => 3); break;
case 8: $widget = array('piece' => 4, 'class' => 'col-lg-2', 'layout' => 'col-lg-6', 'queue' => 1); break;
case 9: $widget = array('piece' => 4, 'class' => 'col-lg-2', 'layout' => 'col-lg-6', 'queue' => 4); break;
default : $widget = array('piece' => 4, 'class' => 'col-lg-3'); break;
}
for( $i = 1; $i < $widget["piece"]+1; $i++ ) {
$widget_class = ( isset( $widget["queue"] ) && $widget["queue"] == $i ) ? $widget["layout"] : $widget["class"];
if (is_active_sidebar('footer-'. $i)) {
$output .= '<div class="'. $widget_class .'">';
ob_start();
dynamic_sidebar( 'footer-'. $i );
$output .= ob_get_clean();
$output .= '</div>';
}
}
}
return $output;
}
}
/* WP Link Pages */
if ( ! function_exists( 'lavelo_wp_link_pages' ) ) {
function lavelo_wp_link_pages() {
$defaults = array(
'before' => '<div class="wp-link-pages">' . esc_html__( 'Pages:', 'lavelo' ),
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'next_or_number' => 'number',
'separator' => ' ',
'pagelink' => '%',
'echo' => 1
);
wp_link_pages( $defaults );
}
}
/* Metas */
if ( ! function_exists( 'lavelo_post_metas' ) ) {
function lavelo_post_metas() {
$metas_hide = (array) cs_get_option( 'theme_metas_hide' );
?>
<div class="bp-top-meta">
<?php
if ( !in_array( 'category', $metas_hide ) ) { // Category Hide
if ( get_post_type() === 'post') {
$category_list = get_the_category_list( ' ' );
if ( $category_list ) {
echo '<div class="bp-cat">'. $category_list .' </div>';
}
}
} // Category Hides
if ( !in_array( 'date', $metas_hide ) ) { // Date Hide
?>
<div class="bp-date">
<span><?php echo get_the_date('M d, Y'); ?></span>
</div>
<?php } // Date Hides
if ( !in_array( 'author', $metas_hide ) ) { // Author Hide
?>
<div class="bp-author">
<?php
printf(
'<span>'. esc_html__('by','lavelo') .' <a href="%1$s" rel="author">%2$s</a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
get_the_author()
);
?>
</div>
<?php } ?>
</div>
<?php
}
}
/* Author Info */
if ( ! function_exists( 'lavelo_author_info' ) ) {
function lavelo_author_info() {
if (get_the_author_meta( 'url' )) {
$author_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
$website_url = get_the_author_meta( 'url' );
$target = 'target="_blank"';
} else {
$author_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
$website_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
$target = '';
}
// variables
$author_text = cs_get_option('author_text');
$author_text = $author_text ? $author_text : esc_html__( 'Author', 'lavelo' );
$author_content = get_the_author_meta( 'description' );
$facebook = get_the_author_meta( 'facebook' );
$twitter = get_the_author_meta( 'twitter' );
$instagram = get_the_author_meta( 'instagram' );
$pinterest = get_the_author_meta( 'pinterest' );
if ($author_content) {
?>
<div class="author-box">
<div class="author-avatar">
<a href="<?php the_permalink(); ?>" target="_blank"><?php echo get_avatar( get_the_author_meta( 'ID' ), 125 ); ?></a>
</div>
<div class="author-content">
<a href="<?php echo esc_url($author_url); ?>" class="author-name"><?php echo get_the_author_meta('first_name').' '.get_the_author_meta('last_name'); ?></a>
<p><?php echo get_the_author_meta( 'description' ); ?></p>
<?php if( $facebook || $twitter || $instagram || $pinterest ) { ?>
<div class="socials">
<ul class="social-lnk">
<li>
<?php if($twitter) { ?>
<a href="<?php echo esc_url( $twitter ); ?>"><i class="fa fa-twitter"></i></a>
<?php } ?>
</li>
<li>
<?php if($facebook) { ?>
<a href="<?php echo esc_url( $facebook ); ?>"><i class="fa fa-facebook"></i></a>
<?php } ?>
</li>
<li>
<?php if($instagram) { ?>
<a href="<?php echo esc_attr( $instagram ); ?>"><i class="fa fa-instagram"></i></a>
<?php } ?>
</li>
<li>
<?php if($pinterest) { ?>
<a href="<?php echo esc_url( $pinterest ); ?>"><i class="fa fa-pinterest-p"></i></a>
<?php } ?>
</li>
</ul>
</div>
<?php } ?>
</div>
</div>
<?php
} // if $author_content
}
}
/* ==============================================
Custom Comment Area Modification
=============================================== */
if ( ! function_exists( 'lavelo_comment_modification' ) ) {
function lavelo_comment_modification($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
$comment_class = empty( $args['has_children'] ) ? '' : 'parent';
?>
<<?php echo esc_attr($tag); ?> <?php comment_class('item ' . $comment_class .' ' ); ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<article>
<div id="div-comment-<?php comment_ID() ?>" class="lavelo-comment">
<?php endif; ?>
<div class="comment-theme">
<div class="comment-image">
<?php if ( $args['avatar_size'] != 0 ) {
echo get_avatar( $comment, 80 );
} ?>
</div>
</div>
<div class="comment-main-area">
<div class="comments-meta">
<h4><?php printf( '%s', get_comment_author() ); ?></h4>
<span class="comments-date"><?php echo 'says '. get_comment_date(' F d, Y'); echo ' at '. get_comment_time(); ?></span>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php echo esc_html__( 'Your comment is awaiting moderation.', 'lavelo' ); ?></em>
<?php endif; ?>
<div class="comment-content">
<?php comment_text(); ?>
<div class="comments-reply">
<?php
comment_reply_link( array_merge( $args, array(
'reply_text' => '<span class="comment-reply-link icofont icofont-reply-all">'.esc_html__( 'Reply', 'lavelo' ).'</span>',
'before' => '',
'class' => '',
'depth' => $depth,
'max_depth' => $args['max_depth']
) ) );
?>
</div>
</div>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
</article>
<?php endif;
}
}
/* Comments Form - Textarea next to Normal Fields */
if( ! function_exists( 'lavelo_move_comment_field' ) ) {
add_filter( 'comment_form_fields', 'lavelo_move_comment_field' );
function lavelo_move_comment_field( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
}
/* Title Area */
if ( ! function_exists( 'lavelo_title_area' ) ) {
function lavelo_title_area() {
global $post, $wp_query;
// Get post meta in all type of WP pages
$lavelo_id = ( isset( $post ) ) ? $post->ID : 0;
$lavelo_id = ( is_home() ) ? get_option( 'page_for_posts' ) : $lavelo_id;
$lavelo_meta = get_post_meta( $lavelo_id, 'page_type_metabox', true );
if ( $lavelo_meta && ( !is_archive() )) {
$custom_title = $lavelo_meta['page_custom_title'];
if ($custom_title) {
$custom_title = $custom_title;
} elseif(post_type_archive_title()) {
post_type_archive_title();
} else {
$custom_title = '';
}
} else { $custom_title = ''; }
if ( is_home() && is_front_page() ) {
echo esc_html__( 'Blog', 'lavelo' );
} elseif ( is_home() && !is_front_page() ) {
single_post_title();
} elseif ( is_search() ) {
printf( esc_html__( 'Search Results for %s', 'lavelo' ), '<span>' . get_search_query() . '</span>' );
} elseif ( is_category() || is_tax() ){
single_cat_title();
} elseif ( is_tag() ){
single_tag_title( esc_html__('Posts Tagged: ', 'lavelo') );
} elseif ( is_archive() ){
if ( is_day() ) {
printf( wp_kses( __( 'Archive for <span>%s</span>', 'lavelo' ), array( 'span' => array() ) ), get_the_date());
} elseif ( is_month() ) {
printf( wp_kses( __( 'Archive for <span>%s</span>', 'lavelo' ), array( 'span' => array() )), get_the_date( 'F, Y' ));
} elseif ( is_year() ) {
printf( wp_kses( __( 'Archive for <span>%s</span>', 'lavelo' ), array( 'span' => array() ) ), get_the_date( 'Y' ));
} elseif ( is_author() ) {
printf( wp_kses( __( 'Posts by: <span>%s</span>', 'lavelo' ), array( 'span' => array() ) ), get_the_author_meta( 'display_name', $wp_query->post->post_author ));
} elseif ( is_post_type_archive() ) {
post_type_archive_title();
} else {
esc_html_e( 'Archives', 'lavelo' );
}
} elseif( is_singular( 'case' ) ) {
esc_html_e('Case', 'lavelo');
} elseif( is_singular( 'attorney' ) ) {
esc_html_e('Attorney', 'lavelo');
} elseif( is_singular( 'service' ) ) {
esc_html_e('Service', 'lavelo');
} elseif( is_404() ) {
esc_html_e('404 Error', 'lavelo');
} elseif( $custom_title ) {
echo esc_attr($custom_title);
} else {
if (is_single()) {
echo esc_html__( 'Blog', 'lavelo' );
} else {
the_title();
}
}
}
}
/**
* Pagination Function
*/
if ( ! function_exists( 'lavelo_paging_nav' ) ) {
function lavelo_paging_nav() {
if ( function_exists('wp_pagenavi')) {
wp_pagenavi();
} else {
$older_post = cs_get_option('older_post');
$newer_post = cs_get_option('newer_post');
$older_post = $older_post ? $older_post : esc_html__( 'OLDER POSTS', 'lavelo' );
$newer_post = $newer_post ? $newer_post : esc_html__( 'NEWER POSTS', 'lavelo' );
global $wp_query;
$big = 999999999;
if($wp_query->max_num_pages == '1' ) {} else {echo '';}
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'prev_text' => $older_post,
'next_text' => $newer_post,
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'list'
));
if($wp_query->max_num_pages == '1' ) {} else {echo '';}
}
}
}
// blog pagination
if ( !function_exists('lavelo_paginate_links') ) {
function lavelo_paginate_links( $echo = true ) {
global $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_next' => true,
'prev_text' => wp_kses_post( __( '<i class="fa fa-angle-left" aria-hidden="true"></i>', 'lavelo' ) ),
'next_text' => wp_kses_post( __( '<i class="fa fa-angle-right" aria-hidden="true"></i>', 'lavelo' ) ),
)
);
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
$pagination = '<div class="row"><nav class="col-lg-12 irs-pagination text-center"><ul class="pagination">';
foreach ( $pages as $page ) {
$pagination .= "<li>$page</li>";
}
$pagination .= '</ul></nav></div>';
if ( $echo ) {
echo wp_kses_post( $pagination );
} else {
return $pagination;
}
}
}
}
// Pingback Head
function lavelo_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
add_action( 'wp_head', 'lavelo_pingback_header' );
// checking video id
function lavelo_video_format_data( $url ){
global $post;
$parsed = parse_url($url);
if ( strpos( $parsed['host'], 'vimeo' ) !== false ) {
$url = $url;
if (preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $regs)) {
$id = $regs[3];
}
return 'https://player.vimeo.com/video/'.$id.'?title=0&byline=0&portrait=0&badge=0&autoplay=0&title=0';
} else {
preg_match(
'/[\\?\\&]v=([^\\?\\&]+)/',
$url,
$matches
);
$id = $matches[1];
return 'https://www.youtube.com/embed/'.$id.'?&autoplay=0&showinfo=0';
}
}
/**
* SINGLE PAGINATION
*/
if(!function_exists('lavelo_single_pagination')) {
function lavelo_single_pagination() {
$next_post = get_next_post( '', false);
$prev_post = get_previous_post( '', false);
$newer_post = cs_get_option('newer_post');
$newer_post = ( $newer_post ) ? $newer_post : esc_html__('Next Article', 'lavelo');
$older_post = cs_get_option('older_post');
$older_post = ( $older_post ) ? $older_post : esc_html__('Previous Article', 'lavelo');
if (empty($next_post) || empty($prev_post)) {
$style = 'border: none; width:100%;';
$class = 'single';
} else {
$style = '';
$class = '';
}
if ( !empty( $prev_post ) || !empty( $next_post ) ) { ?>
<div class="more-posts clearfix">
<?php if (!empty( $prev_post )): ?>
<div class="previous-post <?php echo esc_attr($class); ?>" style="<?php echo esc_attr( $style ); ?>">
<a href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>">
<span class="post-control-link"><?php echo esc_html($older_post); ?>: </span>
<span class="post-name"><?php echo esc_html($prev_post->post_title); ?></span>
</a>
</div>
<?php endif; ?>
<?php if (!empty( $next_post )): ?>
<div class="next-post <?php echo esc_attr($class); ?>" style="<?php echo esc_attr( $style ); ?>">
<a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>">
<span class="post-control-link"><?php echo esc_html($newer_post); ?></span>
<span class="post-name"><?php echo esc_html($next_post->post_title); ?></span>
</a>
</div>
<?php endif; ?>
</div>
<?php
}
}
}