Created
June 17, 2021 22:02
-
-
Save wpjess/5b15142eae2115da958eeb1a5ec7261b to your computer and use it in GitHub Desktop.
Revisions
-
wpjess created this gist
Jun 17, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ function http_auth_headers(){ header('WWW-Authenticate: Basic realm="Web Page Restricted"'); header('HTTP/1.0 401 Unauthorized'); echo 'You must enter the correct credentials to access this page'; exit; } add_action('template_redirect', 'add_http_auth_basic', 0); function add_http_auth_basic(){ $uri = 'contact'; if(!is_admin()){ global $wp; if($wp->request === $uri || strpos($wp->request, $uri.'/') !== false ){ $user = HTTP_USER_NAME; $pass = HTTP_USER_PASS; if (!isset($_SERVER['PHP_AUTH_USER'])) { http_auth_headers(); } else{ if ($_SERVER['PHP_AUTH_USER'] !== $user && $_SERVER['PHP_AUTH_PW'] !== $pass) { http_auth_headers(); } } } } }