Created
March 24, 2025 19:59
-
-
Save joseacat/b2a5d43cf423487cef62343a7fb8aae1 to your computer and use it in GitHub Desktop.
Deshabilitar API WordPress para usuarios no logueados
This file contains 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
add_filter( 'rest_authentication_errors', 'disable_rest_api_not_logged' ); | |
function disable_rest_api_not_logged( $errors ) { | |
if( is_wp_error( $errors ) ) { | |
return $errors; | |
} | |
if( ! is_user_logged_in() ) { | |
return new WP_Error( 'no_rest_api_sorry', 'REST API not allowed', array( 'status' => 401 ) ); | |
} | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment