PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110913
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110913
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / dropins / bridges / _s2member-bbpress-bridge.php

_s2member-bbpress-bridge.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110913, at includes/dropins/bridges/_s2member-bbpress-bridge.php

285 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * s2Member Bridge plugin for bbPress®.
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\Dropins\Bridges\bbPress
15 * @deprecated Use bbPress® 2.0+ when possible.
16 * @since 3.0
17 */
18 /* -- This section for bbPress® parsing. --------------------------------------------------------------------------------
19
20 Version: 110604
21 Stable tag: 110604
22 Framework: WS-BB-DIP-110523
23
24 Tested up to: 1.0.3
25 Requires at least: 1.0.3
26 Requires: s2Member 110604+, bbPress® 1.0.3+
27
28 Copyright: © 2009 WebSharks, Inc.
29 License: GNU General Public License
30 Contributors: WebSharks, PriMoThemes
31 Author URI: http://www.primothemes.com/
32 Author: PriMoThemes.com / WebSharks, Inc.
33 Donate link: http://www.primothemes.com/donate/
34
35 Plugin Name: s2Member Bridge
36 Pro Module / Prices: http://www.s2member.com/prices/
37 Forum URI: http://www.primothemes.com/forums/viewforum.php?f=4
38 Privacy URI: http://www.primothemes.com/about/privacy-policy/
39 Professional Installation URI: http://www.s2member.com/professional-installation/
40 Plugin URI: http://www.primothemes.com/post/product/s2member-membership-plugin-with-paypal/
41 Description: Blocks all non-Member access to bbPress® forums. Only the login-page is available. Forum registration is redirected to your Membership Options Page for s2Member ( on your main WordPress® installation ). This way, a visitor can signup on your site, and gain Membership Access to your forums. This plugin will NOT work, until you've successfully integrated WordPress® into bbPress®. See: `bbPress® -> Settings -> WordPress® Integration`.
42 Tags: membership, members, member, register, signup, paypal, pay pal, s2member, subscriber, members only, bbpress, bb press, forums, forum, buddypress, buddy press, buddy press compatible, shopping cart, checkout, api, options panel included, websharks framework, w3c validated code, multi widget support, includes extensive documentation, highly extensible
43
44 -- end section for bbPress® parsing. --------------------------------------------------------------------------------- */
45 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
46 exit ("Do not access this file directly.");
47 /* ------------------------------------------------------------------------------------------------------------------- */
48 /**
49 * Numeric string 1|0 indicating true or false.
50 *
51 * The %%ovg%% string is replaced dynamically by the s2Member installer.
52 *
53 * @package s2Member\Dropins\Bridges\bbPress
54 * @since 3.5.8
55 *
56 * @var str
57 */
58 if (!defined ("WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_ALLOW_OPEN_VIEWING"))
59 define ("WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_ALLOW_OPEN_VIEWING", "%%ovg%%");
60 /**
61 * Numeric string [0-9]+ indicating an s2Member Access Level.
62 *
63 * The %%min%% string is replaced dynamically by the s2Member installer.
64 *
65 * @package s2Member\Dropins\Bridges\bbPress
66 * @since 3.0
67 *
68 * @var str
69 */
70 if (!defined ("WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_MIN_PARTICIPATION_LEVEL"))
71 define ("WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_MIN_PARTICIPATION_LEVEL", "%%min%%");
72 /* ------------------------------------------------------------------------------------------------------------------- */
73 /*
74 Adds an action for the function below.
75 */
76 add_action ("bb_init", "ws_plugin__s2member_bridge_bbpress_roles", 1);
77 /**/
78 if (!function_exists ("ws_plugin__s2member_bridge_bbpress_roles"))
79 {
80 /**
81 * Converts s2Member Roles into bbPress® "Members" on-the-fly.
82 *
83 * Only when no bbPress® Role has been assigned yet.
84 * This way a site owner can still modify Roles.
85 *
86 * @package s2Member\Dropins\Bridges\bbPress
87 * @since 3.0
88 *
89 * @return null
90 */
91 function ws_plugin__s2member_bridge_bbpress_roles () /* On-the-fly. */
92 {
93 if (is_object ($user = bb_get_current_user ()) && $user->ID) /* Logged in? */
94 {
95 if (empty ($user->roles)) /* Only if/when no bbPress® Role is assigned. */
96 {
97 bb_give_user_default_role ($user); /* Assign default Role. */
98 }
99 }
100 /**/
101 return; /* Return for uniformity. */
102 }
103 }
104 /* ------------------------------------------------------------------------------------------------------------------- */
105 /*
106 Adds an action for the function below.
107 */
108 add_action ("bb_init", "ws_plugin__s2member_bridge_bbpress_access", 1);
109 /**/
110 if (!function_exists ("ws_plugin__s2member_bridge_bbpress_access"))
111 {
112 /**
113 * Overall bbPress® security gate for s2Member.
114 *
115 * Deny all access to the bbPress® registration page.
116 * This will leave the bbPress® login page available, as it should be.
117 *
118 * @package s2Member\Dropins\Bridges\bbPress
119 * @since 3.0
120 *
121 * @return null
122 */
123 function ws_plugin__s2member_bridge_bbpress_access ()
124 {
125 $location = bb_get_location (); /* The current location. */
126 /**/
127 $wp_caps = bb_get_option ("wp_table_prefix") . "capabilities";
128 /**/
129 $ovg = (int)WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_ALLOW_OPEN_VIEWING;
130 $min = (int)WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_MIN_PARTICIPATION_LEVEL;
131 /**/
132 $open_viewing_possible = $ovg; /* Use this for additional clarity. */
133 /**/
134 if (!in_array ($location, array ("login-page", "register-page")))
135 {
136 if ($url = bb_get_option ("wp_siteurl")) /* WordPress® integrated? */
137 {
138 if (!$open_viewing_possible) /* If Open Viewing is NOT possible. */
139 {
140 if (!bb_is_user_logged_in () || !bb_current_user_can ("participate"))
141 {
142 $bbPress = bb_get_option ("url"); /* bbPress® URL location. */
143 /**/
144 if (preg_match ("/^" . preg_quote ($bbPress, "/") . "/", $_SERVER["HTTP_REFERER"]))
145 wp_redirect ($url, apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ()));
146 /**/
147 else /* Otherwise, trigger the Membership Options Page + s2member_level_req = $min. */
148 wp_redirect ($url . "/?s2member_membership_options_page=1&s2member_seeking=bbpress&s2member_level_req=" . urlencode ($min), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ()));
149 /**/
150 exit (); /* Clean exit. */
151 }
152 else if (is_object ($user = bb_get_current_user ()) && $user->ID && isset ($user->$wp_caps) && is_array ($user->$wp_caps))
153 {
154 $wp_role = reset (array_keys ($user->$wp_caps)); /* Looking for ^(subscriber|s2member_level[0-9]+)$. */
155 /**/
156 if (preg_match ("/^(subscriber|s2member_level[0-9]+)$/", $wp_role)) /* Subscribers and/or s2 Roles. */
157 {
158 if (($wp_role === "subscriber" && $min > 0) || ($level = str_replace ("s2member_level", "", $wp_role)) < $min)
159 {
160 $bbPress = bb_get_option ("url"); /* bbPress® URL location. */
161 /**/
162 if (preg_match ("/^" . preg_quote ($bbPress, "/") . "/", $_SERVER["HTTP_REFERER"]))
163 wp_redirect ($url, apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ()));
164 /**/
165 else /* Otherwise, redirect this User to your Membership Options Page. */
166 wp_redirect ($url . "/?s2member_membership_options_page=1&s2member_seeking=bbpress&s2member_level_req=" . urlencode ($min), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ()));
167 /**/
168 exit (); /* Clean exit. */
169 }
170 }
171 }
172 }
173 else if ($open_viewing_possible) /* Else, if Open Viewing IS possible. */
174 {
175 add_filter ("bb_current_user_can", "_ws_plugin__s2member_bridge_bbpress_access_caps", 10, 2);
176 /**/
177 if (!function_exists ("_ws_plugin__s2member_bridge_bbpress_access_caps"))
178 {
179 /**
180 * Filters `bb_current_user_can()` whenever Open Viewing is possible.
181 *
182 * @package s2Member\Dropins\Bridges\bbPress
183 * @since 3.5.8
184 *
185 * @param bool $can bbPress® default return value from `bb_current_user_can()`.
186 * @param str $cap bbPress® Role ID or bbPress® Capability *( i.e. `member`, `participate` )*.
187 * @return bool true if the current bbPress® User has the specified Role or Capability, else false.
188 */
189 function _ws_plugin__s2member_bridge_bbpress_access_caps ($can = FALSE, $cap = FALSE)
190 {
191 $wp_caps = bb_get_option ("wp_table_prefix") . "capabilities";
192 /**/
193 $min = (int)WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_MIN_PARTICIPATION_LEVEL;
194 /**/
195 if (!bb_is_user_logged_in ()) /* If/when they're NOT logged in; read-only. */
196 {
197 return ($cap === "read") ? true : false; /* Read-only access. */
198 }
199 else if (is_object ($user = bb_get_current_user ()) && $user->ID && isset ($user->$wp_caps) && is_array ($user->$wp_caps))
200 {
201 $wp_role = reset (array_keys ($user->$wp_caps)); /* Looking for ^(subscriber|s2member_level[0-9]+)$. */
202 /**/
203 if (preg_match ("/^(subscriber|s2member_level[0-9]+)$/", $wp_role)) /* Subscribers and/or s2 Roles. */
204 {
205 if (($wp_role === "subscriber" && $min > 0) || ($level = str_replace ("s2member_level", "", $wp_role)) < $min)
206 {
207 return ($cap === "read") ? true : false;
208 }
209 }
210 }
211 /**/
212 return $can; /* Return true|false. */
213 }
214 }
215 /**/
216 add_action ("post_post_form", "_ws_plugin__s2member_bridge_bbpress_access_post_form");
217 /**/
218 if (!function_exists ("_ws_plugin__s2member_bridge_bbpress_access_post_form"))
219 {
220 /**
221 * Displays a message whenever the current bbPress® User is unable to participate.
222 *
223 * @package s2Member\Dropins\Bridges\bbPress
224 * @since 3.5.8
225 *
226 * @return null
227 */
228 function _ws_plugin__s2member_bridge_bbpress_access_post_form ()
229 {
230 $min = (int)WS_PLUGIN__S2MEMBER_BRIDGE_BBPRESS_MIN_PARTICIPATION_LEVEL;
231 /**/
232 if (bb_is_user_logged_in () && !bb_current_user_can ("participate")) /* Unable to participate? */
233 {
234 echo '<p class="upgrade-line">Your Membership needs to be <a href="' . esc_attr (bb_get_option ("wp_siteurl") . "/?s2member_membership_options_page=1&s2member_seeking=bbpress&s2member_level_req=" . urlencode ($min)) . '" class="upgrade-link">upgraded</a> before you can Post.</p>';
235 }
236 /**/
237 return; /* Return for uniformity. */
238 }
239 }
240 }
241 }
242 }
243 else if (in_array ($location, array ("register-page"))) /* Send registration requests through WP. */
244 {
245 if ($url = bb_get_option ("wp_siteurl")) /* This will redirect registrants to your Membership Options Page. */
246 {
247 wp_redirect ($url . "/?s2member_membership_options_page=1&s2member_seeking=bbpress&s2member_level_req=" . urlencode ($min), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ()));
248 /**/
249 exit (); /* Clean exit. */
250 }
251 }
252 /**/
253 return; /* Return for uniformity. */
254 }
255 }
256 /* ------------------------------------------------------------------------------------------------------------------- */
257 /*
258 API function for Role Conditionals in bbPress®.
259 */
260 if (!function_exists ("current_wp_user_is"))
261 {
262 /**
263 * API function for Role Conditionals in bbPress®.
264 *
265 * @package s2Member\Dropins\Bridges\bbPress
266 * @since 3.5.8
267 *
268 * @param str $role WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
269 * @return bool true if the current bbPress® User has the specified Role, else false.
270 */
271 function current_wp_user_is ($role = FALSE)
272 {
273 $wp_caps = bb_get_option ("wp_table_prefix") . "capabilities";
274 /**/
275 if ($role && is_object ($user = bb_get_current_user ()) && $user->ID && isset ($user->$wp_caps) && is_array ($user->$wp_caps))
276 {
277 $wp_role = reset (array_keys ($user->$wp_caps));
278 /**/
279 return ($wp_role === $role);
280 }
281 else /* Nope. */
282 return false;
283 }
284 }
285 ?>