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

/**
 * Filter the categories archive widget to add a span around post count
 */
if ( ! function_exists( 'dicom_cat_count_span' ) ) {
	function dicom_cat_count_span( $links ) {
		$links = str_replace( '</a> (', '</a><span class="post-count">(', $links );
		$links = str_replace( ')', ')</span>', $links );
		return $links;
	}
}
add_filter( 'wp_list_categories', 'dicom_cat_count_span' );

/**
 * Filter the archives widget to add a span around post count
 */
if ( ! function_exists( 'dicom_archive_count_span' ) ) {
	function dicom_archive_count_span( $links ) {
		$links = str_replace( '</a>&nbsp;(', '</a><span class="post-count">(', $links );
		$links = str_replace( ')', ')</span>', $links );
		return $links;
	}
}
add_filter( 'get_archives_link', 'dicom_archive_count_span' );

/**
 * Excerpt more text
 */
if ( ! function_exists( 'dicom_excerpt_more' ) ) :
	function dicom_excerpt_more( $more ) {
		return ' ';
	}
endif;
add_filter('excerpt_more', 'dicom_excerpt_more');

/**
 * Remove pages from search result
*/
if ( ! function_exists( 'dicom_remove_pages_from_search' ) ) :
	function dicom_remove_pages_from_search() {
		global $dicom_opt;
		global $wp_post_types;

		if( isset( $dicom_opt['dicom_search_page'] ) ) {
			if( $dicom_opt['dicom_search_page'] != true ) {
				$wp_post_types['page']->exclude_from_search = true;
				if ( post_type_exists( 'service' ) ) {
					$wp_post_types['service']->exclude_from_search = true;
				}
				if ( post_type_exists( 'project' ) ) {
					$wp_post_types['project']->exclude_from_search = true;
				}
			} else {
				$wp_post_types['page']->exclude_from_search = false;
			}
		} else {
			$wp_post_types['page']->exclude_from_search = false;
			if ( post_type_exists( 'service' ) ) {
				$wp_post_types['service']->exclude_from_search = true;
			}
			if ( post_type_exists( 'project' ) ) {
				$wp_post_types['project']->exclude_from_search = true;
			}
		}
	}
endif;
add_action('init', 'dicom_remove_pages_from_search');

/**
 * Menu Registration
*/
if ( ! function_exists( 'dicom_register_primary_menus' ) ) :
	function dicom_register_primary_menus(){
		register_nav_menus(
			array(
				'primary' 		=> esc_html__('Primary Menu', 'dicom'),
				'footer-menu' 	=> esc_html__( 'Footer Menu', 'dicom' ),
			
			)
		);
	}
endif;
add_action('init', 'dicom_register_primary_menus');

// Remove auto p from Contact Form 7 shortcode output
if ( ! function_exists( 'dicom_remove_wpcf7_extra_p' ) ) {
	function dicom_remove_wpcf7_extra_p() {
		return false;
	}
}
add_filter('wpcf7_autop_or_not', 'dicom_remove_wpcf7_extra_p');