<?php
/**
 * Class Head_Cleaner
 *
 * @package dvcrs-core
 */

namespace DVCRS\Core;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Head_Cleaner Class
 */
class Head_Cleaner {

	/**
	 * Head_Cleaner constructor
	 */
	public function __construct() {

		// Remove really simple discovery link.
		\remove_action( 'wp_head', 'rsd_link' );

		// Remove WordPress version.
		\remove_action( 'wp_head', 'wp_generator' );

		// Remove rss feed links.
		\remove_action( 'wp_head', 'feed_links', 2 );

		// Removes all extra rss feed links.
		\remove_action( 'wp_head', 'feed_links_extra', 3 );

		// Remove link to index page.
		\remove_action( 'wp_head', 'index_rel_link' );

		// Remove wlwmanifest.xml (Windows Live Writer).
		\remove_action( 'wp_head', 'wlwmanifest_link' );

		// Remove random post link.
		\remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );

		// Remove parent post link.
		\remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );

		// Remove the next and previous post links.
		\remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
		\remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );

		// Remove shortlink.
		\remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

		// \add_action( 'after_setup_theme', [ $this, 'remove_json_api' ] );
		// \add_action( 'after_setup_theme', [ $this, 'disable_json_api' ] );

	}

	/**
	 * Remove JSON API links form header
	 */
	// TODO: Review each of these so we understand what they are disabling.
	public function remove_json_api() {

		// Remove the REST API lines from the HTML Header
		\remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
		\remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );

		// Turn off oEmbed auto discovery.
		\add_filter( 'embed_oembed_discover', '__return_false' );

		// Don't filter oEmbed results.
		\remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );

		// Remove oEmbed discovery links.
		\remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

		// Remove oEmbed-specific JavaScript from the front-end and back-end.
		\remove_action( 'wp_head', 'wp_oembed_add_host_js' );

	}

	/**
	 * Disable the REST API
	 */
	// TODO: Review each of these so we understand what they are disabling.
	public function disable_json_api() {

		// Filters for WP-API version 1.x
		\add_filter( 'json_enabled', '__return_false' );
		\add_filter( 'json_jsonp_enabled', '__return_false' );

		// Filters for WP-API version 2.x
		// \add_filter( 'rest_enabled', '__return_false' );
		// \add_filter( 'rest_jsonp_enabled', '__return_false' );

	}
}

new Head_Cleaner();
