File: /home/zeusxp5/chuair.org/wp-content/themes/lifttruck/inc/tools.php
<?php
if (!function_exists('lifttruck_dsm')) {
function lifttruck_dsm($var)
{
print "<pre>" . print_r($var, true) . "</pre>";
}
}
/*----------------------------breadcrumb------------------------------*/
if (!function_exists("lifttruck_breadcrumb")) {
function lifttruck_breadcrumb()
{
if (!is_front_page()) {
global $post;
global $wp_query;
echo '<ul class="breadcrumbs">';
echo '<li><a href="'. esc_url(home_url('/')) .'">'. esc_html__('Home','lifttruck') . '</a>';
echo '<i class="fas fa-chevron-right"></i></li>';
if (is_archive() ){
if (is_tag()) {
echo "<li>" . single_tag_title("", false) . "</li>";
} elseif (is_day()) {
echo "<li>" . esc_html__('Archives', 'lifttruck') . "</li>";
} elseif (is_month()) {
echo "<li>" . esc_html__('Monthly Archives', 'lifttruck') . '</li>';
} elseif (is_year()) {
echo "<li>" . esc_html__('Yearly Archives', 'lifttruck') . '</li>';
} elseif (is_author()) {
echo "<li>" . esc_html__('Author Archives', 'lifttruck') . '</li>';
} elseif (is_category()) {
echo "<li>" . single_cat_title("", false) . "</li>";
} else {
echo "<li>" . esc_html__('Archives', 'lifttruck') . '</li>';
}
} elseif (is_category() || is_single()) {
echo '<li>';
the_category(' <i class="fas fa-chevron-right"></i></li><li> ');
echo '<i class="fas fa-chevron-right"></i>';
if (is_single()) {
echo '</li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if ($post->post_parent) {
$anc = get_post_ancestors($post->ID);
$title = get_the_title();
foreach ($anc as $ancestor) {
$output = '<li><a href="' . esc_url(get_permalink($ancestor)) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a><i class="fas fa-chevron-right"></i></li> ';
}
echo html_entity_decode($output);
echo '<li><strong title="' . esc_attr($title) . '"> ' . esc_html($title) . '</strong></li>';
} else {
echo '<li>' . get_the_title() . '</li>';
}
} if ( isset( $wp_query ) && (bool) $wp_query->is_posts_page ) {
echo '<li><strong> ' . esc_html__('Blog', 'lifttruck') . '</strong></li>';
}
if (isset($_GET['paged']) && !empty($_GET['paged'])) {
echo "<li>" . esc_html__('Blog Archives', 'lifttruck');
echo '</li>';
}
if (is_search()) {
echo "<li>" . esc_html__('Search Results', 'lifttruck');
echo '</li>';
}
echo '</ul>';
}
}
}
if (!function_exists('lifttruck_check_if_empty')) {
function lifttruck_check_if_empty($propriete, $value)
{
$result = '';
if ($value !== '' && !is_null($value)) {
if ($propriete == 'background-image') {
$result = $propriete . ': url(' . esc_url($value) . ');';
} else {
$result = $propriete . ':' . $value . ';';
}
}
return $result;
}
}
if (!function_exists('wd_get_heading_separator')) {
function wd_get_heading_separator($headings_separator, $custom_separatore_style, $hr_class)
{
if ($headings_separator == "border") {
echo "<hr class='$hr_class' style='$custom_separatore_style'/>";
}
}
}
function lifttruck_get_post_category()
{
$cat_name = get_the_terms(get_the_ID(), 'category');
$lifttruck_class_name = '';
if (isset($cat_name) && $cat_name != null) {
foreach ($cat_name as $cat) {
$lifttruck_class_name .= ' ' . $cat->slug;
}
}
return $lifttruck_class_name;
}
function lifttruck_get_embedded_media($type = array())
{
$content = do_shortcode(apply_filters('the_content', get_the_content()));
$embed = get_media_embedded_in_content($content, $type);
if (in_array('audio', $type)) {
$output = str_replace('?visual=true', '?visual=false', $type[0]);
} elseif (!empty($type)) {
$output = $type[0];
} else {
$output = "";
}
return $output;
}
function lifttruck_get_attachment($num = 1)
{
$output = '';
if (has_post_thumbnail() && $num == 1):
$output = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
else:
$attachments = get_posts(array(
'post_type' => 'attachment',
'posts_per_page' => $num,
'post_parent' => get_the_ID()
));
if ($attachments && $num == 1):
foreach ($attachments as $attachment):
$output = wp_get_attachment_url($attachment->ID);
endforeach;
elseif ($attachments && $num > 1):
$output = $attachments;
endif;
wp_reset_postdata();
endif;
return $output;
}
// google fonts url
function lifttruck_google_fonts_url( $fonts, $subsets = array() ){
$lifttruck_protocol = is_ssl() ? 'https' : 'http';
/* URL */
$base_url = $lifttruck_protocol."://fonts.googleapis.com/css2?";
$font_args = array();
$family = array();
/* Format Each Font Family in Array */
$lifttruck_family = "";
foreach( $fonts as $font_name => $font_weight ){
$font_name = str_replace( ' ', '+', $lifttruck_family.$font_name.":wght@" );
$lifttruck_family ="family=";
if( !empty( $font_weight ) ){
if( is_array( $font_weight ) ){
$font_weight = implode( ";", $font_weight );
}
$font_weight = trim( $font_weight , ";");
$family[] = trim( $font_name . trim( $font_weight ) );
}
else{
$family[] = trim( $font_name );
}
}
/* Only return URL if font family defined. */
if( !empty( $family ) ){
/* Make Font Family a String */
$family = implode( "&", $family );
/* Add font family in args */
$font_args['family'] = $family;
/* Add font subsets in args */
if( !empty( $subsets ) ){
/* format subsets to string */
if( is_array( $subsets ) ){
$subsets = implode( ',', $subsets );
}
$font_args['subset'] = urlencode( trim( $subsets ) );
}
$font_args['display'] = "swap";
return add_query_arg( $font_args, $base_url );
}
return '';
}
class lifttruck_custom_font {
public $font_url;
public $font_name ;
function extract_extension($link) {
$file_parts = pathinfo($link);
return ($file_parts['extension'] != null) ? $file_parts['extension'] : '';
}
function file_src ($links) {
foreach($links as $link) {
$vr = (end($links)) ? ';' : ',';
if($link != ' ' && $link != '' && $links[0] != $link ) {
$this->font_url .= "url('".$link."') format('".$this->extract_extension($link)."')".$vr."\n";
}
}
return $this->font_url;
}
function font_name($name) {
if(count($name) > 1)
$this->font_name = $name[0];
return $this->font_name;
}
function getGoogleFontURL($fontName) {
$url = "https://fonts.googleapis.com/css2?family=" . str_replace(' ', '+', $fontName);
return $url;
}
}
function theme_required_plugins_link_data(){
$the_user = wp_get_current_user();
$get_var['url'] = home_url();
$get_var['email'] = $the_user->user_email;
$purchase_code = get_user_meta($the_user->user_id, 'wd_purchasecode', true);
$purchase_date = get_user_meta($the_user->user_id, 'wd_purchasedate', true);
if(isset($purchase_code) && !empty($purchase_code)) {
$get_var['wd_purchasecode'] = $purchase_code;
$get_var['wd_purchasedate'] = $purchase_date;
}
//$data = urlencode(base64_encode(serialize(($get_var))));
$data = urlencode(serialize(($get_var)));
return $data;
}