Version Description
(2008-08-25) : = * Added back no_cache add_action that was lost in the admin separation * Removed duplicate add_action for the admin page
Download this release
Release Info
Developer | sivel |
Plugin | Page Restrict |
Version | 1.4.1 |
Comparing to | |
See all releases |
Version 1.4.1
- inc/admin.php +129 -0
- pagerestrict.php +70 -0
- readme.txt +62 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
inc/admin.php
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Part of WordPress Plugin: Page Restrict
|
4 |
+
http://sivel.net/wordpress/
|
5 |
+
*/
|
6 |
+
|
7 |
+
// Set Page Restrict Version Number
|
8 |
+
$pr_version = '1.4';
|
9 |
+
|
10 |
+
// Check the version in the options table and if less than this version perform update
|
11 |
+
function pr_ver_check () {
|
12 |
+
global $pr_version;
|
13 |
+
if ( ( pr_get_opt ( 'version' ) < $pr_version ) || ( !pr_get_opt ( 'version' ) ) ) :
|
14 |
+
$pr_options = array ();
|
15 |
+
$pr_options['version'] = $pr_version;
|
16 |
+
$pr_options['pages'] = pr_get_opt ( 'pages' );
|
17 |
+
$pr_options['method'] = pr_get_opt ( 'method' );
|
18 |
+
pr_delete ();
|
19 |
+
add_option ( 'pr_options' , $pr_options , 'Page Restrict Options' );
|
20 |
+
endif;
|
21 |
+
}
|
22 |
+
|
23 |
+
// Initialize the Page Restrict default options during plugin activation
|
24 |
+
function pr_init () {
|
25 |
+
global $pr_version;
|
26 |
+
$pr_options = array ();
|
27 |
+
$pr_options['version'] = $pr_version;
|
28 |
+
$pr_options['pages'] = '';
|
29 |
+
$pr_options['method'] = 'selected';
|
30 |
+
add_option ( 'pr_options', $pr_options, 'Page Restrict Options' ) ;
|
31 |
+
}
|
32 |
+
|
33 |
+
// Delete all Page Restrict Options
|
34 |
+
function pr_delete () {
|
35 |
+
delete_option ( 'pr_options' );
|
36 |
+
}
|
37 |
+
|
38 |
+
// Add the Page Restrict options page
|
39 |
+
function pr_options_page () {
|
40 |
+
if ( is_admin () ) :
|
41 |
+
if ( function_exists ( 'add_options_page' ) ) :
|
42 |
+
add_options_page ( 'Page Restrict' , 'Page Restrict' , 'manage_options' , 'pagerestrict.php' , 'pr_admin_page' );
|
43 |
+
endif;
|
44 |
+
endif;
|
45 |
+
}
|
46 |
+
|
47 |
+
// The Page Restrict options page
|
48 |
+
function pr_admin_page () {
|
49 |
+
if ( is_admin () ) :
|
50 |
+
pr_ver_check ();
|
51 |
+
if ( $_POST['page_id'] ) :
|
52 |
+
$page_ids_post_arr = $_POST['page_id'];
|
53 |
+
$page_ids_post_str = implode ( ',' , $page_ids_post_arr );
|
54 |
+
$pr_options['pages'] = $page_ids_post_str;
|
55 |
+
$pr_options['method'] = pr_get_opt ( 'method' );
|
56 |
+
$pr_options['version'] = pr_get_opt ( 'version' );
|
57 |
+
update_option ( 'pr_options' , $pr_options );
|
58 |
+
endif;
|
59 |
+
if ( $_POST['method'] ) :
|
60 |
+
$pr_method_post = $_POST['method'];
|
61 |
+
$pr_options['method'] = $pr_method_post;
|
62 |
+
$pr_options['pages'] = pr_get_opt ( 'pages' );
|
63 |
+
$pr_options['version'] = pr_get_opt ( 'version' );
|
64 |
+
update_option ( 'pr_options' , $pr_options );
|
65 |
+
endif;
|
66 |
+
if ( $pr_method_post )
|
67 |
+
$pr_method = $pr_method_post;
|
68 |
+
else
|
69 |
+
$pr_method = pr_get_opt ( 'method' );
|
70 |
+
if ( $pr_method == 'all' ) :
|
71 |
+
$all_checked = ' checked="checked" ';
|
72 |
+
elseif ( $pr_method == 'none' ) :
|
73 |
+
$none_checked = ' checked="checked" ';
|
74 |
+
else :
|
75 |
+
$selected_checked = ' checked="checked" ';
|
76 |
+
endif;
|
77 |
+
echo '<div class="wrap">' . "\r\n";
|
78 |
+
echo '<h2>Page Restrict Options</h2>' . "\r\n";
|
79 |
+
echo '<h3>Choose the restriction method:</h3>' . "\r\n";
|
80 |
+
echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">' . "\r\n";
|
81 |
+
echo '<input type="radio" name="method" value="all"' . $all_checked . ' />Restrict all pages<br />' . "\r\n";
|
82 |
+
echo '<input type="radio" name="method" value="none"' . $none_checked . ' />Restrict no pages<br />' . "\r\n";
|
83 |
+
echo '<input type="radio" name="method" value="selected"' . $selected_checked . ' />Restrict selected pages only<br />' . "\r\n";
|
84 |
+
echo '<input type="submit" name="submit" class="button" value="Submit" /> ';
|
85 |
+
echo '<input type="reset" name="reset" class="button" value="Reset" /> ';
|
86 |
+
echo '<input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" />' . "\r\n";
|
87 |
+
echo '</form>' . "\r\n";
|
88 |
+
if ( $pr_method == 'selected' ) :
|
89 |
+
$page_ids_opt_str = pr_get_opt ( 'pages' );
|
90 |
+
if ( $page_ids_opt_str )
|
91 |
+
$page_ids_opt_arr = explode ( ',' , $page_ids_opt_str );
|
92 |
+
if ( ( $page_ids_opt_arr ) && ( $page_ids_post_arr ) ):
|
93 |
+
$page_ids = array_merge ( $page_ids_opt_arr , $page_ids_post_arr );
|
94 |
+
elseif ( $page_ids_opt_arr ) :
|
95 |
+
$page_ids = $page_ids_opt_arr;
|
96 |
+
else :
|
97 |
+
$page_ids = $page_ids_post_arr;
|
98 |
+
endif;
|
99 |
+
echo '<h3>Select the Pages you wish to restrict to logged in users only:</h3>' . "\r\n";
|
100 |
+
echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">' . "\r\n";
|
101 |
+
$avail_pages = get_pages ();
|
102 |
+
$avail_pages_cnt = count ( $avail_pages );
|
103 |
+
$i = $avail_pages_cnt;
|
104 |
+
while ( $i > 0 ) :
|
105 |
+
$i--;
|
106 |
+
$pr_page_id = $avail_pages[$i]->ID;
|
107 |
+
$pr_page_title = $avail_pages[$i]->post_title;
|
108 |
+
if ( $page_ids ) :
|
109 |
+
if ( in_array ( $pr_page_id , $page_ids ) ) :
|
110 |
+
$page_checked = ' checked="checked" ';
|
111 |
+
else :
|
112 |
+
$page_checked = '';
|
113 |
+
endif;
|
114 |
+
endif;
|
115 |
+
echo '<input type="checkbox" name="page_id[]" value="' . $pr_page_id . '"' . $page_checked . ' />' . $pr_page_title . '<br />' . "\r\n";
|
116 |
+
endwhile;
|
117 |
+
echo '<input type="submit" name="submit" class="button" value="Submit" /> ';
|
118 |
+
echo '<input type="reset" name="reset" class="button" value="Reset" /> ';
|
119 |
+
echo '<input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" />' . "\r\n";
|
120 |
+
echo '</form>' . "\r\n";
|
121 |
+
endif;
|
122 |
+
echo '</div>' . "\r\n";
|
123 |
+
endif;
|
124 |
+
}
|
125 |
+
|
126 |
+
// Add Actions
|
127 |
+
add_action ( 'admin_menu' , 'pr_options_page' ) ;
|
128 |
+
add_action ( 'activate_pagerestrict/pagerestrict.php' , 'pr_init' );
|
129 |
+
?>
|
pagerestrict.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Page Restrict
|
4 |
+
Plugin URI: http://sivel.net/wordpress/
|
5 |
+
Description: Restrict certain pages to logged in users
|
6 |
+
Author: Matt Martz
|
7 |
+
Author URI: http://sivel.net/
|
8 |
+
Version: 1.4.1
|
9 |
+
|
10 |
+
Copyright (c) 2008 Matt Martz (http://sivel.net)
|
11 |
+
Page Restrict is released under the GNU Lesser General Public License (LGPL)
|
12 |
+
http://www.gnu.org/licenses/lgpl-3.0.txt
|
13 |
+
*/
|
14 |
+
|
15 |
+
if ( is_admin () )
|
16 |
+
require_once( dirname ( __FILE__ ) . '/inc/admin.php' );
|
17 |
+
|
18 |
+
// Get Specific Page Restrict Option
|
19 |
+
function pr_get_opt ( $option ) {
|
20 |
+
$pr_options = get_option ( 'pr_options' );
|
21 |
+
return $pr_options[$option];
|
22 |
+
}
|
23 |
+
|
24 |
+
// Add headers to keep browser from caching the pages when user not logged in
|
25 |
+
// Resolves a problem where users see the login form after logging in and need
|
26 |
+
// to refresh to see content
|
27 |
+
function pr_no_cache_headers () {
|
28 |
+
global $user_ID;
|
29 |
+
get_currentuserinfo ();
|
30 |
+
if ( ! $user_ID ) {
|
31 |
+
header ( 'Cache-Control: no-cache, must-revalidate' );
|
32 |
+
header ( 'Expires: ' . gmdate ( 'r' , strtotime ( 'last week' ) ) );
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
// Perform the restriction and if restricted replace the page content with a login form
|
37 |
+
function pr_page_restrict ( $pr_page_content ) {
|
38 |
+
global $user_ID;
|
39 |
+
get_currentuserinfo ();
|
40 |
+
if ( ! $user_ID ) :
|
41 |
+
if ( ( ( is_page ( explode ( ',' , pr_get_opt ( 'pages' ) ) ) ) && ( pr_get_opt ( 'method' ) != 'none' ) ) || ( ( is_page () ) && ( pr_get_opt ( 'method' ) == 'all' ) ) ):
|
42 |
+
$pr_page_content = '
|
43 |
+
<p>You are required to login to view this page.</p>
|
44 |
+
<form style="text-align: left;" action="' . get_bloginfo ( 'url' ) . '/wp-login.php" method="post">
|
45 |
+
<p>
|
46 |
+
<label for="log"><input type="text" name="log" id="log" value="' . wp_specialchars ( stripslashes ( $user_login ) , 1 ) . '" size="22" /> User</label><br />
|
47 |
+
<label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
|
48 |
+
<input type="submit" name="submit" value="Log In" class="button" />
|
49 |
+
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
|
50 |
+
</p>
|
51 |
+
<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />
|
52 |
+
</form>
|
53 |
+
<p><a href="' . get_bloginfo ( 'url' ) . '/wp-register.php">Register</a> | <a href="' . get_bloginfo ( 'url' ) . '/wp-login.php?action=lostpassword">Lost your password?</a></p>
|
54 |
+
';
|
55 |
+
return $pr_page_content;
|
56 |
+
else :
|
57 |
+
return $pr_page_content;
|
58 |
+
endif;
|
59 |
+
else :
|
60 |
+
return $pr_page_content;
|
61 |
+
endif;
|
62 |
+
}
|
63 |
+
|
64 |
+
// Add Actions
|
65 |
+
add_action( 'send_headers' , 'pr_no_cache_headers' );
|
66 |
+
|
67 |
+
// Add Filters
|
68 |
+
add_filter ( 'the_content' , 'pr_page_restrict' );
|
69 |
+
add_filter ( 'the_excerpt' , 'pr_page_restrict' );
|
70 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Page Restrict ===
|
2 |
+
Contributors: sivel
|
3 |
+
Tags: pages, page, restrict, restriction, logged in, cms
|
4 |
+
Requires at least: 2.0
|
5 |
+
Tested up to: 2.6
|
6 |
+
Stable tag: 1.4.1
|
7 |
+
|
8 |
+
Restrict certain pages to logged in users.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
Restrict certain pages to logged in users
|
13 |
+
|
14 |
+
This plugin will allow you to restrict all, none, or certain pages to logged in users only.
|
15 |
+
|
16 |
+
In some cases where you are using WordPress as a CMS and only want logged in users to have access to the content or where you want users to register for purposes unknown so that they can see the content, then this plugin is what you are looking for.
|
17 |
+
|
18 |
+
Simple admin interface to select all, none, or some of your pages. This does not work for posts, only pages.
|
19 |
+
|
20 |
+
== Installation ==
|
21 |
+
|
22 |
+
1. Upload the `pagerestrict` folder to the `/wp-content/plugins/` directory
|
23 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
24 |
+
|
25 |
+
NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pertinent topics.
|
26 |
+
|
27 |
+
== Screenshots ==
|
28 |
+
|
29 |
+
1. Login Form
|
30 |
+
2. Admin Page
|
31 |
+
|
32 |
+
== Upgrade ==
|
33 |
+
|
34 |
+
1. Deactivate the plugin through the 'Plugins' menu in WordPress
|
35 |
+
1. Delete the previous `pagerestrict` folder from the `/wp-content/plugins/` directory
|
36 |
+
1. Upload the new `pagerestrict` folder to the `/wp-content/plugins/` directory
|
37 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
38 |
+
|
39 |
+
== Usage ==
|
40 |
+
|
41 |
+
1. Visit Settings>Page Restrict in the admin area of your blog.
|
42 |
+
1. Select your restriction method (all, none, selected).
|
43 |
+
1. If you chose selected, select the pages you wish to restrict.
|
44 |
+
1. Enjoy.
|
45 |
+
|
46 |
+
== Changelog ==
|
47 |
+
|
48 |
+
= 1.4.1 (2008-08-25) : =
|
49 |
+
* Added back no_cache add_action that was lost in the admin separation
|
50 |
+
* Removed duplicate add_action for the admin page
|
51 |
+
|
52 |
+
= 1.4 (2008-08-25): =
|
53 |
+
* Updated version number scheme
|
54 |
+
* Updated code for readability
|
55 |
+
* Moved admin functionality to separate file included only when is_admin is true
|
56 |
+
|
57 |
+
= 0.3.1 (2008-08-16): =
|
58 |
+
* Updated for PHP4 Support
|
59 |
+
* Restored end PHP tag at end of script
|
60 |
+
|
61 |
+
= 0.3 (2008-08-13): =
|
62 |
+
* Initial Public Release
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|