WordPress Access Control - Version 3.1

Version Description

  • Custom Post Type section is no longer displayed on the options page if there are no custom post types
  • Members Only Blog now properly restricts the entire site
  • Admins now have the ability to override permissions to prevent lower level users from denying admins access to posts
  • Admins may now create menu widgets that are only visible to members or non-members from the Widgets screen
  • Admins may now create WordPress nav menus that are only visible to members
  • Updated the documentation
  • Added new screenshots
Download this release

Release Info

Developer brandon.wamboldt
Plugin Icon wp plugin WordPress Access Control
Version 3.1
Comparing to
See all releases

Code changes from version 3.0.5 to 3.1

default-widgets.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Unregister some the default WordPress widgets on startup and register our
4
+ * slightly modified versions
5
+ *
6
+ * @since 3.1.0
7
+ */
8
+ function wpac_widgets_init()
9
+ {
10
+ if ( ! is_blog_installed() ) {
11
+ return;
12
+ }
13
+
14
+ unregister_widget( 'WP_Nav_Menu_Widget' );
15
+
16
+ register_widget( 'WPAC_Nav_Menu_Widget' );
17
+ }
18
+ add_action( 'widgets_init', 'wpac_widgets_init', 1 );
19
+
20
+ /**
21
+ * Navigation Menu widget class
22
+ *
23
+ * @since 3.1.0
24
+ */
25
+ class WPAC_Nav_Menu_Widget extends WP_Nav_Menu_Widget
26
+ {
27
+ function WPAC_Nav_Menu_Widget()
28
+ {
29
+ $widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
30
+ parent::WP_Widget( 'nav_menu', __('Custom Menu'), $widget_ops );
31
+ }
32
+
33
+ function widget( $args, $instance )
34
+ {
35
+ if ( isset( $instance['wpac_visible_by_members'] ) && $instance['wpac_visible_by_members'] && ! is_user_logged_in() ) {
36
+ return;
37
+ }
38
+
39
+ if ( isset( $instance['wpac_visible_by_nonmembers'] ) && $instance['wpac_visible_by_nonmembers'] && is_user_logged_in() ) {
40
+ return;
41
+ }
42
+
43
+ // Get menu
44
+ $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
45
+
46
+ if ( !$nav_menu )
47
+ return;
48
+
49
+ echo $args['before_widget'];
50
+
51
+ if ( !empty($instance['title']) )
52
+ echo $args['before_title'] . $instance['title'] . $args['after_title'];
53
+
54
+ wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
55
+
56
+ echo $args['after_widget'];
57
+ }
58
+
59
+ function update( $new_instance, $old_instance ) {
60
+ $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
61
+ $instance['nav_menu'] = (int) $new_instance['nav_menu'];
62
+ $instance['wpac_visible_by_members'] = 0;
63
+ $instance['wpac_visible_by_nonmembers'] = 0;
64
+
65
+ if ( isset( $new_instance['wpac_visible_by_members'] ) ) {
66
+ $instance['wpac_visible_by_members'] = 1;
67
+ }
68
+
69
+ if ( isset( $new_instance['wpac_visible_by_nonmembers'] ) ) {
70
+ $instance['wpac_visible_by_nonmembers'] = 1;
71
+ }
72
+
73
+ return $instance;
74
+ }
75
+
76
+ function form( $instance ) {
77
+ $title = isset( $instance['title'] ) ? $instance['title'] : '';
78
+ $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
79
+
80
+ // Get menus
81
+ $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
82
+
83
+ // If no menus exists, direct the user to go and create some.
84
+ if ( !$menus ) {
85
+ echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
86
+ return;
87
+ }
88
+ ?>
89
+ <p>
90
+ <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
91
+ <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
92
+ </p>
93
+ <p>
94
+ <label><?php _e('WordPress Access Control:') ?></label><br />
95
+ <label><input type="checkbox" <?php checked( $instance['wpac_visible_by_members'], true ); ?> name="<?php echo $this->get_field_name('wpac_visible_by_members'); ?>" id="<?php echo $this->get_field_id('wpac_visible_by_members'); ?>" value="yes" /> Only visible by members? </label><br />
96
+ <label><input type="checkbox" <?php checked( $instance['wpac_visible_by_nonmembers'], true ); ?> name="<?php echo $this->get_field_name('wpac_visible_by_nonmembers'); ?>" id="<?php echo $this->get_field_id('wpac_visible_by_nonmembers'); ?>" value="yes" /> Only visible by non-members? </label>
97
+ </p>
98
+ <p>
99
+ <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
100
+ <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
101
+ <?php
102
+ foreach ( $menus as $menu ) {
103
+ $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
104
+ echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
105
+ }
106
+ ?>
107
+ </select>
108
+ </p>
109
+ <?php
110
+ }
111
+ }
documentation/assets/images/menus_interface.jpg ADDED
Binary file
documentation/assets/images/widgets_interface.jpg ADDED
Binary file
documentation/index.html CHANGED
@@ -1,278 +1,359 @@
1
- <!DOCTYPE html>
2
-
3
- <html>
4
-
5
- <head>
6
- <meta charset="UTF-8" />
7
- <title>Documentation &raquo; WordPress Access Control</title>
8
-
9
- <link rel="stylesheet" href="assets/css/readme.css" type="text/css" />
10
- </head>
11
-
12
- <body>
13
- <h1 id="logo">
14
- <a href="http://wordpress.org/"><img alt="WordPress" src="wp-admin/images/wordpress-logo.png" width="250" height="68" /></a><br />
15
- WordPress Access Control Documentation Version 3.0.2
16
- </h1>
17
-
18
- <p style="text-align: center">The complete guide this plugin</p>
19
-
20
- <h1>First Things First</h1>
21
-
22
- <p>
23
- WordPress Access Control is an access control plugin for WordPress, and was
24
- built by Brandon Wamboldt. If you have questions outside of the scope of this
25
- help file, require assistance, want to report a bug, request a feature or
26
- anything else, please <a href="mailto:brandon.wamboldt@gmail.com">email me</a> or
27
- leave a comment on my blog, <a href="http://brandonwamboldt.ca/plugins/members-only-menu-plugin/">http://brandonwamboldt.ca/plugins/members-only-menu-plugin/</a>.
28
- </p>
29
-
30
- <h1>Table Of Contents</h1>
31
-
32
- <ol class="alpha" id="toc">
33
- <li><a href="#introduction">Introduction</a></li>
34
- <li><a href="#requirements">Requirements</a></li>
35
- <li><a href="#installation">Installation &amp; Configuration</a></li>
36
- <li><a href="#settings">Settings</a>
37
- <ol class="alpha">
38
- <li><a href="#general_options">General Options</a></li>
39
- <li><a href="#menu_options">Menu Options</a></li>
40
- <li><a href="#postpage_default_options">Post/Page Default Options</a></li>
41
- <li><a href="#search_options">Search/Archive Options</a></li>
42
- </ol>
43
- </li>
44
- <li><a href="#shortcodes">Shortcodes</a></li>
45
- <li><a href="#interface">Interface</a></li>
46
- <li><a href="#changelog">Changelog</a></li>
47
- <li><a href="#credits">Sources and Credits</a></li>
48
- </ol>
49
-
50
- <h1 id="introduction">A) Introduction - <a href="#toc">top</a></h1>
51
-
52
- <p>
53
- The purpose of WordPress Access Control is to provide an easy interface to users for
54
- restricting access to content. It was designed for use on members sites where not all
55
- content should be accessible by the public, such as with organizations or pay-sites.
56
- </p>
57
-
58
- <p>
59
- WPAC gives you the ability to restrict content to members, specific roles, or even
60
- non-members on a per-page/per-post basis, or using shortcodes. You can still add
61
- restricted pages to the navigation, and by default they will only show up to users
62
- with the required access. This is an option however.
63
- </p>
64
-
65
- <p>
66
- WPAC also gives you the ability to customize search/archive pages, completing hiding
67
- restricted posts/pages from search results if a user can't access them, showing just
68
- the title with a customizable message where the excerpt would be, or showing the title
69
- and excerpt.
70
- </p>
71
-
72
- <p>
73
- This plugin supports custom post types via an easy to use admin option.
74
- </p>
75
-
76
- <h1 id="requirements">B) Requirements - <a href="#toc">top</a></h1>
77
-
78
- <p>
79
- WordPress Access Control has only been tested with WordPress 2.9 and greater. WordPress Access Control requires <strong>PHP4</strong> or higher, although <strong>PHP5</strong> is recommended.
80
- </p>
81
-
82
- <p style="color:red;">
83
- WordPress Access Control may not work with all themes. If you find are using WPAC with a theme and it's not working well, please contact me with the name of the theme as well as a link to the theme, and your PHP version.
84
- </p>
85
-
86
- <h1 id="installation">C) Installation &amp; Configuration - <a href="#toc">top</a></h1>
87
-
88
- <p>
89
- Installation is simple, just follow these steps and you should have no problems.
90
- </p>
91
-
92
- <ol>
93
- <li>Upload the wordpress-access-control/ folder included in the zip to your WordPress installation's plugin folder. The default location should be /wp-content/plugins/</li>
94
- <li>Login to your WordPress administration panel, located by default at http://your-site-here.com/wp-admin/</li>
95
- <li>Click on Plugins on the left menu</li>
96
- <li>Scroll down to &ldquo;WordPress Access Control&rdquo; and click the "Activate" link</li>
97
- <li>Scroll back down to &ldquo;WordPress Access Control&rdquo; and click "Visit options page". Alternatively, you can access this from Settings &gt; Members Only</li>
98
- <li>Set your default settings. An explanation of the settings can be found below.</li>
99
- <li>Finished!</li>
100
- </ol>
101
-
102
- <h1 id="settings">D) Settings - <a href="#toc">top</a></h1>
103
-
104
- <p>
105
- Using the settings screen, you can set many default options for the
106
- plugin, which is useful for saving time if most of your pages/posts
107
- will have similar access settings. Most of these settings can be
108
- overwritten on a per-page/per-post basis.
109
- </p>
110
-
111
- <h2 id="general_options">A) General Options - <a href="#toc">top</a></h2>
112
-
113
- <p>
114
- <strong>Make Blog Members Only</strong><br />
115
- This setting will make the blog page itself, as well as any archive
116
- pages restricted to members. Regular pages will still be accessible
117
- to non-members however. This setting uses the <a href="http://codex.wordpress.org/Function_Reference/is_home">is_home()</a> and
118
- <a href="http://codex.wordpress.org/Function_Reference/is_archive">is_archive()</a> functions to determine blog/archive pages.<br /><br />
119
-
120
- <strong>Members Blog Redirect</strong><br />
121
- This setting is a website address to redirect users to if they try to
122
- access the blog or archive pages with the "Make Blog Members Only"
123
- setting active. By default, it will redirect to the login page.<br /><br />
124
-
125
- <strong>Custom Post Types</strong><br />
126
- This setting allows you to enable the Members Only controls for custom
127
- post types. This setting only works if the custom post type uses the
128
- standard WordPress interface.
129
- </p>
130
-
131
- <h2 id="menu_options">B) Menu Options - <a href="#toc">top</a></h2>
132
-
133
- <p>
134
- <strong>Display In Menus</strong><br />
135
- This setting determines how menu items work when a restricted page/post is
136
- added to the navigation and a user doesn't have access to it. You can
137
- show the menu only if a user has access to it, or you can show it all
138
- the time. If you decide to show it all the time, a user who clicks on a menu
139
- item but does not have access to view it will be redirected.
140
- </p>
141
-
142
- <h2 id="postpage_default_options">C) Post/Page Default Options - <a href="#toc">top</a></h2>
143
-
144
- <p>
145
- <strong>Default Post State</strong><br />
146
- This setting determines the default option when creating a new post. Public
147
- is the default setting and means the post will be accessible to all. Members
148
- Only restricts the post to authenticated users, and Non-Members restricts
149
- the post to unauthenticated users.<br /><br />
150
-
151
- <strong>Posts: Only Accessible By</strong><br />
152
- This setting determines the default option when creating a new page for which
153
- roles can access the post. This setting is only used if the post is set for
154
- Members Only. Roles are managed using plugins.<br /><br />
155
-
156
- <strong>Default Page State</strong><br />
157
- This setting determines the default option when creating a new page. Public
158
- is the default setting and means the page will be accessible to all. Members
159
- Only restricts the page to authenticated users, and Non-Members restricts
160
- the page to unauthenticated users.<br /><br />This setting also acts as
161
- the default for custom post types.<br /><br />
162
-
163
- <strong>Pages: Only Accessible By</strong><br />
164
- This setting determines the default option when creating a new page for which
165
- roles can access the page. This setting is only used if the page is set for
166
- Members Only. Roles are managed using plugins.<br /><br />This setting also acts as
167
- the default for custom post types.<br /><br />
168
-
169
- <strong>Default Redirect For Members Only Pages</strong><br />
170
- This is the default URL to redirect users to when they attempt to access
171
- a restricted page/post.<br /><br />
172
-
173
- The link provided here is automatically appended with a redirect_to query
174
- argument, so that the page may redirect the user back if they wish.
175
- </p>
176
-
177
- <h2 id="search_options">D) Search/Archive Options - <a href="#toc">top</a></h2>
178
-
179
- <p>
180
- <strong>Search Options</strong><br />
181
- This setting determines how restricted posts/pages will appear in
182
- search or archive pages. This setting uses <a href="http://codex.wordpress.org/Function_Reference/is_search">is_search()</a>
183
- and <a href="http://codex.wordpress.org/Function_Reference/is_archive">is_archive()</a>
184
- to determine use.<br /><br />
185
- If you do not check "Show restricted post excerpts in search results?" the excerpt
186
- will be replaced with text from the below options.<br /><br />
187
- The page settings for this setting determine defaults for custom post types.<br /><br />
188
-
189
- <strong>Search Excerpt (Posts)/Search Excerpt (Pages)</strong><br />
190
- This text is displayed instead of the post/page excerpt in archive/search pages to users
191
- without the required access, but only if the post/page is set to now show it's
192
- excerpt.
193
- </p>
194
-
195
- <h1 id="shortcodes">E) Shortcodes - <a href="#toc">top</a></h1>
196
-
197
- <p>
198
- There are two shortcodes available for use with this plugin.<br /><br />
199
-
200
- [members][/members] will hide the content within them unless the user is
201
- authenticated. Also works during searching, so that if a user searches for
202
- a term found in the shortcodes, but is not logged in, the page/post will
203
- not show up in the results.
204
- </p>
205
-
206
- <p>
207
- [nonmembers][/nonmembers] will hide the content within them unless the user is
208
- not authenticated. Also works during searching, so that if a user searches for
209
- a term found in the shortcodes, but is logged in, the page/post will
210
- not show up in the results.
211
- </p>
212
-
213
- <h1 id="interface">F) Interface - <a href="#toc">top</a></h1>
214
-
215
- <p>
216
- By default, when you edit/add a new post/page, the control interface should be displayed on
217
- the right, directly above the "Publish" box. If you do not see it, please ensure it is set to
218
- display under the "Screen Options" panel.
219
- </p>
220
-
221
- <p style="text-align:center;">
222
- <img src="assets/images/default_interface.png" alt="" /><br />
223
- The default interface is very small, and lacks many options. More options will appear once
224
- you've checked an option.
225
- </p>
226
-
227
- <p style="text-align:center;">
228
- <img src="assets/images/members_interface.png" alt="" /><br />
229
- If you select "Only accessible by members?", several new options appear. The default values
230
- are governed by the options screen, and an explanation of the options are available above
231
- as well.
232
- </p>
233
-
234
- <p style="text-align:center;">
235
- <img src="assets/images/nonmembers_interface.png" alt="" /><br />
236
- If you select "Only accessible by non-members?", one new option appears. This is the URL
237
- to redirect a user to, such as the my profile page or even a logout page.
238
- </p>
239
-
240
- <h1 id="changelog">G) Changelog - <a href="#toc">top</a></h1>
241
-
242
- <p><strong>Version 3.0.2 - June 2, 2011</strong></p>
243
-
244
- <ul>
245
- <li>Added do_shortcode commands to allow nested shortcodes in the [members] and [nonmembers] shortcodes</li>
246
- </ul>
247
-
248
- <p><strong>Version 3.0.1 - June 1, 2011</strong></p>
249
-
250
- <ul>
251
- <li>Fixed an issue where a members only blog with no redirect link specified would cause an infinite loop</li>
252
- </ul>
253
-
254
- <p><strong>Version 3.0 - May 26, 2011</strong></p>
255
-
256
- <ul>
257
- <li>Added an admin options page</li>
258
- <li>Added an option to allow pages to show up in menus even if a user cannot access them</li>
259
- <li>Added support to make an entire blog members only</li>
260
- <li>Added options to set the defaults of all options for pages and posts</li>
261
- <li>Added support for posts</li>
262
- <li>Added support for searching/archives</li>
263
- <li>Added better support for custom post types</li>
264
- <li>Added a redirect_to argument even when using custom redirect links</li>
265
- <li>Added [member][/member] and [nonmember][/nonmember] shortcodes</li>
266
- </ul>
267
-
268
- <h1 id="credits">H) Sources and Credits - <a href="#toc">top</a></h1>
269
-
270
- <p>
271
- <ul>
272
- <li>I'd like to thank the <a href="http://wordpress.org/">WordPress community</a> for making such an awesome development platform.</li>
273
- <li>Made use of the WordPress codex extensively <a href="http://codex.wordpress.org/">http://codex.wordpress.org/</a></li>
274
- </ul>
275
- </p>
276
- </body>
277
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  </html>
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+
5
+ <head>
6
+ <meta charset="UTF-8" />
7
+ <title>Documentation &raquo; WordPress Access Control</title>
8
+
9
+ <link rel="stylesheet" href="assets/css/readme.css" type="text/css" />
10
+ </head>
11
+
12
+ <body>
13
+ <h1 id="logo">
14
+ <a href="http://wordpress.org/"><img alt="WordPress" src="wp-admin/images/wordpress-logo.png" width="250" height="68" /></a><br />
15
+ WordPress Access Control Documentation Version 3.1
16
+ </h1>
17
+
18
+ <p style="text-align: center">The complete guide this plugin</p>
19
+
20
+ <h1>First Things First</h1>
21
+
22
+ <p>
23
+ WordPress Access Control is an access control plugin for WordPress, and was
24
+ built by Brandon Wamboldt. If you have questions outside of the scope of this
25
+ help file, require assistance, want to report a bug, request a feature or
26
+ anything else, please <a href="mailto:brandon.wamboldt@gmail.com">email me</a> or
27
+ leave a comment on my blog, <a href="http://brandonwamboldt.ca/plugins/members-only-menu-plugin/">http://brandonwamboldt.ca/plugins/members-only-menu-plugin/</a>.
28
+ </p>
29
+
30
+ <h1>Table Of Contents</h1>
31
+
32
+ <ol class="alpha" id="toc">
33
+ <li><a href="#introduction">Introduction</a></li>
34
+ <li><a href="#requirements">Requirements</a></li>
35
+ <li><a href="#installation">Installation &amp; Configuration</a></li>
36
+ <li><a href="#settings">Settings</a>
37
+ <ol class="alpha">
38
+ <li><a href="#general_options">General Options</a></li>
39
+ <li><a href="#override_permissions">Override Permisisons</a></li>
40
+ <li><a href="#menu_options">Menu Options</a></li>
41
+ <li><a href="#postpage_default_options">Post/Page Default Options</a></li>
42
+ <li><a href="#search_options">Search/Archive Options</a></li>
43
+ </ol>
44
+ </li>
45
+ <li><a href="#shortcodes">Shortcodes</a></li>
46
+ <li><a href="#interface">Posts/Pages Interface</a></li>
47
+ <li><a href="#widgets_interface">Widgets Interface</a></li>
48
+ <li><a href="#menus_interface">Nav Menus Interface</a></li>
49
+ <li><a href="#changelog">Changelog</a></li>
50
+ <li><a href="#credits">Sources and Credits</a></li>
51
+ </ol>
52
+
53
+ <h1 id="introduction">A) Introduction - <a href="#toc">top</a></h1>
54
+
55
+ <p>
56
+ The purpose of WordPress Access Control is to provide an easy interface to users for
57
+ restricting access to content. It was designed for use on members sites where not all
58
+ content should be accessible by the public, such as with organizations or pay-sites.
59
+ </p>
60
+
61
+ <p>
62
+ WPAC gives you the ability to restrict content to members, specific roles, or even
63
+ non-members on a per-page/per-post basis, or using shortcodes. You can still add
64
+ restricted pages to the navigation, and by default they will only show up to users
65
+ with the required access. This is an option however.
66
+ </p>
67
+
68
+ <p>
69
+ WPAC also gives you the ability to customize search/archive pages, completing hiding
70
+ restricted posts/pages from search results if a user can't access them, showing just
71
+ the title with a customizable message where the excerpt would be, or showing the title
72
+ and excerpt.
73
+ </p>
74
+
75
+ <p>
76
+ WPAC now gives admins the ability to set the visibility of certain widgets to members only
77
+ or non-members only, as well as create member only versions of all WordPress nav menus.
78
+ </p>
79
+
80
+ <p>
81
+ This plugin supports custom post types via an easy to use admin option.
82
+ </p>
83
+
84
+ <h1 id="requirements">B) Requirements - <a href="#toc">top</a></h1>
85
+
86
+ <p>
87
+ WordPress Access Control has only been tested with WordPress 2.9 and greater. WordPress Access Control requires <strong>PHP4</strong> or higher, although <strong>PHP5</strong> is recommended.
88
+ </p>
89
+
90
+ <p style="color:red;">
91
+ WordPress Access Control may not work with all themes. If you find are using WPAC with a theme and it's not working well, please contact me with the name of the theme as well as a link to the theme, and your PHP version.
92
+ </p>
93
+
94
+ <h1 id="installation">C) Installation &amp; Configuration - <a href="#toc">top</a></h1>
95
+
96
+ <p>
97
+ Installation is simple, just follow these steps and you should have no problems.
98
+ </p>
99
+
100
+ <ol>
101
+ <li>Upload the wordpress-access-control/ folder included in the zip to your WordPress installation's plugin folder. The default location should be /wp-content/plugins/</li>
102
+ <li>Login to your WordPress administration panel, located by default at http://your-site-here.com/wp-admin/</li>
103
+ <li>Click on Plugins on the left menu</li>
104
+ <li>Scroll down to &ldquo;WordPress Access Control&rdquo; and click the "Activate" link</li>
105
+ <li>Scroll back down to &ldquo;WordPress Access Control&rdquo; and click "Visit options page". Alternatively, you can access this from Settings &gt; Members Only</li>
106
+ <li>Set your default settings. An explanation of the settings can be found below.</li>
107
+ <li>Finished!</li>
108
+ </ol>
109
+
110
+ <h1 id="settings">D) Settings - <a href="#toc">top</a></h1>
111
+
112
+ <p>
113
+ Using the settings screen, you can set many default options for the
114
+ plugin, which is useful for saving time if most of your pages/posts
115
+ will have similar access settings. Most of these settings can be
116
+ overwritten on a per-page/per-post basis.
117
+ </p>
118
+
119
+ <h2 id="general_options">A) General Options - <a href="#toc">top</a></h2>
120
+
121
+ <p>
122
+ <strong>Make Blog Members Only</strong><br />
123
+ This setting will make the blog page itself, as well as any archive
124
+ pages restricted to members. Regular pages will still be accessible
125
+ to non-members however. This setting uses the <a href="http://codex.wordpress.org/Function_Reference/is_home">is_home()</a> and
126
+ <a href="http://codex.wordpress.org/Function_Reference/is_archive">is_archive()</a> functions to determine blog/archive pages.<br /><br />
127
+
128
+ <strong>Members Blog Redirect</strong><br />
129
+ This setting is a website address to redirect users to if they try to
130
+ access the blog or archive pages with the "Make Blog Members Only"
131
+ setting active. By default, it will redirect to the login page.<br /><br />
132
+
133
+ <strong>Custom Post Types</strong><br />
134
+ This setting allows you to enable the Members Only controls for custom
135
+ post types. This setting only works if the custom post type uses the
136
+ standard WordPress interface. This option will not be displayed if there
137
+ are no custom post types.
138
+ </p>
139
+
140
+ <h2 id="override_permissions">B) Override Permisisons - <a href="#toc">top</a></h2>
141
+
142
+ <p>
143
+ <strong>Always Accessible By</strong><br />
144
+
145
+ This will override any per-page or per-post settings and allow the specified user
146
+ groups to always have access to members only content. This was to fix a scenario
147
+ in which a lesser user such as a Contributor could make content invisible to a
148
+ higher user such as an administrator.
149
+ </p>
150
+
151
+ <h2 id="menu_options">C) Menu Options - <a href="#toc">top</a></h2>
152
+
153
+ <p>
154
+ <strong>Display In Menus</strong><br />
155
+ This setting determines how menu items work when a restricted page/post is
156
+ added to the navigation and a user doesn't have access to it. You can
157
+ show the menu only if a user has access to it, or you can show it all
158
+ the time. If you decide to show it all the time, a user who clicks on a menu
159
+ item but does not have access to view it will be redirected.
160
+ </p>
161
+
162
+ <h2 id="postpage_default_options">D) Post/Page Default Options - <a href="#toc">top</a></h2>
163
+
164
+ <p>
165
+ <strong>Default Post State</strong><br />
166
+ This setting determines the default option when creating a new post. Public
167
+ is the default setting and means the post will be accessible to all. Members
168
+ Only restricts the post to authenticated users, and Non-Members restricts
169
+ the post to unauthenticated users.<br /><br />
170
+
171
+ <strong>Posts: Only Accessible By</strong><br />
172
+ This setting determines the default option when creating a new page for which
173
+ roles can access the post. This setting is only used if the post is set for
174
+ Members Only. Roles are managed using plugins.<br /><br />
175
+
176
+ <strong>Default Page State</strong><br />
177
+ This setting determines the default option when creating a new page. Public
178
+ is the default setting and means the page will be accessible to all. Members
179
+ Only restricts the page to authenticated users, and Non-Members restricts
180
+ the page to unauthenticated users.<br /><br />This setting also acts as
181
+ the default for custom post types.<br /><br />
182
+
183
+ <strong>Pages: Only Accessible By</strong><br />
184
+ This setting determines the default option when creating a new page for which
185
+ roles can access the page. This setting is only used if the page is set for
186
+ Members Only. Roles are managed using plugins.<br /><br />This setting also acts as
187
+ the default for custom post types.<br /><br />
188
+
189
+ <strong>Default Redirect For Members Only Pages</strong><br />
190
+ This is the default URL to redirect users to when they attempt to access
191
+ a restricted page/post.<br /><br />
192
+
193
+ The link provided here is automatically appended with a redirect_to query
194
+ argument, so that the page may redirect the user back if they wish.
195
+ </p>
196
+
197
+ <h2 id="search_options">E) Search/Archive Options - <a href="#toc">top</a></h2>
198
+
199
+ <p>
200
+ <strong>Search Options</strong><br />
201
+ This setting determines how restricted posts/pages will appear in
202
+ search or archive pages. This setting uses <a href="http://codex.wordpress.org/Function_Reference/is_search">is_search()</a>
203
+ and <a href="http://codex.wordpress.org/Function_Reference/is_archive">is_archive()</a>
204
+ to determine use.<br /><br />
205
+ If you do not check "Show restricted post excerpts in search results?" the excerpt
206
+ will be replaced with text from the below options.<br /><br />
207
+ The page settings for this setting determine defaults for custom post types.<br /><br />
208
+
209
+ <strong>Search Excerpt (Posts)/Search Excerpt (Pages)</strong><br />
210
+ This text is displayed instead of the post/page excerpt in archive/search pages to users
211
+ without the required access, but only if the post/page is set to now show it's
212
+ excerpt.
213
+ </p>
214
+
215
+ <h1 id="shortcodes">E) Shortcodes - <a href="#toc">top</a></h1>
216
+
217
+ <p>
218
+ There are two shortcodes available for use with this plugin.<br /><br />
219
+
220
+ [members][/members] will hide the content within them unless the user is
221
+ authenticated. Also works during searching, so that if a user searches for
222
+ a term found in the shortcodes, but is not logged in, the page/post will
223
+ not show up in the results.
224
+ </p>
225
+
226
+ <p>
227
+ [nonmembers][/nonmembers] will hide the content within them unless the user is
228
+ not authenticated. Also works during searching, so that if a user searches for
229
+ a term found in the shortcodes, but is logged in, the page/post will
230
+ not show up in the results.
231
+ </p>
232
+
233
+ <h1 id="interface">F) Posts/Pages Interface - <a href="#toc">top</a></h1>
234
+
235
+ <p>
236
+ By default, when you edit/add a new post/page, the control interface should be displayed on
237
+ the right, directly above the "Publish" box. If you do not see it, please ensure it is set to
238
+ display under the "Screen Options" panel.
239
+ </p>
240
+
241
+ <p style="text-align:center;">
242
+ <img src="assets/images/default_interface.png" alt="" /><br />
243
+ The default interface is very small, and lacks many options. More options will appear once
244
+ you've checked an option.
245
+ </p>
246
+
247
+ <p style="text-align:center;">
248
+ <img src="assets/images/members_interface.png" alt="" /><br />
249
+ If you select "Only accessible by members?", several new options appear. The default values
250
+ are governed by the options screen, and an explanation of the options are available above
251
+ as well.
252
+ </p>
253
+
254
+ <p style="text-align:center;">
255
+ <img src="assets/images/nonmembers_interface.png" alt="" /><br />
256
+ If you select "Only accessible by non-members?", one new option appears. This is the URL
257
+ to redirect a user to, such as the my profile page or even a logout page.
258
+ </p>
259
+
260
+ <h1 id="widgets_interface">G) Widgets Interface - <a href="#toc">top</a></h1>
261
+
262
+ <p>
263
+ Now, when you add certain supported widgets to a widget area, you have the option to select
264
+ the visibility of the widget as members only or non-members only. Currently, the only supported
265
+ widget is the Custom Menu widget. If you would like more widgets added, please contact the developer.
266
+ </p>
267
+
268
+ <p style="text-align:center;">
269
+ <img src="assets/images/widgets_interface.jpg" alt="" /><br />
270
+ The additional options are limited. You can select "Only visible by members" and the widget will
271
+ only be displayed to users who are logged in. If you select "Only visibile by non-members" the
272
+ widget will only be displayed to users who are NOT logged in.
273
+ </p>
274
+
275
+ <h1 id="menus_interface">H) Nav Menus Interface - <a href="#toc">top</a></h1>
276
+
277
+ <p>
278
+ Admins now have the ability of creating a second version of any menu that their theme supports,
279
+ which will only be visible to logged in users.
280
+ </p>
281
+
282
+ <p style="text-align:center;">
283
+ <img src="assets/images/menus_interface.jpg" alt="" /><br />
284
+ The second menu in the list, "Primary Menu - Members Only" is automatically generated by this plugin. If
285
+ you assign it a menu that is not empty, it will be displayed instead of it's regular version to any logged
286
+ in user.
287
+ </p>
288
+
289
+ <h1 id="changelog">I) Changelog - <a href="#toc">top</a></h1>
290
+
291
+ <p><strong>Version 3.1 - December 7, 2011</strong></p>
292
+
293
+ <ul>
294
+ <li>Custom Post Type section is no longer displayed on the options page if there are no custom post types</li>
295
+ <li>Members Only Blog now properly restricts the entire site</li>
296
+ <li>Admins now have the ability to override permissions to prevent lower level users from denying admins access to posts</li>
297
+ <li>Admins may now create menu widgets that are only visible to members or non-members from the Widgets screen</li>
298
+ <li>Admins may now create WordPress nav menus that are only visible to members</li>
299
+ <li>Updated the documentation</li>
300
+ <li>Added new screenshots</li>
301
+ </ul>
302
+
303
+ <p><strong>Version 3.0.5 - June 6, 2011</strong></p>
304
+
305
+ <ul>
306
+ <li>Fixed the PHP issue properly this time</li>
307
+ </ul>
308
+
309
+ <p><strong>Version 3.0.4 - June 6, 2011</strong></p>
310
+
311
+ <ul>
312
+ <li>Fixed a PHP issue if a second argument wasn't supplied to several functions</li>
313
+ </ul>
314
+
315
+ <p><strong>Version 3.0.3 - June 5, 2011</strong></p>
316
+
317
+ <ul>
318
+ <li>Added an option to apply members settings to all children of a page</li>
319
+ <li>Fixed a bug where the page navigation for posts/archives was broken</li>
320
+ <li>Fixed a bug where themes that used the_content on archive/search pages could show all the contents of a post instead of the no excerpt message</li>
321
+ </ul>
322
+
323
+ <p><strong>Version 3.0.2 - June 2, 2011</strong></p>
324
+
325
+ <ul>
326
+ <li>Added do_shortcode commands to allow nested shortcodes in the [members] and [nonmembers] shortcodes</li>
327
+ </ul>
328
+
329
+ <p><strong>Version 3.0.1 - June 1, 2011</strong></p>
330
+
331
+ <ul>
332
+ <li>Fixed an issue where a members only blog with no redirect link specified would cause an infinite loop</li>
333
+ </ul>
334
+
335
+ <p><strong>Version 3.0 - May 26, 2011</strong></p>
336
+
337
+ <ul>
338
+ <li>Added an admin options page</li>
339
+ <li>Added an option to allow pages to show up in menus even if a user cannot access them</li>
340
+ <li>Added support to make an entire blog members only</li>
341
+ <li>Added options to set the defaults of all options for pages and posts</li>
342
+ <li>Added support for posts</li>
343
+ <li>Added support for searching/archives</li>
344
+ <li>Added better support for custom post types</li>
345
+ <li>Added a redirect_to argument even when using custom redirect links</li>
346
+ <li>Added [member][/member] and [nonmember][/nonmember] shortcodes</li>
347
+ </ul>
348
+
349
+ <h1 id="credits">J) Sources and Credits - <a href="#toc">top</a></h1>
350
+
351
+ <p>
352
+ <ul>
353
+ <li>I'd like to thank the <a href="http://wordpress.org/">WordPress community</a> for making such an awesome development platform.</li>
354
+ <li>Made use of the WordPress codex extensively <a href="http://codex.wordpress.org/">http://codex.wordpress.org/</a></li>
355
+ </ul>
356
+ </p>
357
+ </body>
358
+
359
  </html>
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
  === WordPress Access Control ===
