Below is the code to set WordPress posts visibility to private by default.

Source: Set WordPress Posts Visibility to Private by Default