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

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

2,339 lines 114.8 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", 100);
1802 add_action ("pre_get_posts", "c_ws_plugin__s2member_querys::force_query_level_access", 100);
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", 100);
1848 add_action ("pre_get_posts", "c_ws_plugin__s2member_security::security_gate_query", 100);
1849 }
1850 }
1851 /**
1852 * Generates a File Download URL 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 * ———— HTML/PHP Code Samples ————
1858 * ```
1859 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.zip")); !>">Download Now</a>
1860 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.pdf", "file_inline" => true)); !>">View PDF</a>
1861 * ```
1862 * ———— Shortcode Equivalents ————
1863 * ```
1864 * <a href="[s2File download="file.zip" /]">Download Now</a>
1865 * <a href="[s2File download="file.pdf" inline="true" /]">View PDF</a>
1866 * ```
1867 *
1868 * ———— Advanced Download Restrictions ————
1869 *
1870 * Or, you can also force s2Member to allow File Downloads, by requesting a File Download Key ( i.e. `file_download_key => true` ).
1871 * When a File Download Key is requested through this parameter ( i.e. `file_download_key => true` ); it tells s2Member to allow the download of this particular file,
1872 * regardless of Membership Level; and WITHOUT checking any Basic Restrictions, that you may, or may not have configured.
1873 *
1874 * ———— HTML/PHP Code Samples Using A Download Key ————
1875 * ```
1876 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.zip", file_download_key => true)); !>">Download Now</a>
1877 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.pdf", file_download_key => true, "file_inline" => true)); !>">View PDF</a>
1878 * ```
1879 * ———— Shortcode Equivalents Using A Download Key ————
1880 * ```
1881 * <a href="[s2File download="file.zip" download_key="true" /]">Download Now</a>
1882 * <a href="[s2File download="file.zip" download_key="true" inline="true" /]">View PDF</a>
1883 * ```
1884 *
1885 * ———— Extra Detail On Function Parameters ————
1886 *
1887 * **Parameter $config ( array Required ).** This should be an array with one or more of the following elements.
1888 *
1889 * o ``"file_download" => "file.zip"`` Location of the file, relative to the `/s2member-files/` directory; or, relative to the root of your Amazon® S3 Bucket, when applicable.
1890 * o ``"file_download_key" => false`` Defaults to `false`. If `true`, s2Member will return a URL with an s2Member-generated File Download Key. You don't need to generate the File Download Key yourself, s2Member does it for you. If you set this to `ip-forever`, the File Download Key that s2Member generates will last forever, for a specific IP Address; otherwise, by default, all File Download Keys expire after 24 hours automatically. If you set this to `universal`, s2Member will generate a File Download Key that is good for anyone/everyone forever, with NO restrictions on who/where/when a file is accessed *( e.g. be careful with this one )*.
1891 * o ``"file_stream" => false`` Defaults to `false`. If `true`, s2Member will return a URL containing a parameter/directive, which forces the File Download to take place over the RTMP protocol. This ONLY works when/if s2Member is configured to run with both Amazon® S3/CloudFront. Please note however, it's better to use the example code provided in the your Dashboard. See: `s2Member -> Download Options -> JW Player® and the RTMP Protocol`. Also note, if ``$get_streamer_array`` is passed, s2Member will automatically force ``"file_stream" => true`` for you.
1892 * o ``"file_inline" => null`` Defaults to `null`. If `true`, s2Member will serve the file inline, instead of as an actual File Download. If empty, s2Member will look at your Inline File Extensions configuration, and serve the file inline; if, and only if, its extension matches one found in your configuration. By default, s2Member serves all files as attachments *( i.e. downloads )*. Please check your Dashboard regarding Inline File Extensions. Also note, this Shortcode Attribute does NOTHING for files served via Amazon® CloudFront. See the tech-notes listed in the Amazon® CloudFront section of your Dashboard for further details and workarounds.
1893 * o ``"file_storage" => null`` Defaults to `null`. Can be one of `local|s3|cf`. When specified, s2Member will serve the file from a specific source location. For example, if you've configured Amazon® S3 and/or CloudFront; but, there are a few files that you want to upload locally to the `/s2member-files/` directory; you can force s2Member to serve a file from local storage by setting ``"file_storage" => "local"`` explicitly.
1894 * o ``"file_remote" => false`` Defaults to `false`. If `true`, s2Member will authenticate access to the File Download via Remote Header Authorization, instead of through your web site. This is similar to `.htaccess` protection routines of yester-year. Please check the Remote Authorization and Podcasting section in your Dashboard for further details about how this works.
1895 * o ``"file_ssl" => null`` Defaults to `null`. If `true`, s2Member will generate a File Download URL with an SSL protocol *( i.e. the URL will start with `https://` or `rtmpe://` )*. If `null`, s2Member will only generate a File Download URL with an SSL protocol, when/if the Post/Page/URL, is also being viewed over SSL. Otherwise, s2Member will use a non-SSL protocol by default.
1896 * o ``"file_rewrite" => false`` Defaults to `false`. If `true`, s2Member will generate a File Download URL that takes full advantage of s2Member's Advanced Mod Rewrite functionality. If you're running an Apache web server, or another server that supports `mod_rewrite`, we highly recommend turning this on. s2Member's `mod_rewrite` URLs do NOT contain query string parameters, making them more portable/compatible with other software applications and/or plugins for WordPress®.
1897 * o ``"file_rewrite_base" => null`` Defaults to `null`. If set to a URL, starting with `http` or another valid protocol, s2Member will generate a File Download URL that takes full advantage of s2Member's Advanced Mod Rewrite functionality, and it will use the rewrite base URL as a prefix. This could be useful on some WordPress® installations that use advanced directory structures. It could also be useful for site owners using virtual directories that point to `/s2member-files/`. Note, if `rewrite_base` is set, s2Member will automatically force ``"rewrite" => true`` for you.
1898 * o ``"skip_confirmation" => false`` Defaults to `false`. If `true`, s2Member will generate a File Download URL which contains a directive, telling s2Member NOT to introduce any JavaScript confirmation prompts on your site, for this File Download URL. Please note, s2Member will automatically detect links, anywhere in your content, and/or anywhere in your theme files, that contain `s2member_file_download` or `s2member-files`. Whenever a logged-in Member clicks a link that contains `s2member_file_download` or `s2member-files`, the system will politely ask the User to confirm the download using a very intuitive JavaScript confirmation prompt, which contains specific details about your configured download limitations. This way your Members will be aware of how many files they've downloaded in the current period; and they'll be able to make a conscious decision about whether to proceed with a specific download or not.
1899 * o ``"url_to_storage_source" => false`` Defaults to `false`. If `true`, s2Member will generate a File Download URL which points directly to the storage source. This is only functional with Amazon® S3 and/or CloudFront integrations. If you create a URL that points directly to the storage source *( i.e. points directly to Amazon® S3 or CloudFront )*, s2Member will NOT be able to further authenticate the current User/Member; and, s2Member will NOT be able to count the File Download against the current User's account record, because the URL being generated does not pass back through s2Member at all, it points directly to the storage source. For this reason, if you set ``"url_to_storage_source" => true``, you should also set ``"check_user" => true`` and ``"count_against_user" => true``, telling s2Member to authenticate the current User, and if authenticated, count this File Download URL against the current User's account record in real-time *( i.e. as the URL is being generated )*, while it still has a chance to do so. This is useful when you stream files over the RTMP protocol; where an `http://` URL is not feasible. It also helps in situations where a 3rd-party software application will not work as intended, with s2Member's internal redirection to Amazon® S3/CloudFront files. Important, when ``"check_user" => true`` and/or ``"count_against_user" => true``, this API Function will return `false` in situations where the current User/Member does NOT have access to the file.
1900 * o ``"count_against_user" => false`` Defaults to `false`. If `true`, it will automatically force ``"check_user" => true`` as well. In other words, s2Member will authenticate the current User, and if authenticated, count this File Download URL against the current User's account record in real-time *( i.e. as the URL is being generated )*. This is off by default. By default, s2Member will simply generate a File Download URL, and upon a User/Member clicking the URL, s2Member will authenticate the User/Member at that time, count the File Download against their account record, and serve the File Download. In other words, under normal circumstances, there is no reason to set ``"check_user" => true`` and/or ``"count_against_user" => true`` when generating the URL itself. However, this is a useful config option when ``"url_to_storage_source" => true``. Please note, when ``"check_user" => true`` and/or ``"count_against_user" => true``, this API Function will return `false` in situations where the current User/Member does NOT have access to the file.
1901 * o ``"check_user => false`` Defaults to `false`. If `true`, s2Member will authenticate the current User before allowing the File Download URL to be generated. This is off by default. By default, s2Member will simply generate a File Download URL, and upon a User/Member clicking the URL, s2Member will authenticate the User/Member at that time, and serve the File Download to the User/Member. In other words, under normal circumstances, there is no reason to set ``"check_user" => true`` and/or ``"count_against_user" => true`` when generating the URL itself. However, this IS a useful config option when ``"url_to_storage_source" => true``. Please note, when ``"check_user" => true`` and/or ``"count_against_user" => true``, this API Function will return `false` in situations where the current User/Member does NOT have access to the file.
1902 *
1903 * **Parameter $get_streamer_array ( bool Optional ).** Defaults to `false`. If `true`, this API Function will return an array with the following elements: `streamer`, `file`, `url`. For further details, please review this section in your Dashboard: `s2Member -> Download Options -> JW Player® & RTMP Protocol Examples`. Note, if this is true, s2Member will automatically force ``"url_to_storage_source" => true`` and ``"file_stream" => true``. For that reason, you should carefully review the details and warning above regarding `url_to_storage_source`. If you set ``$get_streamer_array``, you should also set ``"check_user" => true`` and ``"count_against_user" => true``.
1904 *
1905 * @package s2Member\API_Functions
1906 * @since 110926
1907 *
1908 * @param array $config Required. This is an array of configuration options associated with permissions being checked against the current User/Member; and also the actual URL generated by this routine.
1909 * Possible ``$config`` array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `check_user`.
1910 * @param bool $get_streamer_array Optional. Defaults to `false`. If `true`, this API Function will return an array with the following elements: `streamer`, `file`, `url`. For further details, please review this section in your Dashboard: `s2Member -> Download Options -> JW Player® & RTMP Protocol Examples`. Note, if this is true, s2Member will automatically force ``"url_to_storage_source" => true`` and ``"file_stream" => true``. For that reason, you should carefully review the details and warning above regarding `url_to_storage_source`. If you set ``$get_streamer_array``, you should also set ``"check_user" => true`` and ``"count_against_user" => true``.
1911 * @return str A File Download URL string on success; or an array on success, with elements `streamer`, `file`, `url` when/if ``$get_streamer_array`` is true; else false on any type of failure.
1912 *
1913 * @see s2Member\API_Functions\s2member_file_download_key()
1914 */
1915 if (!function_exists ("s2member_file_download_url"))
1916 {
1917 function s2member_file_download_url ($config = FALSE, $get_streamer_array = FALSE)
1918 {
1919 return c_ws_plugin__s2member_files::create_file_download_url ($config, $get_streamer_array);
1920 }
1921 }
1922 /**
1923 * Generates a File Download Key that provides access to a File protected by s2Member.
1924 *
1925 * By default, s2Member uses your Basic Download Restrictions. For more information on this,
1926 * please check your Dashboard under: `s2Member -> Download Options -> Basic Download Restrictions`.
1927 *
1928 * ———— Advanced Download Restrictions ————
1929 *
1930 * Or, you can also force s2Member to allow File Downloads, using an extra query string parameter `s2member_file_download_key`.
1931 * A File Download Key is passed through this parameter; it tells s2Member to allow the download of this particular file,
1932 * regardless of Membership Level; and WITHOUT checking any Basic Restrictions, that you may, or may not have configured.
1933 *
1934 * ———— Code Sample Using A Download Key ————
1935 * ```
1936 * <a href="/?s2member_file_download=file.zip&s2member_file_download_key=<!php echo s2member_file_download_key("file.zip"); !>">Download Now</a>
1937 * ```
1938 * ———— Shortcode Equivalent ————
1939 * ```
1940 * [s2Key file_download="file.zip" directive="" /]
1941 * ```
1942 *
1943 * This API Funtion produces a time-sensitive File Download Key that is unique to each and every visitor.
1944 * 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;
1945 * as detected by s2Member. This makes it possible for you to create links on your site, which provide access to protected File Downloads;
1946 * without having to worry about one visitor sharing their link with another.
1947 *
1948 * When `/?s2member_file_download_key` = `a valid Key` generated by this function, it works independently from Member Level Access.
1949 * That is, a visitor does NOT have to be logged in to receive access; they just need a valid Key.
1950 * Using this advanced technique, you could extend s2Member's file protection routines,
1951 * or even combine them with Specific Post/Page Access, and more.
1952 * The possibilities are limitless really.
1953 *
1954 * @package s2Member\API_Functions
1955 * @since 3.5
1956 *
1957 * @param str $file Location of the protected File, relative to the `/s2member-files/` directory.
1958 * @param str|bool $directive Optional. Defaults to false. If you set this to any non-zero value ( i.e. the string `universal` ),
1959 * 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.
1960 * It is also possible to pass in the ``$directive`` string `ip-forever`, making the Key last forever, but only for a specific IP address.
1961 * @return str The File Download Key. Which is an MD5 hash *( always 32 characters )*, URL-safe.
1962 *
1963 * @see s2Member\API_Functions\s2member_file_download_url()
1964 *
1965 * @todo Allow custom expiration times.
1966 */
1967 if (!function_exists ("s2member_file_download_key"))
1968 {
1969 function s2member_file_download_key ($file = FALSE, $directive = FALSE)
1970 {
1971 return c_ws_plugin__s2member_files::file_download_key ($file, $directive);
1972 }
1973 }
1974 /**
1975 * Obtains the Registration Time for the current User, and/or for a particular User.
1976 *
1977 * The Registration Time, is the time at which the Username was created for the account, that's it.
1978 * There's nothing special about this. This simply returns a {@link http://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
1979 *
1980 * ———— Code Sample Using Function Parameters ————
1981 * ```
1982 * <!php
1983 * if(s2member_registration_time() <= strtotime("-30 days"))
1984 * echo 'The current User has existed for at least 30 days.';
1985 *
1986 * else if(s2member_registration_time(123) <= strtotime("-30 days"))
1987 * echo 'User with ID #123 has existed for at least 30 days.';
1988 * !>
1989 * ```
1990 * ———— Shortcode Equivalent ————
1991 * ```
1992 * There is NO Shortcode equivalent for this ( yet ).
1993 * ```
1994 *
1995 * @package s2Member\API_Functions
1996 * @since 3.5
1997 *
1998 * @param int $user_id Optional. Defaults to the current User's ID.
1999 * @return int A {@link http://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2000 * The Registration Time, is the time at which the Username was created for the account, that's it.
2001 *
2002 * @see s2Member\API_Functions\get_user_field()
2003 */
2004 if (!function_exists ("s2member_registration_time"))
2005 {
2006 function s2member_registration_time ($user_id = FALSE)
2007 {
2008 return c_ws_plugin__s2member_registration_times::registration_time ($user_id);
2009 }
2010 }
2011 /**
2012 * Retrieves a Paid Registration Time for the current User, and/or for a particular User.
2013 *
2014 * **NOTE** A Paid Registration Time, is NOT necessarily related specifically to a Payment.
2015 * s2Member records a Paid Registration Time, anytime a User acquires paid Membership Level Access.
2016 *
2017 * In other words, if you create a new User inside your Dashboard at a Membership Level greater than Level #0,
2018 * s2Member will record a Paid Registration Time immediately, because Membership Levels > 0, are reserved for paying Members.
2019 * s2Member monitors changes to all User accounts, and records the first Paid Registration Time for each Member, at each paid Membership Level.
2020 * 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.
2021 *
2022 * ———— Code Sample Using Function Parameters ————
2023 * ```
2024 * <!php
2025 * $time = s2member_registration_time (); # first registration time ( free or otherwise ).
2026 * $time = s2member_paid_registration_time (); # first "paid" registration and/or upgrade time.
2027 * $time = s2member_paid_registration_time ("level1"); # first "paid" registration or upgrade time at Level#1.
2028 * $time = s2member_paid_registration_time ("level2"); # first "paid" registration or upgrade time at Level#2.
2029 * $time = s2member_paid_registration_time ("level3"); # first "paid" registration or upgrade time at Level#3.
2030 * $time = s2member_paid_registration_time ("level4"); # first "paid" registration or upgrade time at Level#4.
2031 * !>
2032 * ```
2033 * ———— Shortcode Equivalent ————
2034 * ```
2035 * There is NO Shortcode equivalent for this ( yet ).
2036 * ```
2037 *
2038 * @package s2Member\API_Functions
2039 * @since 3.5
2040 *
2041 * @param str $level Optional. Defaults to the first/initial Paid Registration Time, regardless of Level#.
2042 * @param int $user_id Optional. Defaults to the current User's ID.
2043 * @return int A {@link http://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2044 *
2045 * @see s2Member\API_Functions\get_user_field()
2046 */
2047 if (!function_exists ("s2member_paid_registration_time"))
2048 {
2049 function s2member_paid_registration_time ($level = FALSE, $user_id = FALSE)
2050 {
2051 return c_ws_plugin__s2member_registration_times::paid_registration_time ($level, $user_id);
2052 }
2053 }
2054 /**
2055 * A powerful function that can retrieve almost anything
2056 * you need to know about the current User, and/or a particular User.
2057 *
2058 * Scans all properties of the {@link http://codex.wordpress.org/Function_Reference/wp_get_current_user WP_User object}.
2059 * 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.
2060 *
2061 * It can be used to retrieve basic information like `first_name`, `last_name`, `user_email`, `user_login`.
2062 * It can also be used to retrieve User Meta/Options, Role/Capabilities, and even supports
2063 * Custom Registration/Profile Fields configured with s2Member and many other plugins.
2064 *
2065 * ———— Here Are A Few Examples ————
2066 * ```
2067 * <!php
2068 * $user_login = get_user_field ("user_login"); # Username for the current User.
2069 * $user_email = get_user_field ("user_email"); # Email Address for the current User.
2070 * $first_name = get_user_field ("first_name"); # First Name for the current User.
2071 * $last_name = get_user_field ("last_name"); # Last Name for the current User.
2072 * $full_name = get_user_field ("full_name"); # First and Last Name for the current User.
2073 * $display_name = get_user_field ("display_name"); # Display Name for the current User.
2074 * !>
2075 * ```
2076 * ———— Shortcode Equivalents ————
2077 * ```
2078 * [s2Get user_field="user_login" /] # Username for the current User.
2079 * [s2Get user_field="user_email" /] # Email Address for the current User.
2080 * [s2Get user_field="first_name" /] # First Name for the current User.
2081 * [s2Get user_field="last_name" /] # Last Name for the current User.
2082 * [s2Get user_field="full_name" /] # First and Last Name for the current User.
2083 * [s2Get user_field="display_name" /] # Display Name for the current User.
2084 * ```
2085 * ———— More Examples With s2Member Fields ————
2086 * ```
2087 * <!php
2088 * $s2member_custom = get_user_field ("s2member_custom"); # Custom String value for the current User.
2089 * $s2member_subscr_id = get_user_field ("s2member_subscr_id"); # Paid Subscr. ID for the current User.
2090 * $s2member_subscr_or_wp_id = get_user_field ("s2member_subscr_or_wp_id"); # Paid Subscr. ID, else WordPress® User ID.
2091 * $s2member_subscr_gateway = get_user_field ("s2member_subscr_gateway"); # Paid Subscr. Gateway Code for the current User.
2092 * $s2member_registration_ip = get_user_field ("s2member_registration_ip"); # IP the current User had during registration.
2093 * $s2member_custom_fields = get_user_field ("s2member_custom_fields"); # Associative array of all Custom Registration/Profile Fields.
2094 * $s2member_file_download_access_log = get_user_field ("s2member_file_download_access_log"); # Associative array of all File Downloads by the current User.
2095 * $s2member_auto_eot_time = get_user_field ("s2member_auto_eot_time"); # Auto EOT-Time for the current User ( when applicable ).
2096 * $s2member_last_payment_time = get_user_field ("s2member_last_payment_time"); # Timestamp. Last time an actual payment was received by s2Member.
2097 * $s2member_paid_registration_times = get_user_field ("s2member_paid_registration_times"); # Timestamps. Associative array of all Paid Registration Times.
2098 * $s2member_access_role = get_user_field ("s2member_access_role"); # A WordPress® Role ID ( i.e. s2member_level[0-9]+, administrator, editor, author, contributor, subscriber ).
2099 * $s2member_access_level = get_user_field ("s2member_access_level"); # An s2Member Membership Access Level number.
2100 * $s2member_access_label = get_user_field ("s2member_access_label"); # An s2Member Membership Access Label ( i.e. Bronze, Gold, Silver, Platinum, or whatever is configured ).
2101 * $s2member_access_ccaps = get_user_field ("s2member_access_ccaps"); # An array of Custom Capabilities the current User has ( i.e. music,videos ).
2102 * $s2member_login_counter = get_user_field ("s2member_login_counter"); # Number of times the User has logged into your site.
2103 * !>
2104 * ```
2105 * ———— Practical Shortcode Equivalents ————
2106 * ```
2107 * [s2Get user_field="s2member_custom" /] # Custom String value for the current User.
2108 * [s2Get user_field="s2member_subscr_id" /] # Paid Subscr. ID for the current User.
2109 * [s2Get user_field="s2member_subscr_or_wp_id" /] # Paid Subscr. ID, else WordPress® User ID.
2110 * [s2Get user_field="s2member_subscr_gateway" /] # Paid Subscr. Gateway Code for the current User.
2111 * [s2Get user_field="s2member_registration_ip" /] # IP Address the current User had during registration.
2112 * [s2Get user_field="s2member_access_role" /] # A WordPress® Role ID ( i.e. s2member_level[0-9]+, administrator, editor, author, contributor, subscriber ).
2113 * [s2Get user_field="s2member_access_level" /] # An s2Member Membership Access Level number.
2114 * [s2Get user_field="s2member_access_label" /] # An s2Member Membership Access Label ( i.e. Bronze, Gold, Silver, Platinum, or whatever is configured ).
2115 * [s2Get user_field="s2member_login_counter" /] # Number of times the User has logged into your site.
2116 * ```
2117 * ———— Pulling Data From Your Own Custom Fields ————
2118 * ```
2119 * <!php
2120 * $my_field_data = get_user_field ("my_field_id"); # The Unique Field ID you configured with s2Member.
2121 * !>
2122 * ```
2123 * ———— Shortcode Equivalent ————
2124 * ```
2125 * [s2Get user_field="my_field_id" /] # The Unique Field ID you configured with s2Member.
2126 * ```
2127 * ———— Pulling Data For A Particular User ID ————
2128 * ```
2129 * <!php
2130 * $user_login = get_user_field ("user_login", 123); # Username for the User with ID #123.
2131 * $user_email = get_user_field ("user_email", 123); # Email Address for the User with ID #123.
2132 * $first_name = get_user_field ("first_name", 123); # First Name for the User with ID #123.
2133 * $last_name = get_user_field ("last_name", 123); # Last Name for the User with ID #123.
2134 * $full_name = get_user_field ("full_name", 123); # First and Last Name for the User with ID #123.
2135 * $display_name = get_user_field ("display_name", 123); # Display Name for the User with ID #123.
2136 * !>
2137 * ```
2138 * ———— Shortcode Equivalents ————
2139 * ```
2140 * [s2Get user_field="user_login" user_id="123" /] # Username for the User with ID #123.
2141 * [s2Get user_field="user_email" user_id="123" /] # Email Address for the User with ID #123.
2142 * [s2Get user_field="first_name" user_id="123" /] # First Name for the User with ID #123.
2143 * [s2Get user_field="last_name" user_id="123" /] # Last Name for the User with ID #123.
2144 * [s2Get user_field="full_name" user_id="123" /] # First and Last Name for the User with ID #123.
2145 * [s2Get user_field="display_name" user_id="123" /] # Display Name for the User with ID #123.
2146 * ```
2147 * ———— Finding A User ID, Based On Username ————
2148 * ```
2149 * <!php
2150 * $user = new WP_User("johndoe22");
2151 * $user_id = $user->ID;
2152 * !>
2153 * ```
2154 * ———— Finding A Username, Based On User ID ————
2155 * ```
2156 * <!php
2157 * $user = new WP_User(123);
2158 * $user_login = $user->user_login;
2159 * # Or you could just use this alternate method.
2160 * $user_login = get_user_field ("user_login", 123);
2161 * !>
2162 * ```
2163 *
2164 * ———— Alternative Using ``get_user_option()`` Native To WordPress® ————
2165 * Most of the s2Member fields are stored in the `usermeta` table ( a WordPress® standard ),
2166 * so they could also be retrieved with {@link http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()} if you prefer,
2167 * 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*.
2168 * ```
2169 * <!php
2170 * $s2member_custom = get_user_option ("s2member_custom"); # Custom String value for the current User.
2171 * $s2member_subscr_id = get_user_option ("s2member_subscr_id"); # Paid Subscr. ID for the current User.
2172 * $s2member_subscr_gateway = get_user_option ("s2member_subscr_gateway"); # Paid Subscr. Gateway Code for the current User.
2173 * $s2member_registration_ip = get_user_option ("s2member_registration_ip"); # IP the current User had during registration.
2174 * $s2member_custom_fields = get_user_option ("s2member_custom_fields"); # Associative array of all Custom Registration/Profile Fields.
2175 * $s2member_file_download_access_log = get_user_option ("s2member_file_download_access_log"); # Associative array of all File Downloads by the current User.
2176 * $s2member_auto_eot_time = get_user_option ("s2member_auto_eot_time"); # Auto EOT-Time for the current User ( when applicable ).
2177 * $s2member_last_payment_time = get_user_option ("s2member_last_payment_time"); # Timestamp. Last time an actual payment was received by s2Member.
2178 * $s2member_paid_registration_times = get_user_option ("s2member_paid_registration_times"); # Timestamps. Associative array of all Paid Registration Times.
2179 * $s2member_login_counter = get_user_option ("s2member_login_counter"); # Number of times the User has logged into your site.
2180 * !>
2181 * ```
2182 * ———— Practical Shortcode Equivalents ————
2183 * ```
2184 * [s2Get user_option="s2member_custom" /] # Custom String value for the current User.
2185 * [s2Get user_option="s2member_subscr_id" /] # Paid Subscr. ID for the current User.
2186 * [s2Get user_option="s2member_subscr_gateway" /] # Paid Subscr. Gateway Code for the current User.
2187 * [s2Get user_option="s2member_registration_ip" /] # IP the current User had during registration.
2188 * [s2Get user_option="s2member_login_counter" /] # Number of times the User has logged in.
2189 * ```
2190 *
2191 * @package s2Member\API_Functions
2192 * @since 3.5
2193 *
2194 * @param str $field_id Required. A unique Custom Registration/Profile Field ID, that you configured with s2Member.
2195 * Or, this could be set to any property that exists on the WP_User object for a particular User;
2196 * ( i.e. `id`, `ID`, `user_login`, `user_email`, `first_name`, `last_name`, `display_name`, `ip`, `IP`,
2197 * `s2member_registration_ip`, `s2member_custom`, `s2member_subscr_id`, `s2member_subscr_or_wp_id`,
2198 * `s2member_subscr_gateway`, `s2member_custom_fields`, `s2member_file_download_access_log`,
2199 * `s2member_auto_eot_time`, `s2member_last_payment_time`, `s2member_paid_registration_times`,
2200 * `s2member_access_role`, `s2member_access_level`, `s2member_access_label`,
2201 * `s2member_access_ccaps`, `s2member_login_counter`, etc, etc. ).
2202 * @param int $user_id Optional. Defaults to the current User's ID.
2203 * @return mixed The value of the requested field, or false if the field does not exist.
2204 *
2205 * @see s2Member\API_Functions\get_s2member_custom_fields()
2206 * @see s2Member\API_Functions\s2member_registration_time()
2207 * @see s2Member\API_Functions\s2member_paid_registration_time()
2208 *
2209 * @see http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()
2210 * @see http://codex.wordpress.org/Function_Reference/update_user_option update_user_option()
2211 * @see http://codex.wordpress.org/Function_Reference/wp_get_current_user wp_get_current_user()
2212 */
2213 if (!function_exists ("get_user_field"))
2214 {
2215 function get_user_field ($field_id = FALSE, $user_id = FALSE)
2216 {
2217 return c_ws_plugin__s2member_utils_users::get_user_field ($field_id, $user_id);
2218 }
2219 }
2220 /**
2221 * Custom Registration/Profile Field configuration.
2222 *
2223 * Provides information about the configuration of each Custom Registration/Profile Field.
2224 * Returns an associative array with all Custom Field configurations *( and User values too, if ``$user_id`` is passed in )*.
2225 *
2226 * ———— PHP Code Sample ————
2227 * ```
2228 * <!php
2229 * $fields = get_s2member_custom_fields();
2230 * print_r($fields["my_field_id"]["config"]); # The Unique Field ID you configured with s2Member.
2231 * !>
2232 * ```
2233 * ———— PHP Code Sample ( Specific User ) ————
2234 * ```
2235 * <!php
2236 * $fields = get_s2member_custom_fields(123);
2237 * echo $fields["my_field_id"]["user_value"]; # The Unique Field ID you configured with s2Member.
2238 * print_r($fields["my_field_id"]["config"]); # The Unique Field ID you configured with s2Member.
2239 * !>
2240 * ```
2241 * ———— Shortcode Alternative ( Specific User ) ————
2242 * ```
2243 * [s2Get user_field="my_field_id" /] # The Unique Field ID you configured with s2Member.
2244 * ```
2245 *
2246 * @package s2Member\API_Functions
2247 * @since 110912
2248 *
2249 * @param int|str $user_id Optional. If supplied, the `user_value` for each Custom Field will be included too.
2250 * @return array An associative array with all Custom Field configurations *( and User values too, if ``$user_id`` is supplied )*.
2251 *
2252 * @see s2Member\API_Functions\get_user_field()
2253 * @see s2Member\API_Functions\s2member_registration_time()
2254 * @see s2Member\API_Functions\s2member_paid_registration_time()
2255 *
2256 * @see http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()
2257 * @see http://codex.wordpress.org/Function_Reference/update_user_option update_user_option()
2258 * @see http://codex.wordpress.org/Function_Reference/wp_get_current_user wp_get_current_user()
2259 */
2260 if (!function_exists ("get_s2member_custom_fields"))
2261 {
2262 function get_s2member_custom_fields ($user_id = FALSE)
2263 {
2264 $fields = ($user_id) ? get_user_option ("s2member_custom_fields", $user_id) : false;
2265 /**//**/
2266 foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
2267 {
2268 if ($user_id) /* Should we try to fill the User's value for this Custom Field? */
2269 $s2member_custom_fields[$field["id"]]["user_value"] = (isset ($fields[$field["id"]])) ? $fields[$field["id"]] : false;
2270 $s2member_custom_fields[$field["id"]]["config"] = $field; /* Copy configuration into config element. */
2271 }
2272 /**/
2273 return (isset ($s2member_custom_fields)) ? (array)$s2member_custom_fields : array ();
2274 }
2275 }
2276 /**
2277 * Can be used to auto-fill the `invoice` for PayPal® Button Codes, with a unique Code~IP combination.
2278 *
2279 * ———— PHP Code Sample ————
2280 * ```
2281 * <!php echo s2member_value_for_pp_inv(); !>
2282 * ```
2283 * ———— Shortcode & JavaScript Equivalents ————
2284 * ```
2285 * [s2Get constant="S2MEMBER_VALUE_FOR_PP_INV" /]
2286 *
2287 * <script type="text/javascript">
2288 * document.write(s2member_value_for_pp_inv_gen());
2289 * </script>
2290 * ```
2291 *
2292 * @package s2Member\API_Functions
2293 * @since 110720
2294 *
2295 * @return str A unique Invoice.
2296 *
2297 * @see s2Member\API_Constants\S2MEMBER_VALUE_FOR_PP_INV
2298 *
2299 * @todo Create a true Shortcode equivalent function.
2300 */
2301 if (!function_exists ("s2member_value_for_pp_inv"))
2302 {
2303 function s2member_value_for_pp_inv ()
2304 {
2305 return uniqid () . "~" . $_SERVER["REMOTE_ADDR"];
2306 }
2307 }
2308 /**
2309 * Shortens a long URL, based on s2Member configuration.
2310 *
2311 * ———— PHP Code Samples ————
2312 * ```
2313 * <!php echo s2member_shorten_url("http://www.example.com/a-long-url/"); !>
2314 * <!php echo s2member_shorten_url("http://www.example.com/a-long-url/", "tiny_url"); !>
2315 * <!php echo s2member_shorten_url("http://www.example.com/a-long-url/", "goo_gl"); !>
2316 * ```
2317 * ———— Shortcode Equivalent ————
2318 * ```
2319 * There is NO Shortcode equivalent for this ( yet ).
2320 * ```
2321 *
2322 * @package s2Member\API_Functions
2323 * @since 111004
2324 *
2325 * @param str $url A full/long URL to be shortened.
2326 * @param str $api_sp Optional. A specific URL shortening API to use. Defaults to that which is configured in the s2Member Dashboard. Normally `tiny_url` by default.
2327 * @param bool $try_backups Defaults to true. If a failure occurs with the first API, we'll try others until we have success.
2328 * @return str|bool The shortened URL on success, else false on failure.
2329 *
2330 * @todo Create a Shortcode equivalent for this function.
2331 */
2332 if (!function_exists ("s2member_shorten_url"))
2333 {
2334 function s2member_shorten_url ($url = FALSE, $api_sp = FALSE, $try_backups = TRUE)
2335 {
2336 return c_ws_plugin__s2member_utils_urls::shorten ($url, $api_sp, $try_backups);
2337 }
2338 }
2339 ?>