2
  Contributors: brandon.wamboldt
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y398QNA6FM9TA
4
- Tags: members, only, plugin, restricted, access, menus, 3.0, wp_nav_menu, nonmembers
5
  Requires at least: 2.9
6
- Tested up to: 3.2
7
- Stable tag: 3.0.5
8
 
9
- Restrict pages, posts and custom post types to members, nonmembers or specific roles and still add to navigation
10
 
11
  == Description ==
12
 
@@ -20,6 +20,11 @@ By default, you can add Members only pages to your menus, and users who cannot
20
 
21
  Additionally, you have the ability to customize search pages, completely hiding posts/pages from search results if a user can't access them, showing search results without an excerpt, or showing search results normally.
22
 
 
 
 
 
 
23
  **Translators:** The POT file is included with the plugin and all text output uses gettext functions. Alternatively, you may download the POT file from http://brandonwamboldt.ca/files/wordpress-access-control.pot.
24
 
25
  **Documentation:** The plugin includes comprehensive documentation file accessible via the plugin directory
@@ -47,9 +52,21 @@ Please leave a comment at http://brandonwamboldt.ca/plugins/members-only-menu-pl
47
 
48
  1. The meta box added by this plugin
49
  2. The comprehensive admin settings interface
 
 
50
 
51
  == Changelog ==
52
 
 
 
 
 
 
 
 
 
 
 
53
  = 3.0.5 - June 6, 2011 =
54
 
55
  * Fixed the PHP issue properly this time
@@ -127,6 +144,16 @@ Please leave a comment at http://brandonwamboldt.ca/plugins/members-only-menu-pl
127
 
128
  == Upgrade Notice ==
129
 
 
 
 
 
 
 
 
 
 
 
130
  = 1.6.4 =
131
  * Fixed several bugs including adding support for wp_list_pages
132
 
1
  === WordPress Access Control ===
2
  Contributors: brandon.wamboldt
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y398QNA6FM9TA
4
+ Tags: members, only, plugin, restricted, access, menus, 3.3, wp_nav_menu, nonmembers
5
  Requires at least: 2.9
6
+ Tested up to: 3.3
7
+ Stable tag: 3.1
8
 
9
+ Restrict pages, posts, custom post types, menus and widgets to members, nonmembers or specific roles and still add to navigation
10
 
11
  == Description ==
12
 
20
 
21
  Additionally, you have the ability to customize search pages, completely hiding posts/pages from search results if a user can't access them, showing search results without an excerpt, or showing search results normally.
22
 
23
+ **New Features in 3.1**
24
+
25
+ * You can add member only versions of each menu on your site (Only when using WordPress menus)
26
+ * You can make certain widgets only visible to members or non-members.
27
+
28
  **Translators:** The POT file is included with the plugin and all text output uses gettext functions. Alternatively, you may download the POT file from http://brandonwamboldt.ca/files/wordpress-access-control.pot.
