WordPress Access Control - Version 4.0.11

Version Description

  • September 13, 2014 =

  • Add the ability to set the default state/roles for custom post types instead of just pages & posts

Download this release

Release Info

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

Code changes from version 4.0.10 to 4.0.11

Files changed (3) hide show
  1. readme.txt +5 -1
  2. templates/options.php +96 -118
  3. wordpress-access-control.php +19 -26
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: members, only, plugin, restricted, access, menus, 3.3, wp_nav_menu, nonmembers
5
  Requires at least: 3.0
6
  Tested up to: 4.0
7
- Stable tag: 4.0.10
8
 
9
  Restrict pages, posts, custom post types, menus and widgets to members, nonmembers or specific roles and still add to navigation
10
 
@@ -64,6 +64,10 @@ Yes, this is a new feature in 3.1.3. Use the syntax [members role="administrator
64
 
65
  == Changelog ==
66
 
 
 
 
 
67
  = 4.0.10 - September 13, 2014 =
68
 
69
  * Get the localized roles using translate_user_role
4
  Tags: members, only, plugin, restricted, access, menus, 3.3, wp_nav_menu, nonmembers
5
  Requires at least: 3.0
6
  Tested up to: 4.0
7
+ Stable tag: 4.0.11
8
 
9
  Restrict pages, posts, custom post types, menus and widgets to members, nonmembers or specific roles and still add to navigation
10
 
64
 
65
  == Changelog ==
66
 
67
+ = 4.0.11 - September 13, 2014 =
68
+
69
+ * Add the ability to set the default state/roles for custom post types instead of just pages & posts
70
+
71
  = 4.0.10 - September 13, 2014 =
72
 
73
  * Get the localized roles using translate_user_role
templates/options.php CHANGED
@@ -1,88 +1,93 @@
1
  <?php
2
  global $wp_post_types, $wp_roles;
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
  ?>
@@ -92,24 +97,24 @@ After a user logs in they will be redirected back to the blog', 'wpac' ), '<br
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
  $roles = array_map('translate_user_role', $wp_roles->get_names());
106
- $checked_roles = (array) maybe_unserialize( get_option( 'wpac_always_accessible_by', array( 0 => 'administrator' ) ) );
107
 
108
- foreach ( $roles as $role => $label ) {
109
- if ( in_array( $role, $checked_roles ) ) {
110
- echo '<label><input type="checkbox" name="wpac_always_accessible_by[]" checked="checked" value="' . $role . '" /> ' . $label . '<br /></label>';
111
  } else {
112
- echo '<label><input type="checkbox" name="wpac_always_accessible_by[]" value="' . $role . '" /> ' . $label . '<br /></label>';
113
  }
114
  }
115
  ?>
@@ -118,145 +123,118 @@ After a user logs in they will be redirected back to the blog', 'wpac' ), '<br
118
  </tbody>
119
  </table>
120
 
121
- <h3 class="title"><?php _e( 'Menu Options', 'wpac' ); ?></h3>
122
 
123
  <table class="form-table">
124
  <tbody>
125
  <tr>
126
  <th scope="row">
127
- <?php _e( 'Display In Menus', 'wpac' ); ?>
128
  </th>
129
  <td>
130
- <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>
131
- <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 />
132
- <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>
133
  </td>
134
  </tr>
135
  </tbody>
136
  </table>
137
 
138
- <h3 class="title"><?php _e( 'Post/Page Default Options', 'wpac' ); ?></h3>
139
 
140
  <p>
141
- <?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.' ); ?>
142
  </p>
143
 
144
  <table class="form-table">
145
  <tbody>
 
146
  <tr>
147
  <th scope="row">
148
- <?php _e( 'Default Post State', 'wpac' ); ?>
149
  </th>
150
  <td>
151
- <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 />
152
- <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 />
153
- <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 />
 
154
  </td>
155
  </tr>
156
 
157
  <tr>
158
  <th scope="row">
159
- <?php _e( 'Posts: Only Accessible By', 'wpac' ); ?>
160
  </th>
161
  <td>
162
  <?php
163
  $roles = array_map('translate_user_role', $wp_roles->get_names());
164
- $checked_roles = (array) get_option( 'wpac_posts_default_restricted_to', array() );
165
 
166
- foreach ( $roles as $role => $label ) {
167
- if ( in_array( $role, $checked_roles ) ) {
168
- echo '<label><input type="checkbox" name="wpac_posts_default_restricted_to[]" checked="checked" value="' . $role . '" /> ' . $label . '</label><br />';
169
  } else {
170
- echo '<label><input type="checkbox" name="wpac_posts_default_restricted_to[]" value="' . $role . '" /> ' . $label . '</label><br />';
171
  }
172
  }
173
  ?>
174
- <span class="description"><?php _e( 'Defaults to all roles', 'wpac' ); ?></span>
175
  </td>
176
  </tr>
177
 
178
- <tr>
179
- <th scope="row">
180
- <?php _e( 'Default Page State', 'wpac' ); ?>
181
- </th>
182
- <td>
183
- <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 />
184
- <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 />
185
- <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 />
186
- </td>
187
- </tr>
188
-
189
- <tr>
190
- <th scope="row">
191
- <?php _e( 'Pages: Only Accessible By', 'wpac' ); ?>
192
- </th>
193
- <td>
194
- <?php
195
- $roles = array_map('translate_user_role', $wp_roles->get_names());
196
- $checked_roles = (array) get_option( 'wpac_pages_default_restricted_to', array() );
197
-
198
- foreach ( $roles as $role => $label ) {
199
- if ( in_array( $role, $checked_roles ) ) {
200
- echo '<label><input type="checkbox" name="wpac_pages_default_restricted_to[]" checked="checked" value="' . $role . '" /> ' . $label . '</label><br />';
201
- } else {
202
- echo '<label><input type="checkbox" name="wpac_pages_default_restricted_to[]" value="' . $role . '" /> ' . $label . '</label><br />';
203
- }
204
- }
205
- ?>
206
- <span class="description"><?php _e( 'Defaults to all roles', 'wpac' ); ?></span>
207
- </td>
208
- </tr>
209
 
210
  <tr>
211
  <th scope="row">
212
- <label for="wpac_default_members_redirect"><?php _e( 'Default Redirect For Members Only Pages', 'wpac' ); ?></label>
213
  </th>
214
  <td>
215
- <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" />
216
  <span class="description">
217
- <?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 />' ); ?>
218
  </span>
219
  </td>
220
  </tr>
221
  </tbody>
222
  </table>
223
 
224
- <h3 class="title"><?php _e( 'Search/Archive Options', 'wpac' ); ?></h3>
225
 
226
  <p>
227
- <?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).
228
  <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
229
- post state to Members Only, then set the Search Options to show restricted posts in search results and show post excerpts.', 'wpac' ); ?>
230
  </p>
231
 
232
  <table class="form-table">
233
  <tbody>
234
  <tr>
235
  <th scope="row">
236
- <?php _e( 'Search Options', 'wpac' ); ?>
237
  </th>
238
  <td>
239
- <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 />
240
- <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 />
241
- <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 />
242
- <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 />
243
  </td>
244
  </tr>
245
 
246
  <tr>
247
  <th scope="row">
248
- <label for="post_excerpt_text"><?php _e( 'Search Excerpt (Posts)', 'wpac' ); ?></label>
249
  </th>
250
  <td>
251
  <fieldset>
252
- <legend class="screen-reader-text"><?php _e( 'Search Excerpt (Posts)', 'wpac' ); ?></legend>
253
 
254
  <p>
255
- <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>
256
  </p>
257
 
258
  <p>
259
- <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>
260
  </p>
261
  </fieldset>
262
  </td>
@@ -264,18 +242,18 @@ post state to Members Only, then set the Search Options to show restricted posts
264
 
265
  <tr>
266
  <th scope="row">
267
- <label for="page_excerpt_text"><?php _e( 'Search Excerpt (Pages)', 'wpac' ); ?></label>
268
  </th>
