Skip to content

Instantly share code, notes, and snippets.

@joseacat
Created March 24, 2025 19:59
Show Gist options
  • Save joseacat/b2a5d43cf423487cef62343a7fb8aae1 to your computer and use it in GitHub Desktop.
Save joseacat/b2a5d43cf423487cef62343a7fb8aae1 to your computer and use it in GitHub Desktop.
Deshabilitar API WordPress para usuarios no logueados
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