<?php
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
remove_action('wp_head', 'wp_resource_hints', 2);

add_filter( 'xmlrpc_enabled', '__return_false' );
remove_action( 'wp_head', 'rsd_link' );

// Disable REST API
//remove_action( 'init',          'rest_api_init' );
//remove_action( 'parse_request', 'rest_api_loaded' );
//
//remove_action( 'xmlrpc_rsd_apis',            'rest_output_rsd' );
//remove_action( 'wp_head',                    'rest_output_link_wp_head' );
//remove_action( 'template_redirect',          'rest_output_link_header', 11 );
//remove_action( 'auth_cookie_malformed',      'rest_cookie_collect_status' );
//remove_action( 'auth_cookie_expired',        'rest_cookie_collect_status' );
//remove_action( 'auth_cookie_bad_username',   'rest_cookie_collect_status' );
//remove_action( 'auth_cookie_bad_hash',       'rest_cookie_collect_status' );
//remove_action( 'auth_cookie_valid',          'rest_cookie_collect_status' );

//add_filter( 'rest_enabled',       '__return_false' );
//add_filter( 'rest_jsonp_enabled', '__return_false' );

//remove TinyMCE emojis

function disable_wp_emojicons() {

    // all actions related to emojis
    remove_action( 'admin_print_styles', 'print_emoji_styles' );
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    remove_action( 'wp_print_styles', 'print_emoji_styles' );
    remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
    remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
    remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );

    // filter to remove TinyMCE emojis
    add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );

function disable_emojicons_tinymce( $plugins ) {
    if ( is_array( $plugins ) ) {
        return array_diff( $plugins, array( 'wpemoji' ) );
    } else {
        return array();
    }
}

// remove auto embed
//
//add_filter( 'wp_default_scripts', $af = static function( &$scripts) {
//    if(!is_admin()) {
//        $scripts->remove( 'jquery');
////        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
//    }
//}, PHP_INT_MAX );
unset( $af );

// Remove jQuery Migrate Script from header and Load jQuery from Google API
/*function stop_loading_wp_embed_and_jquery() {
    if (!is_admin()) {
        wp_deregister_script('wp-embed');
    }
}
add_action('init', 'stop_loading_wp_embed_and_jquery');*/

// Remove the REST API endpoint.
//remove_action( 'rest_api_init', 'wp_oembed_register_route' );

// 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' );

// Remove all embeds rewrite rules.
//add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );

// disable Yoast SEO Schema JSON-LD completely
function bybe_remove_yoast_json($data){
    $data = array();
    return $data;
}
add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1);


/*
function secure_api( $result ) {
    if ( ! empty( $result ) ) {
        return $result;
    }
    if ( ! is_user_logged_in() ) {
        return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
    }
    return $result;
}
add_filter('rest_authentication_errors', 'secure_api');*/

add_filter( 'xmlrpc_enabled', '__return_false' );
remove_action( 'wp_head', 'rsd_link' );