Skip to content

Instantly share code, notes, and snippets.

@litonarefin
Created June 25, 2021 06:21
Show Gist options
  • Save litonarefin/183d29140a00d0fe4ed7c5995e478792 to your computer and use it in GitHub Desktop.
Save litonarefin/183d29140a00d0fe4ed7c5995e478792 to your computer and use it in GitHub Desktop.
/** Disable REST 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');
/** Control Interval Heartbeat API **/
add_filter('heartbeat_settings', [$this, 'jltwp_adminify_control_heartbeat']);
/** Remove WP API Links and Scripts **/
remove_action('wp_head', 'rest_output_link_wp_head');
remove_action('wp_head', 'wp_oembed_add_discovery_links');
/** Remove WP API Link from HTTP Headers **/
remove_action('template_redirect', 'rest_output_link_header', 11);
/** Totally Disable WP API Feature **/
remove_action('wp_head', 'rest_output_link_wp_head');
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('template_redirect', 'rest_output_link_header', 11);
// 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');
// More REST API Hooks
remove_action('rest_api_init', 'wp_oembed_register_route'); // Remove the REST API endpoint.
remove_action('wp_head', 'wp_oembed_add_host_js'); // Remove oEmbed-specific JavaScript from the front-end and back-end.
add_filter('embed_oembed_discover', '__return_false'); // Turn off oEmbed auto discovery.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // Remove filter oEmbed results.
add_filter('rewrite_rules_array', [$this, 'adminify_disable_embeds_rewrites']); // Remove all embeds rewrite rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment