Last active
December 17, 2018 19:16
-
-
Save evemilano/15b6f6c09a4e15710f1207521d23fe02 to your computer and use it in GitHub Desktop.
Come disabilitare le Rest API di WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 410 STATUS CODE */ | |
add_filter( 'rest_authentication_errors', function( $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; | |
}); | |
/* Remove JSON API links in header html */ | |
function remove_json_api () { | |
// Disable handling of internal embeds in oembed/1.0/proxy REST route. | |
add_filter( 'oembed_response_data', 'disable_embeds_filter_oembed_response_data' ); | |
// 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 ); | |
// Disable REST API link in HTTP headers | |
remove_action('template_redirect', 'rest_output_link_header', 11, 0); | |
// 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-specific JavaScript from the front-end and back-end. | |
remove_action( 'wp_head', 'wp_oembed_add_host_js' ); | |
add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin', 1 ); | |
// Remove all embeds rewrite rules. | |
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); | |
// Remove filter of the oEmbed result before any HTTP requests are made. | |
remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 ); | |
// Load block editor JavaScript. | |
add_action( 'enqueue_block_editor_assets', 'disable_embeds_enqueue_block_editor_assets' ); | |
// Remove wp-embed dependency of wp-edit-post script handle. | |
add_action( 'wp_default_scripts', 'disable_embeds_remove_script_dependencies'); | |
} | |
add_action( 'after_setup_theme', 'remove_json_api' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Leggi l'articolo di supporto: https://www.evemilano.com/disabilitare-rest-api-wordpress/