29
 
30
  **Documentation:** The plugin includes comprehensive documentation file accessible via the plugin directory
52
 
53
  1. The meta box added by this plugin
54
  2. The comprehensive admin settings interface
55
+ 3. The new nav menu options for creating member only menus
56
+ 4. The widget options for making widgets visible only to members/non-members
57
 
58
  == Changelog ==
59
 
60
+ = 3.1 - December 7, 2011 =
61
+
62
+ * Custom Post Type section is no longer displayed on the options page if there are no custom post types
63
+ * Members Only Blog now properly restricts the entire site
64
+ * Admins now have the ability to override permissions to prevent lower level users from denying admins access to posts
65
+ * Admins may now create menu widgets that are only visible to members or non-members from the Widgets screen
66
+ * Admins may now create WordPress nav menus that are only visible to members
67
+ * Updated the documentation
68
+ * Added new screenshots
69
+
70
  = 3.0.5 - June 6, 2011 =
71
 
72
  * Fixed the PHP issue properly this time
144
 
145
  == Upgrade Notice ==
146
 
147
+ = 3.1 =
148
+
149
+ * Custom Post Type section is no longer displayed on the options page if there are no custom post types
150
+ * Members Only Blog now properly restricts the entire site
151
+ * Admins now have the ability to override permissions to prevent lower level users from denying admins access to posts
152
+ * Admins may now create menu widgets that are only visible to members or non-members from the Widgets screen
153
+ * Admins may now create WordPress nav menus that are only visible to members
154
+ * Updated the documentation
155
+ * Added new screenshots
156
+
157
  = 1.6.4 =
158
  * Fixed several bugs including adding support for wp_list_pages
