Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Last active July 25, 2018 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gkiokan/927e41daf70586225959e6da003adabe to your computer and use it in GitHub Desktop.
Save Gkiokan/927e41daf70586225959e6da003adabe to your computer and use it in GitHub Desktop.
WP Disable Rest API
<?php
/*
* Disable WP REST API JSON endpoints if user not logged in
*/
function chuck_disable_rest_endpoints( $access ) {
if( ! is_user_logged_in() ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
add_filter( 'rest_authentication_errors', 'chuck_disable_rest_endpoints' );
/*
* Diable WP Rest API completly
*/
add_filter('rest_enabled', '_return_false');
add_filter('rest_jsonp_enabled', '_return_false');
/*
* Diable WP Rest URI from Head
*/
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment