Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marco-s/c1e08a282c3ab1deba90c5af80c1da1e to your computer and use it in GitHub Desktop.
Save marco-s/c1e08a282c3ab1deba90c5af80c1da1e to your computer and use it in GitHub Desktop.
Disable WP REST API requests for logged out users
<?php
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'restx_logged_out', 'Sorry, you must be logged in to make a request.', array( 'status' => 401 ) );
}
return $result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment