A default WordPress site is public and hence anyone can access it from any device. This may sometimes lead to large amounts of spam requests from certain users, overloading the server resources and creating performance issues. Also, these requests might come from users trying to break the site functionality or trying to gain access to the user accounts. We can prevent this problem to a certain extent by blocking requests from identified IP addresses or only giving access to a known set of IP addresses. This is especially used in the site-building stage where you don't want anyone else apart from your team to access the site.
In this recipe, we are going to use the .htaccess file on the server to add custom rules and only allow site access to a predefined set of IP addresses.