Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /**
  2. * Disables the WordPress API for unauthorized users.
  3. */
  4. function disable_wp_api() {
  5. add_filter( 'rest_authentication_errors', function( $access ){
  6. if ( ! is_user_logged_in() ) {
  7. $access = new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', [ 'status' => 401 ] );
  8. }
  9.  
  10. return $access;
  11. } );
  12.  
  13. // also remove actions added by wp-includes/default-filters.php
  14. remove_action( 'wp_head', 'rest_output_link_wp_head' );
  15. remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
  16. remove_action( 'template_redirect', 'rest_output_link_header' );
  17. }
  18.  
  19. disable_wp_api();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement