PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110815
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110815
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 110815, at includes/functions/api-functions.inc.php

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