This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpowerpress-feed-auth.php
62 lines (48 loc) · 1.62 KB
/
powerpress-feed-auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
// powerpress-feed-auth.php
function powerpress_feed_auth($feed_slug)
{
// See if a filter exists to perform the authentication...
$authenticated = apply_filters('powerpress_feed_auth', false, 'channel', $feed_slug);
if( !$authenticated )
{
$FeedSettings = get_option('powerpress_feed_'.$feed_slug);
if( !isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) )
powerpress_feed_auth_basic( $FeedSettings['title'] );
$user = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$userObj = wp_authenticate($user, $password);
if( !is_wp_error($userObj) )
{
// Check capability...
if( $userObj->has_cap( $FeedSettings['premium'] ) )
return; // Nice, let us continue...
powerpress_feed_auth_basic( $FeedSettings['title'], __('Access Denied', 'powerpress') );
}
// user authenticated here
powerpress_feed_auth_basic( $FeedSettings['title'], __('Authorization Failed', 'powerpress') );
}
}
function powerpress_feed_auth_basic($realm_name, $error = false )
{
if( !$error )
$error = __('Unauthorized', 'powerpress');
header('HTTP/1.0 401 Unauthorized');
header('WWW-Authenticate: Basic realm="'. str_replace('"', '', $realm_name).'"');
echo '<!DOCTYPE html>'; // HTML5!
echo "\n";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta name="robots" content="noindex" />
<title><?php echo htmlspecialchars($error); ?></title>
</head>
<body>
<p><?php echo htmlspecialchars($error); ?></p>
</body>
</html>
<?php
exit;
}
?>