Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
.git
/
fira-code
:
template-functions.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php /** * Functions which enhance the theme by hooking into WordPress * * @package Prinox */ /** * Adds custom classes to the array of body classes. * * @param array $classes Classes for the body element. * @return array */ function prinox_body_classes( $classes ) { // Adds a class of hfeed to non-singular pages. if ( ! is_singular() ) { $classes[] = 'hfeed'; } // Adds a class of no-sidebar when there is no sidebar present. if ( ! is_active_sidebar( 'sidebar-1' ) ) { $classes[] = 'no-sidebar'; } return $classes; } add_filter( 'body_class', 'prinox_body_classes' ); /** * Add a pingback url auto-discovery header for single posts, pages, or attachments. */ function prinox_pingback_header() { if ( is_singular() && pings_open() ) { printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) ); } } add_action( 'wp_head', 'prinox_pingback_header' ); /** * Authore Avater */ function prinox_author_avatars($size) { echo get_avatar(get_the_author_meta('email'), $size); } add_action('genesis_entry_header', 'prinox_author_avatars'); /** * Post Read Time */ function prinox_reading_time() { global $post; $content = get_post_field( 'post_content', $post->ID ); $word_count = str_word_count( strip_tags( $content ) ); $readingtime = ceil($word_count / 200); if ($readingtime == 1) { $timer = esc_html(" min read"); } else { $timer = esc_html(" min read"); } $totalreadingtime = $readingtime . $timer; return $totalreadingtime; } /** * Search Widget */ function prinox_search_widgets( $form ) { $form = ' <div class="search-box"> <form role="search" method="get" id="searchform" class="widget__search" action="' . home_url( '/' ) . '" > <div class="form-group"> <input class="form_control" placeholder="' .esc_attr__( 'Search Product', 'prinox' ) . '" type="text" value="' . get_search_query() . '" name="s" id="s" /> <button type="submit"><span class="icon fa fa-search"></span></button> </div> </form> </div> '; return $form; } add_filter( 'get_search_form', 'prinox_search_widgets', 100 ); /** * Comment Message Box */ function prinox_comment_reform( $arg ) { $arg['title_reply'] = esc_html__( 'Leave a comment', 'prinox' ); $arg['comment_field'] = '<div class="gl-comment-form-input row"><div class="col-lg-12 col-md-12 col-sm-12 form-group"><textarea id="comment" class="form_control" name="comment" cols="77" rows="3" placeholder="' . esc_attr__( "Comment", "prinox" ) . '" aria-required="true"></textarea></div></div>'; return $arg; } add_filter( 'comment_form_defaults', 'prinox_comment_reform' ); /** * Comment Form Field */ function prinox_modify_comment_form_fields( $fields ) { $commenter = wp_get_current_commenter(); $req = get_option( 'require_name_email' ); $fields['author'] = '<div class="row clearfix"><div class="col-lg-6 col-md-6 col-sm-12 form-group"><input type="text" name="author" id="author" value="' . esc_attr( $commenter['comment_author'] ) . '" placeholder="' . esc_attr__( "Name", "prinox" ) . '" size="22" tabindex="1"' . ( $req ? 'aria-required="true"' : '' ) . ' class="form_control" /></div>'; $fields['email'] = '<div class="col-lg-6 col-md-6 col-sm-12 form-group"><input type="email" name="email" id="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" placeholder="' . esc_attr__( "Email", "prinox" ) . '" size="22" tabindex="2"' . ( $req ? 'aria-required="true"' : '' ) . ' class="form_control" /></div>'; $fields['url'] = '<div class="form-group col-md-12"><input type="url" name="url" id="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" placeholder="' . esc_attr__( "Website", "prinox" ) . '" size="22" tabindex="2"' . ( $req ? 'aria-required="false"' : '' ) . ' class="form_control" /></div></div>'; return $fields; } add_filter( 'comment_form_default_fields', 'prinox_modify_comment_form_fields' ); // comment Move Field function prinox_move_comment_field_to_bottom( $fields ) { $comment_field = $fields['comment']; unset( $fields['comment'] ); $fields['comment'] = $comment_field; return $fields; } add_filter( 'comment_form_fields', 'prinox_move_comment_field_to_bottom' ); /** * Get Breadcrumb * * @return void */ function prinox_the_breadcrumb() { global $wp_query; $queried_object = get_queried_object(); $breadcrumb = ''; $delimiter = ' / '; $before = '<li class="breadcrumb-item">'; $after = '</li>'; $breadcrumb .='<ul class="bread-crumb clearfix">'; if ( ! is_front_page() ) { $breadcrumb .= $before . '<a href="' . home_url( '/' ) . '">' . esc_html__( 'Home', 'prinox' ) . ' </a>' . $after; /** If category or single post */ if ( is_category() ) { $cat_obj = $wp_query->get_queried_object(); $this_category = get_category( $cat_obj->term_id ); if ( $this_category->parent != 0 ) { $parent_category = get_category( $this_category->parent ); $breadcrumb .= get_category_parents( $parent_category, true, $delimiter ); } $breadcrumb .= $before . '<a href="' . get_category_link( get_query_var( 'cat' ) ) . '">' . single_cat_title( '', false ) . '</a>' . $after; } elseif ( $wp_query->is_posts_page ) { $breadcrumb .= $before . $queried_object->post_title . $after; } elseif ( is_tax() ) { $breadcrumb .= $before . '<a href="' . get_term_link( $queried_object ) . '">' . $queried_object->name . '</a>' . $after; } elseif ( is_page() ) /** If WP pages */ { global $post; if ( $post->post_parent ) { $anc = get_post_ancestors( $post->ID ); foreach ( $anc as $ancestor ) { $breadcrumb .= $before . '<a href="' . get_permalink( $ancestor ) . '">' . get_the_title( $ancestor ) . ' </a>' . $after; } $breadcrumb .= $before . '' . get_the_title( $post->ID ) . '' . $after; } else { $breadcrumb .= $before . '' . get_the_title() . '' . $after; } } elseif ( is_singular() ) { if ( $category = wp_get_object_terms( get_the_ID(), array( 'category', 'location', 'tax_feature' ) ) ) { if ( ! is_wp_error( $category ) ) { $breadcrumb .= $before . '<a href="' . get_term_link( prinox_set( $category, '0' ) ) . '">' . prinox_set( prinox_set( $category, '0' ), 'name' ) . ' </a>' . $after; $breadcrumb .= $before . '' . get_the_title() . '' . $after; } else { $breadcrumb .= $before . '' . get_the_title() . '' . $after; } } else { $breadcrumb .= $before . '' . get_the_title() . '' . $after; } } elseif ( is_tag() ) { $breadcrumb .= $before . '<a href="' . get_term_link( $queried_object ) . '">' . single_tag_title( '', false ) . '</a>' . $after; } /**If tag template*/ elseif ( is_day() ) { $breadcrumb .= $before . '<a href="#">' . esc_html__( 'Archive for ', 'prinox' ) . get_the_time( 'F jS, Y' ) . '</a>' . $after; } /** If daily Archives */ elseif ( is_month() ) { $breadcrumb .= $before . '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '">' . __( 'Archive for ', 'prinox' ) . get_the_time( 'F, Y' ) . '</a>' . $after; } /** If montly Archives */ elseif ( is_year() ) { $breadcrumb .= $before . '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '">' . __( 'Archive for ', 'prinox' ) . get_the_time( 'Y' ) . '</a>' . $after; } /** If year Archives */ elseif ( is_author() ) { $breadcrumb .= $before . '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '">' . __( 'Archive for ', 'prinox' ) . get_the_author() . '</a>' . $after; } /** If author Archives */ elseif ( is_search() ) { $breadcrumb .= $before . '' . esc_html__( 'Search Results for ', 'prinox' ) . get_search_query() . '' . $after; } /** if search template */ elseif ( is_404() ) { $breadcrumb .= $before . '' . esc_html__( '404 - Not Found', 'prinox' ) . '' . $after; /** if search template */ } elseif ( is_post_type_archive( 'product' ) ) { $shop_page_id = wc_get_page_id( 'shop' ); if ( get_option( 'page_on_front' ) !== $shop_page_id ) { $shop_page = get_post( $shop_page_id ); $_name = wc_get_page_id( 'shop' ) ? get_the_title( wc_get_page_id( 'shop' ) ) : ''; if ( ! $_name ) { $product_post_type = get_post_type_object( 'product' ); $_name = $product_post_type->labels->singular_name; } if ( is_search() ) { $breadcrumb .= $before . '<a href="' . get_post_type_archive_link( 'product' ) . '">' . $_name . '</a>' . $delimiter . esc_html__( 'Search results for “', 'prinox' ) . get_search_query() . '”' . $after; } elseif ( is_paged() ) { $breadcrumb .= $before . '<a href="' . get_post_type_archive_link( 'product' ) . '">' . $_name . '</a>' . $after; } else { $breadcrumb .= $before . $_name . $after; } } } else { $breadcrumb .= $before . '<a href="' . get_permalink() . '">' . get_the_title() . '</a>' . $after; } /** Default value */ } $breadcrumb .='</ul>'; return $breadcrumb; } /** * Comment List Modification */ function prinox_comments( $comment, $args, $depth ) { $GLOBALS['comment'] = $comment;?> <li <?php comment_class('comment-box');?> id="comment-<?php comment_ID()?>"> <?php if ( get_avatar( $comment ) ) {?> <div class="author-thumb"> <?php echo get_avatar( $comment, 80 ); ?> </div> <?php }?> <div class="comment-info clearfix"> <strong class="name"><?php comment_author_link()?></strong> <span class="comment-time"><?php echo esc_html( get_comment_date( 'j M Y' ) ); ?></span> </div> <div class="text"><?php comment_text();?></div> <?php if ( $comment->comment_approved == '0' ): ?> <p><em><?php esc_html_e( 'Your comment is awaiting moderation.', 'prinox' );?></em></p> <?php endif;?> <div class="reply-btn"> <?php comment_reply_link( array_merge( $args, array( 'reply_text'=>'<i class="flaticon-reply-all"></i>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) );?> </div> </li> <?php } /** * prinox Single Post Nav */ function prinox_single_post_pagination(){ $prinox_prev_post = get_previous_post(); $prinox_next_post = get_next_post(); ?> <div class="more-posts"> <div class="more-posts-inner d-flex justify-content-between align-items-center"> <div class="new-post"> <div class="prev-arrow flaticon-left-arrow-2"></div> <div class="post-inner"> <?php if(has_post_thumbnail($prinox_prev_post)):?> <span class="image"> <a href="<?php echo esc_url(get_the_permalink($prinox_prev_post));?>"><img src="<?php echo esc_url(get_the_post_thumbnail_url($prinox_prev_post, 'thumbnail'));?>" alt="<?php the_title_attribute();?>"></a> </span> <?php endif;?> <a href="<?php echo esc_url(get_the_permalink($prinox_prev_post));?>"><?php echo esc_html(wp_trim_words( get_the_title($prinox_prev_post), 7, '' ));?></a> <div class="post-info"><span class="author"><?php prinox_author_avatars(22);?></span> <?php the_author()?> <span class="date"><?php echo wp_kses( get_the_date('M j, Y', $prinox_prev_post), true ); ?></span></div> </div> </div> <div class="new-post"> <div class="next-arrow flaticon-next-3"></div> <div class="post-inner"> <?php if(has_post_thumbnail($prinox_next_post)):?> <span class="image"> <a href="<?php echo esc_url(get_the_permalink($prinox_next_post));?>"><img src="<?php echo esc_url(get_the_post_thumbnail_url($prinox_next_post, 'thumbnail'));?>" alt="<?php the_title_attribute();?>"></a> </span> <?php endif;?> <a href="<?php echo esc_url(get_the_permalink($prinox_next_post));?>"><?php echo esc_html(wp_trim_words( get_the_title($prinox_next_post), 7, '' ));?></a> <div class="post-info"><span class="author"><?php prinox_author_avatars(22);?></span> <?php the_author()?> <span class="date"><?php echo wp_kses( get_the_date('M j, Y', $prinox_next_post), true ); ?></span></div> </div> </div> </div> </div> <?php } /** * Archive Count Markup */ function prinox_archive_html($links) { $links = str_replace('</a> (', '<span class="number">(', $links); $links = str_replace(')', ')</span></a>', $links); return $links; } add_filter('get_archives_link', 'prinox_archive_html'); /** * Category Count Markup */ function prinox_category_html( $links ) { $links = str_replace( '</a> (', '<span class="number">(', $links ); $links = str_replace( ')', ')</span></a>', $links ); return $links; } add_filter( 'wp_list_categories', 'prinox_category_html' ); /** * post Pagination */ function prinox_pagination() { global $wp_query; $links = paginate_links( array( 'current' => max( 1, get_query_var( 'paged' ) ), 'total' => $wp_query->max_num_pages, 'type' => 'list', 'mid_size' => 3, 'prev_text' => '<i class="fa fa-angle-double-left"></i>', 'next_text' => '<i class="fa fa-angle-double-right"></i>', ) ); echo wp_kses_post( $links ); } /** * Product Per Page Count * * @param [type] $per_page * @return void */ function prinox_prouducts_per_page( $per_page ) { $product_count = cs_get_option('product_count'); $per_page = 12; return $per_page; } add_filter( 'loop_shop_per_page', 'prinox_prouducts_per_page', 9999 ); /* Ajax update cart total number */ add_filter( 'woocommerce_add_to_cart_fragments', 'prinox_woocommerce_sidebar_cart_count_number' ); function prinox_woocommerce_sidebar_cart_count_number( $fragments ) { ob_start(); ?> <span class="widget_cart_counter"><i class="total-cart total-like"><?php echo sprintf (_n( '%d', '%d', WC()->cart->cart_contents_count, 'prinox' ), WC()->cart->cart_contents_count ); ?></i></span> <?php $fragments['.widget_cart_counter'] = ob_get_clean(); return $fragments; } add_filter( 'woocommerce_add_to_cart_fragments', 'prinox_woocommerce_sidebar_cart_count_number_header' ); function prinox_woocommerce_sidebar_cart_count_number_header( $fragments ) { ob_start(); ?> <span class="widget_cart_counter_header"><?php echo sprintf (_n( '%d', '%d', WC()->cart->cart_contents_count, 'prinox' ), WC()->cart->cart_contents_count ); ?> - <span class="cart-total"><?php echo WC()->cart->get_cart_subtotal(); ?></span></span> <?php $fragments['.widget_cart_counter_header'] = ob_get_clean(); return $fragments; } /** * Woc Remove Hook */ add_filter( 'woosw_button_position_archive', '__return_false' ); add_filter( 'woosw_button_position_single', '__return_false' ); add_filter( 'woosc_button_position_archive', '__return_false' ); add_filter( 'woosc_button_position_single', '__return_false' ); /** * prinox Category Search * * @return void */ function prinox_product_search(){ ?> <form name="myform" method="GET" action="<?php echo esc_url(home_url('/'));?>"> <div class="form-group"> <?php if (class_exists('WooCommerce')): ?> <?php if (isset($_REQUEST['product_cat']) && !empty($_REQUEST['product_cat'])) { $optsetlect = $_REQUEST['product_cat']; } else { $optsetlect = 0; } $args = array( 'show_option_all' => esc_html__('All Categories', 'prinox'), 'hierarchical' => 1, 'class' => 'cat', 'echo' => 1, 'value_field' => 'slug', 'selected' => $optsetlect, ); $args['taxonomy'] = 'product_cat'; $args['name'] = 'product_cat'; $args['class'] = 'custom-select-box'; wp_dropdown_categories($args); ?> <input type="hidden" value="product" name="post_type"> <?php endif;?> <input type="text" name="s" class="searchbox" maxlength="128" value="<?php echo get_search_query();?>" placeholder="<?php esc_attr_e('Search For Product', 'prinox');?>"> <button type="submit"><span class="icon far fa-search"></span></button> </div> </form> <?php } add_filter( 'woosq_button_position', '__return_false' ); /** * Discont Percent */ add_filter( 'woocommerce_sale_flash', 'prinox_percentage_to_sale_badge', 20, 3 ); function prinox_percentage_to_sale_badge( $html, $post, $product ) { if( $product->is_type('variable')){ $percentages = array(); // Get all variation prices $prices = $product->get_variation_prices(); // Loop through variation prices foreach( $prices['price'] as $key => $price ){ // Only on sale variations if( $prices['regular_price'][$key] !== $price ){ // Calculate and set in the array the percentage for each variation on sale $percentages[] = round( 100 - ( floatval($prices['sale_price'][$key]) / floatval($prices['regular_price'][$key]) * 100 ) ); } } // We keep the highest value $percentage = max($percentages) . '%'; } elseif( $product->is_type('grouped') ){ $percentages = array(); // Get all variation prices $children_ids = $product->get_children(); // Loop through variation prices foreach( $children_ids as $child_id ){ $child_product = wc_get_product($child_id); $regular_price = (float) $child_product->get_regular_price(); $sale_price = (float) $child_product->get_sale_price(); if ( $sale_price != 0 || ! empty($sale_price) ) { // Calculate and set in the array the percentage for each child on sale $percentages[] = round(100 - ($sale_price / $regular_price * 100)); } } // We keep the highest value $percentage = max($percentages) . '%'; } else { $regular_price = (float) $product->get_regular_price(); $sale_price = (float) $product->get_sale_price(); if ( $sale_price != 0 || ! empty($sale_price) ) { $percentage = round(100 - ($sale_price / $regular_price * 100)) . '%'; } else { return $html; } } return '<span class="onsale"> ' . $percentage . '</span>'; }