<?php

function theme_enqueue_styles()
{
	wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', []);
}
add_action('wp_enqueue_scripts', 'theme_enqueue_styles', 20);

function avada_lang_setup()
{
	$lang = get_stylesheet_directory() . '/languages';
	load_child_theme_textdomain('Avada', $lang);
}
add_action('after_setup_theme', 'avada_lang_setup');

show_admin_bar(false);

function add_page_id_to_body_class($classes)
{
	$classes[] = 'page-slug-' . get_post_field('post_name', get_post());

	return $classes;
}
add_filter('body_class', 'add_page_id_to_body_class');

// Hide comment menu
function remove_comment_menu()
{
	// remove_menu_page('edit-comments.php');
	// remove_menu_page('edit.php');
}
add_action('admin_menu', 'remove_comment_menu');




function theme_enqueue_scripts()
{
	wp_enqueue_script('custom-js', get_stylesheet_directory_uri() . '/custom.js', [], false, true);
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');




function disable_comments_post_types_support()
{
	$post_types = get_post_types();
	foreach ($post_types as $post_type) {
		if (post_type_supports($post_type, 'comments')) {
			remove_post_type_support($post_type, 'comments');
			remove_post_type_support($post_type, 'trackbacks');
		}
	}
}
add_action('admin_init', 'disable_comments_post_types_support');

function disable_comments_status()
{
	return false;
}
add_filter('comments_open', 'disable_comments_status', 20, 2);
add_filter('pings_open', 'disable_comments_status', 20, 2);

function disable_comments_hide_existing_comments($comments)
{
	$comments = [];
	return $comments;
}
add_filter('comments_array', 'disable_comments_hide_existing_comments', 10, 2);

function disable_comments_admin_menu()
{
	remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'disable_comments_admin_menu');

function disable_comments_admin_bar()
{
	if (is_admin_bar_showing()) {
		remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
	}
}
add_action('init', 'disable_comments_admin_bar');

function portfolio_skills_links_to_expertises($termlink, $term, $taxonomy)
{
	if ('portfolio_skills' !== $taxonomy || is_admin() || !is_singular('avada_portfolio')) {
		return $termlink;
	}

	if (!($term instanceof WP_Term) || empty($term->slug)) {
		return $termlink;
	}

	return home_url('/expertises/' . $term->slug . '/');
}
add_filter('term_link', 'portfolio_skills_links_to_expertises', 10, 3);
