Kod dodajemo u functions.php
function enforce_http_auth()
{
// Set your desired username and password
$username = 'alert';
$password = 'alert';
// Check for HTTP auth headers
if (
!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
$_SERVER['PHP_AUTH_USER'] !== $username || $_SERVER['PHP_AUTH_PW'] !== $password
) {
header('WWW-Authenticate: Basic realm="Restricted Area"');
header('HTTP/1.0 401 Unauthorized');
echo 'Unauthorized access';
exit;
}
}
add_action('template_redirect', 'enforce_http_auth');