<?php

/**
 * Comments
 * @category Functions
 * @author Krik
 */

// Disable comments
add_action('admin_init', 'krik_disable_comments');
add_filter('comments_open', 'krik_disable_comments_status', 20, 2);
add_filter('pings_open', 'krik_disable_comments_status', 20, 2);
add_action('admin_menu', 'krik_disable_comments_admin_menu');
add_action('admin_init', 'krik_redirect_comments_pages');
add_action('admin_init', 'krik_disable_comments_dashboard');
add_action('wp_before_admin_bar_render', 'krik_disable_comments_admin_bar');
add_filter('comments_array', 'krik_disable_comments_hide_existing_comments', 10, 2);

function krik_disable_comments()
{
	$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');
		}
	}
}

function krik_disable_comments_status()
{
	return false;
}

function krik_disable_comments_admin_menu()
{
	remove_menu_page('edit-comments.php');
	remove_submenu_page('options-general.php', 'options-discussion.php');
}

function krik_redirect_comments_pages()
{
	global $pagenow;
	if ($pagenow === 'edit-comments.php' || $pagenow === 'options-discussion.php') {
		wp_redirect(admin_url());
		exit;
	}
}

function krik_disable_comments_dashboard()
{
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}

function krik_disable_comments_admin_bar()
{
	global $wp_admin_bar;
	$wp_admin_bar->remove_menu('comments');
}

function krik_disable_comments_hide_existing_comments()
{
	$comments = array();
	return $comments;
}
