How it works...
In order to protect the entire site with a single password, we have to check the password on each request to the frontend or backend. So, we choose WordPress's init action for the implementation as it's executed on all requests to the site.
In step 2, we used a callback function called wpcpp_ch12_global_password_protection on the init action. Inside the function, we added a simple HTML form containing a label, a password field, and a submit button. Also, we used an additional <DIV> element to show the error messages to the user.
In step 3, we added the code to capture and verify the password. The process of requesting the password on each screen is not a user-friendly solution. Therefore, once the user provides the correct ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access