Skip to content

Instantly share code, notes, and snippets.

@alanef
Created October 13, 2022 07:59
Show Gist options
  • Select an option

  • Save alanef/8014aa19860de60c76137b3385f83824 to your computer and use it in GitHub Desktop.

Select an option

Save alanef/8014aa19860de60c76137b3385f83824 to your computer and use it in GitHub Desktop.
add_action(
'rest_authentication_errors',
function() {
if ( ( preg_match( '/users/i', $_SERVER['REQUEST_URI'] ) !== 0 ) || ( isset( $_REQUEST['rest_route'] ) && ( preg_match( '/users/i', $_REQUEST['rest_route'] ) !== 0 ) ) ) {
if ( ! is_user_logged_in() ) {
$this->sue_log();
return new WP_Error( 'rest_cannot_access', esc_html__( 'Only authenticated users can access the User endpoint REST API.', 'stop-user-enumeration' ), array( 'status' => rest_authorization_required_code() ) );
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment