Version Description
(2008-09-03): = * Added ability to change restriction method * Rewrote and simplified areas pertaining to the list of pages
Download this release
Release Info
Developer | sivel |
Plugin | Page Restrict |
Version | 1.5 |
Comparing to | |
See all releases |
Version 1.5
- inc/admin.php +119 -0
- pagerestrict.php +66 -0
- readme.txt +66 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
inc/admin.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Part of WordPress Plugin: Page Restrict
|
4 |
+
http://sivel.net/wordpress/
|
5 |
+
*/
|
6 |
+
|
7 |
+
$pr_version = '1.5';
|
8 |
+
|
9 |
+
// Check the version in the options table and if less than this version perform update
|
10 |
+
function pr_ver_check () {
|
11 |
+
global $pr_version;
|
12 |
+
if ( ( pr_get_opt ( 'version' ) < $pr_version ) || ( !pr_get_opt ( 'version' ) ) ) :
|
13 |
+
$pr_options = array ();
|
14 |
+
$pr_options['version'] = $pr_version;
|
15 |
+
$pr_options['pages'] = explode ( ',' , pr_get_opt ( 'pages' ) );
|
16 |
+
$pr_options['method'] = pr_get_opt ( 'method' );
|
17 |
+
$pr_options['message'] = 'You are required to login to view this page.';
|
18 |
+
pr_delete ();
|
19 |
+
add_option ( 'pr_options' , $pr_options , 'Page Restrict Options' );
|
20 |
+
endif;
|
21 |
+
}
|
22 |
+
|
23 |
+
// Initialize the default options during plugin activation
|
24 |
+
function pr_init () {
|
25 |
+
global $pr_version;
|
26 |
+
if ( ! pr_get_opt( 'version' ) ) :
|
27 |
+
$pr_options = array ();
|
28 |
+
$pr_options['version'] = $pr_version;
|
29 |
+
$pr_options['pages'] = array ();
|
30 |
+
$pr_options['method'] = 'selected';
|
31 |
+
$pr_options['message'] = 'You are required to login to view this page.';
|
32 |
+
add_option ( 'pr_options', $pr_options, 'Page Restrict Options' ) ;
|
33 |
+
else :
|
34 |
+
pr_ver_check ();
|
35 |
+
endif;
|
36 |
+
}
|
37 |
+
|
38 |
+
// Delete all options
|
39 |
+
function pr_delete () {
|
40 |
+
delete_option ( 'pr_options' );
|
41 |
+
}
|
42 |
+
|
43 |
+
// Add the options page
|
44 |
+
function pr_options_page () {
|
45 |
+
if ( is_admin () ) :
|
46 |
+
if ( function_exists ( 'add_options_page' ) ) :
|
47 |
+
add_options_page ( 'Page Restrict' , 'Page Restrict' , 'manage_options' , 'pagerestrict/pagerestrict.php' , 'pr_admin_page' );
|
48 |
+
endif;
|
49 |
+
endif;
|
50 |
+
}
|
51 |
+
|
52 |
+
// The options page
|
53 |
+
function pr_admin_page () {
|
54 |
+
if ( is_admin () ) :
|
55 |
+
pr_ver_check ();
|
56 |
+
if ( $_POST['submit'] ) :
|
57 |
+
$page_ids = $_POST['page_id'];
|
58 |
+
$pr_options['pages'] = $page_ids;
|
59 |
+
$pr_method = $_POST['method'];
|
60 |
+
if ( count ( $page_ids ) == 0 )
|
61 |
+
$pr_options['method'] = 'none';
|
62 |
+
else
|
63 |
+
$pr_options['method'] = $pr_method;
|
64 |
+
$pr_options['version'] = pr_get_opt ( 'version' );
|
65 |
+
$pr_message = $_POST['message'];
|
66 |
+
$pr_options['message'] = $pr_message;
|
67 |
+
update_option ( 'pr_options' , $pr_options );
|
68 |
+
else :
|
69 |
+
$page_ids = pr_get_opt ( 'pages' );
|
70 |
+
$pr_method = pr_get_opt ( 'method' );
|
71 |
+
$pr_message = pr_get_opt ( 'message' );
|
72 |
+
endif;
|
73 |
+
if ( $pr_method == 'all' ) :
|
74 |
+
$all_checked = ' checked="checked" ';
|
75 |
+
elseif ( $pr_method == 'none' ) :
|
76 |
+
$none_checked = ' checked="checked" ';
|
77 |
+
else :
|
78 |
+
$selected_checked = ' checked="checked" ';
|
79 |
+
endif;
|
80 |
+
echo '<div class="wrap">' . "\r\n";
|
81 |
+
echo '<h2>Page Restrict Options</h2>' . "\r\n";
|
82 |
+
echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">' . "\r\n";
|
83 |
+
echo '<h3>Enter your restriction message:</h3>' . "\r\n";
|
84 |
+
echo '<input type="text" size="64" name="message" value="' . $pr_message . '" /><br />';
|
85 |
+
echo '<h3>Choose the restriction method:</h3>' . "\r\n";
|
86 |
+
echo '<input type="radio" name="method" value="all"' . $all_checked . ' />Restrict all pages<br />' . "\r\n";
|
87 |
+
echo '<input type="radio" name="method" value="none"' . $none_checked . ' />Restrict no pages<br />' . "\r\n";
|
88 |
+
echo '<input type="radio" name="method" value="selected"' . $selected_checked . ' />Restrict selected pages only<br />' . "\r\n";
|
89 |
+
if ( $pr_method == 'selected' ) :
|
90 |
+
echo '<h3>Select the Pages you wish to restrict to logged in users only:</h3>' . "\r\n";
|
91 |
+
echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">' . "\r\n";
|
92 |
+
$avail_pages = get_pages ();
|
93 |
+
$i = count ( $avail_pages );
|
94 |
+
while ( $i > 0 ) :
|
95 |
+
$i--;
|
96 |
+
$pr_page_id = $avail_pages[$i]->ID;
|
97 |
+
$pr_page_title = $avail_pages[$i]->post_title;
|
98 |
+
if ( $page_ids ) :
|
99 |
+
if ( in_array ( $pr_page_id , $page_ids ) ) :
|
100 |
+
$page_checked = ' checked="checked" ';
|
101 |
+
else :
|
102 |
+
$page_checked = '';
|
103 |
+
endif;
|
104 |
+
endif;
|
105 |
+
echo '<input type="checkbox" name="page_id[]" value="' . $pr_page_id . '"' . $page_checked . ' />' . $pr_page_title . '<br />' . "\r\n";
|
106 |
+
endwhile;
|
107 |
+
endif;
|
108 |
+
echo '<input type="submit" name="submit" class="button" value="Submit" /> ';
|
109 |
+
echo '<input type="reset" name="reset" class="button" value="Reset" /> ';
|
110 |
+
echo '<input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" />' . "\r\n";
|
111 |
+
echo '</form>' . "\r\n";
|
112 |
+
echo '</div>' . "\r\n";
|
113 |
+
endif;
|
114 |
+
}
|
115 |
+
|
116 |
+
// Add Actions
|
117 |
+
add_action ( 'admin_menu' , 'pr_options_page' ) ;
|
118 |
+
add_action ( 'activate_pagerestrict/pagerestrict.php' , 'pr_init' );
|
119 |
+
?>
|
pagerestrict.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.5
|
9 |
+
|
10 |
+
Copyright (c) 2008 Matt Martz (http://sivel.net)
|
11 |
+
Page Restrict is released under the GNU General Public License (GPL)
|
12 |
+
http://www.gnu.org/licenses/gpl-2.0.txt
|
13 |
+
*/
|
14 |
+
|
15 |
+
// ff we are in the admin load the admin functionality
|
16 |
+
if ( is_admin () )
|
17 |
+
require_once( dirname ( __FILE__ ) . '/inc/admin.php' );
|
18 |
+
|
19 |
+
// get specific option
|
20 |
+
function pr_get_opt ( $option ) {
|
21 |
+
$pr_options = get_option ( 'pr_options' );
|
22 |
+
return $pr_options[$option];
|
23 |
+
}
|
24 |
+
|
25 |
+
// Add headers to keep browser from caching the pages when user not logged in
|
26 |
+
// Resolves a problem where users see the login form after logging in and need
|
27 |
+
// to refresh to see content
|
28 |
+
function pr_no_cache_headers () {
|
29 |
+
global $user_ID;
|
30 |
+
get_currentuserinfo ();
|
31 |
+
if ( ! $user_ID ) {
|
32 |
+
nocache_headers ();
|
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 ( pr_get_opt ( 'pages' ) ) ) && ( pr_get_opt ( 'method' ) != 'none' ) ) || ( ( is_page () ) && ( pr_get_opt ( 'method' ) == 'all' ) ) ):
|
42 |
+
$pr_page_content = '
|
43 |
+
<p>' . pr_get_opt ( 'message' ) . '</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 |
+
endif;
|
56 |
+
endif;
|
57 |
+
return $pr_page_content;
|
58 |
+
}
|
59 |
+
|
60 |
+
// Add Actions
|
61 |
+
add_action( 'send_headers' , 'pr_no_cache_headers' );
|
62 |
+
|
63 |
+
// Add Filters
|
64 |
+
add_filter ( 'the_content' , 'pr_page_restrict' );
|
65 |
+
add_filter ( 'the_excerpt' , 'pr_page_restrict' );
|
66 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Page Restrict ===
|
2 |
+
Contributors: sivel
|
3 |
+
Tags: pages, page, restrict, restriction, logged in, cms
|
4 |
+
Requires at least: 2.5
|
5 |
+
Tested up to: 2.7
|
6 |
+
Stable tag: 1.5
|
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.5 (2008-09-03): =
|
49 |
+
* Added ability to change restriction method
|
50 |
+
* Rewrote and simplified areas pertaining to the list of pages
|
51 |
+
|
52 |
+
= 1.4.1 (2008-08-25): =
|
53 |
+
* Added back no_cache add_action that was lost in the admin separation
|
54 |
+
* Removed duplicate add_action for the admin page
|
55 |
+
|
56 |
+
= 1.4 (2008-08-25): =
|
57 |
+
* Updated version number scheme
|
58 |
+
* Updated code for readability
|
59 |
+
* Moved admin functionality to separate file included only when is_admin is true
|
60 |
+
|
61 |
+
= 0.3.1 (2008-08-16): =
|
62 |
+
* Updated for PHP4 Support
|
63 |
+
* Restored end PHP tag at end of script
|
64 |
+
|
65 |
+
= 0.3 (2008-08-13): =
|
66 |
+
* Initial Public Release
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|