File: /home/homework/public_html/kurs7/wp-content/themes/diet-shop/inc/template-functions.php
<?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package Diet_Shop
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function diet_shop_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', 'diet_shop_body_classes' );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function diet_shop_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'diet_shop_pingback_header' );
/**
* Set up the WordPress core custom header feature.
*
* @uses diet_shop_header_style()
*/
function diet_shop_custom_header_setup() {
add_theme_support( 'custom-header', apply_filters( 'diet_shop_custom_header_args', array(
'default-image' => '',
'default-text-color' => '000000',
'width' => 1000,
'height' => 250,
'flex-height' => true,
'wp-head-callback' => 'diet_shop_header_style',
) ) );
}
add_action( 'after_setup_theme', 'diet_shop_custom_header_setup' );
if ( ! function_exists( 'diet_shop_header_style' ) ) :
/**
* Styles the header image and text displayed on the blog.
*
* @see diet_shop_custom_header_setup().
*/
function diet_shop_header_style() {
$header_text_color = get_header_textcolor();
/*
* If no custom options for text are set, let's bail.
* get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
*/
if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
return;
}
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css">
<?php
// Has the text been hidden?
if ( ! display_header_text() ) :
?>
.site-title,
.site-description {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
}
<?php
// If the user has set a custom color for the text use that.
else :
?>
.site-title a,
.site-description {
color: #<?php echo esc_attr( $header_text_color ); ?>;
}
<?php endif; ?>
</style>
<?php
}
endif;
if ( ! function_exists( 'diet_shop_alowed_tags' ) ) :
/**
* @see diet_shop_alowed_tags().
*/
function diet_shop_alowed_tags() {
$wp_post_allow_tag = wp_kses_allowed_html( 'post' );
$allowed_tags = array(
'a' => array(
'class' => array(),
'href' => array(),
'rel' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array(
'title' => array(),
),
'b' => array(),
'blockquote' => array(
'cite' => array(),
),
'cite' => array(
'title' => array(),
),
'code' => array(),
'del' => array(
'datetime' => array(),
'title' => array(),
),
'dd' => array(),
'div' => array(
'class' => array(),
'title' => array(),
'style' => array(),
),
'dl' => array(),
'dt' => array(),
'em' => array(),
'h1' => array(
'class' => array(),
'title' => array(),
'style' => array(),
),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'i' => array(),
'img' => array(
'alt' => array(),
'class' => array(),
'height' => array(),
'src' => array(),
'width' => array(),
),
'li' => array(
'class' => array(),
),
'i' => array(
'class' => array(),
),
'ol' => array(
'class' => array(),
),
'p' => array(
'class' => array(),
),
'q' => array(
'cite' => array(),
'title' => array(),
),
'span' => array(
'class' => array(),
'title' => array(),
'style' => array(),
),
'strike' => array(),
'strong' => array(),
'ul' => array(
'class' => array(),
),
'iframe' => array(
'src' => array(),
'height' => array(),
'width' => array(),
'frameborder' => array(),
'allowfullscreen' => array(),
),
'time' => array(
'class' => array(),
'title' => array(),
'style' => array(),
'datetime' => array(),
'content' => array(),
),
'main' => array(
'class' => array(),
'id' => array(),
'style' => array(),
),
);
$tags = array_merge($wp_post_allow_tag, $allowed_tags);
return apply_filters( 'diet_shop_alowed_tags', $tags );
}
endif;
if ( ! function_exists( 'diet_shop_walker_comment' ) ) :
/**
* Implement Custom Comment template.
*
* @since 1.0.0
*
* @param $comment, $args, $depth
* @return $html
*/
function diet_shop_walker_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<li <?php comment_class( empty( $args['has_children'] ) ? 'comment shift' : 'comment' ) ?> id="comment-<?php comment_ID() ?>">
<div class="single-comment clearfix">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, 80,'','', array('class' => 'float-left') ); ?>
<div class="comment float-left">
<h6><?php echo get_comment_author_link();?></h6>
<div class="date">
<?php
/* translators: 1: date, 2: time */
printf( esc_html__('%1$s at %2$s', 'diet-shop' ), get_comment_date(), get_comment_time() );
?>
</div>
<div class="reply"> <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></div>
<div class="comment-text"><?php comment_text(); ?></div>
</div>
</div>
<div class="clearfix"></div>
</li>
<?php
}
endif;
function diet_shop_fallback_nav() {
wp_nav_menu( array(
'depth' => 1,
'menu_class' => 'navbar-nav mr-auto diet-shop-main-menu',
'container' =>'ul',
'theme_location' => 'fallback_menu'
) );
}
if( ! function_exists( 'wp_body_open' ) ){
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
function diet_shop_category_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'diet_shop_category_title' );
if( !function_exists('diet_shop_elementor_editor_simplify') ){
function diet_shop_elementor_editor_simplify(){
add_action( 'wp_head', function () {
echo '<style type="text/css">
#elementor-panel-category-pro-elements,
#elementor-panel-category-theme-elements,
#elementor-panel-category-woocommerce-elements,
#elementor-panel-get-pro-elements{
display:none!important;
}
</style>';
} );
}
add_action( 'elementor/editor/init', 'diet_shop_elementor_editor_simplify');
}