Version Description
December 13, 2013 =
Rewrote the Nav Walker classes to be more minimalistic and to defer actual functionality to the originally configured walker, allowing for better compatability with themes or plugins that use their own nav walkers
Code style updates
Fixing some PHP warnings/notices
Download this release
Release Info
Developer | brandon.wamboldt |
Plugin | WordPress Access Control |
Version | 4.0.0 |
Comparing to | |
See all releases |
Code changes from version 3.1.4 to 4.0.0
- documentation/assets/css/readme.css +0 -0
- documentation/assets/images/default_interface.png +0 -0
- documentation/assets/images/htmlstructure.png +0 -0
- documentation/assets/images/members_interface.png +0 -0
- documentation/assets/images/nonmembers_interface.png +0 -0
- documentation/assets/images/white-grad-active.png +0 -0
- documentation/assets/images/white-grad.png +0 -0
- documentation/assets/images/wordpress-logo.png +0 -0
- documentation/index.html +0 -0
- languages/wordpress-access-control.pot +0 -0
- lib/Walker.php +114 -0
- readme.txt +14 -4
- templates/options.php +0 -0
- wordpress-access-control.php +717 -919
documentation/assets/css/readme.css
CHANGED
File without changes
|
documentation/assets/images/default_interface.png
CHANGED
File without changes
|
documentation/assets/images/htmlstructure.png
CHANGED
File without changes
|
documentation/assets/images/members_interface.png
CHANGED
File without changes
|
documentation/assets/images/nonmembers_interface.png
CHANGED
File without changes
|
documentation/assets/images/white-grad-active.png
CHANGED
File without changes
|
documentation/assets/images/white-grad.png
CHANGED
File without changes
|
documentation/assets/images/wordpress-logo.png
CHANGED
File without changes
|
documentation/index.html
CHANGED
File without changes
|
languages/wordpress-access-control.pot
CHANGED
File without changes
|
lib/Walker.php
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Walker class for nav menus. We extend Walker_Nav_Menu in case anything type
|
5 |
+
* checks the walker class. We take the original walker as a constructor arg and
|
6 |
+
* defer method calls to the original walker if the menu item is visible.
|
7 |
+
*
|
8 |
+
* This new approach should allow us to be compatible with code or themes that
|
9 |
+
* implement their own walker classes.
|
10 |
+
*
|
11 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
12 |
+
*/
|
13 |
+
class WpacSecureWalker extends Walker_Nav_Menu
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* @var boolean
|
17 |
+
*/
|
18 |
+
protected $in_private = false;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var integer
|
22 |
+
*/
|
23 |
+
protected $private_depth = 0;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @var Walker_Nav_Menu
|
27 |
+
*/
|
28 |
+
protected $original_walker;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Constructor.
|
32 |
+
*
|
33 |
+
* @param Walker_Nav_Menu $original_walker
|
34 |
+
*/
|
35 |
+
public function __construct($original_walker)
|
36 |
+
{
|
37 |
+
if (empty($original_walker)) {
|
38 |
+
$original_walker = new Walker_Nav_Menu;
|
39 |
+
}
|
40 |
+
|
41 |
+
$this->original_walker = $original_walker;
|
42 |
+
$this->sync_vars_with_original_walker();
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Sync public variables to the original walker.
|
47 |
+
*/
|
48 |
+
public function sync_vars_with_original_walker()
|
49 |
+
{
|
50 |
+
$this->original_walker->tree_type = $this->tree_type;
|
51 |
+
$this->original_walker->db_fields = $this->db_fields;
|
52 |
+
$this->original_walker->max_pages = $this->max_pages;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* {@inheritdoc}
|
57 |
+
*/
|
58 |
+
public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output)
|
59 |
+
{
|
60 |
+
$this->sync_vars_with_original_walker();
|
61 |
+
|
62 |
+
if (WordPressAccessControl::check_conditions($element->object_id) || get_option('wpac_show_in_menus', 'with_access') == 'always') {
|
63 |
+
$this->original_walker->display_element($element, $children_elements, $max_depth, $depth, $args, $output);
|
64 |
+
} else {
|
65 |
+
$children_elements[$element->{$this->db_fields['id']}] = array();
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Divert all other method calls directly to the original walker class.
|
71 |
+
*
|
72 |
+
* @param string $method
|
73 |
+
* @param array $arguments
|
74 |
+
* @return mixed
|
75 |
+
*/
|
76 |
+
public function __call($method, $arguments)
|
77 |
+
{
|
78 |
+
$this->sync_vars_with_original_walker();
|
79 |
+
return call_user_func_array(array($this->original_walker, $method), $arguments);
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Divert all property access requests to the original walker class.
|
84 |
+
*
|
85 |
+
* @param string $var
|
86 |
+
* @return mixed
|
87 |
+
*/
|
88 |
+
public function __get($var)
|
89 |
+
{
|
90 |
+
return $this->original_walker->{$var};
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Divert all property access requests to the original walker class.
|
95 |
+
*
|
96 |
+
* @param string $var
|
97 |
+
* @return mixed
|
98 |
+
*/
|
99 |
+
public function __set($var, $value)
|
100 |
+
{
|
101 |
+
$this->original_walker->{$var} = $value;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Divert all property access requests to the original walker class.
|
106 |
+
*
|
107 |
+
* @param string $var
|
108 |
+
* @return mixed
|
109 |
+
*/
|
110 |
+
public function __isset($var)
|
111 |
+
{
|
112 |
+
return isset($this->original_walker->{$var});
|
113 |
+
}
|
114 |
+
}
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
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:
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag:
|
8 |
|
9 |
Restrict pages, posts, custom post types, menus and widgets to members, nonmembers or specific roles and still add to navigation
|
10 |
|
@@ -20,6 +20,10 @@ 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 |
**New Features in 3.1**
|
24 |
|
25 |
* You can add member only versions of each menu on your site (Only when using WordPress menus)
|
@@ -60,9 +64,15 @@ Yes, this is a new feature in 3.1.3. Use the syntax [members role="administrator
|
|
60 |
|
61 |
== Changelog ==
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
= 3.1.4 - August 30, 2012 =
|
64 |
|
65 |
-
* Added not/or keywords to the role option of the members shortcode, syntax: [members role="not:guest,banned"][/members] and [members role="or:editor,author,contributor"]
|
66 |
|
67 |
= 3.1.3 - August 30, 2012 =
|
68 |
|
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: 3.0
|
6 |
+
Tested up to: 3.8
|
7 |
+
Stable tag: 4.0.0
|
8 |
|
9 |
Restrict pages, posts, custom post types, menus and widgets to members, nonmembers or specific roles and still add to navigation
|
10 |
|
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 4.0**
|
24 |
+
|
25 |
+
Enhanced theme compatiblity! We now have a much smaller impact on sites due to a new way of implementing our nav walker code. This should significantly improve compatability with third party themes.
|
26 |
+
|
27 |
**New Features in 3.1**
|
28 |
|
29 |
* You can add member only versions of each menu on your site (Only when using WordPress menus)
|
64 |
|
65 |
== Changelog ==
|
66 |
|
67 |
+
= 4.0.0 - December 13, 2013 =
|
68 |
+
|
69 |
+
* Rewrote the Nav Walker classes to be more minimalistic and to defer actual functionality to the originally configured walker, allowing for better compatability with themes or plugins that use their own nav walkers
|
70 |
+
* Code style updates
|
71 |
+
* Fixing some PHP warnings/notices
|
72 |
+
|
73 |
= 3.1.4 - August 30, 2012 =
|
74 |
|
75 |
+
* Added not/or keywords to the role option of the members shortcode, syntax: [members role="not:guest,banned"][/members] and [members role="or:editor,author,contributor"](Thanks to Dave Amphlett for the idea)
|
76 |
|
77 |
= 3.1.3 - August 30, 2012 =
|
78 |
|
templates/options.php
CHANGED
File without changes
|
wordpress-access-control.php
CHANGED
@@ -4,836 +4,652 @@
|
|
4 |
* Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
|
5 |
* Author: Brandon Wamboldt
|
6 |
* Author URI: http://brandonwamboldt.ca/
|
7 |
-
* Version:
|
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 |
-
|
12 |
-
|
13 |
-
add_action(
|
14 |
-
add_action(
|
15 |
-
add_action(
|
16 |
-
add_action(
|
17 |
-
add_action(
|
18 |
-
add_action(
|
19 |
-
add_action(
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
add_filter(
|
24 |
-
add_filter(
|
25 |
-
add_filter(
|
26 |
-
add_filter(
|
27 |
-
add_filter(
|
28 |
-
add_filter(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
add_shortcode(
|
35 |
-
add_shortcode(
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
/**
|
42 |
-
* A custom walker that checks our conditions to make sure the user has
|
43 |
-
* permission to view the page linked to from the menu item
|
44 |
-
*
|
45 |
-
* @author Brandon Wamboldt
|
46 |
-
* @package WordPress
|
47 |
-
* @subpackage WordPressAccessControl
|
48 |
-
*/
|
49 |
-
class WPAC_Nav_Menu_Walker extends Walker_Nav_Menu
|
50 |
-
{
|
51 |
-
var $in_private = false;
|
52 |
-
var $private_lvl = 0;
|
53 |
-
|
54 |
-
function start_lvl( & $output, $depth )
|
55 |
-
{
|
56 |
-
if ( ! $this->in_private ) {
|
57 |
-
$indent = str_repeat( ' ', $depth );
|
58 |
-
$output .= "\n$indent<ul class=\"sub-menu\"><li style='display:none;'></li>\n";
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
function end_lvl( & $output, $depth )
|
63 |
-
{
|
64 |
-
if ( ! $this->in_private ) {
|
65 |
-
$indent = str_repeat( ' ', $depth );
|
66 |
-
$output .= "$indent</ul>\n";
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
function start_el( & $output, $item, $depth, $args )
|
71 |
-
{
|
72 |
-
global $wp_query;
|
73 |
-
|
74 |
-
if ( WordPressAccessControl::check_conditions( $item->object_id ) || get_option( 'wpac_show_in_menus', 'with_access' ) == 'always' ) {
|
75 |
-
if ( ! $this->in_private ) {
|
76 |
-
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
77 |
-
|
78 |
-
$class_names = $value = '';
|
79 |
-
|
80 |
-
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
|
81 |
-
|
82 |
-
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
|
83 |
-
$class_names = ' class="' . esc_attr( $class_names ) . '"';
|
84 |
-
|
85 |
-
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
|
86 |
-
|
87 |
-
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
|
88 |
-
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
|
89 |
-
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
|
90 |
-
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
|
91 |
-
|
92 |
-
$item_output = $args->before;
|
93 |
-
$item_output .= '<a'. $attributes .'>';
|
94 |
-
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
|
95 |
-
$item_output .= '</a>';
|
96 |
-
$item_output .= $args->after;
|
97 |
-
|
98 |
-
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
99 |
-
}
|
100 |
-
} else {
|
101 |
-
$this->in_private = true;
|
102 |
-
$this->private_lvl++;
|
103 |
-
}
|
104 |
-
}
|
105 |
-
|
106 |
-
function end_el( & $output, $item, $depth )
|
107 |
-
{
|
108 |
-
if ( WordPressAccessControl::check_conditions( $item->object_id ) || get_option( 'wpac_show_in_menus', 'with_access' ) == 'always' ) {
|
109 |
-
if ( ! $this->in_private ) {
|
110 |
-
$output .= "</li>\n";
|
111 |
-
}
|
112 |
-
} else {
|
113 |
-
$this->private_lvl--;
|
114 |
-
|
115 |
-
if ( $this->private_lvl == 0 ) {
|
116 |
-
$this->in_private = false;
|
117 |
-
}
|
118 |
-
}
|
119 |
-
}
|
120 |
-
}
|
121 |
-
}
|
122 |
-
|
123 |
-
// We check to see if the class exists because it may get removed in the future
|
124 |
-
if ( class_exists( 'Walker_Page' ) ) {
|
125 |
-
add_filter( 'wp_page_menu_args', array( 'WordPressAccessControl' , 'wp_page_menu_args' ) );
|
126 |
-
|
127 |
-
/**
|
128 |
-
* A custom walker that checks our conditions to make sure the user has
|
129 |
-
* permission to view the page linked to from the menu item
|
130 |
-
*
|
131 |
-
* @author Brandon Wamboldt
|
132 |
-
* @package WordPress
|
133 |
-
* @subpackage WordPressAccessControl
|
134 |
-
*/
|
135 |
-
class WPAC_Page_Walker extends Walker_Page
|
136 |
-
{
|
137 |
-
var $in_private = false;
|
138 |
-
var $private_lvl = 0;
|
139 |
-
|
140 |
-
function start_lvl( & $output, $depth )
|
141 |
-
{
|
142 |
-
if ( ! $this->in_private ) {
|
143 |
-
$indent = str_repeat( ' ', $depth );
|
144 |
-
$output .= "\n$indent<ul class=\"sub-menu\"><li style='display:none;'></li>\n";
|
145 |
-
}
|
146 |
-
}
|
147 |
-
|
148 |
-
function end_lvl( & $output, $depth )
|
149 |
-
{
|
150 |
-
if ( ! $this->in_private ) {
|
151 |
-
$indent = str_repeat( ' ', $depth );
|
152 |
-
$output .= "$indent</ul>\n";
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
function start_el( & $output, $page, $depth, $args, $current_page )
|
157 |
-
{
|
158 |
-
global $wp_query;
|
159 |
-
|
160 |
-
if ( WordPressAccessControl::check_conditions( $page->ID ) ) {
|
161 |
-
if ( ! $this->in_private ) {
|
162 |
-
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
163 |
-
|
164 |
-
extract( $args, EXTR_SKIP );
|
165 |
-
|
166 |
-
$css_class = array( 'page_item', 'page-item-' . $page->ID );
|
167 |
-
|
168 |
-
if ( $current_page != '' ) {
|
169 |
-
$_current_page = get_page( $current_page );
|
170 |
-
|
171 |
-
if ( isset( $_current_page->ancestors ) && in_array( $page->ID, (array) $_current_page->ancestors ) ) {
|
172 |
-
$css_class[] = 'current_page_ancestor';
|
173 |
-
}
|
174 |
-
|
175 |
-
if ( $page->ID == $current_page ) {
|
176 |
-
$css_class[] = 'current_page_item';
|
177 |
-
} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
|
178 |
-
$css_class[] = 'current_page_parent';
|
179 |
-
}
|
180 |
-
} elseif ( $page->ID == get_option('page_for_posts') ) {
|
181 |
-
$css_class[] = 'current_page_parent';
|
182 |
-
}
|
183 |
-
|
184 |
-
$css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page ) );
|
185 |
-
|
186 |
-
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link( $page->ID ) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
|
187 |
-
|
188 |
-
if ( ! empty( $show_date ) ) {
|
189 |
-
if ( 'modified' == $show_date ) {
|
190 |
-
$time = $page->post_modified;
|
191 |
-
} else {
|
192 |
-
$time = $page->post_date;
|
193 |
-
}
|
194 |
-
|
195 |
-
$output .= ' ' . mysql2date( $date_format, $time );
|
196 |
-
}
|
197 |
-
}
|
198 |
-
} else {
|
199 |
-
$this->in_private = true;
|
200 |
-
$this->private_lvl++;
|
201 |
-
}
|
202 |
-
}
|
203 |
-
|
204 |
-
function end_el( & $output, $page, $depth )
|
205 |
-
{
|
206 |
-
if ( WordPressAccessControl::check_conditions( $page->ID ) ) {
|
207 |
-
if ( ! $this->in_private ) {
|
208 |
-
$output .= "</li>\n";
|
209 |
-
}
|
210 |
-
} else {
|
211 |
-
$this->private_lvl--;
|
212 |
-
|
213 |
-
if ( $this->private_lvl == 0 ) {
|
214 |
-
$this->in_private = false;
|
215 |
-
}
|
216 |
-
}
|
217 |
-
}
|
218 |
-
}
|
219 |
-
}
|
220 |
|
221 |
/**
|
222 |
* The main plugin
|
223 |
*
|
224 |
-
* @author Brandon Wamboldt
|
225 |
-
* @package WordPress
|
226 |
-
* @subpackage WordPressAccessControl
|
227 |
*/
|
228 |
class WordPressAccessControl
|
229 |
{
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
if ( is_user_logged_in() ) {
|
837 |
if (isset($attributes['role'])) {
|
838 |
|
839 |
// Determine the syntax (Singular role, OR syntax or NOT syntax)
|
@@ -867,103 +683,85 @@ class WordPressAccessControl
|
|
867 |
}
|
868 |
}
|
869 |
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
// Member only menus end in _wpac
|
953 |
-
$theme_location = $args['theme_location'] . '_wpac';
|
954 |
-
|
955 |
-
// Get the nav menu based on the theme_location
|
956 |
-
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
|
957 |
-
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
|
958 |
-
|
959 |
-
// Only use the member only menu if it's not empty
|
960 |
-
if ( $menu && $menu->count > 0 ) {
|
961 |
-
$args['theme_location'] = $theme_location;
|
962 |
-
}
|
963 |
-
}
|
964 |
-
}
|
965 |
-
}
|
966 |
-
|
967 |
-
return $args;
|
968 |
-
}
|
969 |
}
|
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.0
|
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 |
+
require dirname(__FILE__) . '/lib/Walker.php';
|
12 |
+
|
13 |
+
add_action('after_setup_theme', array('WordPressAccessControl', 'load_custom_widgets'));
|
14 |
+
add_action('wp', array('WordPressAccessControl', 'check_for_members_only'));
|
15 |
+
add_action('wp', array('WordPressAccessControl', 'check_for_nonmembers_only'));
|
16 |
+
add_action('init', array('WordPressAccessControl', 'add_wpac_nav_menus'));
|
17 |
+
add_action('admin_init', array('WordPressAccessControl', 'admin_init'));
|
18 |
+
add_action('admin_menu', array('WordPressAccessControl', 'admin_menu'));
|
19 |
+
add_action('add_meta_boxes', array('WordPressAccessControl', 'add_wp_access_meta_boxes'));
|
20 |
+
add_action('save_post', array('WordPressAccessControl', 'save_postdata'));
|
21 |
+
add_action('manage_pages_custom_column', array('WordPressAccessControl', 'show_column'));
|
22 |
+
|
23 |
+
add_filter('get_pages', array('WordPressAccessControl', 'get_pages'));
|
24 |
+
add_filter('manage_edit-page_columns', array('WordPressAccessControl', 'add_column'));
|
25 |
+
add_filter('the_excerpt', array('WordPressAccessControl', 'remove_excerpt'));
|
26 |
+
add_filter('the_content', array('WordPressAccessControl', 'remove_excerpt'));
|
27 |
+
add_filter('plugin_row_meta', array('WordPressAccessControl', 'plugin_row_meta'), 10, 5);
|
28 |
+
add_filter('posts_join_paged', array('WordPressAccessControl', 'posts_join_paged'), 10, 2);
|
29 |
+
add_filter('posts_where_paged', array('WordPressAccessControl', 'posts_where_paged'), 10, 2);
|
30 |
+
add_filter('wp_nav_menu_args', array('WordPressAccessControl', 'wp_nav_menu_members_only'));
|
31 |
+
add_filter('wp_nav_menu_args', array('WordPressAccessControl', 'wp_nav_menu_args'));
|
32 |
+
add_filter('wp_page_menu_args', array('WordPressAccessControl' , 'wp_page_menu_args'));
|
33 |
+
|
34 |
+
add_shortcode('member', array('WordPressAccessControl', 'shortcode_members'));
|
35 |
+
add_shortcode('members', array('WordPressAccessControl', 'shortcode_members'));
|
36 |
+
add_shortcode('non-members', array('WordPressAccessControl', 'shortcode_nonmembers'));
|
37 |
+
add_shortcode('nonmembers', array('WordPressAccessControl', 'shortcode_nonmembers'));
|
38 |
+
add_shortcode('non-member', array('WordPressAccessControl', 'shortcode_nonmembers'));
|
39 |
+
add_shortcode('nonmember', array('WordPressAccessControl', 'shortcode_nonmembers'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
/**
|
42 |
* The main plugin
|
43 |
*
|
44 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
|
|
|
|
45 |
*/
|
46 |
class WordPressAccessControl
|
47 |
{
|
48 |
+
public static function admin_init()
|
49 |
+
{
|
50 |
+
wp_enqueue_style('wpac-style', plugin_dir_url(__FILE__) . 'public/css/wpac.css');
|
51 |
+
|
52 |
+
// Load translation files
|
53 |
+
if (!load_plugin_textdomain('wpac')) {
|
54 |
+
load_plugin_textdomain('wpac', false, 'wordpress-access-control/languages/');
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
public static function admin_menu()
|
59 |
+
{
|
60 |
+
add_options_page('WordPress Access Control Settings', 'Members Only', 'manage_options', 'wpac-options', array('WordPressAccessControl', 'options_page'));
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function options_page()
|
64 |
+
{
|
65 |
+
// Save options?
|
66 |
+
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'update') {
|
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);
|
74 |
+
} else {
|
75 |
+
update_option('wpac_members_only_blog', false);
|
76 |
+
}
|
77 |
+
|
78 |
+
// Members blog redirect link
|
79 |
+
if (isset($_REQUEST['wpac_members_blog_redirect'])) {
|
80 |
+
update_option('wpac_members_blog_redirect', esc_url($_REQUEST['wpac_members_blog_redirect']));
|
81 |
+
} else {
|
82 |
+
delete_option('wpac_members_blog_redirect');
|
83 |
+
}
|
84 |
+
|
85 |
+
// Support custom post types
|
86 |
+
if (isset($_REQUEST['wpac_custom_post_types']) && is_array($_REQUEST['wpac_custom_post_types'])) {
|
87 |
+
update_option('wpac_custom_post_types', $_REQUEST['wpac_custom_post_types']);
|
88 |
+
} else {
|
89 |
+
delete_option('wpac_custom_post_types');
|
90 |
+
}
|
91 |
+
|
92 |
+
// Override per-page permissions
|
93 |
+
if (isset($_REQUEST['wpac_always_accessible_by']) && is_array($_REQUEST['wpac_always_accessible_by'])) {
|
94 |
+
$wpac_always_accessible_by = array();
|
95 |
+
|
96 |
+
foreach ($_REQUEST['wpac_always_accessible_by'] as $role) {
|
97 |
+
$wpac_always_accessible_by[] = $role;
|
98 |
+
}
|
99 |
+
|
100 |
+
update_option('wpac_always_accessible_by', $wpac_always_accessible_by);
|
101 |
+
} else {
|
102 |
+
update_option('wpac_always_accessible_by', array());
|
103 |
+
}
|
104 |
+
|
105 |
+
// Show in the menu settings
|
106 |
+
if (isset($_REQUEST['wpac_show_in_menus']) && $_REQUEST['wpac_show_in_menus'] == 'always') {
|
107 |
+
update_option('wpac_show_in_menus', 'always');
|
108 |
+
} else {
|
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
|
141 |
+
if (isset($_REQUEST['wpac_default_members_redirect']) && !empty($_REQUEST['wpac_default_members_redirect'])) {
|
142 |
+
update_option('wpac_default_members_redirect', $_REQUEST['wpac_default_members_redirect']);
|
143 |
+
} else {
|
144 |
+
update_option('wpac_default_members_redirect', '');
|
145 |
+
}
|
146 |
+
|
147 |
+
// Search Options
|
148 |
+
if (isset($_REQUEST['show_posts_in_search']) && $_REQUEST['show_posts_in_search'] == 'yes') {
|
149 |
+
update_option('wpac_show_posts_in_search', true);
|
150 |
+
} else {
|
151 |
+
update_option('wpac_show_posts_in_search', false);
|
152 |
+
}
|
153 |
+
|
154 |
+
if (isset($_REQUEST['show_post_excerpts_in_search']) && $_REQUEST['show_post_excerpts_in_search'] == 'yes') {
|
155 |
+
update_option('wpac_show_post_excerpts_in_search', true);
|
156 |
+
} else {
|
157 |
+
update_option('wpac_show_post_excerpts_in_search', false);
|
158 |
+
}
|
159 |
+
|
160 |
+
if (isset($_REQUEST['show_pages_in_search']) && $_REQUEST['show_pages_in_search'] == 'yes') {
|
161 |
+
update_option('wpac_show_pages_in_search', true);
|
162 |
+
} else {
|
163 |
+
update_option('wpac_show_pages_in_search', false);
|
164 |
+
}
|
165 |
+
|
166 |
+
if (isset($_REQUEST['show_page_excerpts_in_search']) && $_REQUEST['show_page_excerpts_in_search'] == 'yes') {
|
167 |
+
update_option('wpac_show_page_excerpts_in_search', true);
|
168 |
+
} else {
|
169 |
+
update_option('wpac_show_page_excerpts_in_search', false);
|
170 |
+
}
|
171 |
+
|
172 |
+
// Custom excerpts
|
173 |
+
if (isset($_REQUEST['page_excerpt_text'])) {
|
174 |
+
update_option('wpac_page_excerpt_text', $_REQUEST['page_excerpt_text']);
|
175 |
+
}
|
176 |
+
|
177 |
+
if (isset($_REQUEST['post_excerpt_text'])) {
|
178 |
+
update_option('wpac_post_excerpt_text', $_REQUEST['post_excerpt_text']);
|
179 |
+
}
|
180 |
+
|
181 |
+
$admin_message = '<strong>' . __('Settings Saved.') . '</strong>';
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
include(dirname(__FILE__) . '/templates/options.php');
|
186 |
+
}
|
187 |
+
|
188 |
+
public static function add_column($columns)
|
189 |
+
{
|
190 |
+
$columns['wpac'] = '<img src="' . plugin_dir_url(__FILE__) . 'public/images/lock.png" alt="Access" />';
|
191 |
+
return $columns;
|
192 |
+
}
|
193 |
+
|
194 |
+
public static function show_column($name)
|
195 |
+
{
|
196 |
+
global $post;
|
197 |
+
|
198 |
+
switch ($name) {
|
199 |
+
case 'wpac':
|
200 |
+
if (get_post_meta($post->ID, '_wpac_is_members_only', true)) {
|
201 |
+
echo '<img src="' . plugin_dir_url(__FILE__) . 'public/images/lock.png" alt="Members Only" title="Members Only" />';
|
202 |
+
} else if (get_post_meta($post->ID, '_wpac_is_nonmembers_only', true)) {
|
203 |
+
echo '<img src="' . plugin_dir_url(__FILE__) . 'public/images/unlock.png" alt="Non-members Only" title="Non-members Only" />';
|
204 |
+
}
|
205 |
+
|
206 |
+
break;
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
public static function check_conditions($page_id)
|
211 |
+
{
|
212 |
+
global $wp_roles, $current_user;
|
213 |
+
|
214 |
+
if (is_user_logged_in()) {
|
215 |
+
get_currentuserinfo();
|
216 |
+
|
217 |
+
$allowed_roles = maybe_unserialize(get_post_meta($page_id, '_wpac_restricted_to', true));
|
218 |
+
$override_roles = maybe_unserialize(get_option('wpac_always_accessible_by', array(0 => 'administrator')));
|
219 |
+
|
220 |
+
if (empty($allowed_roles)) {
|
221 |
+
$allowed_roles_tmp = $wp_roles->get_names();
|
222 |
+
$allowed_roles = array();
|
223 |
+
|
224 |
+
foreach ($allowed_roles_tmp as $role => $garbage) {
|
225 |
+
$allowed_roles[] = $role;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
$intersections = array_intersect($current_user->roles, $allowed_roles);
|
230 |
+
$override_intersections = array_intersect($current_user->roles, $override_roles);
|
231 |
+
|
232 |
+
if (empty($intersections) && empty($override_intersections)) {
|
233 |
+
$role = false;
|
234 |
+
} else {
|
235 |
+
$role = true;
|
236 |
+
}
|
237 |
+
} else {
|
238 |
+
$role = true;
|
239 |
+
}
|
240 |
+
|
241 |
+
$is_members_only = get_post_meta($page_id, '_wpac_is_members_only', true);
|
242 |
+
$is_nonmembers_only = get_post_meta($page_id, '_wpac_is_nonmembers_only', true);
|
243 |
+
|
244 |
+
return ((is_user_logged_in() && $is_members_only && $role) || (!is_user_logged_in() && $is_nonmembers_only) || (!$is_members_only && !$is_nonmembers_only));
|
245 |
+
}
|
246 |
+
|
247 |
+
public static function check_for_members_only()
|
248 |
+
{
|
249 |
+
global $post;
|
250 |
+
|
251 |
+
if (is_admin()) return;
|
252 |
+
|
253 |
+
// Check for a members only blog
|
254 |
+
$blog_is_members_only = get_option('wpac_members_only_blog', false);
|
255 |
+
|
256 |
+
if ($blog_is_members_only && !is_user_logged_in()) {
|
257 |
+
$redirect_to = get_option('wpac_members_blog_redirect', wp_login_url($_SERVER['REQUEST_URI']));
|
258 |
+
|
259 |
+
if (empty($redirect_to)) {
|
260 |
+
$redirect_to = wp_login_url($_SERVER['REQUEST_URI']);
|
261 |
+
}
|
262 |
+
|
263 |
+
header('Location: ' . add_query_arg('redirect_to', $_SERVER['REQUEST_URI'], $redirect_to));
|
264 |
+
exit();
|
265 |
+
}
|
266 |
+
|
267 |
+
if (get_post_meta($post->ID, '_wpac_is_members_only', true) && !WordPressAccessControl::check_conditions($post->ID)) {
|
268 |
+
if (is_singular()) {
|
269 |
+
$redirect_to = get_post_meta($post->ID, '_wpac_members_redirect_to', true);
|
270 |
+
|
271 |
+
if (empty($redirect_to)) {
|
272 |
+
header('Location: ' . get_bloginfo('wpurl') . '/wp-login.php?redirect_to=' . $_SERVER['REQUEST_URI']);
|
273 |
+
} else {
|
274 |
+
header('Location: ' . add_query_arg('redirect_to', $_SERVER['REQUEST_URI'], $redirect_to));
|
275 |
+
}
|
276 |
+
|
277 |
+
exit();
|
278 |
+
}
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
public static function check_for_nonmembers_only()
|
283 |
+
{
|
284 |
+
if (is_admin()) return;
|
285 |
+
|
286 |
+
global $post;
|
287 |
+
|
288 |
+
if (get_post_meta($post->ID, '_wpac_is_nonmembers_only', true) && !WordPressAccessControl::check_conditions($post->ID)) {
|
289 |
+
$redirect_to = get_post_meta($post->ID, '_wpac_nonmembers_redirect_to', true);
|
290 |
+
|
291 |
+
if (empty($redirect_to)) {
|
292 |
+
header('Location: ' . get_bloginfo('wpurl') . '/index.php');
|
293 |
+
} else {
|
294 |
+
header('Location: ' . $redirect_to);
|
295 |
+
}
|
296 |
+
|
297 |
+
exit();
|
298 |
+
}
|
299 |
+
}
|
300 |
+
|
301 |
+
public static function remove_excerpt($excerpt)
|
302 |
+
{
|
303 |
+
if (is_admin() || is_single()) return $excerpt;
|
304 |
+
|
305 |
+
global $post;
|
306 |
+
|
307 |
+
if (get_post_meta($post->ID, '_wpac_is_members_only', true) && !WordPressAccessControl::check_conditions($post->ID)) {
|
308 |
+
$show_excerpt = get_post_meta($post->ID, '_wpac_show_excerpt_in_search', true);
|
309 |
+
|
310 |
+
if (!is_singular() && $show_excerpt != 'yes') {
|
311 |
+
if ($post->post_type == 'post') {
|
312 |
+
$excerpt = get_option('wpac_post_excerpt_text', __('To view the contents of this post, you must be authenticated and have the required access level.', 'wpac'));
|
313 |
+
} else {
|
314 |
+
$excerpt = get_option('wpac_page_excerpt_text', __('To view the contents of this page, you must be authenticated and have the required access level.', 'wpac'));
|
315 |
+
}
|
316 |
+
|
317 |
+
return wpautop($excerpt);
|
318 |
+
} else {
|
319 |
+
return $excerpt;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
return $excerpt;
|
324 |
+
}
|
325 |
+
|
326 |
+
public static function posts_join_paged($join, $query)
|
327 |
+
{
|
328 |
+
global $wpdb;
|
329 |
+
|
330 |
+
if (is_admin()) return $join;
|
331 |
+
|
332 |
+
if (!is_singular() && !is_admin()) {
|
333 |
+
$join .= " LEFT JOIN {$wpdb->postmeta} PMWPAC3 ON PMWPAC3.post_id = {$wpdb->posts}.ID AND PMWPAC3.meta_key = '_wpac_show_in_search' LEFT JOIN {$wpdb->postmeta} PMWPAC ON PMWPAC.post_id = {$wpdb->posts}.ID AND PMWPAC.meta_key = '_wpac_is_members_only' LEFT JOIN {$wpdb->postmeta} PMWPAC2 ON PMWPAC2.post_id = {$wpdb->posts}.ID AND PMWPAC2.meta_key = '_wpac_is_nonmembers_only' ";
|
334 |
+
}
|
335 |
+
|
336 |
+
return $join;
|
337 |
+
}
|
338 |
+
|
339 |
+
public static function posts_where_paged($where, $query)
|
340 |
+
{
|
341 |
+
global $wpdb;
|
342 |
+
|
343 |
+
if (is_admin()) return $where;
|
344 |
+
|
345 |
+
if (!is_singular() && !is_admin()) {
|
346 |
+
if (!is_user_logged_in()) {
|
347 |
+
$where .= " AND (PMWPAC.meta_value IS NULL OR PMWPAC3.meta_value = '1' OR PMWPAC.meta_value != 'true') ";
|
348 |
+
} else {
|
349 |
+
$where .= " AND (PMWPAC2.meta_value IS NULL OR PMWPAC2.meta_value != 'true') ";
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
return $where;
|
354 |
+
}
|
355 |
+
|
356 |
+
public static function remove_restricted_posts($posts, $query = false)
|
357 |
+
{
|
358 |
+
return $posts;
|
359 |
+
echo $query->request;exit();
|
360 |
+
|
361 |
+
if (!is_singular() && !is_admin()) {
|
362 |
+
$new_posts = array();
|
363 |
+
|
364 |
+
foreach ($posts as $post) {
|
365 |
+
// The page is members only and we do NOT have access to it
|
366 |
+
if (get_post_meta($post->ID, '_wpac_is_members_only', true) && !WordPressAccessControl::check_conditions($post->ID)) {
|
367 |
+
if (get_post_meta($post->ID, '_wpac_show_in_search', true) != 1) {
|
368 |
+
continue;
|
369 |
+
}
|
370 |
+
}
|
371 |
+
|
372 |
+
// The page is non-members only and we do NOT have access to it
|
373 |
+
if (get_post_meta($post->ID, '_wpac_is_nonmembers_only', true) && !WordPressAccessControl::check_conditions($post->ID)) {
|
374 |
+
if (get_post_meta($post->ID, '_wpac_show_in_search', true) != 1) {
|
375 |
+
continue;
|
376 |
+
}
|
377 |
+
}
|
378 |
+
|
379 |
+
// Remove results where the search term is in a [member] or [nonmember] tag and we don't have access
|
380 |
+
$st = get_search_query();
|
381 |
+
$content = do_shortcode($post->post_content);
|
382 |
+
|
383 |
+
|
384 |
+
if (!empty($st) && is_search() && !stristr($content, $st)) {
|
385 |
+
continue;
|
386 |
+
}
|
387 |
+
|
388 |
+
$new_posts[] = $post;
|
389 |
+
}
|
390 |
+
|
391 |
+
$query->found_posts = count($new_posts);
|
392 |
+
$query->max_num_pages = ceil(count($new_posts) / $query->query_vars['posts_per_page']);
|
393 |
+
$query->posts = $new_posts;
|
394 |
+
$query->post_count = count($new_posts);
|
395 |
+
|
396 |
+
return $new_posts;
|
397 |
+
}
|
398 |
+
|
399 |
+
return $posts;
|
400 |
+
}
|
401 |
+
|
402 |
+
/**
|
403 |
+
* Add our custom meta box to all support post types
|
404 |
+
*
|
405 |
+
* @since WordPress Access Control 2.0
|
406 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
407 |
+
*/
|
408 |
+
public static function add_wp_access_meta_boxes()
|
409 |
+
{
|
410 |
+
$enabled_post_types = get_option('wpac_custom_post_types', array());
|
411 |
+
$supported_pages = apply_filters('wp_access_supported_pages', array_merge(array('page', 'post'), $enabled_post_types));
|
412 |
+
|
413 |
+
foreach ($supported_pages as $page_type) {
|
414 |
+
add_meta_box('wpac_controls_meta', 'WordPress Access Control', array('WordPressAccessControl', 'add_wpac_meta_box'), $page_type, 'side', 'high');
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Display the various per-page/per-post options in the sidebar
|
420 |
+
*
|
421 |
+
* @since WordPress Access Control 2.0
|
422 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
423 |
+
*/
|
424 |
+
public static function add_wpac_meta_box()
|
425 |
+
{
|
426 |
+
global $post;
|
427 |
+
|
428 |
+
$is_members_only = get_post_meta($post->ID, '_wpac_is_members_only', true);
|
429 |
+
$is_nonmembers_only = get_post_meta($post->ID, '_wpac_is_nonmembers_only', true);
|
430 |
+
|
431 |
+
if ($post->post_type == 'post') {
|
432 |
+
$wpac_default_post_state = get_option('wpac_default_post_state', 'public');
|
433 |
+
} else {
|
434 |
+
$wpac_default_post_state = get_option('wpac_default_page_state', 'public');
|
435 |
+
}
|
436 |
+
|
437 |
+
if ($is_members_only == 'true' || ($post->post_status == 'auto-draft' && $wpac_default_post_state == 'members')) {
|
438 |
+
$is_members_only = 'checked="checked"';
|
439 |
+
}
|
440 |
+
|
441 |
+
if ($is_nonmembers_only == 'true' || ($post->post_status == 'auto-draft' && $wpac_default_post_state == 'nonmembers')) {
|
442 |
+
$is_nonmembers_only = 'checked="checked"';
|
443 |
+
}
|
444 |
+
|
445 |
+
$wpac_show_in_search = get_post_meta($post->ID, '_wpac_show_in_search', true);
|
446 |
+
$wpac_show_excerpt_in_search = get_post_meta($post->ID, '_wpac_show_excerpt_in_search', true);
|
447 |
+
$pass_to_children = get_post_meta($post->ID, '_wpac_pass_to_children', true);
|
448 |
+
|
449 |
+
include(dirname(__FILE__) . '/templates/meta_box.php');
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Saves our custom meta data for the post being saved
|
454 |
+
*
|
455 |
+
* @since WordPress Access Control 2.0
|
456 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
457 |
+
*/
|
458 |
+
public static function save_postdata($post_id)
|
459 |
+
{
|
460 |
+
// Security check
|
461 |
+
if (!isset($_POST['members_only_nonce'])) {
|
462 |
+
return $post_id;
|
463 |
+
}
|
464 |
+
|
465 |
+
if (!wp_verify_nonce($_POST['members_only_nonce'], 'members_only')) {
|
466 |
+
return $post_id;
|
467 |
+
}
|
468 |
+
|
469 |
+
// Meta data isn't transmitted during autosaves so don't do anything
|
470 |
+
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
|
471 |
+
return $post_id;
|
472 |
+
}
|
473 |
+
|
474 |
+
if (isset($_POST['members_only']) && $_POST['members_only'] == 'true') {
|
475 |
+
update_post_meta($post_id, '_wpac_is_members_only', 'true');
|
476 |
+
|
477 |
+
if (isset($_POST['wpac_restricted_to']) && !empty($_POST['wpac_restricted_to'])) {
|
478 |
+
update_post_meta($post_id, '_wpac_restricted_to', serialize($_POST['wpac_restricted_to']));
|
479 |
+
} else {
|
480 |
+
delete_post_meta($post_id, '_wpac_restricted_to');
|
481 |
+
}
|
482 |
+
} else {
|
483 |
+
delete_post_meta($post_id, '_wpac_is_members_only');
|
484 |
+
}
|
485 |
+
|
486 |
+
if (isset($_POST['nonmembers_only']) && $_POST['nonmembers_only'] == 'true') {
|
487 |
+
update_post_meta($post_id, '_wpac_is_nonmembers_only', 'true');
|
488 |
+
} else {
|
489 |
+
delete_post_meta($post_id, '_wpac_is_nonmembers_only');
|
490 |
+
}
|
491 |
+
|
492 |
+
if (isset($_POST['wpac_members_redirect_to'])) {
|
493 |
+
update_post_meta($post_id, '_wpac_members_redirect_to', $_POST['wpac_members_redirect_to']);
|
494 |
+
}
|
495 |
+
|
496 |
+
if (isset($_POST['wpac_show_in_search'])) {
|
497 |
+
update_post_meta($post_id, '_wpac_show_in_search', 1);
|
498 |
+
} else {
|
499 |
+
update_post_meta($post_id, '_wpac_show_in_search', 0);
|
500 |
+
}
|
501 |
+
|
502 |
+
if (isset($_POST['wpac_show_excerpt_in_search'])) {
|
503 |
+
update_post_meta($post_id, '_wpac_show_excerpt_in_search', 1);
|
504 |
+
} else {
|
505 |
+
update_post_meta($post_id, '_wpac_show_excerpt_in_search', 0);
|
506 |
+
}
|
507 |
+
|
508 |
+
if (isset($_POST['wpac_nonmembers_redirect_to'])) {
|
509 |
+
update_post_meta($post_id, '_wpac_nonmembers_redirect_to', $_POST['wpac_nonmembers_redirect_to']);
|
510 |
+
}
|
511 |
+
|
512 |
+
if (isset($_POST['pass_to_children']) && $_POST['pass_to_children'] == 'true') {
|
513 |
+
update_post_meta($post_id, '_wpac_pass_to_children', 'true');
|
514 |
+
|
515 |
+
$original_id = $post_id;
|
516 |
+
$is_revision = wp_is_post_revision($original_id);
|
517 |
+
|
518 |
+
if ($is_revision) {
|
519 |
+
$original_id = $is_revision;
|
520 |
+
}
|
521 |
+
|
522 |
+
$children = get_pages(array('child_of' => $original_id));
|
523 |
+
|
524 |
+
foreach ($children as $child) {
|
525 |
+
WordPressAccessControl::save_postdata($child->ID);
|
526 |
+
}
|
527 |
+
} else {
|
528 |
+
delete_post_meta($post_id, '_wpac_pass_to_children');
|
529 |
+
}
|
530 |
+
|
531 |
+
return $post_id;
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Replaces the default WordPress nav menu walker with our own version
|
536 |
+
*
|
537 |
+
* @param array $args The arguments passed to the wp_nav_menu function
|
538 |
+
*
|
539 |
+
* @return array The original arguments, with our custom walker instead of the default
|
540 |
+
*
|
541 |
+
* @since WordPress Access Control 1.1
|
542 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
543 |
+
*/
|
544 |
+
public static function wp_nav_menu_args($args)
|
545 |
+
{
|
546 |
+
$args['walker'] = new WpacSecureWalker($args['walker']);
|
547 |
+
return $args;
|
548 |
+
}
|
549 |
+
|
550 |
+
/**
|
551 |
+
* Prevents the code from degrading terribly when no nav menu is available
|
552 |
+
*
|
553 |
+
* @param array $args The arguments passed to the wp_nav_menu function
|
554 |
+
*
|
555 |
+
* @return array The original arguments, possible with our custom walker instead of the default
|
556 |
+
*
|
557 |
+
* @since WordPress Access Control 1.2
|
558 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
559 |
+
*/
|
560 |
+
public static function wp_page_menu_args($args)
|
561 |
+
{
|
562 |
+
// Only remove the walker if it is ours
|
563 |
+
if (isset($args['walker']) && get_class($args['walker']) == 'WpacSecureWalker') {
|
564 |
+
$args['walker'] = new WpacSecureWalker(new Walker_Page());
|
565 |
+
} else {
|
566 |
+
$args['walker'] = new WpacSecureWalker($args['walker']);
|
567 |
+
}
|
568 |
+
|
569 |
+
return $args;
|
570 |
+
}
|
571 |
+
|
572 |
+
/**
|
573 |
+
* This hooks in at a higher level to make sure functions like wp_list_pages
|
574 |
+
* won't return members only pages.
|
575 |
+
*
|
576 |
+
* @param array $pages
|
577 |
+
* @return array
|
578 |
+
*
|
579 |
+
* @since WordPress Access Control 1.6.4
|
580 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
581 |
+
*/
|
582 |
+
public static function get_pages($pages)
|
583 |
+
{
|
584 |
+
// Don't affect the display of pages when viewing the list in the admin
|
585 |
+
if (is_admin()) {
|
586 |
+
return $pages;
|
587 |
+
}
|
588 |
+
|
589 |
+
// Whether or not the user is logged in
|
590 |
+
$auth = is_user_logged_in();
|
591 |
+
|
592 |
+
// Go through each page, remove ones we can't see
|
593 |
+
foreach ($pages as $key => $page) {
|
594 |
+
$is_members_only = get_post_meta($page->ID, '_wpac_is_members_only', true);
|
595 |
+
$is_nonmembers_only = get_post_meta($page->ID, '_wpac_is_nonmembers_only', true);
|
596 |
+
|
597 |
+
if ($is_members_only && !$auth) {
|
598 |
+
unset($pages[$key]);
|
599 |
+
}
|
600 |
+
|
601 |
+
if ($is_nonmembers_only && $auth) {
|
602 |
+
unset($pages[$key]);
|
603 |
+
}
|
604 |
+
}
|
605 |
+
|
606 |
+
return $pages;
|
607 |
+
}
|
608 |
+
|
609 |
+
/**
|
610 |
+
* Adds links to the plugin row to view the options page or view the plugin
|
611 |
+
* documentation.
|
612 |
+
*
|
613 |
+
* @param array $plugin_meta The links to display in the plugin row
|
614 |
+
* @param string $plugin_file The directory name and filename of the plugin (wordpress-access-control/wordpress-access-control.php)
|
615 |
+
* @param array $plugin_data
|
616 |
+
* @param string $status The status of the plugin (active or inactive)
|
617 |
+
*
|
618 |
+
* @return array The $plugin_meta array of links for this plugin
|
619 |
+
*
|
620 |
+
* @uses plugin_dir_url() to get the URL of the plugin directory since that is where the documentation is
|
621 |
+
*
|
622 |
+
* @since WordPress Access Control 3.0
|
623 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
624 |
+
*/
|
625 |
+
public static function plugin_row_meta($plugin_meta, $plugin_file, $plugin_data, $status)
|
626 |
+
{
|
627 |
+
if ($plugin_file == str_replace('.php', '/', basename(__FILE__)) . basename(__FILE__)) {
|
628 |
+
$plugin_meta[] = '<a href="options-general.php?page=wpac-options">' . __('Visit options page', 'wpac') . '</a>';
|
629 |
+
$plugin_meta[] = '<a href="' . plugin_dir_url(__FILE__) . 'documentation/index.html">' . __('Plugin Documentation', 'wpac') . '</a>';
|
630 |
+
}
|
631 |
+
|
632 |
+
return $plugin_meta;
|
633 |
+
}
|
634 |
+
|
635 |
+
|
636 |
+
/**
|
637 |
+
* Hides content for users that are not logged in and displays content for
|
638 |
+
* users who are logged in. Calls do_shortcode on the content to allow
|
639 |
+
* nested shortcodes.
|
640 |
+
*
|
641 |
+
* @uses is_user_logged_in() to determine if the user is logged in or not
|
642 |
+
* @uses wpautop() to format the text in the shortcodes
|
643 |
+
* @uses do_shortcode() to execute nested shortcodes in our shortcode
|
644 |
+
*
|
645 |
+
* @since WordPress Access Control 3.0
|
646 |
+
* @author Brandon Wamboldt <brandon.wamboldt@gmail.com>
|
647 |
+
*/
|
648 |
+
public static function shortcode_members($attributes, $content = NULL)
|
649 |
+
{
|
650 |
+
global $current_user, $post;
|
651 |
+
|
652 |
+
if (is_user_logged_in()) {
|
|
|
|
|
653 |
if (isset($attributes['role'])) {
|
654 |
|
655 |
// Determine the syntax (Singular role, OR syntax or NOT syntax)
|
683 |
}
|
684 |
}
|
685 |
|
686 |
+
return wpautop(do_shortcode($content));
|
687 |
+
}
|
688 |
+
|
689 |
+
return '';
|
690 |
+
}
|
691 |
+
|
692 |
+
/**
|
693 |
+
* Hides content for users that are logged in and displays content for users
|
694 |
+
* who are not logged in. Calls do_shortcode on the content to allow nested
|
695 |
+
* shortcodes.
|
696 |
+
*
|
697 |
+
* @param array $attributes
|
698 |
+
* @param string $content
|
699 |
+
*/
|
700 |
+
public static function shortcode_nonmembers($attributes, $content = NULL)
|
701 |
+
{
|
702 |
+
global $post;
|
703 |
+
|
704 |
+
if (!is_user_logged_in()) {
|
705 |
+
return wpautop(do_shortcode($content));
|
706 |
+
}
|
707 |
+
|
708 |
+
return '';
|
709 |
+
}
|
710 |
+
|
711 |
+
/**
|
712 |
+
* Loads a file that will override certain WordPress default widgets with
|
713 |
+
* a slightly modified version that allows admins to select it's visibility
|
714 |
+
* (Members only or non members only).
|
715 |
+
*/
|
716 |
+
public static function load_custom_widgets()
|
717 |
+
{
|
718 |
+
require dirname(__FILE__) . '/default-widgets.php';
|
719 |
+
}
|
720 |
+
|
721 |
+
/**
|
722 |
+
* Adds our member only menus for each regular menu
|
723 |
+
*/
|
724 |
+
public static function add_wpac_nav_menus()
|
725 |
+
{
|
726 |
+
global $_wp_registered_nav_menus;
|
727 |
+
|
728 |
+
$original = (array) $_wp_registered_nav_menus;
|
729 |
+
|
730 |
+
foreach ($original as $location => $label) {
|
731 |
+
$_wp_registered_nav_menus[$location . '_wpac'] = $label . ' - Members Only';
|
732 |
+
}
|
733 |
+
}
|
734 |
+
|
735 |
+
/**
|
736 |
+
* Checks to see if a members only version of the current menu is available
|
737 |
+
* and will load that instead of the normal menu.
|
738 |
+
*
|
739 |
+
* @param array $args The arguments passed to the wp_nav_menu function
|
740 |
+
* @return array The original arguments, possible with a new value for theme_location
|
741 |
+
*/
|
742 |
+
public static function wp_nav_menu_members_only($args)
|
743 |
+
{
|
744 |
+
// Don't do anything if the user isn't logged in
|
745 |
+
if (is_user_logged_in()) {
|
746 |
+
|
747 |
+
// See if the theme even passed a proper menu ID
|
748 |
+
if (!empty($args['theme_location'])) {
|
749 |
+
|
750 |
+
// Member only menus end in _wpac
|
751 |
+
$theme_location = $args['theme_location'] . '_wpac';
|
752 |
+
|
753 |
+
// Get the nav menu based on the theme_location
|
754 |
+
if (($locations = get_nav_menu_locations()) && isset($locations[ $theme_location ])) {
|
755 |
+
$menu = wp_get_nav_menu_object($locations[ $theme_location ]);
|
756 |
+
|
757 |
+
// Only use the member only menu if it's not empty
|
758 |
+
if ($menu && $menu->count > 0) {
|
759 |
+
$args['theme_location'] = $theme_location;
|
760 |
+
}
|
761 |
+
}
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
return $args;
|
766 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
767 |
}
|