159
 
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
templates/options.php CHANGED
@@ -1,258 +1,291 @@
1
- <?php
2
- $wpac_members_blog_redirect = get_option( 'wpac_members_blog_redirect', '' );
3
- $wpac_members_only_blog = get_option( 'wpac_members_only_blog', FALSE );
4
- $wpac_show_in_menus = get_option( 'wpac_show_in_menus', 'with_access' );
5
- $wpac_default_post_state = get_option( 'wpac_default_post_state', 'public' );
6
- $wpac_default_page_state = get_option( 'wpac_default_page_state', 'public' );
7
- $wpac_default_members_redirect = get_option( 'wpac_default_members_redirect' , '' );
8
- $wpac_show_posts_in_search = get_option( 'wpac_show_posts_in_search', FALSE );
9
- $wpac_show_post_excerpts_in_search = get_option( 'wpac_show_post_excerpts_in_search', FALSE );
10
- $wpac_show_pages_in_search = get_option( 'wpac_show_pages_in_search', FALSE );
11
- $wpac_show_page_excerpts_in_search = get_option( 'wpac_show_page_excerpts_in_search', FALSE );
12
- ?><div class="wrap">
13
- <div class="icon32" id="icon-options-general"><br /></div>
14
- <h2><?php _e( 'WordPress Access Control Settings', 'wpac' ); ?></h2>
15
-
16
- <?php if ( isset( $admin_message ) && ! empty( $admin_message ) ) { ?>
17
- <div class="updated below-h2" id="message"><p><?php echo $admin_message; ?></p></div>
18
- <?php } ?>
19
-
20
- <?php if ( isset( $admin_error ) && ! empty( $admin_error ) ) { ?>
21
- <div class="error below-h2" id="error"><p><?php echo $admin_error; ?></p></div>
22
- <?php } ?>
23
-
24
- <form action="options-general.php?page=wpac-options" method="post">
25
- <input type="hidden" value="wpac-options" name="options_page" />
26
- <input type="hidden" value="update" name="action" />
27
- <?php wp_nonce_field( 'wpac_options_save' ); ?>
28
-
29
- <h3 class="title"><?php _e( 'Shortcodes', 'wpac' ); ?></h3>
30
-
31
- <p><?php _e( 'To make a specific section of content members only instead of the entire page, sorround it with [member]Your content here[/member] tags. For non-member content, use [nonmember]Your content here[/nonmember].', 'wpac' ); ?></p>
32
-
33
- <h3 class="title"><?php _e( 'General Options', 'wpac' ); ?></h3>
34
-
35
- <table class="form-table">
36
- <tbody>
37
- <tr>
38
- <th scope="row">
39
- <label for="wpac_members_only_blog"><?php _e( 'Make Blog Members Only', 'wpac' ); ?></label>
40
- </th>
41
-
42
- <td>
43
- <label><input type="checkbox" name="wpac_members_only_blog" value="yes" id="wpac_members_only_blog" <?php checked( $wpac_members_only_blog, 1 ); ?>/> <span><?php _e( 'Make Blog Members Only', 'wpac' ); ?></span></label>
44
- </td>
45
- </tr>
46
-
47
- <tr>
48
- <th scope="row">
49
- <label for="wpac_members_blog_redirect"><?php _e( 'Members Blog Redirect', 'wpac' ); ?></label>
50
- </th>
51
-
52
- <td>
53
- <input type="text" class="regular-text" value="<?php esc_attr_e( $wpac_members_blog_redirect ); ?>" id="wpac_members_blog_redirect" name="wpac_members_blog_redirect" />
54
- <span class="description"><?php printf( __( 'Where to redirect non-members when they try to visit the blog. %1$s
55
- Defaults to WordPress login page (%2$s)%1$s
56
- After a user logs in they will be redirected back to the blog', 'wpac' ), '<br />', '<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>' ); ?></span>
57
- </td>
58
- </tr>
59
-
60
- <tr>
61
- <th scope="row">
62
- <label for="wpac_members_only_blog"><?php _e( 'Custom Post Types', 'wpac' ); ?></label>
63
- </th>
64
-
65
- <td>
66
- <p class="description"><?php _e( 'You can enable access controls for custom post types by selecting them below. May not work if the post type uses a custom admin interface.', 'wpac' ); ?></p>
67
- <?php
68
- global $wp_post_types;
69
- $wpac_custom_post_types = get_option( 'wpac_custom_post_types', array() );
70
-
71
- foreach ( $wp_post_types as $post_type => $details ) {
72
- if ( in_array( $post_type, array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' ) ) ) {
73
- continue;
74
- }
75
-
76
- if ( in_array( $post_type, $wpac_custom_post_types ) ) {
77
- echo '<label><input type="checkbox" checked="checked" value="' . esc_attr( $post_type ) . '" id="wpac_enable_for_post_type_' . esc_attr( $post_type ) . '" name="wpac_custom_post_types[]" /> <span>' . $post_type . ' &ndash; ' . $details->labels->name . ' - ' . ( ( ! empty( $details->description ) ) ? $details->description : '<em>No Description</em>' ) . '</span></label><br />';
78
- } else {
79
- echo '<label><input type="checkbox" value="' . esc_attr( $post_type ) . '" id="wpac_enable_for_post_type_' . esc_attr( $post_type ) . '" name="wpac_custom_post_types[]" /> <span>' . $post_type . ' &ndash; ' . $details->labels->name . ' - ' . ( ( ! empty( $details->description ) ) ? $details->description : '<em>No Description</em>' ) . '</span></label><br />';
80
- }
81
- }
82
- ?>
83
- </td>
84
- </tr>
85
- </tbody>
86
- </table>
87
-
88
- <h3 class="title"><?php _e( 'Menu Options', 'wpac' ); ?></h3>
89
-
90
- <table class="form-table">
91
- <tbody>
92
- <tr>
93
- <th scope="row">
94
- <?php _e( 'Display In Menus', 'wpac' ); ?>
95
- </th>
96
- <td>
97
- <p class="description"><?php _e( 'By default, should pages and posts be displayed in your menu even if the user doesn\'t have access to them? Items will always show up for users with access to them', 'wpac' ); ?></p>
98
- <label><input <?php checked( $wpac_show_in_menus, 'with_access' ); ?> type="radio" value="with_access" name="wpac_show_in_menus" /> <span><?php _e( 'Only show menu items to users with access to them', 'wpac' ); ?></span></label><br />
99
- <label><input <?php checked( $wpac_show_in_menus, 'always' ); ?> type="radio" value="always" name="wpac_show_in_menus" /> <span><?php _e( 'Always show all menu items even if the user cannot access them', 'wpac' ); ?></span></label>
100
- </td>
101
- </tr>
102
- </tbody>
103
- </table>
104
-
105
-
106
- <h3 class="title"><?php _e( 'Post/Page Default Options', 'wpac' ); ?></h3>
107
-
108
- <p>
109
- <?php _e( 'These options are defaults for posts and pages in case the majority of your posts and pages will have similar settings. You can override any of these settings on a per-post or per-page basis.' ); ?>
110
- </p>
111
-
112
- <table class="form-table">
113
- <tbody>
114
- <tr>
115
- <th scope="row">
116
- <?php _e( 'Default Post State', 'wpac' ); ?>
117
- </th>
118
- <td>
119
- <label><input <?php checked( $wpac_default_post_state, 'public' ); ?> type="radio" value="public" name="default_post_state" /> <span><?php _e( 'Public', 'wpac' ); ?></span></label><br />
120
- <label><input <?php checked( $wpac_default_post_state, 'members' ); ?> type="radio" value="members" name="default_post_state" /> <span><?php _e( 'Members Only', 'wpac' ); ?></span></label><br />
121
- <label><input <?php checked( $wpac_default_post_state, 'nonmembers' ); ?> type="radio" value="nonmembers" name="default_post_state" /> <span><?php _e( 'Non-Members Only', 'wpac' ); ?></span></label><br />
122
- </td>
123
- </tr>
124
-
125
- <tr>
126
- <th scope="row">
127
- <?php _e( 'Posts: Only Accessible By', 'wpac' ); ?>
128
- </th>
129
- <td>
130
- <?php
131
- global $wp_roles;
132
- $roles = $wp_roles->get_names();
133
- $checked_roles = (array) get_option( 'wpac_posts_default_restricted_to', array() );
134
-
135
- foreach ( $roles as $role => $label ) {
136
- if ( in_array( $role, $checked_roles ) ) {
137
- echo '<input type="checkbox" name="wpac_posts_default_restricted_to[]" checked="checked" value="' . $role . '" /> ' . $label . '<br />';
138
- } else {
139
- echo '<input type="checkbox" name="wpac_posts_default_restricted_to[]" value="' . $role . '" /> ' . $label . '<br />';
140
- }
141
- }
142
- ?>
143
- <span class="description"><?php _e( 'Defaults to all roles', 'wpac' ); ?></span>
144
- </td>
145
- </tr>
146
-
147
- <tr>
148
- <th scope="row">
149
- <?php _e( 'Default Page State', 'wpac' ); ?>
150
- </th>
151
- <td>
152
- <label><input <?php checked( $wpac_default_page_state, 'public' ); ?> type="radio" value="public" name="default_page_state" /> <span><?php _e( 'Public', 'wpac' ); ?></span></label><br />
153
- <label><input <?php checked( $wpac_default_page_state, 'members' ); ?> type="radio" value="members" name="default_page_state" /> <span><?php _e( 'Members Only', 'wpac' ); ?></span></label><br />
154
- <label><input <?php checked( $wpac_default_page_state, 'nonmembers' ); ?> type="radio" value="nonmembers" name="default_page_state" /> <span><?php _e( 'Non-Members Only', 'wpac' ); ?></span></label><br />
155
- </td>
156
- </tr>
157
-
158
- <tr>
159
- <th scope="row">
160
- <?php _e( 'Pages: Only Accessible By', 'wpac' ); ?>
161
- </th>
162
- <td>
163
- <?php
164
- global $wp_roles;
165
- $roles = $wp_roles->get_names();
166
- $checked_roles = (array) get_option( 'wpac_pages_default_restricted_to', array() );
167
-
168
- foreach ( $roles as $role => $label ) {
169
- if ( in_array( $role, $checked_roles ) ) {
170
- echo '<input type="checkbox" name="wpac_pages_default_restricted_to[]" checked="checked" value="' . $role . '" /> ' . $label . '<br />';
171
- } else {
172
- echo '<input type="checkbox" name="wpac_pages_default_restricted_to[]" value="' . $role . '" /> ' . $label . '<br />';
173
- }
174
- }
175
- ?>
176
- <span class="description"><?php _e( 'Defaults to all roles', 'wpac' ); ?></span>
177
- </td>
178
- </tr>
179
-
180
- <tr>
181
- <th scope="row">
182
- <label for="wpac_default_members_redirect"><?php _e( 'Default Redirect For Members Only Pages', 'wpac' ); ?></label>
183
- </th>
184
- <td>
185
- <input type="text" class="regular-text" value="<?php esc_attr_e( $wpac_default_members_redirect ); ?>" id="wpac_default_members_redirect" name="wpac_default_members_redirect" />
186
- <span class="description">
187
- <?php /* translators: Text in the brackets (%1$s) is a link to the default login page */ printf( __( 'Defaults to WordPress login page (%1$s)%2$sAfter a user logs in they will be redirected back to the page they attempted to view', 'wpac' ), '<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>', '<br />' ); ?>
188
- </span>
189
- </td>
190
- </tr>
191
- </tbody>
192
- </table>
193
-
194
- <h3 class="title"><?php _e( 'Search/Archive Options', 'wpac' ); ?></h3>
195
-
196
- <p>
197
- <?php __( 'I use the wording "search" below, but these settings apply to search AND archive pages (Such as the blog page, categories and tags pages, and such).
198
- <strong>For example</strong>, if you wanted a blog where non-members could see post titles and excerpts but not the actual posts, set the default
199
- post state to Members Only, then set the Search Options to show restricted posts in search results and show post excerpts.', 'wpac' ); ?>
200
- </p>
201
-
202
- <table class="form-table">
203
- <tbody>
204
- <tr>
205
- <th scope="row">
206
- <?php _e( 'Search Options', 'wpac' ); ?>
207
- </th>
208
- <td>
209
- <label><input type="checkbox" <?php checked( $wpac_show_posts_in_search, 1 ); ?> value="yes" name="show_posts_in_search" /> <span><?php _e( 'Show restricted posts in search results?', 'wpac' ); ?></span></label><br />
210
- <label><input type="checkbox" <?php checked( $wpac_show_post_excerpts_in_search, 1 ); ?> value="yes" name="show_post_excerpts_in_search" /> <span><?php _e( 'Show restricted post excerpts in search results?', 'wpac' ); ?></span></label><br />
211
- <label><input type="checkbox" <?php checked( $wpac_show_pages_in_search, 1 ); ?> value="yes" name="show_pages_in_search" /> <span><?php _e( 'Show restricted pages in search results?', 'wpac' ); ?></span></label><br />
212
- <label><input type="checkbox" <?php checked( $wpac_show_page_excerpts_in_search, 1 ); ?> value="yes" name="show_page_excerpts_in_search" /> <span><?php _e( 'Show restricted page excerpts in search results?', 'wpac' ); ?></span></label><br />
213
- </td>
214
- </tr>
215
-
216
- <tr>
217
- <th scope="row">
218
- <label for="post_excerpt_text"><?php _e( 'Search Excerpt (Posts)', 'wpac' ); ?></label>
219
- </th>
220
- <td>
221
- <fieldset>
222
- <legend class="screen-reader-text"><?php _e( 'Search Excerpt (Posts)', 'wpac' ); ?></legend>
223
-
224
- <p>
225
- <label for="post_excerpt_text"><?php _e( 'If a post is set to show in search results WITHOUT an excerpt, this text will be displayed instead.', 'wpac' ); ?></label>
226
- </p>
227
-
228
- <p>
229
- <textarea id="post_excerpt_text" name="post_excerpt_text" class="large-text" cols="50" rows="5"><?php echo get_option( 'wpac_post_excerpt_text', __( 'To view the contents of this post, you must be authenticated and have the required access level.', 'wpac' ) ); ?></textarea>
230
- </p>
231
- </fieldset>
232
- </td>
233
- </tr>
234
-
235
- <tr>
236
- <th scope="row">
237
- <label for="page_excerpt_text"><?php _e( 'Search Excerpt (Pages)', 'wpac' ); ?></label>
238
- </th>
239
- <td>
240
- <fieldset>
241
- <legend class="screen-reader-text"><?php _e( 'Search Excerpt (Pages)', 'wpac' ); ?>)</legend>
242
-
243
- <p>
244
- <label for="page_excerpt_text"><?php _e( 'If a page is set to show in search results WITHOUT an excerpt, this text will be displayed instead.', 'wpac' ); ?></label>
245
- </p>
246
-
247
- <p>
248
- <textarea id="page_excerpt_text" name="page_excerpt_text" class="large-text" cols="50" rows="5"><?php echo get_option( 'wpac_page_excerpt_text', __( 'To view the contents of this page, you must be authenticated and have the required access level.', 'wpac' ) ); ?></textarea>
249
- </p>
250
- </fieldset>
251
- </td>
252
- </tr>
253
- </tbody>
254
- </table>
255
-
256
- <p class="submit"><input type="submit" value="<?php _e( 'Save Changes', 'wpac' ); ?>" class="button-primary" id="submit" name="submit" /></p>
257
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  </div>
1
+ <?php
2
+ global $wp_post_types;
3
+
4
+ $custom_post_types = array();
5
+
6
+ foreach ( $wp_post_types as $post_type => $details ) {
7
+ if ( ! in_array( $post_type, array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' ) ) ) {
8
+ $custom_post_types[$post_type] = $details;
9
+ }
10
+ }
11
+
12
+ $wpac_members_blog_redirect = get_option( 'wpac_members_blog_redirect', '' );
13
+ $wpac_members_only_blog = get_option( 'wpac_members_only_blog', FALSE );
14
+ $wpac_show_in_menus = get_option( 'wpac_show_in_menus', 'with_access' );
15
+ $wpac_default_post_state = get_option( 'wpac_default_post_state', 'public' );
16
+ $wpac_default_page_state = get_option( 'wpac_default_page_state', 'public' );
17
+ $wpac_default_members_redirect = get_option( 'wpac_default_members_redirect' , '' );
18
+ $wpac_show_posts_in_search = get_option( 'wpac_show_posts_in_search', FALSE );
19
+ $wpac_show_post_excerpts_in_search = get_option( 'wpac_show_post_excerpts_in_search', FALSE );
20
+ $wpac_show_pages_in_search = get_option( 'wpac_show_pages_in_search', FALSE );
21
+ $wpac_show_page_excerpts_in_search = get_option( 'wpac_show_page_excerpts_in_search', FALSE );
22
+ ?><div class="wrap">
23
+ <div class="icon32" id="icon-options-general"><br /></div>
24
+ <h2><?php _e( 'WordPress Access Control Settings', 'wpac' ); ?></h2>
25
+
26
+ <?php if ( isset( $admin_message ) && ! empty( $admin_message ) ) { ?>
27
+ <div class="updated below-h2" id="message"><p><?php echo $admin_message; ?></p></div>
28
+ <?php } ?>
29
+
30
+ <?php if ( isset( $admin_error ) && ! empty( $admin_error ) ) { ?>
31
+ <div class="error below-h2" id="error"><p><?php echo $admin_error; ?></p></div>
32
+ <?php } ?>
33
+
34
+ <form action="options-general.php?page=wpac-options" method="post">
35
+ <input type="hidden" value="wpac-options" name="options_page" />
36
+ <input type="hidden" value="update" name="action" />
37
+ <?php wp_nonce_field( 'wpac_options_save' ); ?>
38
+
39
+ <h3 class="title"><?php _e( 'Shortcodes', 'wpac' ); ?></h3>
40
+
41
+ <p><?php _e( 'To make a specific section of content members only instead of the entire page, sorround it with [member]Your content here[/member] tags. For non-member content, use [nonmember]Your content here[/nonmember].', 'wpac' ); ?></p>
42
+
43
+ <h3 class="title"><?php _e( 'General Options', 'wpac' ); ?></h3>
44
+
45
+ <table class="form-table">
46
+ <tbody>
47
+ <tr>
48
+ <th scope="row">
49
+ <label for="wpac_members_only_blog"><?php _e( 'Make Blog Members Only', 'wpac' ); ?></label>
50
+ </th>
51
+
52
+ <td>
53
+ <label><input type="checkbox" name="wpac_members_only_blog" value="yes" id="wpac_members_only_blog" <?php checked( $wpac_members_only_blog, 1 ); ?>/> <span><?php _e( 'Make Blog Members Only', 'wpac' ); ?></span></label>
54
+ </td>
55
+ </tr>
56
+
57
+ <tr>
58
+ <th scope="row">
59
+ <label for="wpac_members_blog_redirect"><?php _e( 'Members Blog Redirect', 'wpac' ); ?></label>
60
+ </th>
61
+
62
+ <td>
63
+ <input type="text" class="regular-text" value="<?php esc_attr_e( $wpac_members_blog_redirect ); ?>" id="wpac_members_blog_redirect" name="wpac_members_blog_redirect" />
64
+ <span class="description"><?php printf( __( 'Where to redirect non-members when they try to visit the blog. %1$s
65
+ Defaults to WordPress login page (%2$s)%1$s
66
+ After a user logs in they will be redirected back to the blog', 'wpac' ), '<br />', '<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>' ); ?></span>
67
+ </td>
68
+ </tr>
69
+
70
+ <?php if ( ! empty( $custom_post_types ) ) { ?>
71
+ <tr>
72
+ <th scope="row">
73
+ <label for="wpac_members_only_blog"><?php _e( 'Custom Post Types', 'wpac' ); ?></label>
74
+ </th>
75
+
76
+ <td>
77
+ <p class="description"><?php _e( 'You can enable access controls for custom post types by selecting them below. May not work if the post type uses a custom admin interface.', 'wpac' ); ?></p>
78
+ <?php
79
+ $wpac_custom_post_types = get_option( 'wpac_custom_post_types', array() );
80
+
81
+ foreach ( $custom_post_types as $post_type => $details ) {
82
+ if ( in_array( $post_type, $wpac_custom_post_types ) ) {
83
+ echo '<label><input type="checkbox" checked="checked" value="' . esc_attr( $post_type ) . '" id="wpac_enable_for_post_type_' . esc_attr( $post_type ) . '" name="wpac_custom_post_types[]" /> <span>' . $post_type . ' &ndash; ' . $details->labels->name . ' - ' . ( ( ! empty( $details->description ) ) ? $details->description : '<em>No Description</em>' ) . '</span></label><br />';
84
+ } else {
85
+ echo '<label><input type="checkbox" value="' . esc_attr( $post_type ) . '" id="wpac_enable_for_post_type_' . esc_attr( $post_type ) . '" name="wpac_custom_post_types[]" /> <span>' . $post_type . ' &ndash; ' . $details->labels->name . ' - ' . ( ( ! empty( $details->description ) ) ? $details->description : '<em>No Description</em>' ) . '</span></label><br />';
86
+ }
87
+ }
88
+ ?>
89
+ </td>
90
+ </tr>
91
+ <?php } ?>
92
+ </tbody>
93
+ </table>
94
+
95
+ <h3 class="title"><?php _e( 'Override Permisisons', 'wpac' ); ?></h3>
96
+
97
+ <table class="form-table">
98
+ <tbody>
99
+ <tr>
100
+ <th scope="row">
101
+ <?php _e( 'Always Accessible By', 'wpac' ); ?>
102
+ </th>
103
+ <td>
104
+ <?php
105
+ global $wp_roles;
106
+ $roles = $wp_roles->get_names();
107
+ $checked_roles = (array) maybe_unserialize( get_option( 'wpac_always_accessible_by', array( 0 => 'administrator' ) ) );
108
+
109
+ foreach ( $roles as $role => $label ) {
110
+ if ( in_array( $role, $checked_roles ) ) {
111
+ echo '<label><input type="checkbox" name="wpac_always_accessible_by[]" checked="checked" value="' . $role . '" /> ' . $label . '<br /></label>';
112
+ } else {
113
+ echo '<label><input type="checkbox" name="wpac_always_accessible_by[]" value="' . $role . '" /> ' . $label . '<br /></label>';
114
+ }
115
+ }
116
+ ?>
117
+ </td>
118
+ </tr>
119
+ </tbody>
120
+ </table>
121
+
122
+ <h3 class="title"><?php _e( 'Menu Options', 'wpac' ); ?></h3>
123
+
124
+ <table class="form-table">
125
+ <tbody>
126
+ <tr>
127
+ <th scope="row">
128
+ <?php _e( 'Display In Menus', 'wpac' ); ?>
129
+ </th>
130
+ <td>
131
+ <p class="description"><?php _e( 'By default, should pages and posts be displayed in your menu even if the user doesn\'t have access to them? Items will always show up for users with access to them', 'wpac' ); ?></p>
132
+ <label><input <?php checked( $wpac_show_in_menus, 'with_access' ); ?> type="radio" value="with_access" name="wpac_show_in_menus" /> <span><?php _e( 'Only show menu items to users with access to them', 'wpac' ); ?></span></label><br />
133
+ <label><input <?php checked( $wpac_show_in_menus, 'always' ); ?> type="radio" value="always" name="wpac_show_in_menus" /> <span><?php _e( 'Always show all menu items even if the user cannot access them', 'wpac' ); ?></span></label>
134
+ </td>
135
+ </tr>
136
+ </tbody>
137
+ </table>
138
+
139
+ <h3 class="title"><?php _e( 'Post/Page Default Options', 'wpac' ); ?></h3>
140
+
141
+ <p>
142
+ <?php _e( 'These options are defaults for posts and pages in case the majority of your posts and pages will have similar settings. You can override any of these settings on a per-post or per-page basis.' ); ?>
143
+ </p>
144
+
145
+ <table class="form-table">
146
+ <tbody>
147
+ <tr>
148
+ <th scope="row">
149
+ <?php _e( 'Default Post State', 'wpac' ); ?>
150
+ </th>
151
+ <td>
152
+ <label><input <?php checked( $wpac_default_post_state, 'public' ); ?> type="radio" value="public" name="default_post_state" /> <span><?php _e( 'Public', 'wpac' ); ?></span></label><br />
153
+ <label><input <?php checked( $wpac_default_post_state, 'members' ); ?> type="radio" value="members" name="default_post_state" /> <span><?php _e( 'Members Only', 'wpac' ); ?></span></label><br />
154
+ <label><input <?php checked( $wpac_default_post_state, 'nonmembers' ); ?> type="radio" value="nonmembers" name="default_post_state" /> <span><?php _e( 'Non-Members Only', 'wpac' ); ?></span></label><br />
155
+ </td>
156
+ </tr>
157
+
158
+ <tr>
159
+ <th scope="row">
160
+ <?php _e( 'Posts: Only Accessible By', 'wpac' ); ?>
161
+ </th>
162
+ <td>
163
+ <?php
164
+ global $wp_roles;
165
+ $roles = $wp_roles->get_names();
166
+ $checked_roles = (array) get_option( 'wpac_posts_default_restricted_to', array() );
167
+
168
+ foreach ( $roles as $role => $label ) {
169
+ if ( in_array( $role, $checked_roles ) ) {
170
+ echo '<input type="checkbox" name="wpac_posts_default_restricted_to[]" checked="checked" value="' . $role . '" /> ' . $label . '<br />';
171
+ } else {
172
+ echo '<input type="checkbox" name="wpac_posts_default_restricted_to[]" value="' . $role . '" /> ' . $label . '<br />';
173
+ }
174
+ }
175
+ ?>
176
+ <span class="description"><?php _e( 'Defaults to all roles', 'wpac' ); ?></span>
177
+ </td>
178
+ </tr>
179
+
180
+ <tr>
181
+ <th scope="row">
182
+ <?php _e( 'Default Page State', 'wpac' ); ?>
183
+ </th>
184
+ <td>
185
+ <label><input <?php checked( $wpac_default_page_state, 'public' ); ?> type="radio" value="public" name="default_page_state" /> <span><?php _e( 'Public', 'wpac' ); ?></span></label><br />
186
+ <label><input <?php checked( $wpac_default_page_state, 'members' ); ?> type="radio" value="members" name="default_page_state" /> <span><?php _e( 'Members Only', 'wpac' ); ?></span></label><br />
187
+ <label><input <?php checked( $wpac_default_page_state, 'nonmembers' ); ?> type="radio" value="nonmembers" name="default_page_state" /> <span><?php _e( 'Non-Members Only', 'wpac' ); ?></span></label><br />
188
+ </td>
189
+ </tr>
190
+
191
+ <tr>
192
+ <th scope="row">
193
+ <?php _e( 'Pages: Only Accessible By', 'wpac' ); ?>
194
+ </th>
195
+ <td>
196
+ <?php
197
+ global $wp_roles;
198
+ $roles = $wp_roles->get_names();
199
+ $checked_roles = (array) get_option( 'wpac_pages_default_restricted_to', array() );
200
+
201
+ foreach ( $roles as $role => $label ) {
202
+ if ( in_array( $role, $checked_roles ) ) {
203
+ echo '<input type="checkbox" name="wpac_pages_default_restricted_to[]" checked="checked" value="' . $role . '" /> ' . $label . '<br />';
204
+ } else {
205
+ echo '<input type="checkbox" name="wpac_pages_default_restricted_to[]" value="' . $role . '" /> ' . $label . '<br />';
206
+ }
207
+ }
208
+ ?>
209
+ <span class="description"><?php _e( 'Defaults to all roles', 'wpac' ); ?></span>
210
+ </td>
211
+ </tr>
212
+
213
+ <tr>
214
+ <th scope="row">
215
+ <label for="wpac_default_members_redirect"><?php _e( 'Default Redirect For Members Only Pages', 'wpac' ); ?></label>
216
+ </th>
217
+ <td>
218
+ <input type="text" class="regular-text" value="<?php esc_attr_e( $wpac_default_members_redirect ); ?>" id="wpac_default_members_redirect" name="wpac_default_members_redirect" />
219
+ <span class="description">
220
+ <?php /* translators: Text in the brackets (%1$s) is a link to the default login page */ printf( __( 'Defaults to WordPress login page (%1$s)%2$sAfter a user logs in they will be redirected back to the page they attempted to view', 'wpac' ), '<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>', '<br />' ); ?>
221
+ </span>
222
+ </td>
223
+ </tr>
224
+ </tbody>
225
+ </table>
226
+
227
+ <h3 class="title"><?php _e( 'Search/Archive Options', 'wpac' ); ?></h3>
228
+
229
+ <p>
230
+ <?php __( 'I use the wording "search" below, but these settings apply to search AND archive pages (Such as the blog page, categories and tags pages, and such).
231
+ <strong>For example</strong>, if you wanted a blog where non-members could see post titles and excerpts but not the actual posts, set the default
232
+ post state to Members Only, then set the Search Options to show restricted posts in search results and show post excerpts.', 'wpac' ); ?>
233
+ </p>
234
+
235
+ <table class="form-table">
236
+ <tbody>
237
+ <tr>
238
+ <th scope="row">
239
+ <?php _e( 'Search Options', 'wpac' ); ?>
240
+ </th>
241
+ <td>
242
+ <label><input type="checkbox" <?php checked( $wpac_show_posts_in_search, 1 ); ?> value="yes" name="show_posts_in_search" /> <span><?php _e( 'Show restricted posts in search results?', 'wpac' ); ?></span></label><br />
243
+ <label><input type="checkbox" <?php checked( $wpac_show_post_excerpts_in_search, 1 ); ?> value="yes" name="show_post_excerpts_in_search" /> <span><?php _e( 'Show restricted post excerpts in search results?', 'wpac' ); ?></span></label><br />
244
+ <label><input type="checkbox" <?php checked( $wpac_show_pages_in_search, 1 ); ?> value="yes" name="show_pages_in_search" /> <span><?php _e( 'Show restricted pages in search results?', 'wpac' ); ?></span></label><br />
245
+ <label><input type="checkbox" <?php checked( $wpac_show_page_excerpts_in_search, 1 ); ?> value="yes" name="show_page_excerpts_in_search" /> <span><?php _e( 'Show restricted page excerpts in search results?', 'wpac' ); ?></span></label><br />
246
+ </td>
247
+ </tr>
248
+
249
+ <tr>
250
+ <th scope="row">
251
+ <label for="post_excerpt_text"><?php _e( 'Search Excerpt (Posts)', 'wpac' ); ?></label>
252
+ </th>
253
+ <td>
254
+ <fieldset>
255
+ <legend class="screen-reader-text"><?php _e( 'Search Excerpt (Posts)', 'wpac' ); ?></legend>
256
+
257
+ <p>
258
+ <label for="post_excerpt_text"><?php _e( 'If a post is set to show in search results WITHOUT an excerpt, this text will be displayed instead.', 'wpac' ); ?></label>
259
+ </p>
260
+
261
+ <p>
262
+ <textarea id="post_excerpt_text" name="post_excerpt_text" class="large-text" cols="50" rows="5"><?php echo get_option( 'wpac_post_excerpt_text', __( 'To view the contents of this post, you must be authenticated and have the required access level.', 'wpac' ) ); ?></textarea>
263
+ </p>
264
+ </fieldset>
265
+ </td>
266
+ </tr>
267
+
268
+ <tr>
269
+ <th scope="row">
270
+ <label for="page_excerpt_text"><?php _e( 'Search Excerpt (Pages)', 'wpac' ); ?></label>
271
+ </th>
272
+ <td>
273
+ <fieldset>
274
+ <legend class="screen-reader-text"><?php _e( 'Search Excerpt (Pages)', 'wpac' ); ?>)</legend>
275
+
276
+ <p>
277
+ <label for="page_excerpt_text"><?php _e( 'If a page is set to show in search results WITHOUT an excerpt, this text will be displayed instead.', 'wpac' ); ?></label>
278
+ </p>
279
+
280
+ <p>
281
+ <textarea id="page_excerpt_text" name="page_excerpt_text" class="large-text" cols="50" rows="5"><?php echo get_option( 'wpac_page_excerpt_text', __( 'To view the contents of this page, you must be authenticated and have the required access level.', 'wpac' ) ); ?></textarea>
282
+ </p>
283
+ </fieldset>
284
+ </td>
285
+ </tr>
286
+ </tbody>
287
+ </table>
288
+
289
+ <p class="submit"><input type="submit" value="<?php _e( 'Save Changes', 'wpac' ); ?>" class="button-primary" id="submit" name="submit" /></p>
290
+ </form>
291
  </div>
wordpress-access-control.php CHANGED
@@ -4,12 +4,14 @@
4
  * Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
5
  * Author: Brandon Wamboldt
6
  * Author URI: http://brandonwamboldt.ca/
7
- * Version: 3.0.5
8
  * Description: This plugin is a powerful tool which gives you fine grained control over your pages and posts (and custom post types), allowing you to restrict a page, post, or custom post type to members, non-members, or even specific roles. You can customize how these pages and posts show up in search results, where users are directed when they visit them, and much more. <strong>You can even make your entire blog members only!</strong>.
9
  */
10
 
 
11
  add_action( 'wp', array( 'WordPressAccessControl', 'check_for_members_only' ) );
12
  add_action( 'wp', array( 'WordPressAccessControl', 'check_for_nonmembers_only' ) );
 
13
  add_action( 'admin_init', array( 'WordPressAccessControl', 'admin_init' ) );
14
  add_action( 'admin_menu', array( 'WordPressAccessControl', 'admin_menu' ) );
15
  add_action( 'add_meta_boxes', array( 'WordPressAccessControl', 'add_wp_access_meta_boxes' ) );
@@ -23,6 +25,7 @@ add_filter( 'the_content', array( 'WordPressAccessControl', 'remove_excerpt' ) )
23
  add_filter( 'plugin_row_meta', array( 'WordPressAccessControl', 'plugin_row_meta' ), 10, 5 );
24
  add_filter( 'posts_join_paged', array( 'WordPressAccessControl', 'posts_join_paged' ), 10, 2 );
25
  add_filter( 'posts_where_paged', array( 'WordPressAccessControl', 'posts_where_paged' ), 10, 2 );
 
26
 
27
  add_shortcode( 'member', array( 'WordPressAccessControl', 'shortcode_members' ) );
28
  add_shortcode( 'members', array( 'WordPressAccessControl', 'shortcode_members' ) );
@@ -268,6 +271,19 @@ class WordPressAccessControl
268
  delete_option( 'wpac_custom_post_types' );
269
  }
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  // Show in the menu settings
272
  if ( isset( $_REQUEST['wpac_show_in_menus'] ) && $_REQUEST['wpac_show_in_menus'] == 'always' ) {
273
  update_option( 'wpac_show_in_menus', 'always' );
@@ -380,7 +396,8 @@ class WordPressAccessControl
380
  if ( is_user_logged_in() ) {
381
  get_currentuserinfo();
382
 
383
- $allowed_roles = maybe_unserialize( get_post_meta( $page_id, '_wpac_restricted_to', true ) );
 
384
 
385
  if ( empty( $allowed_roles ) ) {
386
  $allowed_roles_tmp = $wp_roles->get_names();
@@ -392,8 +409,9 @@ class WordPressAccessControl
392
  }
393
 
394
  $intersections = array_intersect( $current_user->roles, $allowed_roles );
 
395
 
396
- if ( empty( $intersections ) ) {
397
  $role = false;
398
  } else {
399
  $role = true;
@@ -422,16 +440,14 @@ class WordPressAccessControl
422
  $blog_is_members_only = get_option( 'wpac_members_only_blog', false );
423
 
424
  if ( $blog_is_members_only && ! is_user_logged_in() ) {
425
- if ( is_home() || is_archive() || is_search() || is_feed() ) {
426
- $redirect_to = get_option( 'wpac_members_blog_redirect', wp_login_url( $_SERVER['REQUEST_URI'] ) );
427
 
428
- if ( empty( $redirect_to ) ) {
429
- $redirect_to = wp_login_url( $_SERVER['REQUEST_URI'] );
430
- }
431
-
432
- header( 'Location: ' . add_query_arg( 'redirect_to', $_SERVER['REQUEST_URI'], $redirect_to ) );
433
- exit();
434
  }
 
 
 
435
  }
436
 
437
  if ( get_post_meta( $post->ID, '_wpac_is_members_only', true ) && ! WordPressAccessControl::check_conditions( $post->ID ) ) {
@@ -569,6 +585,12 @@ class WordPressAccessControl
569
  return $posts;
570
  }
571
 
 
 
 
 
 
 
572
  function add_wp_access_meta_boxes()
573
  {
574
  $enabled_post_types = get_option( 'wpac_custom_post_types', array() );
@@ -579,6 +601,12 @@ class WordPressAccessControl
579
  }
580
  }
581
 
 
 
 
 
 
 
582
  function add_wpac_meta_box()
583
  {
584
  global $post;
@@ -607,8 +635,15 @@ class WordPressAccessControl
607
  include( dirname( __FILE__ ) . '/templates/meta_box.php' );
608
  }
609
 
 
 
 
 
 
 
610
  function save_postdata( $post_id )
611
  {
 
612
  if ( ! isset( $_POST['members_only_nonce'] ) ) {
613
  return $post_id;
614
  }
@@ -617,6 +652,7 @@ class WordPressAccessControl
617
  return $post_id;
618
  }
619
 
 
620
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
621
  return $post_id;
622
  }
@@ -681,12 +717,32 @@ class WordPressAccessControl
681
  return $post_id;
682
  }
683
 
 
 
 
 
 
 
 
 
 
 
684
  function wp_nav_menu_args( $args )
685
  {
686
  $args['walker'] = new WPAC_Nav_Menu_Walker();
687
  return $args;
688
  }
689
 
 
 
 
 
 
 
 
 
 
 
690
  function wp_page_menu_args( $args )
691
  {
692
  // Only remove the walker if it is ours
@@ -698,18 +754,26 @@ class WordPressAccessControl
698
  }
699
 
700
  /**
701
- * This hooks in at a higher level to make sure functions like
702
- * wp_list_pages won't return members only pages.
703
  *
704
- * @param $pages
705
  * @return array
 
 
 
706
  */
707
  function get_pages( $pages )
708
  {
709
- if ( is_admin() ) return $pages;
 
 
 
710
 
 
711
  $auth = is_user_logged_in();
712
 
 
713
  foreach ( $pages as $key => $page ) {
714
  $is_members_only = get_post_meta( $page->ID, '_wpac_is_members_only', true );
715
  $is_nonmembers_only = get_post_meta( $page->ID, '_wpac_is_nonmembers_only', true );
@@ -726,6 +790,22 @@ class WordPressAccessControl
726
  return $pages;
727
  }
728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status )
730
  {
731
  if ( $plugin_file == str_replace( '.php', '/', basename( __FILE__ ) ) . basename( __FILE__ ) ) {
@@ -736,6 +816,19 @@ class WordPressAccessControl
736
  return $plugin_meta;
737
  }
738
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739
  function shortcode_members( $attributes, $content = NULL )
740
  {
741
  global $post;
@@ -747,6 +840,18 @@ class WordPressAccessControl
747
  return '';
748
  }
749
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  function shortcode_nonmembers( $attributes, $content = NULL )
751
  {
752
  global $post;
@@ -757,4 +862,73 @@ class WordPressAccessControl
757
 
758
  return '';
759
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
760
  }
4
  * Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
5
  * Author: Brandon Wamboldt
6
  * Author URI: http://brandonwamboldt.ca/
7
+ * Version: 3.1
8
  * Description: This plugin is a powerful tool which gives you fine grained control over your pages and posts (and custom post types), allowing you to restrict a page, post, or custom post type to members, non-members, or even specific roles. You can customize how these pages and posts show up in search results, where users are directed when they visit them, and much more. <strong>You can even make your entire blog members only!</strong>.
9
  */
10
 
11
+ add_action( 'after_setup_theme', array( 'WordPressAccessControl', 'load_custom_widgets' ) );
12
  add_action( 'wp', array( 'WordPressAccessControl', 'check_for_members_only' ) );
13
  add_action( 'wp', array( 'WordPressAccessControl', 'check_for_nonmembers_only' ) );
14
+ add_action( 'init', array( 'WordPressAccessControl', 'add_wpac_nav_menus' ) );
15
  add_action( 'admin_init', array( 'WordPressAccessControl', 'admin_init' ) );
16
  add_action( 'admin_menu', array( 'WordPressAccessControl', 'admin_menu' ) );
17
  add_action( 'add_meta_boxes', array( 'WordPressAccessControl', 'add_wp_access_meta_boxes' ) );
25
  add_filter( 'plugin_row_meta', array( 'WordPressAccessControl', 'plugin_row_meta' ), 10, 5 );
26
  add_filter( 'posts_join_paged', array( 'WordPressAccessControl', 'posts_join_paged' ), 10, 2 );
27
  add_filter( 'posts_where_paged', array( 'WordPressAccessControl', 'posts_where_paged' ), 10, 2 );
28
+ add_filter( 'wp_nav_menu_args', array( 'WordPressAccessControl', 'wp_nav_menu_members_only' ) );
29
 
30
  add_shortcode( 'member', array( 'WordPressAccessControl', 'shortcode_members' ) );
31
  add_shortcode( 'members', array( 'WordPressAccessControl', 'shortcode_members' ) );
271
  delete_option( 'wpac_custom_post_types' );
272
  }
273
 
274
+ // Override per-page permissions
275
+ if ( isset( $_REQUEST['wpac_always_accessible_by'] ) && is_array( $_REQUEST['wpac_always_accessible_by'] ) ) {
276
+ $wpac_always_accessible_by = array();
277
+
278
+ foreach ( $_REQUEST['wpac_always_accessible_by'] as $role ) {
279
+ $wpac_always_accessible_by[] = $role;
280
+ }
281
+
282
+ update_option( 'wpac_always_accessible_by', $wpac_always_accessible_by );
283
+ } else {
284
+ update_option( 'wpac_always_accessible_by', array() );
285
+ }
286
+
287
  // Show in the menu settings
288
  if ( isset( $_REQUEST['wpac_show_in_menus'] ) && $_REQUEST['wpac_show_in_menus'] == 'always' ) {
289
  update_option( 'wpac_show_in_menus', 'always' );
396
  if ( is_user_logged_in() ) {
397
  get_currentuserinfo();
398
 
399
+ $allowed_roles = maybe_unserialize( get_post_meta( $page_id, '_wpac_restricted_to', true ) );
400
+ $override_roles = maybe_unserialize( get_option( 'wpac_always_accessible_by', array( 0 => 'administrator' ) ) );
401
 
402
  if ( empty( $allowed_roles ) ) {
403
  $allowed_roles_tmp = $wp_roles->get_names();
409
  }
410
 
411
  $intersections = array_intersect( $current_user->roles, $allowed_roles );
412
+ $override_intersections = array_intersect( $current_user->roles, $override_roles );
413
 
414
+ if ( empty( $intersections ) && empty( $override_intersections ) ) {
415
  $role = false;
416
  } else {
417
  $role = true;
440
  $blog_is_members_only = get_option( 'wpac_members_only_blog', false );
441
 
442
  if ( $blog_is_members_only && ! is_user_logged_in() ) {
443
+ $redirect_to = get_option( 'wpac_members_blog_redirect', wp_login_url( $_SERVER['REQUEST_URI'] ) );
 
444
 
445
+ if ( empty( $redirect_to ) ) {
446
+ $redirect_to = wp_login_url( $_SERVER['REQUEST_URI'] );
 
 
 
 
447
  }
448
+
449
+ header( 'Location: ' . add_query_arg( 'redirect_to', $_SERVER['REQUEST_URI'], $redirect_to ) );
450
+ exit();
451
  }
452
 
453
  if ( get_post_meta( $post->ID, '_wpac_is_members_only', true ) && ! WordPressAccessControl::check_conditions( $post->ID ) ) {
585
  return $posts;
586
  }
587
 
588
+ /**
589
+ * Add our custom meta box to all support post types
590
+ *
591
+ * @since WordPress Access Control 2.0
592
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
593
+ */
594
  function add_wp_access_meta_boxes()
595
  {
596
  $enabled_post_types = get_option( 'wpac_custom_post_types', array() );
601
  }
602
  }
603
 
604
+ /**
605
+ * Display the various per-page/per-post options in the sidebar
606
+ *
607
+ * @since WordPress Access Control 2.0
608
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
609
+ */
610
  function add_wpac_meta_box()
611
  {
612
  global $post;
635
  include( dirname( __FILE__ ) . '/templates/meta_box.php' );
636
  }
637
 
638
+ /**
639
+ * Saves our custom meta data for the post being saved
640
+ *
641
+ * @since WordPress Access Control 2.0
642
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
643
+ */
644
  function save_postdata( $post_id )
645
  {
646
+ // Security check
647
  if ( ! isset( $_POST['members_only_nonce'] ) ) {
648
  return $post_id;
649
  }
652
  return $post_id;
653
  }
654
 
655
+ // Meta data isn't transmitted during autosaves so don't do anything
656
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
657
  return $post_id;
658
  }
717
  return $post_id;
718
  }
719
 
720
+ /**
721
+ * Replaces the default WordPress nav menu walker with our own version
722
+ *
723
+ * @param array $args The arguments passed to the wp_nav_menu function
724
+ *
725
+ * @return array The original arguments, with our custom walker instead of the default
726
+ *
727
+ * @since WordPress Access Control 1.1
728
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
729
+ */
730
  function wp_nav_menu_args( $args )
731
  {
732
  $args['walker'] = new WPAC_Nav_Menu_Walker();
733
  return $args;
734
  }
735
 
736
+ /**
737
+ * Prevents the code from degrading terribly when no nav menu is available
738
+ *
739
+ * @param array $args The arguments passed to the wp_nav_menu function
740
+ *
741
+ * @return array The original arguments, possible with our custom walker instead of the default
742
+ *
743
+ * @since WordPress Access Control 1.2
744
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
745
+ */
746
  function wp_page_menu_args( $args )
747
  {
748
  // Only remove the walker if it is ours
754
  }
755
 
756
  /**
757
+ * This hooks in at a higher level to make sure functions like wp_list_pages
758
+ * won't return members only pages.
759
  *
760
+ * @param array $pages
761
  * @return array
762
+ *
763
+ * @since WordPress Access Control 1.6.4
764
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
765
  */
766
  function get_pages( $pages )
767
  {
768
+ // Don't affect the display of pages when viewing the list in the admin
769
+ if ( is_admin() ) {
770
+ return $pages;
771
+ }
772
 
773
+ // Whether or not the user is logged in
774
  $auth = is_user_logged_in();
775
 
776
+ // Go through each page, remove ones we can't see
777
  foreach ( $pages as $key => $page ) {
778
  $is_members_only = get_post_meta( $page->ID, '_wpac_is_members_only', true );
779
  $is_nonmembers_only = get_post_meta( $page->ID, '_wpac_is_nonmembers_only', true );
790
  return $pages;
791
  }
792
 
793
+ /**
794
+ * Adds links to the plugin row to view the options page or view the plugin
795
+ * documentation.
796
+ *
797
+ * @param array $plugin_meta The links to display in the plugin row
798
+ * @param string $plugin_file The directory name and filename of the plugin (wordpress-access-control/wordpress-access-control.php)
799
+ * @param array $plugin_data
800
+ * @param string $status The status of the plugin (active or inactive)
801
+ *
802
+ * @return array The $plugin_meta array of links for this plugin
803
+ *
804
+ * @uses plugin_dir_url() to get the URL of the plugin directory since that is where the documentation is
805
+ *
806
+ * @since WordPress Access Control 3.0
807
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
808
+ */
809
  function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status )
810
  {
811
  if ( $plugin_file == str_replace( '.php', '/', basename( __FILE__ ) ) . basename( __FILE__ ) ) {
816
  return $plugin_meta;
817
  }
818
 
819
+
820
+ /**
821
+ * Hides content for users that are not logged in and displays content for
822
+ * users who are logged in. Calls do_shortcode on the content to allow
823
+ * nested shortcodes.
824
+ *
825
+ * @uses is_user_logged_in() to determine if the user is logged in or not
826
+ * @uses wpautop() to format the text in the shortcodes
827
+ * @uses do_shortcode() to execute nested shortcodes in our shortcode
828
+ *
829
+ * @since WordPress Access Control 3.0
830
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
831
+ */
832
  function shortcode_members( $attributes, $content = NULL )
833
  {
834
  global $post;
840
  return '';
841
  }
842
 
843
+ /**
844
+ * Hides content for users that are logged in and displays content for users
845
+ * who are not logged in. Calls do_shortcode on the content to allow nested
846
+ * shortcodes.
847
+ *
848
+ * @uses is_user_logged_in() to determine if the user is logged in or not
849
+ * @uses wpautop() to format the text in the shortcodes
850
+ * @uses do_shortcode() to execute nested shortcodes in our shortcode
851
+ *
852
+ * @since WordPress Access Control 3.0
853
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
854
+ */
855
  function shortcode_nonmembers( $attributes, $content = NULL )
856
  {
857
  global $post;
862
 
863
  return '';
864
  }
865
+
866
+ /*
867
+ * Loads a file that will override certain WordPress default widgets with
868
+ * a slightly modified version that allows admins to select it's visibility
869
+ * (Members only or non members only).
870
+ *
871
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
872
+ * @since WordPress Access Control 3.1
873
+ */
874
+ function load_custom_widgets()
875
+ {
876
+ require( dirname( __FILE__ ) . '/default-widgets.php' );
877
+ }
878
+
879
+ /**
880
+ * Adds our member only menus for each regular menu
881
+ *
882
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
883
+ * @since WordPress Access Control 3.1
884
+ */
885
+ function add_wpac_nav_menus()
886
+ {
887
+ global $_wp_registered_nav_menus;
888
+
889
+ foreach ( $_wp_registered_nav_menus as $location => $label ) {
890
+ $_wp_registered_nav_menus[$location . '_wpac'] = $label . ' - Members Only';
891
+ }
892
+ }
893
+
894
+ /**
895
+ * Checks to see if a members only version of the current menu is available
896
+ * and will load that instead of the normal menu.
897
+ *
898
+ * @param array $args The arguments passed to the wp_nav_menu function
899
+ *
900
+ * @return array The original arguments, possible with a new value for theme_location
901
+ *
902
+ * @uses is_user_logged_in() to determine if the user is logged in
903
+ * @uses get_nav_menu_locations() to get a list of valid theme locations
904
+ * @uses wp_get_nav_menu_object() to get our custom members only menu
905
+ *
906
+ * @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
907
+ * @since WordPress Access Control 3.1
908
+ */
909
+ function wp_nav_menu_members_only( $args )
910
+ {
911
+ // Don't do anything if the user isn't logged in
912
+ if ( is_user_logged_in() ) {
913
+
914
+ // See if the theme even passed a proper menu ID
915
+ if ( ! empty( $args['theme_location'] ) ) {
916
+
917
+ // Member only menus end in _wpac
918
+ $theme_location = $args['theme_location'] . '_wpac';
919
+
920
+ // Get the nav menu based on the theme_location
921
+ if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
922
+ $menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
923
+
924
+ // Only use the member only menu if it's not empty
925
+ if ( $menu->count > 0 ) {
926
+ $args['theme_location'] = $theme_location;
927
+ }
928
+ }
929
+ }
930
+ }
931
+
932
+ return $args;
933
+ }
934
  }