<?php
/**
 * Sample implementation of the Custom functions
 *
 * @package Godhuli
 */

/**
 * Modify default read more link
 */
function godhuli_modify_read_more_link() {

	$posted_on = sprintf(
		'<div class="text-center"><a href="%s" rel="bookmark" class="btn btn-outline-custom" >%s <i class="mdi mdi-arrow-right" aria-hidden="true"></i></a></div> ',
		esc_url( get_permalink() ),
		esc_html__( 'Continue Reading', 'godhuli' )
	);
	return $posted_on;

}
add_filter( 'the_content_more_link', 'godhuli_modify_read_more_link' );



/*
 * WordPress number pagination
 */
if ( ! function_exists( 'godhuli_number_paging_nav' ) ) :

	function godhuli_number_paging_nav() {

		$pagination_args = array(
			'prev_text'          => '<i class="mdi mdi-chevron-left" aria-hidden="true"></i><span class="screen-reader-text">' . esc_html__( 'Previous page', 'godhuli' ) . '</span>',
			'next_text'          => '<span class="screen-reader-text">' . esc_html__( 'Next page', 'godhuli' ) . '</span><i class="mdi mdi-chevron-right" aria-hidden="true"></i>',
			'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'godhuli' ) . ' </span>',
		);

		the_posts_pagination( $pagination_args );

	}

endif;




/*
 * Modify WordPress comment box textarea — move comment field to bottom
 */
function godhuli_move_comment_field_to_bottom( $fields ) {
	$comment_field = $fields['comment'];
	unset( $fields['comment'] );
	$fields['comment'] = $comment_field;

	return $fields;
}
add_filter( 'comment_form_fields', 'godhuli_move_comment_field_to_bottom' );




/*
 * Get comment depth
 */
function godhuli_get_comment_depth( $my_comment_id ) {
	$depth_level = 0;
	while ( $my_comment_id > 0 ) {
		$my_comment    = get_comment( $my_comment_id );
		$my_comment_id = $my_comment->comment_parent;
		$depth_level++;
	}
	return $depth_level;
}




/*
 * Fetch all categories
 */
if ( ! function_exists( 'godhuli_fatch_all_cats' ) ) :

	function godhuli_fatch_all_cats() {

		$get_all_cats  = get_categories();
		$cats_to_fetch = array();
		foreach ( $get_all_cats as $cats ) {

			$cats_to_fetch[ $cats->slug ] = $cats->name;

		}
		return $cats_to_fetch;

	}


endif;



/**
 * Callback for WordPress 'prepend_attachment' filter.
 * Change the attachment page image size to 'large'
 */

add_filter( 'prepend_attachment', 'godhuli_prepend_attachment' );

function godhuli_prepend_attachment( $attachment_content ) {

	// Set the attachment image size to 'large'.
	$attachment_content = sprintf( '<p>%s</p>', wp_get_attachment_link( 0, 'large', false ) );

	// return the attachment content.
	return $attachment_content;

}


/*
 * Add class to comment reply
 */

add_filter( 'comment_reply_link', 'godhuli_replace_reply_link_class' );

function godhuli_replace_reply_link_class( $class ) {
	$class = str_replace( "class='comment-reply-link", "class='comment-reply-link text-custom reply-btn", $class );
	return $class;
}



/**
 * Include a skip to content link at the top of the page so that users can bypass the menu.
 */
function godhuli_skip_link() {
	echo '<a class="skip-link screen-reader-text" href="#content">' . esc_html__( 'Skip to the content', 'godhuli' ) . '</a>';
}

add_action( 'wp_body_open', 'godhuli_skip_link', 5 );
