PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110710
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110710
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / functions / api-functions.inc.php

api-functions.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110710, at includes/functions/api-functions.inc.php

2,129 lines 96.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Core API Functions *( for site owners )*.
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\API_Functions
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit("Do not access this file directly.");
19 /**
20 * Conditional to determine if the current User is NOT logged in.
21 *
22 * Counterpart {@link http://codex.wordpress.org/Function_Reference/is_user_logged_in is_user_logged_in()} already exists in the WordPress® core.
23 *
24 * ———— Code Sample Using Both Functions ————
25 * ```
26 * <!php
27 * if(is_user_logged_in())
28 * echo 'You ARE logged in.';
29 *
30 * else if(is_user_not_logged_in())
31 * echo 'You are NOT logged in.';
32 * !>
33 * ```
34 * ———— Shortcode Conditional Equivalent ————
35 * ```
36 * [s2If is_user_logged_in()]
37 * You ARE logged in.
38 * [/s2If]
39 * [s2If is_user_not_logged_in()]
40 * You are NOT logged in.
41 * [/s2If]
42 * ```
43 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
44 *
45 * @package s2Member\API_Functions
46 * @since 3.5
47 *
48 * @return bool True if the current User is NOT logged in, else false.
49 *
50 * @see http://codex.wordpress.org/Function_Reference/is_user_logged_in is_user_logged_in()
51 */
52 if (!function_exists ("is_user_not_logged_in"))
53 {
54 function is_user_not_logged_in ()
55 {
56 return (!is_user_logged_in ());
57 }
58 }
59 /**
60 * Conditional to determine if a specific User is/has a specific Role.
61 *
62 * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress® core.
63 *
64 * ———— Code Sample Using Both Functions ————
65 * ```
66 * <!php
67 * if(user_is(123, "subscriber"))
68 * echo 'User ID# 123 is a Free Subscriber at Level #0.';
69 *
70 * else if(user_is(123, "s2member_level1"))
71 * echo 'User ID# 123 is a Member at Level #1.';
72 *
73 * else if(user_can(123, "access_s2member_level2"))
74 * echo 'User ID# 123 has access to content protected at Level #2.';
75 * # But, (important) they could actually be a Level #3 or #4 Member;
76 * # because Membership Levels provide incremental access.
77 * !>
78 * ```
79 *
80 * ———— Shortcode Conditional Equivalent ————
81 * ```
82 * [s2If user_is(123, subscriber)]
83 * User ID# 123 is a Free Subscriber at Level #0.
84 * [/s2If]
85 * [s2If user_is(123, s2member_level1)]
86 * User ID# 123 is a Member at Level #1.
87 * [/s2If]
88 * [s2If user_can(123, access_s2member_level2)]
89 * User ID# 123 has access to content protected at Level #2.
90 * [/s2If]
91 * ```
92 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
93 *
94 * ———— Membership Levels Provide Incremental Access ————
95 *
96 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
97 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
98 * o A Member with Level 2 access, will also be able to access Levels 0, 1
99 * o A Member with Level 1 access, will also be able to access Level 0.
100 * o A Subscriber with Level 0 access, can ONLY access Level 0.
101 * o A public Visitor will have NO access to protected content.
102 *
103 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
104 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
105 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
106 *
107 * @package s2Member\API_Functions
108 * @since 110524RC
109 *
110 * @param int|str $id A numeric WordPress® User ID.
111 * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
112 * @return bool True if the specific User is/has the specified Role, else false.
113 *
114 * @see s2Member\API_Functions\user_is()
115 * @see s2Member\API_Functions\user_is_not()
116 *
117 * @see s2Member\API_Functions\current_user_is()
118 * @see s2Member\API_Functions\current_user_is_not()
119 * @see s2Member\API_Functions\current_user_is_for_blog()
120 * @see s2Member\API_Functions\current_user_is_not_for_blog()
121 *
122 * @see s2Member\API_Functions\user_cannot()
123 * @see s2Member\API_Functions\current_user_cannot()
124 * @see s2Member\API_Functions\current_user_cannot_for_blog()
125 *
126 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
127 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
128 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
129 */
130 if (!function_exists ("user_is"))
131 {
132 function user_is ($id = FALSE, $role = FALSE)
133 {
134 $role = ($role === "s2member_level0") ? "subscriber" : $role;
135 return user_can ($id, preg_replace ("/^access_/i", "", $role));
136 }
137 }
138 /**
139 * Conditional to determine if a specific User is/does NOT have a specific Role.
140 *
141 * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress® core.
142 *
143 * ———— Code Sample Using Three Functions ————
144 * ```
145 * <!php
146 * if(user_is(123, "subscriber"))
147 * echo 'User ID# 123 is a Free Subscriber at Level #0.';
148 *
149 * else if(user_is(123, "s2member_level1"))
150 * echo 'User ID# 123 is a Member at Level #1.';
151 *
152 * else if(user_can(123, "access_s2member_level2") && user_is_not(123, "s2member_level2"))
153 * echo 'User ID# 123 has access to content protected at Level #2, but they are NOT a Level #2 Member.';
154 * # So, (important) they could actually be a Level #3 or #4 Member;
155 * # because Membership Levels provide incremental access.
156 * !>
157 * ```
158 * ———— Shortcode Conditional Equivalent ————
159 * ```
160 * [s2If user_is(123, subscriber)]
161 * User ID# 123 is a Free Subscriber at Level #0.
162 * [/s2If]
163 * [s2If user_is(123, s2member_level1)]
164 * User ID# 123 is a Member at Level #1.
165 * [/s2If]
166 * [s2If user_can(123, access_s2member_level2) AND user_is_not(123, s2member_level2)]
167 * User ID# 123 has access to content protected at Level #2, but they are NOT a Level #2 Member.
168 * [/s2If]
169 * ```
170 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
171 *
172 * ———— Membership Levels Provide Incremental Access ————
173 *
174 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
175 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
176 * o A Member with Level 2 access, will also be able to access Levels 0, 1
177 * o A Member with Level 1 access, will also be able to access Level 0.
178 * o A Subscriber with Level 0 access, can ONLY access Level 0.
179 * o A public Visitor will have NO access to protected content.
180 *
181 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
182 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
183 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
184 *
185 * @package s2Member\API_Functions
186 * @since 110524RC
187 *
188 * @param int|str $id A numeric WordPress® User ID.
189 * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
190 * @return bool True if the specific User is/does NOT have the specified Role, else false.
191 *
192 * @see s2Member\API_Functions\user_is()
193 * @see s2Member\API_Functions\user_is_not()
194 *
195 * @see s2Member\API_Functions\current_user_is()
196 * @see s2Member\API_Functions\current_user_is_not()
197 * @see s2Member\API_Functions\current_user_is_for_blog()
198 * @see s2Member\API_Functions\current_user_is_not_for_blog()
199 *
200 * @see s2Member\API_Functions\user_cannot()
201 * @see s2Member\API_Functions\current_user_cannot()
202 * @see s2Member\API_Functions\current_user_cannot_for_blog()
203 *
204 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
205 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
206 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
207 */
208 if (!function_exists ("user_is_not"))
209 {
210 function user_is_not ($id = FALSE, $role = FALSE)
211 {
212 $role = ($role === "s2member_level0") ? "subscriber" : $role;
213 return (!user_can ($id, preg_replace ("/^access_/i", "", $role)));
214 }
215 }
216 /**
217 * Conditional to determine if the current User is/has a specific Role.
218 *
219 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress® core.
220 *
221 * ———— Code Sample Using Both Functions ————
222 * ```
223 * <!php
224 * if(current_user_is("subscriber"))
225 * echo 'You ARE a Free Subscriber at Level #0.';
226 *
227 * else if(current_user_is("s2member_level1"))
228 * echo 'You ARE a Member at Level #1.';
229 *
230 * else if(current_user_can("access_s2member_level2"))
231 * echo 'You DO have access to content protected at Level #2.';
232 * # But, (important) they could actually be a Level #3 or #4 Member;
233 * # because Membership Levels provide incremental access.
234 * !>
235 * ```
236 *
237 * ———— Shortcode Conditional Equivalent ————
238 * ```
239 * [s2If curent_user_is(subscriber)]
240 * You ARE a Free Subscriber at Level #0.
241 * [/s2If]
242 * [s2If curent_user_is(s2member_level1)]
243 * You ARE a Member at Level #1.
244 * [/s2If]
245 * [s2If current_user_can(access_s2member_level2)]
246 * You DO have access to content protected at Level #2.
247 * [/s2If]
248 * ```
249 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
250 *
251 * ———— Membership Levels Provide Incremental Access ————
252 *
253 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
254 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
255 * o A Member with Level 2 access, will also be able to access Levels 0, 1
256 * o A Member with Level 1 access, will also be able to access Level 0.
257 * o A Subscriber with Level 0 access, can ONLY access Level 0.
258 * o A public Visitor will have NO access to protected content.
259 *
260 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
261 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
262 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
263 *
264 * @package s2Member\API_Functions
265 * @since 3.5
266 *
267 * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
268 * @return bool True if the current User is/has the specified Role, else false.
269 *
270 * @see s2Member\API_Functions\user_is()
271 * @see s2Member\API_Functions\user_is_not()
272 *
273 * @see s2Member\API_Functions\current_user_is()
274 * @see s2Member\API_Functions\current_user_is_not()
275 * @see s2Member\API_Functions\current_user_is_for_blog()
276 * @see s2Member\API_Functions\current_user_is_not_for_blog()
277 *
278 * @see s2Member\API_Functions\user_cannot()
279 * @see s2Member\API_Functions\current_user_cannot()
280 * @see s2Member\API_Functions\current_user_cannot_for_blog()
281 *
282 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
283 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
284 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
285 */
286 if (!function_exists ("current_user_is"))
287 {
288 function current_user_is ($role = FALSE)
289 {
290 $role = ($role === "s2member_level0") ? "subscriber" : $role;
291 return current_user_can (preg_replace ("/^access_/i", "", $role));
292 }
293 }
294 /**
295 * Conditional to determine if the current User is/does NOT have a specific Role.
296 *
297 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress® core.
298 *
299 * ———— Code Sample Using Three Functions ————
300 * ```
301 * <!php
302 * if(current_user_is("subscriber"))
303 * echo 'You ARE a Free Subscriber at Level #0.';
304 *
305 * else if(current_user_is("s2member_level1"))
306 * echo 'You ARE a Member at Level #1.';
307 *
308 * else if(current_user_can("access_s2member_level2") && current_user_is_not("s2member_level2"))
309 * echo 'You DO have access to content protected at Level #2, but you are NOT a Level #2 Member.';
310 * # So, (important) they could actually be a Level #3 or #4 Member;
311 * # because Membership Levels provide incremental access.
312 * !>
313 * ```
314 * ———— Shortcode Conditional Equivalent ————
315 * ```
316 * [s2If current_user_is(subscriber)]
317 * You ARE a Free Subscriber at Level #0.
318 * [/s2If]
319 * [s2If current_user_is(s2member_level1)]
320 * You ARE a Member at Level #1.
321 * [/s2If]
322 * [s2If current_user_can(access_s2member_level2) AND current_user_is_not(s2member_level2)]
323 * You DO have access to content protected at Level #2, but you are NOT a Level #2 Member.
324 * [/s2If]
325 * ```
326 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
327 *
328 * ———— Membership Levels Provide Incremental Access ————
329 *
330 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
331 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
332 * o A Member with Level 2 access, will also be able to access Levels 0, 1
333 * o A Member with Level 1 access, will also be able to access Level 0.
334 * o A Subscriber with Level 0 access, can ONLY access Level 0.
335 * o A public Visitor will have NO access to protected content.
336 *
337 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
338 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
339 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
340 *
341 * @package s2Member\API_Functions
342 * @since 3.5
343 *
344 * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
345 * @return bool True if the current User is/does NOT have the specified Role, else false.
346 *
347 * @see s2Member\API_Functions\user_is()
348 * @see s2Member\API_Functions\user_is_not()
349 *
350 * @see s2Member\API_Functions\current_user_is()
351 * @see s2Member\API_Functions\current_user_is_not()
352 * @see s2Member\API_Functions\current_user_is_for_blog()
353 * @see s2Member\API_Functions\current_user_is_not_for_blog()
354 *
355 * @see s2Member\API_Functions\user_cannot()
356 * @see s2Member\API_Functions\current_user_cannot()
357 * @see s2Member\API_Functions\current_user_cannot_for_blog()
358 *
359 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
360 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
361 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
362 */
363 if (!function_exists ("current_user_is_not"))
364 {
365 function current_user_is_not ($role = FALSE)
366 {
367 $role = ($role === "s2member_level0") ? "subscriber" : $role;
368 return (!current_user_can (preg_replace ("/^access_/i", "", $role)));
369 }
370 }
371 /**
372 * Conditional to determine if the current User is/has a specific Role, on a specific Blog within a Multisite Network.
373 *
374 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()} already exists in the WordPress® core.
375 *
376 * ———— Code Sample Using Three Functions ————
377 * ```
378 * <!php
379 * if(current_user_is("subscriber"))
380 * echo 'You ARE a Free Subscriber at Level #0 ( on this Blog ).';
381 *
382 * else if(current_user_is_for_blog(5, "subscriber"))
383 * echo 'You ARE a Free Subscriber at Level #0 ( on Blog ID 5 ).';
384 *
385 * else if(current_user_is_for_blog(5, "s2member_level1"))
386 * echo 'You ARE a Member at Level #1 ( on Blog ID 5 ).';
387 *
388 * else if(current_user_can_for_blog(5, "access_s2member_level2"))
389 * echo 'You DO have access to content protected at Level #2 ( on Blog ID 5 ).';
390 * # But, (important) they could actually be a Level #3 or #4 Member ( on Blog ID 5 );
391 * # because Membership Levels provide incremental access.
392 * !>
393 * ```
394 * ———— Shortcode Conditional Equivalent ————
395 * ```
396 * [s2If current_user_is(subscriber)]
397 * You ARE a Free Subscriber at Level #0 ( on this Blog ).
398 * [/s2If]
399 * [s2If current_user_is_for_blog(5, subscriber)]
400 * You ARE a Free Subscriber at Level #0 ( on Blog ID 5 ).
401 * [/s2If]
402 * [s2If current_user_is_for_blog(5, s2member_level1)]
403 * You ARE a Member at Level #1 ( on Blog ID 5 ).
404 * [/s2If]
405 * [s2If current_user_can_for_blog(5, access_s2member_level2)]
406 * You DO have access to content protected at Level #2 ( on Blog ID 5 ).
407 * [/s2If]
408 * ```
409 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
410 *
411 * ———— Membership Levels Provide Incremental Access ————
412 *
413 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
414 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
415 * o A Member with Level 2 access, will also be able to access Levels 0, 1
416 * o A Member with Level 1 access, will also be able to access Level 0.
417 * o A Subscriber with Level 0 access, can ONLY access Level 0.
418 * o A public Visitor will have NO access to protected content.
419 *
420 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
421 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
422 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
423 *
424 * @package s2Member\API_Functions
425 * @since 3.5
426 *
427 * @param int|str $blog_id A WordPress® Blog ID *( must be numeric )*.
428 * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
429 * @return bool True if the current User is/has the specified Role, on the specified Blog, else false.
430 *
431 * @see s2Member\API_Functions\user_is()
432 * @see s2Member\API_Functions\user_is_not()
433 *
434 * @see s2Member\API_Functions\current_user_is()
435 * @see s2Member\API_Functions\current_user_is_not()
436 * @see s2Member\API_Functions\current_user_is_for_blog()
437 * @see s2Member\API_Functions\current_user_is_not_for_blog()
438 *
439 * @see s2Member\API_Functions\user_cannot()
440 * @see s2Member\API_Functions\current_user_cannot()
441 * @see s2Member\API_Functions\current_user_cannot_for_blog()
442 *
443 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
444 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
445 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
446 */
447 if (!function_exists ("current_user_is_for_blog"))
448 {
449 function current_user_is_for_blog ($blog_id = FALSE, $role = FALSE)
450 {
451 $role = ($role === "s2member_level0") ? "subscriber" : $role;
452 return current_user_can_for_blog ($blog_id, preg_replace ("/^access_/i", "", $role));
453 }
454 }
455 /**
456 * Conditional to determine if the current User is/does NOT have a specific Role, on a specific Blog within a Multisite Network.
457 *
458 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()} already exists in the WordPress® core.
459 *
460 * ———— Code Sample Using Three Functions ————
461 * ```
462 * <!php
463 * if(current_user_is_for_blog(5, "subscriber"))
464 * echo 'You ARE a Free Subscriber at Level #0 ( on Blog ID 5 ).';
465 *
466 * else if(current_user_can_for_blog(5, "access_s2member_level1") && current_user_is_not_for_blog(5, "s2member_level1"))
467 * echo 'You DO have access to content protected at Level #1 ( on Blog ID 5 ), but you are NOT a Level #1 Member ( on Blog ID 5 ).';
468 * # So, (important) they could actually be a Level #2 or #3 or #4 Member ( on Blog ID 5 );
469 * # because Membership Levels provide incremental access.
470 * !>
471 * ```
472 * ———— Shortcode Conditional Equivalent ————
473 * ```
474 * [s2If current_user_is_for_blog(5, subscriber)]
475 * You ARE a Free Subscriber at Level #0 ( on Blog ID 5 ).
476 * [/s2If]
477 * [s2If current_user_can_for_blog(5, access_s2member_level1) AND current_user_is_not_for_blog(5, s2member_level1)]
478 * You DO have access to content protected at Level #1 ( on Blog ID 5 ), but you are NOT a Level #1 Member ( on Blog ID 5 ).
479 * [/s2If]
480 * ```
481 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
482 *
483 * ———— Membership Levels Provide Incremental Access ————
484 *
485 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
486 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
487 * o A Member with Level 2 access, will also be able to access Levels 0, 1
488 * o A Member with Level 1 access, will also be able to access Level 0.
489 * o A Subscriber with Level 0 access, can ONLY access Level 0.
490 * o A public Visitor will have NO access to protected content.
491 *
492 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
493 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
494 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
495 *
496 * @package s2Member\API_Functions
497 * @since 3.5
498 *
499 * @param int|str $blog_id A WordPress® Blog ID *( must be numeric )*.
500 * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
501 * @return bool True if the current User is/does NOT have the specified Role, on the specified Blog, else false.
502 *
503 * @see s2Member\API_Functions\user_is()
504 * @see s2Member\API_Functions\user_is_not()
505 *
506 * @see s2Member\API_Functions\current_user_is()
507 * @see s2Member\API_Functions\current_user_is_not()
508 * @see s2Member\API_Functions\current_user_is_for_blog()
509 * @see s2Member\API_Functions\current_user_is_not_for_blog()
510 *
511 * @see s2Member\API_Functions\user_cannot()
512 * @see s2Member\API_Functions\current_user_cannot()
513 * @see s2Member\API_Functions\current_user_cannot_for_blog()
514 *
515 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
516 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
517 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
518 */
519 if (!function_exists ("current_user_is_not_for_blog"))
520 {
521 function current_user_is_not_for_blog ($blog_id = FALSE, $role = FALSE)
522 {
523 $role = ($role === "s2member_level0") ? "subscriber" : $role;
524 return (!current_user_can_for_blog ($blog_id, preg_replace ("/^access_/i", "", $role)));
525 }
526 }
527 /**
528 * Conditional to determine if a specific User does NOT have a specific Capability or Role.
529 *
530 * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress® core.
531 *
532 * ———— Code Sample Using Both Functions ————
533 * ```
534 * <!php
535 * if(user_can(123, "access_s2member_level0"))
536 * echo 'User ID# 123 CAN access content protected at Level #0.';
537 *
538 * else if(user_cannot(123, "access_s2member_level0"))
539 * echo 'User ID# 123 CANNOT access content at Level #0.';
540 * !>
541 * ```
542 * ———— Shortcode Conditional Equivalent ————
543 * ```
544 * [s2If user_can(123, access_s2member_level0)]
545 * User ID# 123 CAN access content protected at Level #0.
546 * [/s2If]
547 * [s2If user_cannot(123, access_s2member_level0)]
548 * User ID# 123 CANNOT access content at Level #0.
549 * [/s2If]
550 * ```
551 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
552 *
553 * ———— Membership Levels Provide Incremental Access ————
554 *
555 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
556 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
557 * o A Member with Level 2 access, will also be able to access Levels 0, 1
558 * o A Member with Level 1 access, will also be able to access Level 0.
559 * o A Subscriber with Level 0 access, can ONLY access Level 0.
560 * o A public Visitor will have NO access to protected content.
561 *
562 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
563 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
564 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
565 *
566 * @package s2Member\API_Functions
567 * @since 3.5
568 *
569 * @param int|str $id A numeric WordPress® User ID.
570 * @param str $capability A WordPress® Capability ID *( i.e. `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
571 * @return bool True if the specific User does NOT have the specified Capability or Role, else false.
572 *
573 * @see s2Member\API_Functions\user_is()
574 * @see s2Member\API_Functions\user_is_not()
575 *
576 * @see s2Member\API_Functions\current_user_is()
577 * @see s2Member\API_Functions\current_user_is_not()
578 * @see s2Member\API_Functions\current_user_is_for_blog()
579 * @see s2Member\API_Functions\current_user_is_not_for_blog()
580 *
581 * @see s2Member\API_Functions\user_cannot()
582 * @see s2Member\API_Functions\current_user_cannot()
583 * @see s2Member\API_Functions\current_user_cannot_for_blog()
584 *
585 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
586 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
587 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
588 */
589 if (!function_exists ("user_cannot"))
590 {
591 function user_cannot ($id = FALSE, $capability = FALSE)
592 {
593 return (!user_can ($id, $capability));
594 }
595 }
596 /**
597 * Conditional to determine if the current User does NOT have a specific Capability or Role.
598 *
599 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress® core.
600 *
601 * ———— Code Sample Using Both Functions ————
602 * ```
603 * <!php
604 * if(current_user_can("access_s2member_level0"))
605 * echo 'You CAN access content protected at Level #0.';
606 *
607 * else if(current_user_cannot("access_s2member_level0"))
608 * echo 'You CANNOT access content protected at Level #0.';
609 * !>
610 * ```
611 * ———— Shortcode Conditional Equivalent ————
612 * ```
613 * [s2If current_user_can(access_s2member_level0)]
614 * You CAN access content protected at Level #0.
615 * [/s2If]
616 * [s2If current_user_cannot(access_s2member_level0)]
617 * You CANNOT access content protected at Level #0.
618 * [/s2If]
619 * ```
620 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
621 *
622 * ———— Membership Levels Provide Incremental Access ————
623 *
624 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
625 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
626 * o A Member with Level 2 access, will also be able to access Levels 0, 1
627 * o A Member with Level 1 access, will also be able to access Level 0.
628 * o A Subscriber with Level 0 access, can ONLY access Level 0.
629 * o A public Visitor will have NO access to protected content.
630 *
631 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
632 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
633 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
634 *
635 * @package s2Member\API_Functions
636 * @since 3.5
637 *
638 * @param str $capability A WordPress® Capability ID *( i.e. `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
639 * Or a Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
640 * @return bool True if the current User does NOT have the specified Capability or Role, else false.
641 *
642 * @see s2Member\API_Functions\user_is()
643 * @see s2Member\API_Functions\user_is_not()
644 *
645 * @see s2Member\API_Functions\current_user_is()
646 * @see s2Member\API_Functions\current_user_is_not()
647 * @see s2Member\API_Functions\current_user_is_for_blog()
648 * @see s2Member\API_Functions\current_user_is_not_for_blog()
649 *
650 * @see s2Member\API_Functions\user_cannot()
651 * @see s2Member\API_Functions\current_user_cannot()
652 * @see s2Member\API_Functions\current_user_cannot_for_blog()
653 *
654 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
655 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
656 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
657 */
658 if (!function_exists ("current_user_cannot"))
659 {
660 function current_user_cannot ($capability = FALSE)
661 {
662 return (!current_user_can ($capability));
663 }
664 }
665 /**
666 * Conditional to determine if the current User does NOT have a specific Capability or Role, on a specific Blog within a Multisite Network.
667 *
668 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()} already exists in the WordPress® core.
669 *
670 * ———— Code Sample Using Both Functions ————
671 * ```
672 * <!php
673 * if(current_user_can_for_blog(5, "access_s2member_level0"))
674 * echo 'You CAN access content protected at Level #0 ( on Blog ID 5 ).';
675 *
676 * else if(current_user_cannot_for_blog(5, "access_s2member_level0"))
677 * echo 'You CANNOT access content protected at Level #0 ( on Blog ID 5 ).';
678 * !>
679 * ```
680 * ———— Shortcode Conditional Equivalent ————
681 * ```
682 * [s2If current_user_can_for_blog(5, access_s2member_level0)]
683 * You CAN access content protected at Level #0 ( on Blog ID 5 ).
684 * [/s2If]
685 * [s2If current_user_cannot_for_blog(5, access_s2member_level0)]
686 * You CANNOT access content protected at Level #0 ( on Blog ID 5 ).
687 * [/s2If]
688 * ```
689 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
690 *
691 * ———— Membership Levels Provide Incremental Access ————
692 *
693 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
694 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
695 * o A Member with Level 2 access, will also be able to access Levels 0, 1
696 * o A Member with Level 1 access, will also be able to access Level 0.
697 * o A Subscriber with Level 0 access, can ONLY access Level 0.
698 * o A public Visitor will have NO access to protected content.
699 *
700 * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *( a Free Subscriber )*.
701 * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
702 * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
703 *
704 * @package s2Member\API_Functions
705 * @since 3.5
706 *
707 * @param int|str $blog_id A WordPress® Blog ID *( must be numeric )*.
708 * @param str $capability A WordPress® Capability ID *( i.e. `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
709 * Or a Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
710 * @return bool True if the current User does NOT have the specified Capability or Role, else false.
711 *
712 * @see s2Member\API_Functions\user_is()
713 * @see s2Member\API_Functions\user_is_not()
714 *
715 * @see s2Member\API_Functions\current_user_is()
716 * @see s2Member\API_Functions\current_user_is_not()
717 * @see s2Member\API_Functions\current_user_is_for_blog()
718 * @see s2Member\API_Functions\current_user_is_not_for_blog()
719 *
720 * @see s2Member\API_Functions\user_cannot()
721 * @see s2Member\API_Functions\current_user_cannot()
722 * @see s2Member\API_Functions\current_user_cannot_for_blog()
723 *
724 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
725 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
726 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
727 */
728 if (!function_exists ("current_user_cannot_for_blog"))
729 {
730 function current_user_cannot_for_blog ($blog_id = FALSE, $capability = FALSE)
731 {
732 return (!current_user_can_for_blog ($blog_id, $capability));
733 }
734 }
735 /**
736 * Conditional to determine if a specific Category, Tag, Post, Page, URL or URI is protected by s2Member;
737 * without considering the current User's Role/Capabilites.
738 *
739 * ———— Extra Detail On Function Parameters ————
740 *
741 * **Parameter $what ( int|str Optional ).**
742 * Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
743 * If passed in, this should be a WordPress® Category ID, Tag ID, Post ID, or Page ID. Or a full URL. A URI is also fine.
744 *
745 * o If you pass in an ID, s2Member will check everything, including your configured URI Restrictions against the ID.
746 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
747 * So using an ID results in an all-inclusive scan against your configured Restrictions,
748 * including any URI Restrictions that you may have configured.
749 *
750 * o If you pass in a URL or URI, s2Member will ONLY check URI Restrictions, because it has no ID to work with.
751 * This is useful though. Some protected content is not associated with an ID. In those cases, URI Restrictions are all the matter.
752 *
753 * o Note: when passing in a URL or URI, the $type parameter must be set to `URI` or `uri`. Case insensitive.
754 *
755 * **Parameter $type ( str Optional ).**
756 * One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *( i.e. a Post or Page )*.
757 *
758 * **Parameter $check_user ( bool Optional ).**
759 * Consider the current User? Defaults to false.
760 *
761 * o In other words, by default, this Conditional function is only checking to see if the content is protected, and that's it.
762 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
763 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_permitted_by_s2member()}.
764 *
765 * ———— Code Sample Using Function Parameters ————
766 * ```
767 * <!php
768 * if(is_protected_by_s2member(123))
769 * echo 'Post or Page ID #123 is protected by s2Member.';
770 *
771 * else if(is_protected_by_s2member(332, "tag"))
772 * echo 'Tag ID #332 is protected by s2Member.';
773 *
774 * else if(is_protected_by_s2member(554, "category"))
775 * echo 'Category ID #554 is protected by s2Member.';
776 *
777 * else if(is_protected_by_s2member("http://example.com/members/", "uri"))
778 * echo 'This URL is protected by URI Restrictions.';
779 *
780 * else if(is_protected_by_s2member("/members/", "uri"))
781 * echo 'This URI is protected by URI Restrictions.';
782 * !>
783 * ```
784 * ———— Shortcode Conditional Equivalent ————
785 * ```
786 * [s2If is_protected_by_s2member(123)]
787 * Post or Page ID #123 is protected by s2Member.
788 * [/s2If]
789 * [s2If is_protected_by_s2member(332, tag)]
790 * Tag ID #332 is protected by s2Member.
791 * [/s2If]
792 * [s2If is_protected_by_s2member(554, category)]
793 * Category ID #554 is protected by s2Member.
794 * [/s2If]
795 * [s2If is_protected_by_s2member(http://example.com/members/, uri)]
796 * This URL is protected by URI Restrictions.
797 * [/s2If]
798 * [s2If is_protected_by_s2member(/members/, uri)]
799 * This URI is protected by URI Restrictions.
800 * [/s2If]
801 * ```
802 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
803 *
804 * @package s2Member\API_Functions
805 * @since 3.5
806 *
807 * @param int|str $what Optional. Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
808 * If passed in, this should be a WordPress® Category ID, Tag ID, Post ID, or Page ID. Or a full URL. A URI is also fine.
809 * @param str $type Optional. One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *( i.e. a Post or Page )*.
810 * @param bool $check_user Optional. Consider the current User? Defaults to false.
811 * @return array|bool A non-empty array *( meaning true )*, or false if the content is not protected *( i.e. available publicly )*.
812 * When/if content IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
813 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the content.
814 * In other words, the reason why it's protected; based on your s2Member configuration.
815 *
816 * @see s2Member\API_Functions\is_protected_by_s2member()
817 * @see s2Member\API_Functions\is_permitted_by_s2member()
818 *
819 * @see s2Member\API_Functions\is_category_protected_by_s2member()
820 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
821 *
822 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
823 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
824 *
825 * @see s2Member\API_Functions\is_post_protected_by_s2member()
826 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
827 *
828 * @see s2Member\API_Functions\is_page_protected_by_s2member()
829 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
830 *
831 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
832 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
833 *
834 * @see s2Member\API_Functions\attach_s2member_query_filters()
835 * @see s2Member\API_Functions\detach_s2member_query_filters()
836 */
837 if (!function_exists ("is_protected_by_s2member"))
838 {
839 function is_protected_by_s2member ($what = FALSE, $type = FALSE, $check_user = FALSE)
840 {
841 global $post; /* Global reference to $post in The Loop. */
842 /**/
843 $what = ($what) ? $what : ((is_object ($post) && $post->ID) ? $post->ID : false);
844 $type = ($type) ? strtolower ($type) : "singular";
845 /**/
846 if ($type === "category" && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access ($what, $check_user)))
847 return $array; /* A non-empty array with ["s2member_level_req"]. */
848 /**/
849 else if ($type === "tag" && ($array = c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access ($what, $check_user)))
850 return $array; /* A non-empty array with ["s2member_level_req"]. */
851 /**/
852 else if (($type === "post" || $type === "singular") && ($array = c_ws_plugin__s2member_posts_sp::check_specific_post_level_access ($what, $check_user)))
853 return $array; /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */
854 /**/
855 else if (($type === "page" || $type === "singular") && ($array = c_ws_plugin__s2member_pages_sp::check_specific_page_level_access ($what, $check_user)))
856 return $array; /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */
857 /**/
858 else if ($type === "uri" && ($array = c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access ($what, $check_user)))
859 return $array; /* A non-empty array with ["s2member_level_req"]. */
860 /**/
861 return false;
862 }
863 }
864 /**
865 * Conditional to determine if a specific Category, Tag, Post, Page, URL or URI is permitted by s2Member,
866 * with consideration given to the current User's Role/Capabilites.
867 *
868 * This function is similar to {@link s2Member\API_Functions\is_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
869 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_protected_by_s2member()} does; it only returns true|false.
870 *
871 * ———— Extra Detail On Function Parameters ————
872 *
873 * **Parameter $what ( int|str Optional ).**
874 * Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
875 * If passed in, this should be a WordPress® Category ID, Tag ID, Post ID, or Page ID. Or a full URL. A URI is also fine.
876 *
877 * o If you pass in an ID, s2Member will check everything, including your configured URI Restrictions against the ID.
878 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
879 * So using an ID results in an all-inclusive scan against your configured Restrictions,
880 * including any URI Restrictions that you may have configured.
881 *
882 * o If you pass in a URL or URI, s2Member will ONLY check URI Restrictions, because it has no ID to work with.
883 * This is useful though. Some protected content is not associated with an ID. In those cases, URI Restrictions are all the matter.
884 *
885 * o Note: when passing in a URL or URI, the $type parameter must be set to `URI` or `uri`. Case insensitive.
886 *
887 * **Parameter $type ( str Optional ).**
888 * One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *( i.e. a Post or Page )*.
889 *
890 * ———— Code Sample Using Function Parameters ————
891 * ```
892 * <!php
893 * if(is_permitted_by_s2member(123))
894 * echo 'Post or Page ID #123 is permitted by s2Member.';
895 *
896 * else if(is_permitted_by_s2member(332, "tag"))
897 * echo 'Tag ID #332 is permitted by s2Member.';
898 *
899 * else if(is_permitted_by_s2member(554, "category"))
900 * echo 'Category ID #554 is permitted by s2Member.';
901 *
902 * else if(is_permitted_by_s2member("http://example.com/members/", "uri"))
903 * echo 'This URL is permitted by s2Member.';
904 *
905 * else if(is_permitted_by_s2member("/members/", "uri"))
906 * echo 'This URI is permitted by s2Member.';
907 * !>
908 * ```
909 * ———— Shortcode Conditional Equivalent ————
910 * ```
911 * [s2If is_permitted_by_s2member(123)]
912 * Post or Page ID #123 is permitted by s2Member.
913 * [/s2If]
914 * [s2If is_permitted_by_s2member(332, tag)]
915 * Tag ID #332 is permitted by s2Member.
916 * [/s2If]
917 * [s2If is_permitted_by_s2member(554, category)]
918 * Category ID #554 is permitted by s2Member.
919 * [/s2If]
920 * [s2If is_permitted_by_s2member(http://example.com/members/, uri)]
921 * This URL is permitted by s2Member.
922 * [/s2If]
923 * [s2If is_permitted_by_s2member(/members/, uri)]
924 * This URI is permitted by s2Member.
925 * [/s2If]
926 * ```
927 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
928 *
929 * @package s2Member\API_Functions
930 * @since 3.5
931 *
932 * @param int|str $what Optional. Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
933 * If passed in, this should be a WordPress® Category ID, Tag ID, Post ID, or Page ID. Or a full URL. A URI is also fine.
934 * @param str $type Optional. One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *( i.e. a Post or Page )*.
935 * @return bool True if the current User IS permitted, else false if the content is NOT available to the current User;
936 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
937 *
938 * @see s2Member\API_Functions\is_protected_by_s2member()
939 * @see s2Member\API_Functions\is_permitted_by_s2member()
940 *
941 * @see s2Member\API_Functions\is_category_protected_by_s2member()
942 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
943 *
944 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
945 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
946 *
947 * @see s2Member\API_Functions\is_post_protected_by_s2member()
948 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
949 *
950 * @see s2Member\API_Functions\is_page_protected_by_s2member()
951 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
952 *
953 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
954 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
955 *
956 * @see s2Member\API_Functions\attach_s2member_query_filters()
957 * @see s2Member\API_Functions\detach_s2member_query_filters()
958 */
959 if (!function_exists ("is_permitted_by_s2member"))
960 {
961 function is_permitted_by_s2member ($what = FALSE, $type = FALSE)
962 {
963 global $post; /* Global reference to $post in The Loop. */
964 /**/
965 $what = ($what) ? $what : ((is_object ($post) && $post->ID) ? $post->ID : false);
966 $type = ($type) ? strtolower ($type) : "singular";
967 /**/
968 if ($type === "category" && c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access ($what, true))
969 return false;
970 /**/
971 else if ($type === "tag" && c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access ($what, true))
972 return false;
973 /**/
974 else if (($type === "post" || $type === "singular") && c_ws_plugin__s2member_posts_sp::check_specific_post_level_access ($what, true))
975 return false;
976 /**/
977 else if (($type === "page" || $type === "singular") && c_ws_plugin__s2member_pages_sp::check_specific_page_level_access ($what, true))
978 return false;
979 /**/
980 else if ($type === "uri" && c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access ($what, true))
981 return false;
982 /**/
983 return true;
984 }
985 }
986 /**
987 * Conditional to determine if a specific Category is protected by s2Member;
988 * without considering the current User's Role/Capabilites.
989 *
990 * ———— Extra Detail On Function Parameters ————
991 *
992 * **Parameter $cat_id ( int Required ).** This should be a WordPress® Category ID.
993 *
994 * o s2Member will check everything, including your configured URI Restrictions against the ID.
995 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
996 * So using an ID results in an all-inclusive scan against your configured Restrictions,
997 * including any URI Restrictions that you may have configured.
998 *
999 * **Parameter $check_user ( bool Optional ).**
1000 * Consider the current User? Defaults to false.
1001 *
1002 * o In other words, by default, this Conditional function is only checking to see if the Category is protected, and that's it.
1003 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1004 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_category_permitted_by_s2member()}.
1005 *
1006 * ———— Code Sample Using Function Parameters ————
1007 * ```
1008 * <!php
1009 * if(is_category_protected_by_s2member(123))
1010 * echo 'Category ID #123 is protected by s2Member.';
1011 * !>
1012 * ```
1013 * ———— Shortcode Conditional Equivalent ————
1014 * ```
1015 * [s2If is_category_protected_by_s2member(123)]
1016 * Category ID #123 is protected by s2Member.
1017 * [/s2If]
1018 * ```
1019 *
1020 * @package s2Member\API_Functions
1021 * @since 3.5
1022 *
1023 * @param int $cat_id Required. This should be a WordPress® Category ID.
1024 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1025 * @return array|bool A non-empty array *( meaning true )*, or false if the Category is not protected *( i.e. available publicly )*.
1026 * When/if the Category IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1027 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Category.
1028 * In other words, the reason why it's protected; based on your s2Member configuration.
1029 *
1030 * @see s2Member\API_Functions\is_protected_by_s2member()
1031 * @see s2Member\API_Functions\is_permitted_by_s2member()
1032 *
1033 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1034 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1035 *
1036 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1037 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1038 *
1039 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1040 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1041 *
1042 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1043 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1044 *
1045 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1046 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1047 *
1048 * @see s2Member\API_Functions\attach_s2member_query_filters()
1049 * @see s2Member\API_Functions\detach_s2member_query_filters()
1050 */
1051 if (!function_exists ("is_category_protected_by_s2member"))
1052 {
1053 function is_category_protected_by_s2member ($cat_id = FALSE, $check_user = FALSE)
1054 {
1055 if ($cat_id && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access ($cat_id, $check_user)))
1056 return $array; /* A non-empty array with ["s2member_level_req"]. */
1057 /**/
1058 return false;
1059 }
1060 }
1061 /**
1062 * Conditional to determine if a specific Category is permitted by s2Member,
1063 * with consideration given to the current User's Role/Capabilites.
1064 *
1065 * This function is similar to {@link s2Member\API_Functions\is_category_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1066 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_category_protected_by_s2member()} does; it only returns true|false.
1067 *
1068 * ———— Extra Detail On Function Parameters ————
1069 *
1070 * **Parameter $cat_id ( int Required ).** This should be a WordPress® Category ID.
1071 *
1072 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1073 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1074 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1075 * including any URI Restrictions that you may have configured.
1076 *
1077 * ———— Code Sample Using Function Parameters ————
1078 * ```
1079 * <!php
1080 * if(is_category_permitted_by_s2member(123))
1081 * echo 'Category ID #123 is permitted by s2Member.';
1082 * !>
1083 * ```
1084 * ———— Shortcode Conditional Equivalent ————
1085 * ```
1086 * [s2If is_category_permitted_by_s2member(123)]
1087 * Category ID #123 is permitted by s2Member.
1088 * [/s2If]
1089 * ```
1090 *
1091 * @package s2Member\API_Functions
1092 * @since 3.5
1093 *
1094 * @param int $cat_id Required. This should be a WordPress® Category ID.
1095 * @return bool True if the current User IS permitted, else false if the Category is NOT available to the current User;
1096 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1097 *
1098 * @see s2Member\API_Functions\is_protected_by_s2member()
1099 * @see s2Member\API_Functions\is_permitted_by_s2member()
1100 *
1101 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1102 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1103 *
1104 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1105 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1106 *
1107 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1108 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1109 *
1110 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1111 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1112 *
1113 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1114 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1115 *
1116 * @see s2Member\API_Functions\attach_s2member_query_filters()
1117 * @see s2Member\API_Functions\detach_s2member_query_filters()
1118 */
1119 if (!function_exists ("is_category_permitted_by_s2member"))
1120 {
1121 function is_category_permitted_by_s2member ($cat_id = FALSE)
1122 {
1123 if ($cat_id && c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access ($cat_id, true))
1124 return false;
1125 /**/
1126 return true;
1127 }
1128 }
1129 /**
1130 * Conditional to determine if a specific Tag is protected by s2Member;
1131 * without considering the current User's Role/Capabilites.
1132 *
1133 * ———— Extra Detail On Function Parameters ————
1134 *
1135 * **Parameter $tag_id_slug_or_name ( int|str Required ).** This should be a WordPress® Tag ID, Tag Slug, or Tag Name.
1136 *
1137 * o s2Member will check everything, including your configured URI Restrictions against the ID, Slug, or Name.
1138 * In other words, s2Member is capable of determining a URI based on the ID, or Slug, or Name that you pass in.
1139 * So using an ID, or Slug, or Name results in an all-inclusive scan against your configured Restrictions,
1140 * including any URI Restrictions that you may have configured.
1141 *
1142 * **Parameter $check_user ( bool Optional ).**
1143 * Consider the current User? Defaults to false.
1144 *
1145 * o In other words, by default, this Conditional function is only checking to see if the Tag is protected, and that's it.
1146 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1147 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_tag_permitted_by_s2member()}.
1148 *
1149 * ———— Code Sample Using Function Parameters ————
1150 * ```
1151 * <!php
1152 * if(is_tag_protected_by_s2member(123))
1153 * echo 'Tag ID #123 is protected by s2Member.';
1154 *
1155 * else if(is_tag_protected_by_s2member("members-only"))
1156 * echo 'Tag Slug (members-only) is protected by s2Member.';
1157 *
1158 * else if(is_tag_protected_by_s2member("Members Only"))
1159 * echo 'Tag Name (Members Only) is protected by s2Member.';
1160 * !>
1161 * ```
1162 * ———— Shortcode Conditional Equivalent ————
1163 * ```
1164 * [s2If is_tag_protected_by_s2member(123)]
1165 * Tag ID #123 is protected by s2Member.
1166 * [/s2If]
1167 * [s2If is_tag_protected_by_s2member(members-only)]
1168 * Tag Slug (members-only) is protected by s2Member.
1169 * [/s2If]
1170 * NOTE: It's NOT possible to check a Tag Named "Members Only" with [s2If /],
1171 * because Shortcode Conditionals may NOT contain spaces in their argument values.
1172 * If you're using [s2If /] to check a Tag, please use the Slug or ID instead.
1173 * ```
1174 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1175 *
1176 * @package s2Member\API_Functions
1177 * @since 3.5
1178 *
1179 * @param int|str $tag_id_slug_or_name Required. This should be a WordPress® Tag ID, Tag Slug, or Tag Name.
1180 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1181 * @return array|bool A non-empty array *( meaning true )*, or false if the Tag is not protected *( i.e. available publicly )*.
1182 * When/if the Tag IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1183 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Tag.
1184 * In other words, the reason why it's protected; based on your s2Member configuration.
1185 *
1186 * @see s2Member\API_Functions\is_protected_by_s2member()
1187 * @see s2Member\API_Functions\is_permitted_by_s2member()
1188 *
1189 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1190 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1191 *
1192 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1193 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1194 *
1195 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1196 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1197 *
1198 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1199 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1200 *
1201 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1202 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1203 *
1204 * @see s2Member\API_Functions\attach_s2member_query_filters()
1205 * @see s2Member\API_Functions\detach_s2member_query_filters()
1206 */
1207 if (!function_exists ("is_tag_protected_by_s2member"))
1208 {
1209 function is_tag_protected_by_s2member ($tag_id_slug_or_name = FALSE, $check_user = FALSE)
1210 {
1211 if ($tag_id_slug_or_name && ($array = c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access ($tag_id_slug_or_name, $check_user)))
1212 return $array; /* A non-empty array with ["s2member_level_req"]. */
1213 /**/
1214 return false;
1215 }
1216 }
1217 /**
1218 * Conditional to determine if a specific Tag is permitted by s2Member,
1219 * with consideration given to the current User's Role/Capabilites.
1220 *
1221 * This function is similar to {@link s2Member\API_Functions\is_tag_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1222 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_tag_protected_by_s2member()} does; it only returns true|false.
1223 *
1224 * ———— Extra Detail On Function Parameters ————
1225 *
1226 * **Parameter $tag_id_slug_or_name ( int|str Required ).** This should be a WordPress® Tag ID, Tag Slug, or Tag Name.
1227 *
1228 * o s2Member will check everything, including your configured URI Restrictions against the ID, or Slug, or Name.
1229 * In other words, s2Member is capable of determining a URI based on the ID, or Slug, or Name that you pass in.
1230 * So using an ID, or Slug, or Name results in an all-inclusive scan against your configured Restrictions,
1231 * including any URI Restrictions that you may have configured.
1232 *
1233 * ———— Code Sample Using Function Parameters ————
1234 * ```
1235 * <!php
1236 * if(is_tag_permitted_by_s2member(123))
1237 * echo 'Tag ID #123 is permitted by s2Member.';
1238 *
1239 * else if(is_tag_permitted_by_s2member("members-only"))
1240 * echo 'Tag Slug (members-only) is permitted by s2Member.';
1241 *
1242 * else if(is_tag_permitted_by_s2member("Members Only"))
1243 * echo 'Tag Name (Members Only) is permitted by s2Member.';
1244 * !>
1245 * ```
1246 * ———— Shortcode Conditional Equivalent ————
1247 * ```
1248 * [s2If is_tag_permitted_by_s2member(123)]
1249 * Tag ID #123 is permitted by s2Member.
1250 * [/s2If]
1251 * [s2If is_tag_permitted_by_s2member(members-only)]
1252 * Tag Slug (members-only) is permitted by s2Member.
1253 * [/s2If]
1254 * NOTE: It's NOT possible to check a Tag Named "Members Only" with [s2If /],
1255 * because Shortcode Conditionals may NOT contain spaces in their argument values.
1256 * If you're using [s2If /] to check a Tag, please use the Slug or ID instead.
1257 * ```
1258 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1259 *
1260 * @package s2Member\API_Functions
1261 * @since 3.5
1262 *
1263 * @param int|str $tag_id_slug_or_name Required. This should be a WordPress® Tag ID, Tag Slug, or Tag Name.
1264 * @return bool True if the current User IS permitted, else false if the Tag is NOT available to the current User;
1265 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1266 *
1267 * @see s2Member\API_Functions\is_protected_by_s2member()
1268 * @see s2Member\API_Functions\is_permitted_by_s2member()
1269 *
1270 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1271 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1272 *
1273 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1274 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1275 *
1276 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1277 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1278 *
1279 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1280 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1281 *
1282 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1283 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1284 *
1285 * @see s2Member\API_Functions\attach_s2member_query_filters()
1286 * @see s2Member\API_Functions\detach_s2member_query_filters()
1287 */
1288 if (!function_exists ("is_tag_permitted_by_s2member"))
1289 {
1290 function is_tag_permitted_by_s2member ($tag_id_slug_or_name = FALSE)
1291 {
1292 if ($tag_id_slug_or_name && c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access ($tag_id_slug_or_name, true))
1293 return false;
1294 /**/
1295 return true;
1296 }
1297 }
1298 /**
1299 * Conditional to determine if a specific Post ( or Custom Post Type ) is protected by s2Member;
1300 * without considering the current User's Role/Capabilites.
1301 *
1302 * ———— Extra Detail On Function Parameters ————
1303 *
1304 * **Parameter $post_id ( int Required ).** This should be a WordPress® Post ID, or a Custom Post Type ID.
1305 *
1306 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1307 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1308 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1309 * including any URI Restrictions that you may have configured.
1310 *
1311 * **Parameter $check_user ( bool Optional ).**
1312 * Consider the current User? Defaults to false.
1313 *
1314 * o In other words, by default, this Conditional function is only checking to see if the Post is protected, and that's it.
1315 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1316 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_post_permitted_by_s2member()}.
1317 *
1318 * ———— Code Sample Using Function Parameters ————
1319 * ```
1320 * <!php
1321 * if(is_post_protected_by_s2member(123))
1322 * echo 'Post ID #123 is protected by s2Member.';
1323 * !>
1324 * ```
1325 * ———— Shortcode Conditional Equivalent ————
1326 * ```
1327 * [s2If is_post_protected_by_s2member(123)]
1328 * Post ID #123 is protected by s2Member.
1329 * [/s2If]
1330 * ```
1331 *
1332 * @package s2Member\API_Functions
1333 * @since 3.5
1334 *
1335 * @param int $post_id Required. This should be a WordPress® Post ID, or a Custom Post Type ID.
1336 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1337 * @return array|bool A non-empty array *( meaning true )*, or false if the Post is not protected *( i.e. available publicly )*.
1338 * When/if the Post IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1339 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Post.
1340 * In other words, the reason why it's protected; based on your s2Member configuration.
1341 *
1342 * @see s2Member\API_Functions\is_protected_by_s2member()
1343 * @see s2Member\API_Functions\is_permitted_by_s2member()
1344 *
1345 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1346 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1347 *
1348 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1349 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1350 *
1351 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1352 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1353 *
1354 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1355 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1356 *
1357 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1358 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1359 *
1360 * @see s2Member\API_Functions\attach_s2member_query_filters()
1361 * @see s2Member\API_Functions\detach_s2member_query_filters()
1362 */
1363 if (!function_exists ("is_post_protected_by_s2member"))
1364 {
1365 function is_post_protected_by_s2member ($post_id = FALSE, $check_user = FALSE)
1366 {
1367 if ($post_id && ($array = c_ws_plugin__s2member_posts_sp::check_specific_post_level_access ($post_id, $check_user)))
1368 return $array; /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */
1369 /**/
1370 return false;
1371 }
1372 }
1373 /**
1374 * Conditional to determine if a specific Post or Custom Post Type is permitted by s2Member,
1375 * with consideration given to the current User's Role/Capabilites.
1376 *
1377 * This function is similar to {@link s2Member\API_Functions\is_post_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1378 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_post_protected_by_s2member()} does; it only returns true|false.
1379 *
1380 * ———— Extra Detail On Function Parameters ————
1381 *
1382 * **Parameter $post_id ( int Required ).** This should be a WordPress® Post ID, or a Custom Post Type ID.
1383 *
1384 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1385 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1386 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1387 * including any URI Restrictions that you may have configured.
1388 *
1389 * ———— Code Sample Using Function Parameters ————
1390 * ```
1391 * <!php
1392 * if(is_post_permitted_by_s2member(123))
1393 * echo 'Post ID #123 is permitted by s2Member.';
1394 * !>
1395 * ```
1396 * ———— Shortcode Conditional Equivalent ————
1397 * ```
1398 * [s2If is_post_permitted_by_s2member(123)]
1399 * Post ID #123 is permitted by s2Member.
1400 * [/s2If]
1401 * ```
1402 *
1403 * @package s2Member\API_Functions
1404 * @since 3.5
1405 *
1406 * @param int $post_id Required. This should be a WordPress® Post ID, or a Custom Post Type ID.
1407 * @return bool True if the current User IS permitted, else false if the Post is NOT available to the current User;
1408 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1409 *
1410 * @see s2Member\API_Functions\is_protected_by_s2member()
1411 * @see s2Member\API_Functions\is_permitted_by_s2member()
1412 *
1413 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1414 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1415 *
1416 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1417 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1418 *
1419 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1420 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1421 *
1422 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1423 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1424 *
1425 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1426 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1427 *
1428 * @see s2Member\API_Functions\attach_s2member_query_filters()
1429 * @see s2Member\API_Functions\detach_s2member_query_filters()
1430 */
1431 if (!function_exists ("is_post_permitted_by_s2member"))
1432 {
1433 function is_post_permitted_by_s2member ($post_id = FALSE)
1434 {
1435 if ($post_id && c_ws_plugin__s2member_posts_sp::check_specific_post_level_access ($post_id, true))
1436 return false;
1437 /**/
1438 return true;
1439 }
1440 }
1441 /**
1442 * Conditional to determine if a specific Page is protected by s2Member;
1443 * without considering the current User's Role/Capabilites.
1444 *
1445 * ———— Extra Detail On Function Parameters ————
1446 *
1447 * **Parameter $page_id ( int Required ).** This should be a WordPress® Page ID.
1448 *
1449 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1450 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1451 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1452 * including any URI Restrictions that you may have configured.
1453 *
1454 * **Parameter $check_user ( bool Optional ).**
1455 * Consider the current User? Defaults to false.
1456 *
1457 * o In other words, by default, this Conditional function is only checking to see if the Page is protected, and that's it.
1458 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1459 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_page_permitted_by_s2member()}.
1460 *
1461 * ———— Code Sample Using Function Parameters ————
1462 * ```
1463 * <!php
1464 * if(is_page_protected_by_s2member(123))
1465 * echo 'Page ID #123 is protected by s2Member.';
1466 * !>
1467 * ```
1468 * ———— Shortcode Conditional Equivalent ————
1469 * ```
1470 * [s2If is_page_protected_by_s2member(123)]
1471 * Page ID #123 is protected by s2Member.
1472 * [/s2If]
1473 * ```
1474 *
1475 * @package s2Member\API_Functions
1476 * @since 3.5
1477 *
1478 * @param int $page_id Required. This should be a WordPress® Page ID.
1479 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1480 * @return array|bool A non-empty array *( meaning true )*, or false if the Page is not protected *( i.e. available publicly )*.
1481 * When/if the Page IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1482 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Page.
1483 * In other words, the reason why it's protected; based on your s2Member configuration.
1484 *
1485 * @see s2Member\API_Functions\is_protected_by_s2member()
1486 * @see s2Member\API_Functions\is_permitted_by_s2member()
1487 *
1488 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1489 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1490 *
1491 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1492 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1493 *
1494 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1495 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1496 *
1497 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1498 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1499 *
1500 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1501 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1502 *
1503 * @see s2Member\API_Functions\attach_s2member_query_filters()
1504 * @see s2Member\API_Functions\detach_s2member_query_filters()
1505 */
1506 if (!function_exists ("is_page_protected_by_s2member"))
1507 {
1508 function is_page_protected_by_s2member ($page_id = FALSE, $check_user = FALSE)
1509 {
1510 if ($page_id && ($array = c_ws_plugin__s2member_pages_sp::check_specific_page_level_access ($page_id, $check_user)))
1511 return $array; /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */
1512 /**/
1513 return false;
1514 }
1515 }
1516 /**
1517 * Conditional to determine if a specific Page is permitted by s2Member,
1518 * with consideration given to the current User's Role/Capabilites.
1519 *
1520 * This function is similar to {@link s2Member\API_Functions\is_page_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1521 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_page_protected_by_s2member()} does; it only returns true|false.
1522 *
1523 * ———— Extra Detail On Function Parameters ————
1524 *
1525 * **Parameter $page_id ( int Required ).** This should be a WordPress® Page ID.
1526 *
1527 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1528 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1529 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1530 * including any URI Restrictions that you may have configured.
1531 *
1532 * ———— Code Sample Using Function Parameters ————
1533 * ```
1534 * <!php
1535 * if(is_page_permitted_by_s2member(123))
1536 * echo 'Page ID #123 is permitted by s2Member.';
1537 * !>
1538 * ```
1539 * ———— Shortcode Conditional Equivalent ————
1540 * ```
1541 * [s2If is_page_permitted_by_s2member(123)]
1542 * Page ID #123 is permitted by s2Member.
1543 * [/s2If]
1544 * ```
1545 *
1546 * @package s2Member\API_Functions
1547 * @since 3.5
1548 *
1549 * @param int $page_id Required. This should be a WordPress® Page ID.
1550 * @return bool True if the current User IS permitted, else false if the Page is NOT available to the current User;
1551 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1552 *
1553 * @see s2Member\API_Functions\is_protected_by_s2member()
1554 * @see s2Member\API_Functions\is_permitted_by_s2member()
1555 *
1556 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1557 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1558 *
1559 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1560 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1561 *
1562 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1563 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1564 *
1565 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1566 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1567 *
1568 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1569 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1570 *
1571 * @see s2Member\API_Functions\attach_s2member_query_filters()
1572 * @see s2Member\API_Functions\detach_s2member_query_filters()
1573 */
1574 if (!function_exists ("is_page_permitted_by_s2member"))
1575 {
1576 function is_page_permitted_by_s2member ($page_id = FALSE)
1577 {
1578 if ($page_id && c_ws_plugin__s2member_pages_sp::check_specific_page_level_access ($page_id, true))
1579 return false;
1580 /**/
1581 return true;
1582 }
1583 }
1584 /**
1585 * Conditional to determine if a specific URI or URL is protected by s2Member;
1586 * without considering the current User's Role/Capabilites.
1587 *
1588 * ———— Extra Detail On Function Parameters ————
1589 *
1590 * **Parameter $uri_or_full_url ( str Required ).** This should be a URI starting with `/`, or a full URL is also fine.
1591 *
1592 * **Parameter $check_user ( bool Optional ).**
1593 * Consider the current User? Defaults to false.
1594 *
1595 * o In other words, by default, this Conditional function is only checking to see if the URI or URL is protected, and that's it.
1596 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1597 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_uri_permitted_by_s2member()}.
1598 *
1599 * ———— Important Notes About This Function ————
1600 *
1601 * This function will ONLY test against URI Restrictions you've configured with s2Member.
1602 * If you need an all-inclusive test, please use {@link s2Member\API_Functions\is_protected_by_s2member()} with an ID.
1603 *
1604 * ———— Code Sample Using Function Parameters ————
1605 * ```
1606 * <!php
1607 * if(is_uri_protected_by_s2member("/members-only/sub-section"))
1608 * echo 'The URI (/members-only/sub-section) is protected by URI Restrictions.';
1609 *
1610 * else if(is_uri_protected_by_s2member("http://example.com/members-only/sub-section"))
1611 * echo 'The URL (http://example.com/members-only/sub-section) is protected by URI Restrictions.';
1612 * !>
1613 * ```
1614 * ———— Shortcode Conditional Equivalent ————
1615 * ```
1616 * [s2If is_uri_protected_by_s2member(/members-only/sub-section)]
1617 * The URI (/members-only/sub-section) is protected by URI Restrictions.
1618 * [/s2If]
1619 * [s2If is_uri_protected_by_s2member(http://example.com/members-only/sub-section)]
1620 * The URL (http://example.com/members-only/sub-section) is protected by URI Restrictions.
1621 * [/s2If]
1622 * ```
1623 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1624 *
1625 * @package s2Member\API_Functions
1626 * @since 3.5
1627 *
1628 * @param str $uri_or_full_url Required. This should be a URI starting with `/`, or a full URL is also fine.
1629 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1630 * @return array|bool A non-empty array *( meaning true )*, or false if the URI or URL is not protected *( i.e. available publicly )*.
1631 * When/if the URI or URL IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1632 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the URI or URL.
1633 * In other words, the reason why it's protected; based on your s2Member configuration.
1634 *
1635 * @see s2Member\API_Functions\is_protected_by_s2member()
1636 * @see s2Member\API_Functions\is_permitted_by_s2member()
1637 *
1638 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1639 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1640 *
1641 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1642 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1643 *
1644 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1645 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1646 *
1647 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1648 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1649 *
1650 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1651 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1652 *
1653 * @see s2Member\API_Functions\attach_s2member_query_filters()
1654 * @see s2Member\API_Functions\detach_s2member_query_filters()
1655 */
1656 if (!function_exists ("is_uri_protected_by_s2member"))
1657 {
1658 function is_uri_protected_by_s2member ($uri_or_full_url = FALSE, $check_user = FALSE)
1659 {
1660 if ($uri_or_full_url && ($array = c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access ($uri_or_full_url, $check_user)))
1661 return $array; /* A non-empty array with ["s2member_level_req"]. */
1662 /**/
1663 return false;
1664 }
1665 }
1666 /**
1667 * Conditional to determine if a specific URI or URL is permitted by s2Member,
1668 * with consideration given to the current User's Role/Capabilites.
1669 *
1670 * This function is similar to {@link s2Member\API_Functions\is_uri_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1671 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_uri_protected_by_s2member()} does; it only returns true|false.
1672 *
1673 * ———— Extra Detail On Function Parameters ————
1674 *
1675 * **Parameter $uri_or_full_url ( str Required ).** This should be a URI starting with `/`, or a full URL is also fine.
1676 *
1677 * ———— Important Notes About This Function ————
1678 *
1679 * This function will ONLY test against URI Restrictions you've configured with s2Member.
1680 * If you need an all-inclusive test, please use {@link s2Member\API_Functions\is_permitted_by_s2member()} with an ID.
1681 *
1682 * ———— Code Sample Using Function Parameters ————
1683 * ```
1684 * <!php
1685 * if(is_uri_permitted_by_s2member("/members-only/sub-section"))
1686 * echo 'The URI (/members-only/sub-section) is permitted by URI Restrictions.';
1687 *
1688 * else if(is_uri_permitted_by_s2member("http://example.com/members-only/sub-section"))
1689 * echo 'The URL (http://example.com/members-only/sub-section) is permitted by URI Restrictions.';
1690 * !>
1691 * ```
1692 * ———— Shortcode Conditional Equivalent ————
1693 * ```
1694 * [s2If is_uri_permitted_by_s2member(/members-only/sub-section)]
1695 * The URI (/members-only/sub-section) is permitted by URI Restrictions.
1696 * [/s2If]
1697 * [s2If is_uri_permitted_by_s2member(http://example.com/members-only/sub-section)]
1698 * The URL (http://example.com/members-only/sub-section) is permitted by URI Restrictions.
1699 * [/s2If]
1700 * ```
1701 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1702 *
1703 * @package s2Member\API_Functions
1704 * @since 3.5
1705 *
1706 * @param str $uri_or_full_url Required. This should be a URI starting with `/`, or a full URL is also fine.
1707 * @return bool True if the current User IS permitted, else false if the URI or URL is NOT available to the current User;
1708 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1709 *
1710 * @see s2Member\API_Functions\is_protected_by_s2member()
1711 * @see s2Member\API_Functions\is_permitted_by_s2member()
1712 *
1713 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1714 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1715 *
1716 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1717 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1718 *
1719 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1720 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1721 *
1722 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1723 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1724 *
1725 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1726 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1727 *
1728 * @see s2Member\API_Functions\attach_s2member_query_filters()
1729 * @see s2Member\API_Functions\detach_s2member_query_filters()
1730 */
1731 if (!function_exists ("is_uri_permitted_by_s2member"))
1732 {
1733 function is_uri_permitted_by_s2member ($uri_or_full_url = FALSE)
1734 {
1735 if ($uri_or_full_url && c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access ($uri_or_full_url, true))
1736 return false;
1737 /**/
1738 return true;
1739 }
1740 }
1741 /**
1742 * Allows plugin/theme developers to pre-filter WP Queries easily, so that protected content
1743 * *( i.e content NOT available to the current User )*, is excluded automatically.
1744 *
1745 * This functionality is already built right into s2Member's UI configuration panels,
1746 * but in cases where a plugin/theme developer needs more control, this may come in handy.
1747 * In the UI configuration for s2Member, please see: `Alternative View Protection`.
1748 *
1749 * ———— Code Sample Using s2Member's Query Filters ————
1750 * ```
1751 * <!php
1752 * attach_s2member_query_filters();
1753 * query_posts("posts_per_page=5");
1754 *
1755 * if (have_posts()):
1756 * while (have_posts()):
1757 * the_post();
1758 * # Protected content will be excluded automatically.
1759 * # ( based on the current User's Role/Capabilities )
1760 * endwhile;
1761 * endif;
1762 *
1763 * wp_reset_query();
1764 * detach_s2member_query_filters();
1765 * !>
1766 * ```
1767 * ———— Shortcode Equivalent ————
1768 * ```
1769 * There is NO Shortcode equivalent for this.
1770 * ```
1771 *
1772 * @package s2Member\API_Functions
1773 * @since 3.5
1774 *
1775 * @return null
1776 *
1777 * @see s2Member\API_Functions\detach_s2member_query_filters()
1778 */
1779 if (!function_exists ("attach_s2member_query_filters"))
1780 {
1781 function attach_s2member_query_filters ()
1782 {
1783 remove_action ("pre_get_posts", "c_ws_plugin__s2member_security::security_gate_query", 20);
1784 add_action ("pre_get_posts", "c_ws_plugin__s2member_querys::force_query_level_access", 20);
1785 }
1786 }
1787 /**
1788 * Allows plugin/theme developers to pre-filter WP Queries easily, so that protected content
1789 * *( i.e content NOT available to the current User )*, is excluded automatically.
1790 *
1791 * This functionality is already built right into s2Member's UI configuration panels,
1792 * but in cases where a plugin/theme developer needs more control, this may come in handy.
1793 * In the UI configuration for s2Member, please see: `Alternative View Protection`.
1794 *
1795 * ———— Code Sample Using s2Member's Query Filters ————
1796 * ```
1797 * <!php
1798 * attach_s2member_query_filters();
1799 * query_posts("posts_per_page=5");
1800 *
1801 * if (have_posts()):
1802 * while (have_posts()):
1803 * the_post();
1804 * # Protected content will be excluded automatically.
1805 * # ( based on the current User's Role/Capabilities )
1806 * endwhile;
1807 * endif;
1808 *
1809 * wp_reset_query();
1810 * detach_s2member_query_filters();
1811 * !>
1812 * ```
1813 * ———— Shortcode Equivalent ————
1814 * ```
1815 * There is NO Shortcode equivalent for this.
1816 * ```
1817 *
1818 * @package s2Member\API_Functions
1819 * @since 3.5
1820 *
1821 * @return null
1822 *
1823 * @see s2Member\API_Functions\attach_s2member_query_filters()
1824 */
1825 if (!function_exists ("detach_s2member_query_filters"))
1826 {
1827 function detach_s2member_query_filters ()
1828 {
1829 remove_action ("pre_get_posts", "c_ws_plugin__s2member_querys::force_query_level_access", 20);
1830 add_action ("pre_get_posts", "c_ws_plugin__s2member_security::security_gate_query", 20);
1831 }
1832 }
1833 /**
1834 * Generates a File Download Key that provides access to a File protected by s2Member.
1835 *
1836 * By default, s2Member uses your Basic Download Restrictions. For more information on this,
1837 * please check your Dashboard under: `s2Member -> Download Options -> Basic Download Restrictions`.
1838 *
1839 * ———— Advanced Download Restrictions ————
1840 *
1841 * Or, you can also force s2Member to allow File Downloads, using an extra query string parameter `s2member_file_download_key`.
1842 * A File Download Key is passed through this parameter; it tells s2Member to allow the download of this particular file,
1843 * regardless of Membership Level; and WITHOUT checking any Basic Restrictions, that you may, or may not, have configured.
1844 *
1845 * ———— Code Sample Using A Download Key ————
1846 * ```
1847 * <a href="/?s2member_file_download=file.zip&s2member_file_download_key=<!php echo s2member_file_download_key("file.zip"); !>">Download Now</a>
1848 * ```
1849 * ———— Shortcode Equivalent ————
1850 * ```
1851 * There is NO Shortcode equivalent for this ( yet ).
1852 * ```
1853 *
1854 * This API Funtion produces a time-sensitive File Download Key that is unique to each and every visitor.
1855 * Each Key it produces *( at the time it is produced )*, will be valid for the current day, and only for a specific IP address and User-Agent string;
1856 * as detected by s2Member. This makes it possible for you to create links on your site, which provide access to protected File Downloads;
1857 * without having to worry about one visitor sharing their link with another.
1858 *
1859 * When `/?s2member_file_download_key` = `a valid Key` generated by this function, it works independently from Member Level Access.
1860 * That is, a visitor does NOT have to be logged in to receive access; they just need a valid Key.
1861 * Using this advanced technique, you could extend s2Member's file protection routines,
1862 * or even combine them with Specific Post/Page Access, and more.
1863 * The possibilities are limitless really.
1864 *
1865 * @package s2Member\API_Functions
1866 * @since 3.5
1867 *
1868 * @param str $file Location of the protected File, relative to the `/s2member-files/` directory.
1869 * @param str|bool $directive Optional. Defaults to false. If you set this to any non-zero value ( i.e. the string `universal` ),
1870 * the resulting Key will be universal *( i.e. valid for any User, at any time, from any browser )*. That is to say; universal, for this particular File.
1871 * It is also possible to pass in the $directive string `ip-forever`, making the Key last forever, but only for a specific IP address.
1872 * @return str The File Download Key. Which is an MD5 hash *( always 32 characters )*, URL-safe.
1873 *
1874 * @todo Create a Shortcode equivalent.
1875 * @todo Allow custom expiration times.
1876 */
1877 if (!function_exists ("s2member_file_download_key"))
1878 {
1879 function s2member_file_download_key ($file = FALSE, $directive = FALSE)
1880 {
1881 return c_ws_plugin__s2member_files::file_download_key ($file, $directive);
1882 }
1883 }
1884 /**
1885 * Obtains the Registration Time for the current User, and/or for a particular User.
1886 *
1887 * The Registration Time, is the time at which the Username was created for the account, that's it.
1888 * There's nothing special about this. This simply returns a {@link http://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
1889 *
1890 * ———— Code Sample Using Function Parameters ————
1891 * ```
1892 * <!php
1893 * if(s2member_registration_time() <= strtotime("-30 days"))
1894 * echo 'The current User has existed for at least 30 days.';
1895 *
1896 * else if(s2member_registration_time(123) <= strtotime("-30 days"))
1897 * echo 'User with ID #123 has existed for at least 30 days.';
1898 * !>
1899 * ```
1900 * ———— Shortcode Equivalent ————
1901 * ```
1902 * There is NO Shortcode equivalent for this ( yet ).
1903 * ```
1904 *
1905 * @package s2Member\API_Functions
1906 * @since 3.5
1907 *
1908 * @param int $user_id Optional. Defaults to the current User's ID.
1909 * @return int A {@link http://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
1910 * The Registration Time, is the time at which the Username was created for the account, that's it.
1911 *
1912 * @see s2Member\API_Functions\get_user_field()
1913 *
1914 * @todo Create a Shortcode equivalent.
1915 */
1916 if (!function_exists ("s2member_registration_time"))
1917 {
1918 function s2member_registration_time ($user_id = FALSE)
1919 {
1920 return c_ws_plugin__s2member_registration_times::registration_time ($user_id);
1921 }
1922 }
1923 /**
1924 * Retrieves a Paid Registration Time for the current User, and/or for a particular User.
1925 *
1926 * **NOTE** A Paid Registration Time, is NOT necessarily related specifically to a Payment.
1927 * s2Member records a Paid Registration Time, anytime a User acquires paid Membership Level Access.
1928 *
1929 * In other words, if you create a new User inside your Dashboard at a Membership Level greater than Level #0,
1930 * s2Member will record a Paid Registration Time immediately, because Membership Levels > 0, are reserved for paying Members.
1931 * s2Member monitors changes to all User accounts, and records the first Paid Registration Time for each Member, at each paid Membership Level.
1932 * So, s2Member stores the first Time a Member reaches each Level of paid access; and s2Member does NOT care if they *actually* paid, or not.
1933 *
1934 * ———— Code Sample Using Function Parameters ————
1935 * ```
1936 * <!php
1937 * $time = s2member_registration_time (); # first registration time ( free or otherwise ).
1938 * $time = s2member_paid_registration_time (); # first "paid" registration and/or upgrade time.
1939 * $time = s2member_paid_registration_time ("level1"); # first "paid" registration or upgrade time at Level#1.
1940 * $time = s2member_paid_registration_time ("level2"); # first "paid" registration or upgrade time at Level#2.
1941 * $time = s2member_paid_registration_time ("level3"); # first "paid" registration or upgrade time at Level#3.
1942 * $time = s2member_paid_registration_time ("level4"); # first "paid" registration or upgrade time at Level#4.
1943 * !>
1944 * ```
1945 * ———— Shortcode Equivalent ————
1946 * ```
1947 * There is NO Shortcode equivalent for this ( yet ).
1948 * ```
1949 *
1950 * @package s2Member\API_Functions
1951 * @since 3.5
1952 *
1953 * @param str $level Optional. Defaults to the first/initial Paid Registration Time, regardless of Level#.
1954 * @param int $user_id Optional. Defaults to the current User's ID.
1955 * @return int A {@link http://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
1956 *
1957 * @see s2Member\API_Functions\get_user_field()
1958 *
1959 * @todo Create a Shortcode equivalent.
1960 */
1961 if (!function_exists ("s2member_paid_registration_time"))
1962 {
1963 function s2member_paid_registration_time ($level = FALSE, $user_id = FALSE)
1964 {
1965 return c_ws_plugin__s2member_registration_times::paid_registration_time ($level, $user_id);
1966 }
1967 }
1968 /**
1969 * A powerful function that can retrieve almost anything
1970 * you need to know about the current User, and/or a particular User.
1971 *
1972 * Scans all properties of the {@link http://codex.wordpress.org/Function_Reference/wp_get_current_user WP_User object}.
1973 * It defaults to the current User, but can also be used to obtain information about a particular User, by passing in a specific User ID.
1974 *
1975 * It can be used to retrieve basic information like `first_name`, `last_name`, `user_email`, `user_login`.
1976 * It can also be used to retrieve User Meta/Options, Role/Capabilities, and even supports
1977 * Custom Registration Fields configured with s2Member and many other plugins.
1978 *
1979 * ———— Here Are A Few Examples ————
1980 * ```
1981 * <!php
1982 * $user_login = get_user_field ("user_login"); # Username for the current User.
1983 * $user_email = get_user_field ("user_email"); # Email Address for the current User.
1984 * $first_name = get_user_field ("first_name"); # First Name for the current User.
1985 * $last_name = get_user_field ("last_name"); # Last Name for the current User.
1986 * $full_name = get_user_field ("full_name"); # First and Last Name for the current User.
1987 * $display_name = get_user_field ("display_name"); # Display Name for the current User.
1988 * !>
1989 * ```
1990 * ———— Shortcode Equivalents ————
1991 * ```
1992 * [s2Get user_field="user_login" /] # Username for the current User.
1993 * [s2Get user_field="user_email" /] # Email Address for the current User.
1994 * [s2Get user_field="first_name" /] # First Name for the current User.
1995 * [s2Get user_field="last_name" /] # Last Name for the current User.
1996 * [s2Get user_field="full_name" /] # First and Last Name for the current User.
1997 * [s2Get user_field="display_name" /] # Display Name for the current User.
1998 * ```
1999 * ———— More Examples With s2Member Fields ————
2000 * ```
2001 * <!php
2002 * $s2member_custom = get_user_field ("s2member_custom"); # Custom String value for the current User.
2003 * $s2member_subscr_id = get_user_field ("s2member_subscr_id"); # Paid Subscr. ID for the current User.
2004 * $s2member_subscr_or_wp_id = get_user_field ("s2member_subscr_or_wp_id"); # Paid Subscr. ID, else WordPress® User ID.
2005 * $s2member_subscr_gateway = get_user_field ("s2member_subscr_gateway"); # Paid Subscr. Gateway Code for the current User.
2006 * $s2member_registration_ip = get_user_field ("s2member_registration_ip"); # IP the current User had during registration.
2007 * $s2member_custom_fields = get_user_field ("s2member_custom_fields"); # Associative array of all Custom Registration Fields.
2008 * $s2member_file_download_access_log = get_user_field ("s2member_file_download_access_log"); # Associative array of all File Downloads by the current User.
2009 * $s2member_auto_eot_time = get_user_field ("s2member_auto_eot_time"); # Auto EOT-Time for the current User ( when applicable ).
2010 * $s2member_last_payment_time = get_user_field ("s2member_last_payment_time"); # Timestamp. Last time an actual payment was received by s2Member.
2011 * $s2member_paid_registration_times = get_user_field ("s2member_paid_registration_times"); # Timestamps. Associative array of all Paid Registration Times.
2012 * $s2member_access_role = get_user_field ("s2member_access_role"); # A WordPress® Role ID ( i.e. s2member_level[0-9]+, administrator, editor, author, contributor, subscriber ).
2013 * $s2member_access_level = get_user_field ("s2member_access_level"); # An s2Member Membership Access Level number.
2014 * $s2member_access_label = get_user_field ("s2member_access_label"); # An s2Member Membership Access Label ( i.e. Bronze, Gold, Silver, Platinum, or whatever is configured ).
2015 * $s2member_access_ccaps = get_user_field ("s2member_access_ccaps"); # An array of Custom Capabilities the current User has ( i.e. music,videos ).
2016 * !>
2017 * ```
2018 * ———— Practical Shortcode Equivalents ————
2019 * ```
2020 * [s2Get user_field="s2member_custom" /] # Custom String value for the current User.
2021 * [s2Get user_field="s2member_subscr_id" /] # Paid Subscr. ID for the current User.
2022 * [s2Get user_field="s2member_subscr_or_wp_id" /] # Paid Subscr. ID, else WordPress® User ID.
2023 * [s2Get user_field="s2member_subscr_gateway" /] # Paid Subscr. Gateway Code for the current User.
2024 * [s2Get user_field="s2member_registration_ip" /] # IP Address the current User had during registration.
2025 * [s2Get user_field="s2member_access_role" /] # A WordPress® Role ID ( i.e. s2member_level[0-9]+, administrator, editor, author, contributor, subscriber ).
2026 * [s2Get user_field="s2member_access_level" /] # An s2Member Membership Access Level number.
2027 * [s2Get user_field="s2member_access_label" /] # An s2Member Membership Access Label ( i.e. Bronze, Gold, Silver, Platinum, or whatever is configured ).
2028 * ```
2029 * ———— Pulling Data From Your Own Custom Fields ————
2030 * ```
2031 * <!php
2032 * $my_field_data = get_user_field ("my_field_id"); # The Unique Field ID you configured with s2Member.
2033 * !>
2034 * ```
2035 * ———— Shortcode Equivalent ————
2036 * ```
2037 * [s2Get user_field="my_field_id" /] # The Unique Field ID you configured with s2Member.
2038 * ```
2039 * ———— Pulling Data For A Particular User ID ————
2040 * ```
2041 * <!php
2042 * $user_login = get_user_field ("user_login", 123); # Username for the User with ID #123.
2043 * $user_email = get_user_field ("user_email", 123); # Email Address for the User with ID #123.
2044 * $first_name = get_user_field ("first_name", 123); # First Name for the User with ID #123.
2045 * $last_name = get_user_field ("last_name", 123); # Last Name for the User with ID #123.
2046 * $full_name = get_user_field ("full_name", 123); # First and Last Name for the User with ID #123.
2047 * $display_name = get_user_field ("display_name", 123); # Display Name for the User with ID #123.
2048 * !>
2049 * ```
2050 * ———— Shortcode Equivalents ————
2051 * ```
2052 * [s2Get user_field="user_login" user_id="123" /] # Username for the User with ID #123.
2053 * [s2Get user_field="user_email" user_id="123" /] # Email Address for the User with ID #123.
2054 * [s2Get user_field="first_name" user_id="123" /] # First Name for the User with ID #123.
2055 * [s2Get user_field="last_name" user_id="123" /] # Last Name for the User with ID #123.
2056 * [s2Get user_field="full_name" user_id="123" /] # First and Last Name for the User with ID #123.
2057 * [s2Get user_field="display_name" user_id="123" /] # Display Name for the User with ID #123.
2058 * ```
2059 * ———— Finding A User ID, Based On Username ————
2060 * ```
2061 * <!php
2062 * $user = new WP_User("johndoe22");
2063 * $user_id = $user->ID;
2064 * !>
2065 * ```
2066 * ———— Finding A Username, Based On User ID ————
2067 * ```
2068 * <!php
2069 * $user = new WP_User(123);
2070 * $user_login = $user->user_login;
2071 * # Or you could just use this alternate method.
2072 * $user_login = get_user_field ("user_login", 123);
2073 * !>
2074 * ```
2075 *
2076 * ———— Alternative Using ``get_user_option()`` Native To WordPress® ————
2077 * Most of the s2Member fields are stored in the `usermeta` table ( a WordPress® standard ),
2078 * so they could also be retrieved with {@link http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()} if you prefer,
2079 * which is already native to WordPress®. That being said, {@link s2Member\API_Functions\get_user_field()} is provided by s2Member as a way to retrieve *almost anything*.
2080 * ```
2081 * <!php
2082 * $s2member_custom = get_user_option ("s2member_custom"); # Custom String value for the current User.
2083 * $s2member_subscr_id = get_user_option ("s2member_subscr_id"); # Paid Subscr. ID for the current User.
2084 * $s2member_subscr_gateway = get_user_option ("s2member_subscr_gateway"); # Paid Subscr. Gateway Code for the current User.
2085 * $s2member_registration_ip = get_user_option ("s2member_registration_ip"); # IP the current User had during registration.
2086 * $s2member_custom_fields = get_user_option ("s2member_custom_fields"); # Associative array of all Custom Registration Fields.
2087 * $s2member_file_download_access_log = get_user_option ("s2member_file_download_access_log"); # Associative array of all File Downloads by the current User.
2088 * $s2member_auto_eot_time = get_user_option ("s2member_auto_eot_time"); # Auto EOT-Time for the current User ( when applicable ).
2089 * $s2member_last_payment_time = get_user_option ("s2member_last_payment_time"); # Timestamp. Last time an actual payment was received by s2Member.
2090 * $s2member_paid_registration_times = get_user_option ("s2member_paid_registration_times"); # Timestamps. Associative array of all Paid Registration Times.
2091 * !>
2092 * ```
2093 * ———— Practical Shortcode Equivalents ————
2094 * ```
2095 * [s2Get user_option="s2member_custom" /] # Custom String value for the current User.
2096 * [s2Get user_option="s2member_subscr_id" /] # Paid Subscr. ID for the current User.
2097 * [s2Get user_option="s2member_subscr_gateway" /] # Paid Subscr. Gateway Code for the current User.
2098 * [s2Get user_option="s2member_registration_ip" /] # IP the current User had during registration.
2099 * ```
2100 *
2101 * @package s2Member\API_Functions
2102 * @since 3.5
2103 *
2104 * @param str $field_id Required. A unique Custom Registration Field ID, that you configured with s2Member.
2105 * Or, this could be set to any property that exists on the WP_User object for a particular User;
2106 * ( i.e. `id`, `ID`, `user_login`, `user_email`, `first_name`, `last_name`, `display_name`, `ip`, `IP`,
2107 * `s2member_registration_ip`, `s2member_custom`, `s2member_subscr_id`, `s2member_subscr_or_wp_id`,
2108 * `s2member_subscr_gateway`, `s2member_custom_fields`, `s2member_file_download_access_log`,
2109 * `s2member_auto_eot_time`, `s2member_last_payment_time`, `s2member_paid_registration_times`,
2110 * `s2member_access_role`, `s2member_access_level`, `s2member_access_label`,
2111 * `s2member_access_ccaps`, etc, etc. ).
2112 * @param int $user_id Optional. Defaults to the current User's ID.
2113 * @return mixed The value of the requested field, or false if the field does not exist.
2114 *
2115 * @see s2Member\API_Functions\s2member_registration_time()
2116 * @see s2Member\API_Functions\s2member_paid_registration_time()
2117 *
2118 * @see http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()
2119 * @see http://codex.wordpress.org/Function_Reference/update_user_option update_user_option()
2120 * @see http://codex.wordpress.org/Function_Reference/wp_get_current_user wp_get_current_user()
2121 */
2122 if (!function_exists ("get_user_field"))
2123 {
2124 function get_user_field ($field_id = FALSE, $user_id = FALSE)
2125 {
2126 return c_ws_plugin__s2member_utils_users::get_user_field ($field_id, $user_id);
2127 }
2128 }
2129 ?>