<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package wheelify
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function wheelify_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', 'wheelify_body_classes' );

/**
 * Add a pingback url auto-discovery header for single posts, pages, or attachments.
 */
function wheelify_pingback_header() {
	if ( is_singular() && pings_open() ) {
		printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
	}
}
add_action( 'wp_head', 'wheelify_pingback_header' );

/**
 * Comment Form
*/
function wheelify_comment_field_to_bottom( $fields ) {
    $comment_field = $fields['comment'];
    unset( $fields['comment'] );
    $fields['comment'] = $comment_field;
    return $fields;
}
add_filter( 'comment_form_fields', 'wheelify_comment_field_to_bottom' );

/**
 * Custom Comment List
*/
function wheelify_comment_list( $comment, $args, $depth ) {
    if ( 'div' === $args['style'] ) {
        $tag       = 'div';
        $add_below = 'comment';
    } else {
        $tag       = 'li';
        $add_below = 'div-comment';
    }
    ?>
    <<?php echo ''.esc_attr($tag); ?> class="media comment_box" id="comment-<?php comment_ID() ?>">
    <?php $avatar_url = get_avatar_url( $comment, $args['avatar_size'] ); 
    if($avatar_url ):?>
        <div class="pull_left_comment">
            <?php if ($args['avatar_size'] != 0) echo wp_kses_post(get_avatar($comment, $args['avatar_size'])); ?>
        </div>
    <?php endif;?>
    <div class="media-body">
        <div class="comment_detail <?php  if(!$avatar_url ): echo "noprofile"; endif;?>"><h4 class="comment_detail_title"><?php printf('%s', get_comment_author_link()); ?> |</h4><span class="comment_date"><?php esc_html(comment_date()) . ' at ' . esc_html(comment_time()); ?></span>
        <?php comment_reply_link(array_merge($args, array('reply_text' => __('<i class="fas fa-reply-all"></i>', 'wheelify'),'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
        <?php if ( $comment->comment_approved == '0' ) : ?>
        <p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'wheelify' ); ?></p>
        
        <?php endif; ?> 
        <?php comment_text(); ?>
    </div>
    </div>
    
<?php 
}