Forked from danielbachhuber/disable-logged-out-users.php
Created
February 10, 2017 23:08
-
-
Save marco-s/c1e08a282c3ab1deba90c5af80c1da1e to your computer and use it in GitHub Desktop.
Disable WP REST API requests for logged out users
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
<?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