269
  <td>
270
  <fieldset>
271
- <legend class="screen-reader-text"><?php _e( 'Search Excerpt (Pages)', 'wpac' ); ?>)</legend>
272
 
273
  <p>
274
- <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>
275
  </p>
276
 
277
  <p>
278
- <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>
279
  </p>
280
  </fieldset>
281
  </td>
@@ -283,6 +261,6 @@ post state to Members Only, then set the Search Options to show restricted posts
283
  </tbody>
284
  </table>
285
 
286
- <p class="submit"><input type="submit" value="<?php _e( 'Save Changes', 'wpac' ); ?>" class="button-primary" id="submit" name="submit" /></p>
287
  </form>
288
  </div>
1
  <?php
2
  global $wp_post_types, $wp_roles;
3
 
4
+ $all_post_types = array();
5
+ $default_post_types = array();
6
 
7
+ foreach ($wp_post_types as $post_type => $details) {
8
+ $all_post_types[$post_type] = $details;
9
+
10
+ if (!in_array($post_type, array('post', 'page', 'attachment', 'revision', 'nav_menu_item'))) {
11
  $custom_post_types[$post_type] = $details;
12
  }
13
  }
14
 
15
+ $wpac_members_blog_redirect = get_option('wpac_members_blog_redirect', '');
16
+ $wpac_members_only_blog = get_option('wpac_members_only_blog', false);
17
+ $wpac_custom_post_types = get_option('wpac_custom_post_types', array());
18
+ $wpac_show_in_menus = get_option('wpac_show_in_menus', 'with_access');
19
+ $wpac_default_page_state = get_option('wpac_default_page_state', 'public');
20
+ $wpac_default_members_redirect = get_option('wpac_default_members_redirect' , '');
21
+ $wpac_show_posts_in_search = get_option('wpac_show_posts_in_search', false);
22
+ $wpac_show_post_excerpts_in_search = get_option('wpac_show_post_excerpts_in_search', false);
23
+ $wpac_show_pages_in_search = get_option('wpac_show_pages_in_search', false);
24
+ $wpac_show_page_excerpts_in_search = get_option('wpac_show_page_excerpts_in_search', false);
25
+
26
+ // All post types that WPAC is enabled for
27
+ $wpac_enabled_post_types = array_merge(array('post', 'page'), $wpac_custom_post_types);
28
+ ?>
29
+ <div class="wrap">
30
+ <div class="icon32" id="icon-options-general"><br></div>
31
+ <h2><?php _e('WordPress Access Control Settings', 'wpac') ?></h2>
32
+
33
+ <?php if (isset($admin_message) && ! empty($admin_message)) { ?>
34
+ <div class="updated below-h2" id="message"><p><?php echo $admin_message ?></p></div>
35
  <?php } ?>
36
 
37
+ <?php if (isset($admin_error) && ! empty($admin_error)) { ?>
38
+ <div class="error below-h2" id="error"><p><?php echo $admin_error ?></p></div>
39
  <?php } ?>
40
 
41
  <form action="options-general.php?page=wpac-options" method="post">
42
+ <input type="hidden" value="wpac-options" name="options_page">
43
+ <input type="hidden" value="update" name="action">
44
+ <?php wp_nonce_field('wpac_options_save') ?>
45
 
46
+ <h3 class="title"><?php _e('Shortcodes', 'wpac') ?></h3>
47
 
48
+ <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>
49
 
50
+ <h3 class="title"><?php _e('General Options', 'wpac') ?></h3>
51
 
52
  <table class="form-table">
53
  <tbody>
54
  <tr>
55
  <th scope="row">
56
+ <label for="wpac_members_only_blog"><?php _e('Make Website Members Only', 'wpac') ?></label>
57
  </th>
58
 
59
  <td>
60
+ <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>
61
  </td>
62
  </tr>
63
 
64
  <tr>
65
  <th scope="row">
66
+ <label for="wpac_members_blog_redirect"><?php _e('Members Website Redirect', 'wpac') ?></label>
67
  </th>
68
 
69
  <td>
70
+ <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">
71
+ <span class="description"><?php printf(__('Where to redirect non-members when they try to visit the Website. %1$s
72
  Defaults to WordPress login page (%2$s)%1$s
73
+ After a user logs in they will be redirected back to the Website', 'wpac'), '<br>', '<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>') ?></span>
74
  </td>
75
  </tr>
76
 
77
+ <?php if (! empty($custom_post_types)) { ?>
78
  <tr>
79
  <th scope="row">
80
+ <label for="wpac_members_only_blog"><?php _e('Custom Post Types', 'wpac') ?></label>
81
  </th>
82
 
83
  <td>
84
+ <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>
85
  <?php
86
+ foreach ($custom_post_types as $post_type => $details) {
87
+ if (in_array($post_type, $wpac_custom_post_types)) {
88
+ 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>';
 
 
89
  } else {
90
+ 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>';
91
  }
92
  }
93
  ?>
97
  </tbody>
98
  </table>
99
 
100
+ <h3 class="title"><?php _e('Override Permisisons', 'wpac') ?></h3>
101
 
102
  <table class="form-table">
103
  <tbody>
104
  <tr>
105
  <th scope="row">
106
+ <?php _e('Always Accessible By', 'wpac') ?>
107
  </th>
108
  <td>
109
  <?php
110
  $roles = array_map('translate_user_role', $wp_roles->get_names());
111
+ $checked_roles = (array) maybe_unserialize(get_option('wpac_always_accessible_by', array(0 => 'administrator')));
112
 
113
+ foreach ($roles as $role => $label) {
114
+ if (in_array($role, $checked_roles)) {
115
+ echo '<label><input type="checkbox" name="wpac_always_accessible_by[]" checked="checked" value="' . $role . '"> ' . $label . '<br></label>';
116
  } else {
117
+ echo '<label><input type="checkbox" name="wpac_always_accessible_by[]" value="' . $role . '"> ' . $label . '<br></label>';
118
  }
119
  }
120
  ?>
123
  </tbody>
124
  </table>
125
 
126
+ <h3 class="title"><?php _e('Menu Options', 'wpac') ?></h3>
127
 
128
  <table class="form-table">
129
  <tbody>
130
  <tr>
131
  <th scope="row">
132
+ <?php _e('Display In Menus', 'wpac') ?>
133
  </th>
134
  <td>
135
+ <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>
136
+ <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>
137
+ <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>
138
  </td>
139
  </tr>
140
  </tbody>
141
  </table>
142
 
143
+ <h3 class="title"><?php _e('Post Type Default Options', 'wpac') ?></h3>
144
 
145
  <p>
146
+ <?php _e('These options are defaults for post types in case the majority of your posts will have similar settings. You can override any of these settings on a per-post basis.') ?>
147
  </p>
148
 
149
  <table class="form-table">
150
  <tbody>
151
+ <?php foreach ($wpac_enabled_post_types as $post_type) : ?>
152
  <tr>
153
  <th scope="row">
154
+ <?php printf(__('Default State For: %s', 'wpac'), $all_post_types[$post_type]->labels->name) ?>
155
  </th>
156
  <td>
157
+ <?php $default_state = get_option('wpac_default_' . $post_type . '_state', 'public'); ?>
158
+ <label><input <?php checked($default_state, 'public') ?> type="radio" value="public" name="default_state[<?php echo $post_type ?>]"> <span><?php _e('Public', 'wpac') ?></span></label><br>
159
+ <label><input <?php checked($default_state, 'members') ?> type="radio" value="members" name="default_state[<?php echo $post_type ?>]"> <span><?php _e('Members Only', 'wpac') ?></span></label><br>
160
+ <label><input <?php checked($default_state, 'nonmembers') ?> type="radio" value="nonmembers" name="default_state[<?php echo $post_type ?>]"> <span><?php _e('Non-Members Only', 'wpac') ?></span></label><br>
161
  </td>
162
  </tr>
163
 
164
  <tr>
165
  <th scope="row">
166
+ <?php printf(__('%s: Default Roles', 'wpac'), $all_post_types[$post_type]->labels->name) ?>
167
  </th>
168
  <td>
169
  <?php
170
  $roles = array_map('translate_user_role', $wp_roles->get_names());
171
+ $checked_roles = (array) get_option('wpac_' . $post_type . 's_default_restricted_to', array());
172
 
173
+ foreach ($roles as $role => $label) {
174
+ if (in_array($role, $checked_roles)) {
175
+ echo '<label><input type="checkbox" name="wpac_default_restricted_to[' . $post_type . '][]" checked value="' . $role . '"> ' . $label . '</label><br>';
176
  } else {
177
+ echo '<label><input type="checkbox" name="wpac_default_restricted_to[' . $post_type . '][]" value="' . $role . '"> ' . $label . '</label><br>';
178
  }
179
  }
180
  ?>
181
+ <span class="description"><?php _e('Defaults to all roles', 'wpac') ?></span>
182
  </td>
183
  </tr>
184
 
185
+ <tr><td colspan="2"><hr></td></tr>
186
+ <?php endforeach ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  <tr>
189
  <th scope="row">
190
+ <label for="wpac_default_members_redirect"><?php _e('Default Redirect For Members Only Pages', 'wpac') ?></label>
191
  </th>
192
  <td>
193
+ <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">
194
  <span class="description">
195
+ <?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>') ?>
196
  </span>
197
  </td>
198
  </tr>
199
  </tbody>
200
  </table>
201
 
202
+ <h3 class="title"><?php _e('Search/Archive Options', 'wpac') ?></h3>
203
 
204
  <p>
205
+ <?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).
206
  <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
207
+ post state to Members Only, then set the Search Options to show restricted posts in search results and show post excerpts.', 'wpac') ?>
208
  </p>
209
 
210
  <table class="form-table">
211
  <tbody>
212
  <tr>
213
  <th scope="row">
214
+ <?php _e('Search Options', 'wpac') ?>
215
  </th>
216
  <td>
217
+ <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>
218
+ <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>
219
+ <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>
220
+ <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>
221
  </td>
222
  </tr>
223
 
224
  <tr>
225
  <th scope="row">
226
+ <label for="post_excerpt_text"><?php _e('Search Excerpt (Posts)', 'wpac') ?></label>
227
  </th>
228
  <td>
229
  <fieldset>
230
+ <legend class="screen-reader-text"><?php _e('Search Excerpt (Posts)', 'wpac') ?></legend>
231
 
232
  <p>
233
+ <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>
234
  </p>
235
 
236
  <p>
237
+ <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>
238
  </p>
239
  </fieldset>
240
  </td>
242
 
243
  <tr>
244
  <th scope="row">
245
+ <label for="page_excerpt_text"><?php _e('Search Excerpt (Pages)', 'wpac') ?></label>
246
  </th>
247
  <td>
248
  <fieldset>
249
+ <legend class="screen-reader-text"><?php _e('Search Excerpt (Pages)', 'wpac') ?>)</legend>
250
 
251
  <p>
252
+ <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>
253
  </p>
254
 
255
  <p>
256
+ <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>
257
  </p>
258
  </fieldset>
259
  </td>
261
  </tbody>
262
  </table>
263
 
264
+ <p class="submit"><input type="submit" value="<?php _e('Save Changes', 'wpac') ?>" class="button-primary" id="submit" name="submit"></p>
265
  </form>
266
  </div>
wordpress-access-control.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
5
  * Author: Brandon Wamboldt
6
  * Author URI: http://brandonwamboldt.ca/
7
- * Version: 4.0.10
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
 
@@ -67,7 +67,6 @@ class WordPressAccessControl
67
  if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'wpac_options_save')) {
68
  $admin_error = __('Security check failed, please try again', 'wpac');
69
  } else {
70
-
71
  // Make the blog members only
72
  if (isset($_REQUEST['wpac_members_only_blog']) && $_REQUEST['wpac_members_only_blog'] == 'yes') {
73
  update_option('wpac_members_only_blog', true);
@@ -109,32 +108,26 @@ class WordPressAccessControl
109
  update_option('wpac_show_in_menus', 'with_access');
110
  }
111
 
112
- // Default post state setting
113
- if (isset($_REQUEST['default_post_state']) && in_array($_REQUEST['default_post_state'], array('public', 'members', 'nonmembers'))) {
114
- update_option('wpac_default_post_state', $_REQUEST['default_post_state']);
115
- } else {
116
- update_option('wpac_default_post_state', 'public');
117
- }
118
-
119
- // Default post roles
120
- if (isset($_REQUEST['wpac_posts_default_restricted_to']) && is_array($_REQUEST['wpac_posts_default_restricted_to'])) {
121
- update_option('wpac_posts_default_restricted_to', $_REQUEST['wpac_posts_default_restricted_to']);
122
- } else {
123
- update_option('wpac_posts_default_restricted_to', array());
124
- }
125
-
126
- // Default page state setting
127
- if (isset($_REQUEST['default_page_state']) && in_array($_REQUEST['default_page_state'], array('public', 'members', 'nonmembers'))) {
128
- update_option('wpac_default_page_state', $_REQUEST['default_page_state']);
129
- } else {
130
- update_option('wpac_default_page_state', 'public');
131
  }
132
 
133
- // Default page roles
134
- if (isset($_REQUEST['wpac_pages_default_restricted_to']) && is_array($_REQUEST['wpac_pages_default_restricted_to'])) {
135
- update_option('wpac_pages_default_restricted_to', $_REQUEST['wpac_pages_default_restricted_to']);
136
- } else {
137
- update_option('wpac_pages_default_restricted_to', array());
 
 
 
 
138
  }
139
 
140
  // Default redirect
4
  * Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
5
  * Author: Brandon Wamboldt
6
  * Author URI: http://brandonwamboldt.ca/
7
+ * Version: 4.0.11
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
 
67
  if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'wpac_options_save')) {
68
  $admin_error = __('Security check failed, please try again', 'wpac');
69
  } else {
 
70
  // Make the blog members only
71
  if (isset($_REQUEST['wpac_members_only_blog']) && $_REQUEST['wpac_members_only_blog'] == 'yes') {
72
  update_option('wpac_members_only_blog', true);
108
  update_option('wpac_show_in_menus', 'with_access');
109
  }
110
 
111
+ // Default post-type state setting
112
+ if (isset($_POST['default_state'])) {
113
+ foreach ($_POST['default_state'] as $post_type => $value) {
114
+ if (in_array($value, array('public', 'members', 'nonmembers'))) {
115
+ update_option('wpac_default_' . $post_type . '_state', $value);
116
+ } else {
117
+ update_option('wpac_default_' . $post_type . '_state', 'public');
118
+ }
119
+ }
 
 
 
 
 
 
 
 
 
 
120
  }
121
 
122
+ // Default post-type roles
123
+ if (isset($_POST['wpac_default_restricted_to'])) {
124
+ foreach ($_POST['wpac_default_restricted_to'] as $post_type => $value) {
125
+ if (is_array($value)) {
126
+ update_option('wpac_' . $post_type . 's_default_restricted_to', $value);
127
+ } else {
128
+ update_option('wpac_' . $post_type . 's_default_restricted_to', array());
129
+ }
130
+ }
131
  }
132
 
133
  // Default redirect