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

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

2,840 lines 137.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreFile
3 /**
4 * Core API Functions *(for site owners)*.
5 *
6 * Copyright: © 2009-2011
7 * {@link http://websharks-inc.com/ WebSharks, Inc.}
8 * (coded in the USA)
9 *
10 * Released under the terms of the GNU General Public License.
11 * You should have received a copy of the GNU General Public License,
12 * along with this software. In the main directory, see: /licensing/
13 * If not, see: {@link http://www.gnu.org/licenses/}.
14 *
15 * @package s2Member\API_Functions
16 * @since 3.5
17 */
18 if(!defined('WPINC')) // MUST have WordPress.
19 exit("Do not access this file directly.");
20 /**
21 * Conditional to determine if the current User is NOT logged in.
22 *
23 * Counterpart {@link http://codex.wordpress.org/Function_Reference/is_user_logged_in is_user_logged_in()} already exists in the WordPress core.
24 *
25 * ———— Code Sample Using Both Functions ————
26 * ```
27 * <!php
28 * if(is_user_logged_in())
29 * echo 'You ARE logged in.';
30 *
31 * else if(is_user_not_logged_in())
32 * echo 'You are NOT logged in.';
33 * !>
34 * ```
35 * ———— Shortcode Conditional Equivalent ————
36 * ```
37 * [s2If is_user_logged_in()]
38 * You ARE logged in.
39 * [/s2If]
40 * [s2If is_user_not_logged_in()]
41 * You are NOT logged in.
42 * [/s2If]
43 * ```
44 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
45 *
46 * @package s2Member\API_Functions
47 * @since 3.5
48 *
49 * @return bool True if the current User is NOT logged in, else false.
50 *
51 * @see http://codex.wordpress.org/Function_Reference/is_user_logged_in is_user_logged_in()
52 */
53 if(!function_exists("is_user_not_logged_in"))
54 {
55 function is_user_not_logged_in()
56 {
57 return (!is_user_logged_in());
58 }
59 }
60 /**
61 * Conditional to determine if a specific User is/has a specific Role.
62 *
63 * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress core.
64 *
65 * ———— Code Sample Using Both Functions ————
66 * ```
67 * <!php
68 * if(user_is(123, "subscriber"))
69 * echo 'User ID# 123 is a Free Subscriber at Level #0.';
70 *
71 * else if(user_is(123, "s2member_level1"))
72 * echo 'User ID# 123 is a Member at Level #1.';
73 *
74 * else if(user_can(123, "access_s2member_level2"))
75 * echo 'User ID# 123 has access to content protected at Level #2.';
76 * # But, (important) they could actually be a Level #3 or #4 Member;
77 * # because Membership Levels provide incremental access.
78 * !>
79 * ```
80 *
81 * ———— Shortcode Conditional Equivalent ————
82 * ```
83 * [s2If user_is(123, subscriber)]
84 * User ID# 123 is a Free Subscriber at Level #0.
85 * [/s2If]
86 * [s2If user_is(123, s2member_level1)]
87 * User ID# 123 is a Member at Level #1.
88 * [/s2If]
89 * [s2If user_can(123, access_s2member_level2)]
90 * User ID# 123 has access to content protected at Level #2.
91 * [/s2If]
92 * ```
93 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
94 *
95 * ———— Membership Levels Provide Incremental Access ————
96 *
97 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
98 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
99 * o A Member with Level 2 access, will also be able to access Levels 0, 1
100 * o A Member with Level 1 access, will also be able to access Level 0.
101 * o A Subscriber with Level 0 access, can ONLY access Level 0.
102 * o A public Visitor will have NO access to protected content.
103 *
104 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
105 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
106 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
107 *
108 * @package s2Member\API_Functions
109 * @since 110524RC
110 *
111 * @param int|string $id A numeric WordPress User ID.
112 * @param string $role A WordPress Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
113 * @return bool True if the specific User is/has the specified Role, else false.
114 *
115 * @see s2Member\API_Functions\user_is()
116 * @see s2Member\API_Functions\user_is_not()
117 *
118 * @see s2Member\API_Functions\current_user_is()
119 * @see s2Member\API_Functions\current_user_is_not()
120 * @see s2Member\API_Functions\current_user_is_for_blog()
121 * @see s2Member\API_Functions\current_user_is_not_for_blog()
122 *
123 * @see s2Member\API_Functions\user_cannot()
124 * @see s2Member\API_Functions\current_user_cannot()
125 * @see s2Member\API_Functions\current_user_cannot_for_blog()
126 *
127 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
128 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
129 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
130 */
131 if(!function_exists("user_is"))
132 {
133 function user_is($id = FALSE, $role = FALSE)
134 {
135 $role = ($role === "s2member_level0") ? "subscriber" : preg_replace("/^access_/i", "", $role);
136
137 if(($role === "super_administrator" || $role === "administrator") && is_multisite() && is_super_admin($id))
138 return /* Return true, Super Admins are always considered an Admnistrator, for all Blogs. */ true;
139
140 else if /* Else return false for Super Admins here. */(is_multisite() && is_super_admin($id))
141 return /* Super Admins can access all Capabilities, so the default handling would fail. */ false;
142
143 return user_can($id, $role);
144 }
145 }
146 /**
147 * Conditional to determine if a specific User is/does NOT have a specific Role.
148 *
149 * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress core.
150 *
151 * ———— Code Sample Using Three Functions ————
152 * ```
153 * <!php
154 * if(user_is(123, "subscriber"))
155 * echo 'User ID# 123 is a Free Subscriber at Level #0.';
156 *
157 * else if(user_is(123, "s2member_level1"))
158 * echo 'User ID# 123 is a Member at Level #1.';
159 *
160 * else if(user_can(123, "access_s2member_level2") && user_is_not(123, "s2member_level2"))
161 * echo 'User ID# 123 has access to content protected at Level #2, but they are NOT a Level #2 Member.';
162 * # So, (important) they could actually be a Level #3 or #4 Member;
163 * # because Membership Levels provide incremental access.
164 * !>
165 * ```
166 * ———— Shortcode Conditional Equivalent ————
167 * ```
168 * [s2If user_is(123, subscriber)]
169 * User ID# 123 is a Free Subscriber at Level #0.
170 * [/s2If]
171 * [s2If user_is(123, s2member_level1)]
172 * User ID# 123 is a Member at Level #1.
173 * [/s2If]
174 * [s2If user_can(123, access_s2member_level2) AND user_is_not(123, s2member_level2)]
175 * User ID# 123 has access to content protected at Level #2, but they are NOT a Level #2 Member.
176 * [/s2If]
177 * ```
178 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
179 *
180 * ———— Membership Levels Provide Incremental Access ————
181 *
182 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
183 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
184 * o A Member with Level 2 access, will also be able to access Levels 0, 1
185 * o A Member with Level 1 access, will also be able to access Level 0.
186 * o A Subscriber with Level 0 access, can ONLY access Level 0.
187 * o A public Visitor will have NO access to protected content.
188 *
189 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
190 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
191 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
192 *
193 * @package s2Member\API_Functions
194 * @since 110524RC
195 *
196 * @param int|string $id A numeric WordPress User ID.
197 * @param string $role A WordPress Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
198 * @return bool True if the specific User is/does NOT have the specified Role, else false.
199 *
200 * @see s2Member\API_Functions\user_is()
201 * @see s2Member\API_Functions\user_is_not()
202 *
203 * @see s2Member\API_Functions\current_user_is()
204 * @see s2Member\API_Functions\current_user_is_not()
205 * @see s2Member\API_Functions\current_user_is_for_blog()
206 * @see s2Member\API_Functions\current_user_is_not_for_blog()
207 *
208 * @see s2Member\API_Functions\user_cannot()
209 * @see s2Member\API_Functions\current_user_cannot()
210 * @see s2Member\API_Functions\current_user_cannot_for_blog()
211 *
212 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
213 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
214 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
215 */
216 if(!function_exists("user_is_not"))
217 {
218 function user_is_not($id = FALSE, $role = FALSE)
219 {
220 return (!user_is($id, $role));
221 }
222 }
223 /**
224 * Conditional to determine if the current User is/has a specific Role.
225 *
226 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress core.
227 *
228 * ———— Code Sample Using Both Functions ————
229 * ```
230 * <!php
231 * if(current_user_is("subscriber"))
232 * echo 'You ARE a Free Subscriber at Level #0.';
233 *
234 * else if(current_user_is("s2member_level1"))
235 * echo 'You ARE a Member at Level #1.';
236 *
237 * else if(current_user_can("access_s2member_level2"))
238 * echo 'You DO have access to content protected at Level #2.';
239 * # But, (important) they could actually be a Level #3 or #4 Member;
240 * # because Membership Levels provide incremental access.
241 * !>
242 * ```
243 *
244 * ———— Shortcode Conditional Equivalent ————
245 * ```
246 * [s2If current_user_is(subscriber)]
247 * You ARE a Free Subscriber at Level #0.
248 * [/s2If]
249 * [s2If current_user_is(s2member_level1)]
250 * You ARE a Member at Level #1.
251 * [/s2If]
252 * [s2If current_user_can(access_s2member_level2)]
253 * You DO have access to content protected at Level #2.
254 * [/s2If]
255 * ```
256 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
257 *
258 * ———— Membership Levels Provide Incremental Access ————
259 *
260 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
261 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
262 * o A Member with Level 2 access, will also be able to access Levels 0, 1
263 * o A Member with Level 1 access, will also be able to access Level 0.
264 * o A Subscriber with Level 0 access, can ONLY access Level 0.
265 * o A public Visitor will have NO access to protected content.
266 *
267 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
268 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
269 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
270 *
271 * @package s2Member\API_Functions
272 * @since 3.5
273 *
274 * @param string $role A WordPress Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
275 * @return bool True if the current User is/has the specified Role, else false.
276 *
277 * @see s2Member\API_Functions\user_is()
278 * @see s2Member\API_Functions\user_is_not()
279 *
280 * @see s2Member\API_Functions\current_user_is()
281 * @see s2Member\API_Functions\current_user_is_not()
282 * @see s2Member\API_Functions\current_user_is_for_blog()
283 * @see s2Member\API_Functions\current_user_is_not_for_blog()
284 *
285 * @see s2Member\API_Functions\user_cannot()
286 * @see s2Member\API_Functions\current_user_cannot()
287 * @see s2Member\API_Functions\current_user_cannot_for_blog()
288 *
289 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
290 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
291 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
292 */
293 if(!function_exists("current_user_is"))
294 {
295 function current_user_is($role = FALSE)
296 {
297 $role = ($role === "s2member_level0") ? "subscriber" : preg_replace("/^access_/i", "", $role);
298
299 if(($role === "super_administrator" || $role === "administrator") && is_multisite() && is_super_admin())
300 return /* Return true, Super Admins are always considered an Admnistrator, for all Blogs. */ true;
301
302 else if /* Else return false for Super Admins here. */(is_multisite() && is_super_admin())
303 return /* Super Admins can access all Capabilities, so the default handling would fail. */ false;
304
305 return current_user_can($role);
306 }
307 }
308 /**
309 * Conditional to determine if the current User is/does NOT have a specific Role.
310 *
311 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress core.
312 *
313 * ———— Code Sample Using Three Functions ————
314 * ```
315 * <!php
316 * if(current_user_is("subscriber"))
317 * echo 'You ARE a Free Subscriber at Level #0.';
318 *
319 * else if(current_user_is("s2member_level1"))
320 * echo 'You ARE a Member at Level #1.';
321 *
322 * else if(current_user_can("access_s2member_level2") && current_user_is_not("s2member_level2"))
323 * echo 'You DO have access to content protected at Level #2, but you are NOT a Level #2 Member.';
324 * # So, (important) they could actually be a Level #3 or #4 Member;
325 * # because Membership Levels provide incremental access.
326 * !>
327 * ```
328 * ———— Shortcode Conditional Equivalent ————
329 * ```
330 * [s2If current_user_is(subscriber)]
331 * You ARE a Free Subscriber at Level #0.
332 * [/s2If]
333 * [s2If current_user_is(s2member_level1)]
334 * You ARE a Member at Level #1.
335 * [/s2If]
336 * [s2If current_user_can(access_s2member_level2) AND current_user_is_not(s2member_level2)]
337 * You DO have access to content protected at Level #2, but you are NOT a Level #2 Member.
338 * [/s2If]
339 * ```
340 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
341 *
342 * ———— Membership Levels Provide Incremental Access ————
343 *
344 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
345 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
346 * o A Member with Level 2 access, will also be able to access Levels 0, 1
347 * o A Member with Level 1 access, will also be able to access Level 0.
348 * o A Subscriber with Level 0 access, can ONLY access Level 0.
349 * o A public Visitor will have NO access to protected content.
350 *
351 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
352 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
353 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
354 *
355 * @package s2Member\API_Functions
356 * @since 3.5
357 *
358 * @param string $role A WordPress Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
359 * @return bool True if the current User is/does NOT have the specified Role, else false.
360 *
361 * @see s2Member\API_Functions\user_is()
362 * @see s2Member\API_Functions\user_is_not()
363 *
364 * @see s2Member\API_Functions\current_user_is()
365 * @see s2Member\API_Functions\current_user_is_not()
366 * @see s2Member\API_Functions\current_user_is_for_blog()
367 * @see s2Member\API_Functions\current_user_is_not_for_blog()
368 *
369 * @see s2Member\API_Functions\user_cannot()
370 * @see s2Member\API_Functions\current_user_cannot()
371 * @see s2Member\API_Functions\current_user_cannot_for_blog()
372 *
373 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
374 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
375 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
376 */
377 if(!function_exists("current_user_is_not"))
378 {
379 function current_user_is_not($role = FALSE)
380 {
381 return (!current_user_is($role));
382 }
383 }
384 /**
385 * Conditional to determine if the current User is/has a specific Role, on a specific Blog within a Multisite Network.
386 *
387 * 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.
388 *
389 * ———— Code Sample Using Three Functions ————
390 * ```
391 * <!php
392 * if(current_user_is("subscriber"))
393 * echo 'You ARE a Free Subscriber at Level #0 (on this Blog).';
394 *
395 * else if(current_user_is_for_blog(5, "subscriber"))
396 * echo 'You ARE a Free Subscriber at Level #0 (on Blog ID 5).';
397 *
398 * else if(current_user_is_for_blog(5, "s2member_level1"))
399 * echo 'You ARE a Member at Level #1 (on Blog ID 5).';
400 *
401 * else if(current_user_can_for_blog(5, "access_s2member_level2"))
402 * echo 'You DO have access to content protected at Level #2 (on Blog ID 5).';
403 * # But, (important) they could actually be a Level #3 or #4 Member (on Blog ID 5);
404 * # because Membership Levels provide incremental access.
405 * !>
406 * ```
407 * ———— Shortcode Conditional Equivalent ————
408 * ```
409 * [s2If current_user_is(subscriber)]
410 * You ARE a Free Subscriber at Level #0 (on this Blog).
411 * [/s2If]
412 * [s2If current_user_is_for_blog(5, subscriber)]
413 * You ARE a Free Subscriber at Level #0 (on Blog ID 5).
414 * [/s2If]
415 * [s2If current_user_is_for_blog(5, s2member_level1)]
416 * You ARE a Member at Level #1 (on Blog ID 5).
417 * [/s2If]
418 * [s2If current_user_can_for_blog(5, access_s2member_level2)]
419 * You DO have access to content protected at Level #2 (on Blog ID 5).
420 * [/s2If]
421 * ```
422 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
423 *
424 * ———— Membership Levels Provide Incremental Access ————
425 *
426 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
427 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
428 * o A Member with Level 2 access, will also be able to access Levels 0, 1
429 * o A Member with Level 1 access, will also be able to access Level 0.
430 * o A Subscriber with Level 0 access, can ONLY access Level 0.
431 * o A public Visitor will have NO access to protected content.
432 *
433 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
434 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
435 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
436 *
437 * @package s2Member\API_Functions
438 * @since 3.5
439 *
440 * @param int|string $blog_id A WordPress Blog ID *(must be numeric)*.
441 * @param string $role A WordPress Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
442 * @return bool True if the current User is/has the specified Role, on the specified Blog, else false.
443 *
444 * @see s2Member\API_Functions\user_is()
445 * @see s2Member\API_Functions\user_is_not()
446 *
447 * @see s2Member\API_Functions\current_user_is()
448 * @see s2Member\API_Functions\current_user_is_not()
449 * @see s2Member\API_Functions\current_user_is_for_blog()
450 * @see s2Member\API_Functions\current_user_is_not_for_blog()
451 *
452 * @see s2Member\API_Functions\user_cannot()
453 * @see s2Member\API_Functions\current_user_cannot()
454 * @see s2Member\API_Functions\current_user_cannot_for_blog()
455 *
456 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
457 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
458 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
459 */
460 if(!function_exists("current_user_is_for_blog"))
461 {
462 function current_user_is_for_blog($blog_id = FALSE, $role = FALSE)
463 {
464 $role = ($role === "s2member_level0") ? "subscriber" : preg_replace("/^access_/i", "", $role);
465
466 if(($role === "super_administrator" || $role === "administrator") && is_multisite() && is_super_admin())
467 return /* Return true, Super Admins are always considered an Admnistrator, for all Blogs. */ true;
468
469 else if /* Else return false for Super Admins here. */(is_multisite() && is_super_admin())
470 return /* Super Admins can access all Capabilities, so the default handling would fail. */ false;
471
472 return current_user_can_for_blog($blog_id, $role);
473 }
474 }
475 /**
476 * Conditional to determine if the current User is/does NOT have a specific Role, on a specific Blog within a Multisite Network.
477 *
478 * 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.
479 *
480 * ———— Code Sample Using Three Functions ————
481 * ```
482 * <!php
483 * if(current_user_is_for_blog(5, "subscriber"))
484 * echo 'You ARE a Free Subscriber at Level #0 (on Blog ID 5).';
485 *
486 * else if(current_user_can_for_blog(5, "access_s2member_level1") && current_user_is_not_for_blog(5, "s2member_level1"))
487 * 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).';
488 * # So, (important) they could actually be a Level #2 or #3 or #4 Member (on Blog ID 5);
489 * # because Membership Levels provide incremental access.
490 * !>
491 * ```
492 * ———— Shortcode Conditional Equivalent ————
493 * ```
494 * [s2If current_user_is_for_blog(5, subscriber)]
495 * You ARE a Free Subscriber at Level #0 (on Blog ID 5).
496 * [/s2If]
497 * [s2If current_user_can_for_blog(5, access_s2member_level1) AND current_user_is_not_for_blog(5, s2member_level1)]
498 * 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).
499 * [/s2If]
500 * ```
501 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
502 *
503 * ———— Membership Levels Provide Incremental Access ————
504 *
505 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
506 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
507 * o A Member with Level 2 access, will also be able to access Levels 0, 1
508 * o A Member with Level 1 access, will also be able to access Level 0.
509 * o A Subscriber with Level 0 access, can ONLY access Level 0.
510 * o A public Visitor will have NO access to protected content.
511 *
512 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
513 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
514 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
515 *
516 * @package s2Member\API_Functions
517 * @since 3.5
518 *
519 * @param int|string $blog_id A WordPress Blog ID *(must be numeric)*.
520 * @param string $role A WordPress Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
521 * @return bool True if the current User is/does NOT have the specified Role, on the specified Blog, else false.
522 *
523 * @see s2Member\API_Functions\user_is()
524 * @see s2Member\API_Functions\user_is_not()
525 *
526 * @see s2Member\API_Functions\current_user_is()
527 * @see s2Member\API_Functions\current_user_is_not()
528 * @see s2Member\API_Functions\current_user_is_for_blog()
529 * @see s2Member\API_Functions\current_user_is_not_for_blog()
530 *
531 * @see s2Member\API_Functions\user_cannot()
532 * @see s2Member\API_Functions\current_user_cannot()
533 * @see s2Member\API_Functions\current_user_cannot_for_blog()
534 *
535 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
536 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
537 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
538 */
539 if(!function_exists("current_user_is_not_for_blog"))
540 {
541 function current_user_is_not_for_blog($blog_id = FALSE, $role = FALSE)
542 {
543 return (!current_user_is_for_blog($blog_id, $role));
544 }
545 }
546 /**
547 * Conditional to determine if a specific User does NOT have a specific Capability or Role.
548 *
549 * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress core.
550 *
551 * ———— Code Sample Using Both Functions ————
552 * ```
553 * <!php
554 * if(user_can(123, "access_s2member_level0"))
555 * echo 'User ID# 123 CAN access content protected at Level #0.';
556 *
557 * else if(user_cannot(123, "access_s2member_level0"))
558 * echo 'User ID# 123 CANNOT access content at Level #0.';
559 * !>
560 * ```
561 * ———— Shortcode Conditional Equivalent ————
562 * ```
563 * [s2If user_can(123, access_s2member_level0)]
564 * User ID# 123 CAN access content protected at Level #0.
565 * [/s2If]
566 * [s2If user_cannot(123, access_s2member_level0)]
567 * User ID# 123 CANNOT access content at Level #0.
568 * [/s2If]
569 * ```
570 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
571 *
572 * ———— Membership Levels Provide Incremental Access ————
573 *
574 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
575 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
576 * o A Member with Level 2 access, will also be able to access Levels 0, 1
577 * o A Member with Level 1 access, will also be able to access Level 0.
578 * o A Subscriber with Level 0 access, can ONLY access Level 0.
579 * o A public Visitor will have NO access to protected content.
580 *
581 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
582 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
583 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
584 *
585 * @package s2Member\API_Functions
586 * @since 3.5
587 *
588 * @param int|string $id A numeric WordPress User ID.
589 * @param string $capability A WordPress Capability ID *( i.e., `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
590 * @return bool True if the specific User does NOT have the specified Capability or Role, else false.
591 *
592 * @see s2Member\API_Functions\user_is()
593 * @see s2Member\API_Functions\user_is_not()
594 *
595 * @see s2Member\API_Functions\current_user_is()
596 * @see s2Member\API_Functions\current_user_is_not()
597 * @see s2Member\API_Functions\current_user_is_for_blog()
598 * @see s2Member\API_Functions\current_user_is_not_for_blog()
599 *
600 * @see s2Member\API_Functions\user_cannot()
601 * @see s2Member\API_Functions\current_user_cannot()
602 * @see s2Member\API_Functions\current_user_cannot_for_blog()
603 *
604 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
605 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
606 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
607 */
608 if(!function_exists("user_cannot"))
609 {
610 function user_cannot($id = FALSE, $capability = FALSE)
611 {
612 return (!user_can($id, $capability));
613 }
614 }
615 /**
616 * Conditional to determine if the current User does NOT have a specific Capability or Role.
617 *
618 * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress core.
619 *
620 * ———— Code Sample Using Both Functions ————
621 * ```
622 * <!php
623 * if(current_user_can("access_s2member_level0"))
624 * echo 'You CAN access content protected at Level #0.';
625 *
626 * else if(current_user_cannot("access_s2member_level0"))
627 * echo 'You CANNOT access content protected at Level #0.';
628 * !>
629 * ```
630 * ———— Shortcode Conditional Equivalent ————
631 * ```
632 * [s2If current_user_can(access_s2member_level0)]
633 * You CAN access content protected at Level #0.
634 * [/s2If]
635 * [s2If current_user_cannot(access_s2member_level0)]
636 * You CANNOT access content protected at Level #0.
637 * [/s2If]
638 * ```
639 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
640 *
641 * ———— Membership Levels Provide Incremental Access ————
642 *
643 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
644 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
645 * o A Member with Level 2 access, will also be able to access Levels 0, 1
646 * o A Member with Level 1 access, will also be able to access Level 0.
647 * o A Subscriber with Level 0 access, can ONLY access Level 0.
648 * o A public Visitor will have NO access to protected content.
649 *
650 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
651 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
652 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
653 *
654 * @package s2Member\API_Functions
655 * @since 3.5
656 *
657 * @param string $capability A WordPress Capability ID *( i.e., `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
658 * Or a Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
659 * @return bool True if the current User does NOT have the specified Capability or Role, else false.
660 *
661 * @see s2Member\API_Functions\user_is()
662 * @see s2Member\API_Functions\user_is_not()
663 *
664 * @see s2Member\API_Functions\current_user_is()
665 * @see s2Member\API_Functions\current_user_is_not()
666 * @see s2Member\API_Functions\current_user_is_for_blog()
667 * @see s2Member\API_Functions\current_user_is_not_for_blog()
668 *
669 * @see s2Member\API_Functions\user_cannot()
670 * @see s2Member\API_Functions\current_user_cannot()
671 * @see s2Member\API_Functions\current_user_cannot_for_blog()
672 *
673 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
674 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
675 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
676 */
677 if(!function_exists("current_user_cannot"))
678 {
679 function current_user_cannot($capability = FALSE)
680 {
681 return (!current_user_can($capability));
682 }
683 }
684 /**
685 * Conditional to determine if the current User does NOT have a specific Capability or Role, on a specific Blog within a Multisite Network.
686 *
687 * 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.
688 *
689 * ———— Code Sample Using Both Functions ————
690 * ```
691 * <!php
692 * if(current_user_can_for_blog(5, "access_s2member_level0"))
693 * echo 'You CAN access content protected at Level #0 (on Blog ID 5).';
694 *
695 * else if(current_user_cannot_for_blog(5, "access_s2member_level0"))
696 * echo 'You CANNOT access content protected at Level #0 (on Blog ID 5).';
697 * !>
698 * ```
699 * ———— Shortcode Conditional Equivalent ————
700 * ```
701 * [s2If current_user_can_for_blog(5, access_s2member_level0)]
702 * You CAN access content protected at Level #0 (on Blog ID 5).
703 * [/s2If]
704 * [s2If current_user_cannot_for_blog(5, access_s2member_level0)]
705 * You CANNOT access content protected at Level #0 (on Blog ID 5).
706 * [/s2If]
707 * ```
708 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
709 *
710 * ———— Membership Levels Provide Incremental Access ————
711 *
712 * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
713 * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
714 * o A Member with Level 2 access, will also be able to access Levels 0, 1
715 * o A Member with Level 1 access, will also be able to access Level 0.
716 * o A Subscriber with Level 0 access, can ONLY access Level 0.
717 * o A public Visitor will have NO access to protected content.
718 *
719 * WordPress Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
720 * WordPress Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
721 * All of their other {@link http://s2member.com/r/wordpress-rolescaps/ Roles/Capabilities} are left untouched.
722 *
723 * @package s2Member\API_Functions
724 * @since 3.5
725 *
726 * @param int|string $blog_id A WordPress Blog ID *(must be numeric)*.
727 * @param string $capability A WordPress Capability ID *( i.e., `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
728 * Or a Role ID *( i.e., `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
729 * @return bool True if the current User does NOT have the specified Capability or Role, else false.
730 *
731 * @see s2Member\API_Functions\user_is()
732 * @see s2Member\API_Functions\user_is_not()
733 *
734 * @see s2Member\API_Functions\current_user_is()
735 * @see s2Member\API_Functions\current_user_is_not()
736 * @see s2Member\API_Functions\current_user_is_for_blog()
737 * @see s2Member\API_Functions\current_user_is_not_for_blog()
738 *
739 * @see s2Member\API_Functions\user_cannot()
740 * @see s2Member\API_Functions\current_user_cannot()
741 * @see s2Member\API_Functions\current_user_cannot_for_blog()
742 *
743 * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
744 * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
745 * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
746 */
747 if(!function_exists("current_user_cannot_for_blog"))
748 {
749 function current_user_cannot_for_blog($blog_id = FALSE, $capability = FALSE)
750 {
751 return (!current_user_can_for_blog($blog_id, $capability));
752 }
753 }
754 /**
755 * Conditional to determine if a specific Category, Tag, Post, Page, URL or URI is protected by s2Member;
756 * without considering the current User's Role/Capabilites.
757 *
758 * ———— Extra Detail On Function Parameters ————
759 *
760 * **Parameter $what (int|str Optional).**
761 * Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
762 * 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.
763 *
764 * o If you pass in an ID, s2Member will check everything, including your configured URI Restrictions against the ID.
765 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
766 * So using an ID results in an all-inclusive scan against your configured Restrictions,
767 * including any URI Restrictions that you may have configured.
768 *
769 * o If you pass in a URL or URI, s2Member will ONLY check URI Restrictions, because it has no ID to work with.
770 * This is useful though. Some protected content is not associated with an ID. In those cases, URI Restrictions are all the matter.
771 *
772 * o Note: when passing in a URL or URI, the $type parameter must be set to `URI` or `uri`. Case insensitive.
773 *
774 * **Parameter $type (str Optional).**
775 * One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e., a Post or Page)*.
776 *
777 * **Parameter $check_user (bool Optional).**
778 * Consider the current User? Defaults to false.
779 *
780 * o In other words, by default, this Conditional function is only checking to see if the content is protected, and that's it.
781 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
782 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_permitted_by_s2member()}.
783 *
784 * ———— Code Sample Using Function Parameters ————
785 * ```
786 * <!php
787 * if(is_protected_by_s2member(123))
788 * echo 'Post or Page ID #123 is protected by s2Member.';
789 *
790 * else if(is_protected_by_s2member(332, "tag"))
791 * echo 'Tag ID #332 is protected by s2Member.';
792 *
793 * else if(is_protected_by_s2member(554, "category"))
794 * echo 'Category ID #554 is protected by s2Member.';
795 *
796 * else if(is_protected_by_s2member("http://example.com/members/", "uri"))
797 * echo 'This URL is protected by URI Restrictions.';
798 *
799 * else if(is_protected_by_s2member("/members/", "uri"))
800 * echo 'This URI is protected by URI Restrictions.';
801 * !>
802 * ```
803 * ———— Shortcode Conditional Equivalent ————
804 * ```
805 * [s2If is_protected_by_s2member(123)]
806 * Post or Page ID #123 is protected by s2Member.
807 * [/s2If]
808 * [s2If is_protected_by_s2member(332, tag)]
809 * Tag ID #332 is protected by s2Member.
810 * [/s2If]
811 * [s2If is_protected_by_s2member(554, category)]
812 * Category ID #554 is protected by s2Member.
813 * [/s2If]
814 * [s2If is_protected_by_s2member(http://example.com/members/, uri)]
815 * This URL is protected by URI Restrictions.
816 * [/s2If]
817 * [s2If is_protected_by_s2member(/members/, uri)]
818 * This URI is protected by URI Restrictions.
819 * [/s2If]
820 * ```
821 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
822 *
823 * @package s2Member\API_Functions
824 * @since 3.5
825 *
826 * @param int|string $what Optional. Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
827 * 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.
828 * @param string $type Optional. One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e., a Post or Page)*.
829 * @param bool $check_user Optional. Consider the current User? Defaults to false.
830 * @return array|bool A non-empty array *(meaning true)*, or false if the content is not protected *(i.e., available publicly)*.
831 * When/if content IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
832 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the content.
833 * In other words, the reason why it's protected; based on your s2Member configuration.
834 *
835 * @see s2Member\API_Functions\is_protected_by_s2member()
836 * @see s2Member\API_Functions\is_permitted_by_s2member()
837 *
838 * @see s2Member\API_Functions\is_category_protected_by_s2member()
839 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
840 *
841 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
842 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
843 *
844 * @see s2Member\API_Functions\is_post_protected_by_s2member()
845 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
846 *
847 * @see s2Member\API_Functions\is_page_protected_by_s2member()
848 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
849 *
850 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
851 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
852 *
853 * @see s2Member\API_Functions\attach_s2member_query_filters()
854 * @see s2Member\API_Functions\detach_s2member_query_filters()
855 */
856 if(!function_exists("is_protected_by_s2member"))
857 {
858 function is_protected_by_s2member($what = FALSE, $type = FALSE, $check_user = FALSE)
859 {
860 global /* Global reference to $post in The Loop. */ $post;
861
862 $what = ($what) ? $what : ((is_object($post) && $post->ID) ? $post->ID : false);
863 $type = ($type) ? strtolower($type) : "singular";
864
865 if($type === "category" && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($what, $check_user)))
866 return /* A non-empty array with ["s2member_level_req"]. */ $array;
867
868 else if($type === "tag" && ($array = c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access($what, $check_user)))
869 return /* A non-empty array with ["s2member_level_req"]. */ $array;
870
871 else if(($type === "post" || $type === "singular") && ($array = c_ws_plugin__s2member_posts_sp::check_specific_post_level_access($what, $check_user)))
872 return /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */ $array;
873
874 else if(($type === "page" || $type === "singular") && ($array = c_ws_plugin__s2member_pages_sp::check_specific_page_level_access($what, $check_user)))
875 return /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */$array;
876
877 else if($type === "uri" && ($array = c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access($what, $check_user)))
878 return /* A non-empty array with ["s2member_level_req"]. */ $array;
879
880 return false;
881 }
882 }
883 /**
884 * Conditional to determine if a specific Category, Tag, Post, Page, URL or URI is permitted by s2Member,
885 * with consideration given to the current User's Role/Capabilites.
886 *
887 * This function is similar to {@link s2Member\API_Functions\is_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
888 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_protected_by_s2member()} does; it only returns true|false.
889 *
890 * ———— Extra Detail On Function Parameters ————
891 *
892 * **Parameter $what (int|str Optional).**
893 * Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
894 * 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.
895 *
896 * o If you pass in an ID, s2Member will check everything, including your configured URI Restrictions against the ID.
897 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
898 * So using an ID results in an all-inclusive scan against your configured Restrictions,
899 * including any URI Restrictions that you may have configured.
900 *
901 * o If you pass in a URL or URI, s2Member will ONLY check URI Restrictions, because it has no ID to work with.
902 * This is useful though. Some protected content is not associated with an ID. In those cases, URI Restrictions are all the matter.
903 *
904 * o Note: when passing in a URL or URI, the $type parameter must be set to `URI` or `uri`. Case insensitive.
905 *
906 * **Parameter $type (str Optional).**
907 * One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e., a Post or Page)*.
908 *
909 * ———— Code Sample Using Function Parameters ————
910 * ```
911 * <!php
912 * if(is_permitted_by_s2member(123))
913 * echo 'Post or Page ID #123 is permitted by s2Member.';
914 *
915 * else if(is_permitted_by_s2member(332, "tag"))
916 * echo 'Tag ID #332 is permitted by s2Member.';
917 *
918 * else if(is_permitted_by_s2member(554, "category"))
919 * echo 'Category ID #554 is permitted by s2Member.';
920 *
921 * else if(is_permitted_by_s2member("http://example.com/members/", "uri"))
922 * echo 'This URL is permitted by s2Member.';
923 *
924 * else if(is_permitted_by_s2member("/members/", "uri"))
925 * echo 'This URI is permitted by s2Member.';
926 * !>
927 * ```
928 * ———— Shortcode Conditional Equivalent ————
929 * ```
930 * [s2If is_permitted_by_s2member(123)]
931 * Post or Page ID #123 is permitted by s2Member.
932 * [/s2If]
933 * [s2If is_permitted_by_s2member(332, tag)]
934 * Tag ID #332 is permitted by s2Member.
935 * [/s2If]
936 * [s2If is_permitted_by_s2member(554, category)]
937 * Category ID #554 is permitted by s2Member.
938 * [/s2If]
939 * [s2If is_permitted_by_s2member(http://example.com/members/, uri)]
940 * This URL is permitted by s2Member.
941 * [/s2If]
942 * [s2If is_permitted_by_s2member(/members/, uri)]
943 * This URI is permitted by s2Member.
944 * [/s2If]
945 * ```
946 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
947 *
948 * @package s2Member\API_Functions
949 * @since 3.5
950 *
951 * @param int|string $what Optional. Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
952 * 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.
953 * @param string $type Optional. One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e., a Post or Page)*.
954 * @return bool True if the current User IS permitted, else false if the content is NOT available to the current User;
955 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
956 *
957 * @see s2Member\API_Functions\is_protected_by_s2member()
958 * @see s2Member\API_Functions\is_permitted_by_s2member()
959 *
960 * @see s2Member\API_Functions\is_category_protected_by_s2member()
961 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
962 *
963 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
964 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
965 *
966 * @see s2Member\API_Functions\is_post_protected_by_s2member()
967 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
968 *
969 * @see s2Member\API_Functions\is_page_protected_by_s2member()
970 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
971 *
972 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
973 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
974 *
975 * @see s2Member\API_Functions\attach_s2member_query_filters()
976 * @see s2Member\API_Functions\detach_s2member_query_filters()
977 */
978 if(!function_exists("is_permitted_by_s2member"))
979 {
980 function is_permitted_by_s2member($what = FALSE, $type = FALSE)
981 {
982 global /* Global reference to $post in The Loop. */ $post;
983
984 $what = ($what) ? $what : ((is_object($post) && $post->ID) ? $post->ID : false);
985 $type = ($type) ? strtolower($type) : "singular";
986
987 if($type === "category" && c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($what, true))
988 return false;
989
990 else if($type === "tag" && c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access($what, true))
991 return false;
992
993 else if(($type === "post" || $type === "singular") && c_ws_plugin__s2member_posts_sp::check_specific_post_level_access($what, true))
994 return false;
995
996 else if(($type === "page" || $type === "singular") && c_ws_plugin__s2member_pages_sp::check_specific_page_level_access($what, true))
997 return false;
998
999 else if($type === "uri" && c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access($what, true))
1000 return false;
1001
1002 return true;
1003 }
1004 }
1005 /**
1006 * Conditional to determine if a specific Category is protected by s2Member;
1007 * without considering the current User's Role/Capabilites.
1008 *
1009 * ———— Extra Detail On Function Parameters ————
1010 *
1011 * **Parameter $cat_id (int Required).** This should be a WordPress Category ID.
1012 *
1013 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1014 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1015 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1016 * including any URI Restrictions that you may have configured.
1017 *
1018 * **Parameter $check_user (bool Optional).**
1019 * Consider the current User? Defaults to false.
1020 *
1021 * o In other words, by default, this Conditional function is only checking to see if the Category is protected, and that's it.
1022 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1023 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_category_permitted_by_s2member()}.
1024 *
1025 * ———— Code Sample Using Function Parameters ————
1026 * ```
1027 * <!php
1028 * if(is_category_protected_by_s2member(123))
1029 * echo 'Category ID #123 is protected by s2Member.';
1030 * !>
1031 * ```
1032 * ———— Shortcode Conditional Equivalent ————
1033 * ```
1034 * [s2If is_category_protected_by_s2member(123)]
1035 * Category ID #123 is protected by s2Member.
1036 * [/s2If]
1037 * ```
1038 *
1039 * @package s2Member\API_Functions
1040 * @since 3.5
1041 *
1042 * @param int $cat_id Required. This should be a WordPress Category ID.
1043 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1044 * @return array|bool A non-empty array *(meaning true)*, or false if the Category is not protected *(i.e., available publicly)*.
1045 * When/if the Category IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1046 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Category.
1047 * In other words, the reason why it's protected; based on your s2Member configuration.
1048 *
1049 * @see s2Member\API_Functions\is_protected_by_s2member()
1050 * @see s2Member\API_Functions\is_permitted_by_s2member()
1051 *
1052 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1053 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1054 *
1055 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1056 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1057 *
1058 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1059 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1060 *
1061 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1062 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1063 *
1064 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1065 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1066 *
1067 * @see s2Member\API_Functions\attach_s2member_query_filters()
1068 * @see s2Member\API_Functions\detach_s2member_query_filters()
1069 */
1070 if(!function_exists("is_category_protected_by_s2member"))
1071 {
1072 function is_category_protected_by_s2member($cat_id = FALSE, $check_user = FALSE)
1073 {
1074 if($cat_id && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($cat_id, $check_user)))
1075 return /* A non-empty array with ["s2member_level_req"]. */ $array;
1076
1077 return false;
1078 }
1079 }
1080 /**
1081 * Conditional to determine if a specific Category is permitted by s2Member,
1082 * with consideration given to the current User's Role/Capabilites.
1083 *
1084 * This function is similar to {@link s2Member\API_Functions\is_category_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1085 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_category_protected_by_s2member()} does; it only returns true|false.
1086 *
1087 * ———— Extra Detail On Function Parameters ————
1088 *
1089 * **Parameter $cat_id (int Required).** This should be a WordPress Category ID.
1090 *
1091 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1092 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1093 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1094 * including any URI Restrictions that you may have configured.
1095 *
1096 * ———— Code Sample Using Function Parameters ————
1097 * ```
1098 * <!php
1099 * if(is_category_permitted_by_s2member(123))
1100 * echo 'Category ID #123 is permitted by s2Member.';
1101 * !>
1102 * ```
1103 * ———— Shortcode Conditional Equivalent ————
1104 * ```
1105 * [s2If is_category_permitted_by_s2member(123)]
1106 * Category ID #123 is permitted by s2Member.
1107 * [/s2If]
1108 * ```
1109 *
1110 * @package s2Member\API_Functions
1111 * @since 3.5
1112 *
1113 * @param int $cat_id Required. This should be a WordPress Category ID.
1114 * @return bool True if the current User IS permitted, else false if the Category is NOT available to the current User;
1115 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1116 *
1117 * @see s2Member\API_Functions\is_protected_by_s2member()
1118 * @see s2Member\API_Functions\is_permitted_by_s2member()
1119 *
1120 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1121 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1122 *
1123 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1124 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1125 *
1126 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1127 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1128 *
1129 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1130 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1131 *
1132 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1133 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1134 *
1135 * @see s2Member\API_Functions\attach_s2member_query_filters()
1136 * @see s2Member\API_Functions\detach_s2member_query_filters()
1137 */
1138 if(!function_exists("is_category_permitted_by_s2member"))
1139 {
1140 function is_category_permitted_by_s2member($cat_id = FALSE)
1141 {
1142 if($cat_id && c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($cat_id, true))
1143 return false;
1144
1145 return true;
1146 }
1147 }
1148 /**
1149 * Conditional to determine if a specific Tag is protected by s2Member;
1150 * without considering the current User's Role/Capabilites.
1151 *
1152 * ———— Extra Detail On Function Parameters ————
1153 *
1154 * **Parameter $tag_id_slug_or_name (int|str Required).** This should be a WordPress Tag ID, Tag Slug, or Tag Name.
1155 *
1156 * o s2Member will check everything, including your configured URI Restrictions against the ID, Slug, or Name.
1157 * In other words, s2Member is capable of determining a URI based on the ID, or Slug, or Name that you pass in.
1158 * So using an ID, or Slug, or Name results in an all-inclusive scan against your configured Restrictions,
1159 * including any URI Restrictions that you may have configured.
1160 *
1161 * **Parameter $check_user (bool Optional).**
1162 * Consider the current User? Defaults to false.
1163 *
1164 * o In other words, by default, this Conditional function is only checking to see if the Tag is protected, and that's it.
1165 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1166 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_tag_permitted_by_s2member()}.
1167 *
1168 * ———— Code Sample Using Function Parameters ————
1169 * ```
1170 * <!php
1171 * if(is_tag_protected_by_s2member(123))
1172 * echo 'Tag ID #123 is protected by s2Member.';
1173 *
1174 * else if(is_tag_protected_by_s2member("members-only"))
1175 * echo 'Tag Slug (members-only) is protected by s2Member.';
1176 *
1177 * else if(is_tag_protected_by_s2member("Members Only"))
1178 * echo 'Tag Name (Members Only) is protected by s2Member.';
1179 * !>
1180 * ```
1181 * ———— Shortcode Conditional Equivalent ————
1182 * ```
1183 * [s2If is_tag_protected_by_s2member(123)]
1184 * Tag ID #123 is protected by s2Member.
1185 * [/s2If]
1186 * [s2If is_tag_protected_by_s2member(members-only)]
1187 * Tag Slug (members-only) is protected by s2Member.
1188 * [/s2If]
1189 * NOTE: It's NOT possible to check a Tag Named "Members Only" with [s2If /],
1190 * because Shortcode Conditionals may NOT contain spaces in their argument values.
1191 * If you're using [s2If /] to check a Tag, please use the Slug or ID instead.
1192 * ```
1193 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1194 *
1195 * @package s2Member\API_Functions
1196 * @since 3.5
1197 *
1198 * @param int|string $tag_id_slug_or_name Required. This should be a WordPress Tag ID, Tag Slug, or Tag Name.
1199 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1200 * @return array|bool A non-empty array *(meaning true)*, or false if the Tag is not protected *(i.e., available publicly)*.
1201 * When/if the Tag IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1202 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Tag.
1203 * In other words, the reason why it's protected; based on your s2Member configuration.
1204 *
1205 * @see s2Member\API_Functions\is_protected_by_s2member()
1206 * @see s2Member\API_Functions\is_permitted_by_s2member()
1207 *
1208 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1209 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1210 *
1211 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1212 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1213 *
1214 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1215 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1216 *
1217 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1218 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1219 *
1220 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1221 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1222 *
1223 * @see s2Member\API_Functions\attach_s2member_query_filters()
1224 * @see s2Member\API_Functions\detach_s2member_query_filters()
1225 */
1226 if(!function_exists("is_tag_protected_by_s2member"))
1227 {
1228 function is_tag_protected_by_s2member($tag_id_slug_or_name = FALSE, $check_user = FALSE)
1229 {
1230 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)))
1231 return /* A non-empty array with ["s2member_level_req"]. */ $array;
1232
1233 return false;
1234 }
1235 }
1236 /**
1237 * Conditional to determine if a specific Tag is permitted by s2Member,
1238 * with consideration given to the current User's Role/Capabilites.
1239 *
1240 * This function is similar to {@link s2Member\API_Functions\is_tag_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1241 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_tag_protected_by_s2member()} does; it only returns true|false.
1242 *
1243 * ———— Extra Detail On Function Parameters ————
1244 *
1245 * **Parameter $tag_id_slug_or_name (int|str Required).** This should be a WordPress Tag ID, Tag Slug, or Tag Name.
1246 *
1247 * o s2Member will check everything, including your configured URI Restrictions against the ID, or Slug, or Name.
1248 * In other words, s2Member is capable of determining a URI based on the ID, or Slug, or Name that you pass in.
1249 * So using an ID, or Slug, or Name results in an all-inclusive scan against your configured Restrictions,
1250 * including any URI Restrictions that you may have configured.
1251 *
1252 * ———— Code Sample Using Function Parameters ————
1253 * ```
1254 * <!php
1255 * if(is_tag_permitted_by_s2member(123))
1256 * echo 'Tag ID #123 is permitted by s2Member.';
1257 *
1258 * else if(is_tag_permitted_by_s2member("members-only"))
1259 * echo 'Tag Slug (members-only) is permitted by s2Member.';
1260 *
1261 * else if(is_tag_permitted_by_s2member("Members Only"))
1262 * echo 'Tag Name (Members Only) is permitted by s2Member.';
1263 * !>
1264 * ```
1265 * ———— Shortcode Conditional Equivalent ————
1266 * ```
1267 * [s2If is_tag_permitted_by_s2member(123)]
1268 * Tag ID #123 is permitted by s2Member.
1269 * [/s2If]
1270 * [s2If is_tag_permitted_by_s2member(members-only)]
1271 * Tag Slug (members-only) is permitted by s2Member.
1272 * [/s2If]
1273 * NOTE: It's NOT possible to check a Tag Named "Members Only" with [s2If /],
1274 * because Shortcode Conditionals may NOT contain spaces in their argument values.
1275 * If you're using [s2If /] to check a Tag, please use the Slug or ID instead.
1276 * ```
1277 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1278 *
1279 * @package s2Member\API_Functions
1280 * @since 3.5
1281 *
1282 * @param int|string $tag_id_slug_or_name Required. This should be a WordPress Tag ID, Tag Slug, or Tag Name.
1283 * @return bool True if the current User IS permitted, else false if the Tag is NOT available to the current User;
1284 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1285 *
1286 * @see s2Member\API_Functions\is_protected_by_s2member()
1287 * @see s2Member\API_Functions\is_permitted_by_s2member()
1288 *
1289 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1290 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1291 *
1292 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1293 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1294 *
1295 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1296 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1297 *
1298 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1299 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1300 *
1301 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1302 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1303 *
1304 * @see s2Member\API_Functions\attach_s2member_query_filters()
1305 * @see s2Member\API_Functions\detach_s2member_query_filters()
1306 */
1307 if(!function_exists("is_tag_permitted_by_s2member"))
1308 {
1309 function is_tag_permitted_by_s2member($tag_id_slug_or_name = FALSE)
1310 {
1311 if($tag_id_slug_or_name && c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access($tag_id_slug_or_name, true))
1312 return false;
1313
1314 return true;
1315 }
1316 }
1317 /**
1318 * Conditional to determine if a specific Post (or Custom Post Type) is protected by s2Member;
1319 * without considering the current User's Role/Capabilites.
1320 *
1321 * ———— Extra Detail On Function Parameters ————
1322 *
1323 * **Parameter $post_id (int Required).** This should be a WordPress Post ID, or a Custom Post Type ID.
1324 *
1325 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1326 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1327 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1328 * including any URI Restrictions that you may have configured.
1329 *
1330 * **Parameter $check_user (bool Optional).**
1331 * Consider the current User? Defaults to false.
1332 *
1333 * o In other words, by default, this Conditional function is only checking to see if the Post is protected, and that's it.
1334 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1335 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_post_permitted_by_s2member()}.
1336 *
1337 * ———— Code Sample Using Function Parameters ————
1338 * ```
1339 * <!php
1340 * if(is_post_protected_by_s2member(123))
1341 * echo 'Post ID #123 is protected by s2Member.';
1342 * !>
1343 * ```
1344 * ———— Shortcode Conditional Equivalent ————
1345 * ```
1346 * [s2If is_post_protected_by_s2member(123)]
1347 * Post ID #123 is protected by s2Member.
1348 * [/s2If]
1349 * ```
1350 *
1351 * @package s2Member\API_Functions
1352 * @since 3.5
1353 *
1354 * @param int $post_id Required. This should be a WordPress Post ID, or a Custom Post Type ID.
1355 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1356 * @return array|bool A non-empty array *(meaning true)*, or false if the Post is not protected *(i.e., available publicly)*.
1357 * When/if the Post IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1358 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Post.
1359 * In other words, the reason why it's protected; based on your s2Member configuration.
1360 *
1361 * @see s2Member\API_Functions\is_protected_by_s2member()
1362 * @see s2Member\API_Functions\is_permitted_by_s2member()
1363 *
1364 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1365 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1366 *
1367 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1368 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1369 *
1370 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1371 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1372 *
1373 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1374 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1375 *
1376 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1377 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1378 *
1379 * @see s2Member\API_Functions\attach_s2member_query_filters()
1380 * @see s2Member\API_Functions\detach_s2member_query_filters()
1381 */
1382 if(!function_exists("is_post_protected_by_s2member"))
1383 {
1384 function is_post_protected_by_s2member($post_id = FALSE, $check_user = FALSE)
1385 {
1386 if($post_id && ($array = c_ws_plugin__s2member_posts_sp::check_specific_post_level_access($post_id, $check_user)))
1387 return /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */ $array;
1388
1389 return false;
1390 }
1391 }
1392 /**
1393 * Conditional to determine if a specific Post or Custom Post Type is permitted by s2Member,
1394 * with consideration given to the current User's Role/Capabilites.
1395 *
1396 * This function is similar to {@link s2Member\API_Functions\is_post_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1397 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_post_protected_by_s2member()} does; it only returns true|false.
1398 *
1399 * ———— Extra Detail On Function Parameters ————
1400 *
1401 * **Parameter $post_id (int Required).** This should be a WordPress Post ID, or a Custom Post Type ID.
1402 *
1403 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1404 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1405 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1406 * including any URI Restrictions that you may have configured.
1407 *
1408 * ———— Code Sample Using Function Parameters ————
1409 * ```
1410 * <!php
1411 * if(is_post_permitted_by_s2member(123))
1412 * echo 'Post ID #123 is permitted by s2Member.';
1413 * !>
1414 * ```
1415 * ———— Shortcode Conditional Equivalent ————
1416 * ```
1417 * [s2If is_post_permitted_by_s2member(123)]
1418 * Post ID #123 is permitted by s2Member.
1419 * [/s2If]
1420 * ```
1421 *
1422 * @package s2Member\API_Functions
1423 * @since 3.5
1424 *
1425 * @param int $post_id Required. This should be a WordPress Post ID, or a Custom Post Type ID.
1426 * @return bool True if the current User IS permitted, else false if the Post is NOT available to the current User;
1427 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1428 *
1429 * @see s2Member\API_Functions\is_protected_by_s2member()
1430 * @see s2Member\API_Functions\is_permitted_by_s2member()
1431 *
1432 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1433 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1434 *
1435 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1436 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1437 *
1438 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1439 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1440 *
1441 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1442 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1443 *
1444 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1445 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1446 *
1447 * @see s2Member\API_Functions\attach_s2member_query_filters()
1448 * @see s2Member\API_Functions\detach_s2member_query_filters()
1449 */
1450 if(!function_exists("is_post_permitted_by_s2member"))
1451 {
1452 function is_post_permitted_by_s2member($post_id = FALSE)
1453 {
1454 if($post_id && c_ws_plugin__s2member_posts_sp::check_specific_post_level_access($post_id, true))
1455 return false;
1456
1457 return true;
1458 }
1459 }
1460 /**
1461 * Conditional to determine if a specific Page is protected by s2Member;
1462 * without considering the current User's Role/Capabilites.
1463 *
1464 * ———— Extra Detail On Function Parameters ————
1465 *
1466 * **Parameter $page_id (int Required).** This should be a WordPress Page ID.
1467 *
1468 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1469 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1470 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1471 * including any URI Restrictions that you may have configured.
1472 *
1473 * **Parameter $check_user (bool Optional).**
1474 * Consider the current User? Defaults to false.
1475 *
1476 * o In other words, by default, this Conditional function is only checking to see if the Page is protected, and that's it.
1477 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1478 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_page_permitted_by_s2member()}.
1479 *
1480 * ———— Code Sample Using Function Parameters ————
1481 * ```
1482 * <!php
1483 * if(is_page_protected_by_s2member(123))
1484 * echo 'Page ID #123 is protected by s2Member.';
1485 * !>
1486 * ```
1487 * ———— Shortcode Conditional Equivalent ————
1488 * ```
1489 * [s2If is_page_protected_by_s2member(123)]
1490 * Page ID #123 is protected by s2Member.
1491 * [/s2If]
1492 * ```
1493 *
1494 * @package s2Member\API_Functions
1495 * @since 3.5
1496 *
1497 * @param int $page_id Required. This should be a WordPress Page ID.
1498 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1499 * @return array|bool A non-empty array *(meaning true)*, or false if the Page is not protected *(i.e., available publicly)*.
1500 * When/if the Page IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1501 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Page.
1502 * In other words, the reason why it's protected; based on your s2Member configuration.
1503 *
1504 * @see s2Member\API_Functions\is_protected_by_s2member()
1505 * @see s2Member\API_Functions\is_permitted_by_s2member()
1506 *
1507 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1508 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1509 *
1510 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1511 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1512 *
1513 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1514 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1515 *
1516 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1517 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1518 *
1519 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1520 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1521 *
1522 * @see s2Member\API_Functions\attach_s2member_query_filters()
1523 * @see s2Member\API_Functions\detach_s2member_query_filters()
1524 */
1525 if(!function_exists("is_page_protected_by_s2member"))
1526 {
1527 function is_page_protected_by_s2member($page_id = FALSE, $check_user = FALSE)
1528 {
1529 if($page_id && ($array = c_ws_plugin__s2member_pages_sp::check_specific_page_level_access($page_id, $check_user)))
1530 return /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */ $array;
1531
1532 return false;
1533 }
1534 }
1535 /**
1536 * Conditional to determine if a specific Page is permitted by s2Member,
1537 * with consideration given to the current User's Role/Capabilites.
1538 *
1539 * This function is similar to {@link s2Member\API_Functions\is_page_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1540 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_page_protected_by_s2member()} does; it only returns true|false.
1541 *
1542 * ———— Extra Detail On Function Parameters ————
1543 *
1544 * **Parameter $page_id (int Required).** This should be a WordPress Page ID.
1545 *
1546 * o s2Member will check everything, including your configured URI Restrictions against the ID.
1547 * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
1548 * So using an ID results in an all-inclusive scan against your configured Restrictions,
1549 * including any URI Restrictions that you may have configured.
1550 *
1551 * ———— Code Sample Using Function Parameters ————
1552 * ```
1553 * <!php
1554 * if(is_page_permitted_by_s2member(123))
1555 * echo 'Page ID #123 is permitted by s2Member.';
1556 * !>
1557 * ```
1558 * ———— Shortcode Conditional Equivalent ————
1559 * ```
1560 * [s2If is_page_permitted_by_s2member(123)]
1561 * Page ID #123 is permitted by s2Member.
1562 * [/s2If]
1563 * ```
1564 *
1565 * @package s2Member\API_Functions
1566 * @since 3.5
1567 *
1568 * @param int $page_id Required. This should be a WordPress Page ID.
1569 * @return bool True if the current User IS permitted, else false if the Page is NOT available to the current User;
1570 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1571 *
1572 * @see s2Member\API_Functions\is_protected_by_s2member()
1573 * @see s2Member\API_Functions\is_permitted_by_s2member()
1574 *
1575 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1576 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1577 *
1578 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1579 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1580 *
1581 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1582 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1583 *
1584 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1585 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1586 *
1587 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1588 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1589 *
1590 * @see s2Member\API_Functions\attach_s2member_query_filters()
1591 * @see s2Member\API_Functions\detach_s2member_query_filters()
1592 */
1593 if(!function_exists("is_page_permitted_by_s2member"))
1594 {
1595 function is_page_permitted_by_s2member($page_id = FALSE)
1596 {
1597 if($page_id && c_ws_plugin__s2member_pages_sp::check_specific_page_level_access($page_id, true))
1598 return false;
1599
1600 return true;
1601 }
1602 }
1603 /**
1604 * Conditional to determine if a specific URI or URL is protected by s2Member;
1605 * without considering the current User's Role/Capabilities.
1606 *
1607 * ———— Extra Detail On Function Parameters ————
1608 *
1609 * **Parameter $uri_or_full_url (str Required).** This should be a URI starting with `/`, or a full URL is also fine.
1610 *
1611 * **Parameter $check_user (bool Optional).**
1612 * Consider the current User? Defaults to false.
1613 *
1614 * 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.
1615 * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
1616 * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_uri_permitted_by_s2member()}.
1617 *
1618 * ———— Important Notes About This Function ————
1619 *
1620 * This function will ONLY test against URI Restrictions you've configured with s2Member.
1621 * If you need an all-inclusive test, please use {@link s2Member\API_Functions\is_protected_by_s2member()} with an ID.
1622 *
1623 * ———— Code Sample Using Function Parameters ————
1624 * ```
1625 * <!php
1626 * if(is_uri_protected_by_s2member("/members-only/sub-section"))
1627 * echo 'The URI (/members-only/sub-section) is protected by URI Restrictions.';
1628 *
1629 * else if(is_uri_protected_by_s2member("http://example.com/members-only/sub-section"))
1630 * echo 'The URL (http://example.com/members-only/sub-section) is protected by URI Restrictions.';
1631 * !>
1632 * ```
1633 * ———— Shortcode Conditional Equivalent ————
1634 * ```
1635 * [s2If is_uri_protected_by_s2member(/members-only/sub-section)]
1636 * The URI (/members-only/sub-section) is protected by URI Restrictions.
1637 * [/s2If]
1638 * [s2If is_uri_protected_by_s2member(http://example.com/members-only/sub-section)]
1639 * The URL (http://example.com/members-only/sub-section) is protected by URI Restrictions.
1640 * [/s2If]
1641 * ```
1642 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1643 *
1644 * @package s2Member\API_Functions
1645 * @since 3.5
1646 *
1647 * @param string $uri_or_full_url Required. This should be a URI starting with `/`, or a full URL is also fine.
1648 * @param bool $check_user Optional. Consider the current User? Defaults to false.
1649 * @return array|bool A non-empty array *(meaning true)*, or false if the URI or URL is not protected *(i.e., available publicly)*.
1650 * When/if the URI or URL IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
1651 * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the URI or URL.
1652 * In other words, the reason why it's protected; based on your s2Member configuration.
1653 *
1654 * @see s2Member\API_Functions\is_protected_by_s2member()
1655 * @see s2Member\API_Functions\is_permitted_by_s2member()
1656 *
1657 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1658 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1659 *
1660 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1661 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1662 *
1663 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1664 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1665 *
1666 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1667 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1668 *
1669 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1670 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1671 *
1672 * @see s2Member\API_Functions\attach_s2member_query_filters()
1673 * @see s2Member\API_Functions\detach_s2member_query_filters()
1674 */
1675 if(!function_exists("is_uri_protected_by_s2member"))
1676 {
1677 function is_uri_protected_by_s2member($uri_or_full_url = FALSE, $check_user = FALSE)
1678 {
1679 if($uri_or_full_url && ($array = c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access($uri_or_full_url, $check_user)))
1680 return /* A non-empty array with ["s2member_level_req"]. */ $array;
1681
1682 return false;
1683 }
1684 }
1685 /**
1686 * Conditional to determine if a specific URI or URL is permitted by s2Member,
1687 * with consideration given to the current User's Role/Capabilites.
1688 *
1689 * This function is similar to {@link s2Member\API_Functions\is_uri_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
1690 * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_uri_protected_by_s2member()} does; it only returns true|false.
1691 *
1692 * ———— Extra Detail On Function Parameters ————
1693 *
1694 * **Parameter $uri_or_full_url (str Required).** This should be a URI starting with `/`, or a full URL is also fine.
1695 *
1696 * ———— Important Notes About This Function ————
1697 *
1698 * This function will ONLY test against URI Restrictions you've configured with s2Member.
1699 * If you need an all-inclusive test, please use {@link s2Member\API_Functions\is_permitted_by_s2member()} with an ID.
1700 *
1701 * ———— Code Sample Using Function Parameters ————
1702 * ```
1703 * <!php
1704 * if(is_uri_permitted_by_s2member("/members-only/sub-section"))
1705 * echo 'The URI (/members-only/sub-section) is permitted by URI Restrictions.';
1706 *
1707 * else if(is_uri_permitted_by_s2member("http://example.com/members-only/sub-section"))
1708 * echo 'The URL (http://example.com/members-only/sub-section) is permitted by URI Restrictions.';
1709 * !>
1710 * ```
1711 * ———— Shortcode Conditional Equivalent ————
1712 * ```
1713 * [s2If is_uri_permitted_by_s2member(/members-only/sub-section)]
1714 * The URI (/members-only/sub-section) is permitted by URI Restrictions.
1715 * [/s2If]
1716 * [s2If is_uri_permitted_by_s2member(http://example.com/members-only/sub-section)]
1717 * The URL (http://example.com/members-only/sub-section) is permitted by URI Restrictions.
1718 * [/s2If]
1719 * ```
1720 * *but please note, `else if()` logic is not possible with `[s2If /]`.*
1721 *
1722 * @package s2Member\API_Functions
1723 * @since 3.5
1724 *
1725 * @param string $uri_or_full_url Required. This should be a URI starting with `/`, or a full URL is also fine.
1726 * @return bool True if the current User IS permitted, else false if the URI or URL is NOT available to the current User;
1727 * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
1728 *
1729 * @see s2Member\API_Functions\is_protected_by_s2member()
1730 * @see s2Member\API_Functions\is_permitted_by_s2member()
1731 *
1732 * @see s2Member\API_Functions\is_category_protected_by_s2member()
1733 * @see s2Member\API_Functions\is_category_permitted_by_s2member()
1734 *
1735 * @see s2Member\API_Functions\is_tag_protected_by_s2member()
1736 * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
1737 *
1738 * @see s2Member\API_Functions\is_post_protected_by_s2member()
1739 * @see s2Member\API_Functions\is_post_permitted_by_s2member()
1740 *
1741 * @see s2Member\API_Functions\is_page_protected_by_s2member()
1742 * @see s2Member\API_Functions\is_page_permitted_by_s2member()
1743 *
1744 * @see s2Member\API_Functions\is_uri_protected_by_s2member()
1745 * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
1746 *
1747 * @see s2Member\API_Functions\attach_s2member_query_filters()
1748 * @see s2Member\API_Functions\detach_s2member_query_filters()
1749 */
1750 if(!function_exists("is_uri_permitted_by_s2member"))
1751 {
1752 function is_uri_permitted_by_s2member($uri_or_full_url = FALSE)
1753 {
1754 if($uri_or_full_url && c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access($uri_or_full_url, true))
1755 return false;
1756
1757 return true;
1758 }
1759 }
1760 /**
1761 * Allows plugin/theme developers to pre-filter WP Queries easily, so that protected content
1762 * *(i.e content NOT available to the current User)*, is excluded automatically.
1763 *
1764 * This functionality is already built right into s2Member's UI configuration panels,
1765 * but in cases where a plugin/theme developer needs more control, this may come in handy.
1766 * In the UI configuration for s2Member, please see: `Alternative View Protection`.
1767 *
1768 * ———— Code Sample Using s2Member's Query Filters ————
1769 * ```
1770 * <!php
1771 * attach_s2member_query_filters();
1772 * query_posts("posts_per_page=5");
1773 *
1774 * if (have_posts()):
1775 * while (have_posts()):
1776 * the_post();
1777 * # Protected content will be excluded automatically.
1778 * # (based on the current User's Role/Capabilities)
1779 * endwhile;
1780 * endif;
1781 *
1782 * wp_reset_query();
1783 * detach_s2member_query_filters();
1784 * !>
1785 * ```
1786 * ———— Shortcode Equivalent ————
1787 * ```
1788 * There is NO Shortcode equivalent for this.
1789 * ```
1790 *
1791 * @package s2Member\API_Functions
1792 * @since 3.5
1793 *
1794 * @return null
1795 *
1796 * @see s2Member\API_Functions\detach_s2member_query_filters()
1797 */
1798 if(!function_exists("attach_s2member_query_filters"))
1799 {
1800 function attach_s2member_query_filters()
1801 {
1802 remove_action("pre_get_posts", "c_ws_plugin__s2member_security::security_gate_query", 100);
1803 add_action("pre_get_posts", "c_ws_plugin__s2member_querys::force_query_level_access", 100);
1804 }
1805 }
1806 /**
1807 * Allows plugin/theme developers to pre-filter WP Queries easily, so that protected content
1808 * *(i.e content NOT available to the current User)*, is excluded automatically.
1809 *
1810 * This functionality is already built right into s2Member's UI configuration panels,
1811 * but in cases where a plugin/theme developer needs more control, this may come in handy.
1812 * In the UI configuration for s2Member, please see: `Alternative View Protection`.
1813 *
1814 * ———— Code Sample Using s2Member's Query Filters ————
1815 * ```
1816 * <!php
1817 * attach_s2member_query_filters();
1818 * query_posts("posts_per_page=5");
1819 *
1820 * if (have_posts()):
1821 * while (have_posts()):
1822 * the_post();
1823 * # Protected content will be excluded automatically.
1824 * # (based on the current User's Role/Capabilities)
1825 * endwhile;
1826 * endif;
1827 *
1828 * wp_reset_query();
1829 * detach_s2member_query_filters();
1830 * !>
1831 * ```
1832 * ———— Shortcode Equivalent ————
1833 * ```
1834 * There is NO Shortcode equivalent for this.
1835 * ```
1836 *
1837 * @package s2Member\API_Functions
1838 * @since 3.5
1839 *
1840 * @return null
1841 *
1842 * @see s2Member\API_Functions\attach_s2member_query_filters()
1843 */
1844 if(!function_exists("detach_s2member_query_filters"))
1845 {
1846 function detach_s2member_query_filters()
1847 {
1848 remove_action("pre_get_posts", "c_ws_plugin__s2member_querys::force_query_level_access", 100);
1849 add_action("pre_get_posts", "c_ws_plugin__s2member_security::security_gate_query", 100);
1850 }
1851 }
1852 /**
1853 * Generates a File Download URL that provides access to a File protected by s2Member.
1854 *
1855 * By default, s2Member uses your Basic Download Restrictions. For more information on this,
1856 * please check your Dashboard under: `s2Member → Download Options → Basic Download Restrictions`.
1857 *
1858 * ———— HTML/PHP Code Samples ————
1859 * ```
1860 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.zip")); !>">Download Now</a>
1861 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.pdf", "file_inline" => true)); !>">View PDF</a>
1862 * ```
1863 * ———— Shortcode Equivalents ————
1864 * ```
1865 * <a href="[s2File download="file.zip" /]">Download Now</a>
1866 * <a href="[s2File download="file.pdf" inline="true" /]">View PDF</a>
1867 * ```
1868 *
1869 * ———— Advanced Download Restrictions ————
1870 *
1871 * Or, you can also force s2Member to allow File Downloads, by requesting a File Download Key ( i.e., `file_download_key => true` ).
1872 * 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,
1873 * regardless of Membership Level; and WITHOUT checking any Basic Restrictions, that you may, or may not have configured.
1874 *
1875 * ———— HTML/PHP Code Samples Using A Download Key ————
1876 * ```
1877 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.zip", file_download_key => true)); !>">Download Now</a>
1878 * <a href="<!php echo s2member_file_download_url(array("file_download" => "file.pdf", file_download_key => true, "file_inline" => true)); !>">View PDF</a>
1879 * ```
1880 * ———— Shortcode Equivalents Using A Download Key ————
1881 * ```
1882 * <a href="[s2File download="file.zip" download_key="true" /]">Download Now</a>
1883 * <a href="[s2File download="file.zip" download_key="true" inline="true" /]">View PDF</a>
1884 * ```
1885 *
1886 * ———— Extra Detail On Function Parameters ————
1887 *
1888 * **Parameter $config (array Required).** This should be an array with one or more of the following elements.
1889 *
1890 * 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.
1891 * 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)*.
1892 * 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.
1893 * 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.
1894 * 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.
1895 * 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.
1896 * 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.
1897 * 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.
1898 * 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.
1899 * 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.
1900 * 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.
1901 * 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.
1902 * 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.
1903 *
1904 * **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``.
1905 *
1906 * @package s2Member\API_Functions
1907 * @since 110926
1908 *
1909 * @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.
1910 * 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`.
1911 * @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``.
1912 * @return string 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.
1913 *
1914 * @see s2Member\API_Functions\s2member_file_download_key()
1915 */
1916 if(!function_exists("s2member_file_download_url"))
1917 {
1918 function s2member_file_download_url($config = FALSE, $get_streamer_array = FALSE)
1919 {
1920 return c_ws_plugin__s2member_files::create_file_download_url($config, $get_streamer_array);
1921 }
1922 }
1923 /**
1924 * Generates a File Download Key that provides access to a File protected by s2Member.
1925 *
1926 * By default, s2Member uses your Basic Download Restrictions. For more information on this,
1927 * please check your Dashboard under: `s2Member → Download Options → Basic Download Restrictions`.
1928 *
1929 * ———— Advanced Download Restrictions ————
1930 *
1931 * Or, you can also force s2Member to allow File Downloads, using an extra query string parameter `s2member_file_download_key`.
1932 * A File Download Key is passed through this parameter; it tells s2Member to allow the download of this particular file,
1933 * regardless of Membership Level; and WITHOUT checking any Basic Restrictions, that you may, or may not have configured.
1934 *
1935 * ———— Code Sample Using A Download Key ————
1936 * ```
1937 * <a href="/?s2member_file_download=file.zip&s2member_file_download_key=<!php echo s2member_file_download_key("file.zip"); !>">Download Now</a>
1938 * ```
1939 * ———— Shortcode Equivalent ————
1940 * ```
1941 * [s2Key file_download="file.zip" directive="" /]
1942 * ```
1943 *
1944 * This API Funtion produces a time-sensitive File Download Key that is unique to each and every visitor.
1945 * 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;
1946 * as detected by s2Member. This makes it possible for you to create links on your site, which provide access to protected File Downloads;
1947 * without having to worry about one visitor sharing their link with another.
1948 *
1949 * When `/?s2member_file_download_key` = `a valid Key` generated by this function, it works independently from Member Level Access.
1950 * That is, a visitor does NOT have to be logged in to receive access; they just need a valid Key.
1951 * Using this advanced technique, you could extend s2Member's file protection routines,
1952 * or even combine them with Specific Post/Page Access, and more.
1953 * The possibilities are limitless really.
1954 *
1955 * @package s2Member\API_Functions
1956 * @since 3.5
1957 *
1958 * @param string $file Location of the protected File, relative to the `/s2member-files/` directory.
1959 * @param str|bool $directive Optional. Defaults to false. If you set this to any non-zero value ( i.e., the string `universal` ),
1960 * 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.
1961 * It is also possible to pass in the ``$directive`` string `ip-forever`, making the Key last forever, but only for a specific IP address.
1962 * @return string The File Download Key. Which is an MD5 hash *(always 32 characters)*, URL-safe.
1963 *
1964 * @see s2Member\API_Functions\s2member_file_download_url()
1965 *
1966 * @todo Allow custom expiration times.
1967 */
1968 if(!function_exists("s2member_file_download_key"))
1969 {
1970 function s2member_file_download_key($file = FALSE, $directive = FALSE)
1971 {
1972 return c_ws_plugin__s2member_files::file_download_key($file, $directive);
1973 }
1974 }
1975 /**
1976 * Retrieves an array of details, related to a User's File Downloads.
1977 *
1978 * ———— PHP Code Samples ————
1979 * ```
1980 * <!php
1981 * $user_downloads = s2member_user_downloads();
1982 * $specific_user_downloads = s2member_user_downloads(($user_id = 123));
1983 * !>
1984 * ```
1985 * ———— Shortcode Equivalent ————
1986 * ```
1987 * There is NO Shortcode equivalent for this yet.
1988 * ```
1989 *
1990 * @package s2Member\API_Functions
1991 * @since 111026
1992 *
1993 * @param string|int $user_id Optional. Defaults to the currently logged-in User's ID.
1994 * @param string $not_counting_this_particular_file Optional. If you want to exclude a particular file, relative to the `/s2member-files/` directory, or relative to the root of your Amazon S3 Bucket *(when applicable)*.
1995 * @return array An array with the following elements... File Downloads allowed for this User: (int)`allowed`, Download Period for this User in days: (int)`allowed_days`, Files downloaded by this User in the current Period: (int)`currently`, log of all Files downloaded in the current Period, with file names/dates: (array)`log`, archive of all Files downloaded in prior Periods, with file names/dates: (array)`archive`.
1996 *
1997 * @note Calculations returned by this function do NOT include File Downloads that were accessed with an Advanced File Download Key.
1998 *
1999 * @see s2Member\API_Functions\s2member_total_downloads_of()
2000 * @see s2Member\API_Functions\s2member_total_unique_downloads_of()
2001 *
2002 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED
2003 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED
2004 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS
2005 *
2006 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY
2007 *
2008 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_ID
2009 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL
2010 *
2011 * @see s2Member\API_Constants\S2MEMBER_LEVELn_FILE_DOWNLOADS_ALLOWED
2012 * @see s2Member\API_Constants\S2MEMBER_LEVELn_FILE_DOWNLOADS_ALLOWED_DAYS
2013 *
2014 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_INLINE_EXTENSIONS
2015 *
2016 * @todo Make it possible for s2Member to keep a count of files downloaded with an Advanced Download Key.
2017 * @todo Create a Shortcode equivalent.
2018 */
2019 if(!function_exists("s2member_user_downloads"))
2020 {
2021 function s2member_user_downloads($user_id = FALSE, $not_counting_this_particular_file = FALSE)
2022 {
2023 $user = ($user_id && is_object($user = new WP_User((int)$user_id)) && !empty($user->ID)) ? $user : false;
2024 return c_ws_plugin__s2member_files::user_downloads($user, $not_counting_this_particular_file);
2025 }
2026 }
2027 /**
2028 * Total downloads of a particular file; possibly by a particular User.
2029 *
2030 * ———— PHP Code Samples ————
2031 * ```
2032 * File: `example-file.zip`, has been downloaded a total of <!php echo s2member_total_downloads_of("example-file.zip"); !> times; collectively, among all Users/Members, for all time *(includes all duplicate downloads of the same file by the same User/Member)*.
2033 * File: `example-file.zip`, has been downloaded a total of <!php echo s2member_total_downloads_of("example-file.zip", false, false); !> times; collectively, among all Users/Members, in this Period only *(includes all duplicate downloads of the same file by the same User/Member)*.
2034 * File: `example-file.zip`, has been downloaded by User ID# 123, a total of <!php echo s2member_total_downloads_of("example-file.zip", 123); !> times; for all time, since they first became a User/Member of the site *(includes all duplicate downloads of the same file by this User/Member)*.
2035 * File: `example-file.zip`, has been downloaded by User ID# 123, a total of <!php echo s2member_total_downloads_of("example-file.zip", 123, false); !> times; in this Period only *(includes all duplicate downloads of the same file by this User/Member)*.
2036 * ```
2037 * ———— Shortcode Equivalent ————
2038 * ```
2039 * There is NO Shortcode equivalent for this yet.
2040 * ```
2041 *
2042 * @package s2Member\API_Functions
2043 * @since 111026
2044 *
2045 * @param string $file Required. Location of the file, relative to the `/s2member-files/` directory, or relative to the root of your Amazon S3 Bucket *(when applicable)*.
2046 * @param string|int $user_id Optional. If specified, s2Member will return total downloads by a particular User/Member, instead of collectively *(i.e among all Users/Members)*.
2047 * @param bool $check_archives_too Optional. Defaults to true. When true, s2Member checks its File Download Archive too, instead of ONLY looking at Files downloaded in the current Period. Period is based on your Basic Download Restrictions setting of allowed days across various Levels of Membership, for each respective User/Member. Or, if ``$user_id`` is specified, based solely on a specific User's `allowed_days`, configured in your Basic Download Restrictions, at the User's current Membership Level.
2048 * @return int The total for this particular ``$file``, based on configuration of function arguments.
2049 *
2050 * @note Calculations returned by this function do NOT include File Downloads that were accessed with an Advanced File Download Key.
2051 *
2052 * @see s2Member\API_Functions\s2member_user_downloads()
2053 * @see s2Member\API_Functions\s2member_total_unique_downloads_of()
2054 *
2055 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED
2056 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED
2057 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS
2058 *
2059 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY
2060 *
2061 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_ID
2062 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL
2063 *
2064 * @see s2Member\API_Constants\S2MEMBER_LEVELn_FILE_DOWNLOADS_ALLOWED
2065 * @see s2Member\API_Constants\S2MEMBER_LEVELn_FILE_DOWNLOADS_ALLOWED_DAYS
2066 *
2067 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_INLINE_EXTENSIONS
2068 *
2069 * @todo Make it possible for s2Member to keep a count of files downloaded with an Advanced Download Key.
2070 * @todo Create a Shortcode equivalent.
2071 */
2072 if(!function_exists("s2member_total_downloads_of"))
2073 {
2074 function s2member_total_downloads_of($file = FALSE, $user_id = FALSE, $check_archives_too = TRUE)
2075 {
2076 return c_ws_plugin__s2member_files::total_downloads_of($file, $user_id, $check_archives_too);
2077 }
2078 }
2079 /**
2080 * Total unique downloads of a particular file; possibly by a particular User.
2081 *
2082 * ———— PHP Code Samples ————
2083 * ```
2084 * File: `example-file.zip`, has been downloaded a total of <!php echo s2member_total_unique_downloads_of("example-file.zip"); !> times; collectively, among all Users/Members, for all time *(does NOT include duplicate downloads of the same file, in a single Period, by the same User/Member)*.
2085 * File: `example-file.zip`, has been downloaded a total of <!php echo s2member_total_unique_downloads_of("example-file.zip", false, false); !> times; collectively, among all Users/Members, in this Period only *(does NOT include duplicate downloads of the same file, in a single Period, by the same User/Member)*.
2086 * File: `example-file.zip`, has been downloaded by User ID# 123, a total of <!php echo s2member_total_unique_downloads_of("example-file.zip", 123); !> times; for all time, since they first became a User/Member of the site *(does NOT include duplicate downloads of the same file, in a single Period, by this User/Member)*.
2087 * File: `example-file.zip`, has been downloaded by User ID# 123, a total of <!php echo s2member_total_unique_downloads_of("example-file.zip", 123, false); !> times; in this Period only *(does NOT include duplicate downloads of the same file, in a single Period, by this User/Member)*.
2088 * ```
2089 * ———— Shortcode Equivalent ————
2090 * ```
2091 * There is NO Shortcode equivalent for this yet.
2092 * ```
2093 *
2094 * @package s2Member\API_Functions
2095 * @since 111026
2096 *
2097 * @param string $file Required. Location of the file, relative to the `/s2member-files/` directory, or relative to the root of your Amazon S3 Bucket *(when applicable)*.
2098 * @param string|int $user_id Optional. If specified, s2Member will return total downloads by a particular User/Member, instead of collectively *(i.e among all Users/Members)*.
2099 * @param bool $check_archives_too Optional. Defaults to true. When true, s2Member checks its File Download Archive too, instead of ONLY looking at Files downloaded in the current Period. Period is based on your Basic Download Restrictions setting of allowed days across various Levels of Membership, for each respective User/Member. Or, if ``$user_id`` is specified, based solely on a specific User's `allowed_days`, configured in your Basic Download Restrictions, at the User's current Membership Level.
2100 * @return int The total for this particular ``$file``, based on configuration of function arguments.
2101 *
2102 * @note Calculations returned by this function do NOT include File Downloads that were accessed with an Advanced File Download Key.
2103 *
2104 * @see s2Member\API_Functions\s2member_user_downloads()
2105 * @see s2Member\API_Functions\s2member_total_downloads_of()
2106 *
2107 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED
2108 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED
2109 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS
2110 *
2111 * @see s2Member\API_Constants\S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY
2112 *
2113 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_ID
2114 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_LIMIT_EXCEEDED_PAGE_URL
2115 *
2116 * @see s2Member\API_Constants\S2MEMBER_LEVELn_FILE_DOWNLOADS_ALLOWED
2117 * @see s2Member\API_Constants\S2MEMBER_LEVELn_FILE_DOWNLOADS_ALLOWED_DAYS
2118 *
2119 * @see s2Member\API_Constants\S2MEMBER_FILE_DOWNLOAD_INLINE_EXTENSIONS
2120 *
2121 * @todo Make it possible for s2Member to keep a count of files downloaded with an Advanced Download Key.
2122 * @todo Create a Shortcode equivalent.
2123 */
2124 if(!function_exists("s2member_total_unique_downloads_of"))
2125 {
2126 function s2member_total_unique_downloads_of($file = FALSE, $user_id = FALSE, $check_archives_too = TRUE)
2127 {
2128 return c_ws_plugin__s2member_files::total_unique_downloads_of($file, $user_id, $check_archives_too);
2129 }
2130 }
2131 /**
2132 * Obtains the Last Login Time for the current User, and/or for a particular User.
2133 *
2134 * The Last Login Time, is the time at which the Username last logged into the site.
2135 * There's nothing special about this. This simply returns a {@link https://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2136 *
2137 * ———— Code Sample Using Function Parameters ————
2138 * ```
2139 * <!php
2140 * if(s2member_last_login_time() <= strtotime("-30 days"))
2141 * echo 'The current User last logged-in over 30 days ago.';
2142 *
2143 * else if(s2member_last_login_time(123) <= strtotime("-30 days"))
2144 * echo 'User with ID #123 last logged-in over 30 days ago.';
2145 * !>
2146 * ```
2147 * ———— Shortcode Equivalent ————
2148 * ```
2149 * [s2Get user_option="s2member_last_login_time" /] # Last Login Time.
2150 * ```
2151 *
2152 * @package s2Member\API_Functions
2153 * @since 130210
2154 *
2155 * @param int $user_id Optional. Defaults to the current User's ID.
2156 * @return int A {@link https://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2157 * The Last Login Time, is the time at which the Username last logged into the site.
2158 * If the User has never logged into the site (or s2Member has never recorded them logging in), this will return `0`.
2159 *
2160 * @see s2Member\API_Functions\get_user_field()
2161 */
2162 if(!function_exists("s2member_last_login_time"))
2163 {
2164 function s2member_last_login_time($user_id = FALSE)
2165 {
2166 return (int)get_user_option ("s2member_last_login_time", (int)$user_id);
2167 }
2168 }
2169 /**
2170 * Obtains the Registration Time for the current User, and/or for a particular User.
2171 *
2172 * The Registration Time, is the time at which the Username was created for the account, that's it.
2173 * There's nothing special about this. This simply returns a {@link https://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2174 *
2175 * ———— Code Sample Using Function Parameters ————
2176 * ```
2177 * <!php
2178 * if(s2member_registration_time() <= strtotime("-30 days"))
2179 * echo 'The current User has existed for at least 30 days.';
2180 *
2181 * else if(s2member_registration_time(123) <= strtotime("-30 days"))
2182 * echo 'User with ID #123 has existed for at least 30 days.';
2183 * !>
2184 * ```
2185 * ———— Shortcode Equivalent ————
2186 * ```
2187 * There is NO Shortcode equivalent for this (yet).
2188 * ```
2189 *
2190 * @package s2Member\API_Functions
2191 * @since 3.5
2192 *
2193 * @param int $user_id Optional. Defaults to the current User's ID.
2194 * @return int A {@link https://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2195 * The Registration Time, is the time at which the Username was created for the account, that's it.
2196 *
2197 * @see s2Member\API_Functions\get_user_field()
2198 */
2199 if(!function_exists("s2member_registration_time"))
2200 {
2201 function s2member_registration_time($user_id = FALSE)
2202 {
2203 return c_ws_plugin__s2member_registration_times::registration_time($user_id);
2204 }
2205 }
2206 /**
2207 * Retrieves a Paid Registration Time for the current User, and/or for a particular User.
2208 *
2209 * **NOTE** A Paid Registration Time, is NOT necessarily related specifically to a Payment.
2210 * s2Member records a Paid Registration Time, anytime a User acquires paid Membership Level Access.
2211 *
2212 * In other words, if you create a new User inside your Dashboard at a Membership Level greater than Level #0,
2213 * s2Member will record a Paid Registration Time immediately, because Membership Levels > 0, are reserved for paying Members.
2214 * s2Member monitors changes to all User accounts, and records the first Paid Registration Time for each Member, at each paid Membership Level.
2215 * 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.
2216 *
2217 * ———— Code Sample Using Function Parameters ————
2218 * ```
2219 * <!php
2220 * $time = s2member_registration_time (); # first registration time (free or otherwise).
2221 * $time = s2member_paid_registration_time (); # first "paid" registration and/or upgrade time.
2222 * $time = s2member_paid_registration_time ("level1"); # first "paid" registration or upgrade time at Level#1.
2223 * $time = s2member_paid_registration_time ("level2"); # first "paid" registration or upgrade time at Level#2.
2224 * $time = s2member_paid_registration_time ("level3"); # first "paid" registration or upgrade time at Level#3.
2225 * $time = s2member_paid_registration_time ("level4"); # first "paid" registration or upgrade time at Level#4.
2226 * !>
2227 * ```
2228 * ———— Shortcode Equivalent ————
2229 * ```
2230 * There is NO Shortcode equivalent for this (yet).
2231 * ```
2232 *
2233 * @package s2Member\API_Functions
2234 * @since 3.5
2235 *
2236 * @param string $level Optional. Defaults to the first/initial Paid Registration Time, regardless of Level#.
2237 * @param int $user_id Optional. Defaults to the current User's ID.
2238 * @return int A {@link https://en.wikipedia.org/wiki/Unix_time Unix Timestamp}.
2239 *
2240 * @see s2Member\API_Functions\get_user_field()
2241 */
2242 if(!function_exists("s2member_paid_registration_time"))
2243 {
2244 function s2member_paid_registration_time($level = false, $user_id = false)
2245 {
2246 return c_ws_plugin__s2member_registration_times::paid_registration_time($level, $user_id);
2247 }
2248 }
2249 /**
2250 * Gets access capability times.
2251 *
2252 * @package s2Member\API_Functions
2253 * @since 140514
2254 *
2255 * @param integer $user_id WP User ID.
2256 * @param array $access_caps Optional. If not passed, this returns all times for all caps.
2257 * If passed, please pass an array of specific access capabilities to get the times for.
2258 * If removal times are desired, you should add a `-` prefix.
2259 * e.g., `array('ccap_music','level2','-ccap_video')`
2260 *
2261 * @return array An array of all access capability times.
2262 * Keys are UTC timestamps (w/ microtime precision), values are the capabilities (including `-` prefixed removals).
2263 * e.g., `array('1234567890.0001' => 'ccap_music', '1234567890.0002' => 'level2', '1234567890.0003' => '-ccap_video')`
2264 */
2265 if(!function_exists("s2member_access_cap_times") && !function_exists("s2member_capability_times"))
2266 {
2267 function s2member_access_cap_times($user_id = NULL, $access_caps = array())
2268 {
2269 if(!$user_id) $user_id = get_current_user_id();
2270
2271 return c_ws_plugin__s2member_access_cap_times::get_access_cap_times($user_id, $access_caps);
2272 }
2273 /* Deprecated in favor of `s2member_access_cap_times()`. */
2274 function s2member_capability_times($user_id = NULL, $access_caps = array())
2275 {
2276 if(!$user_id) $user_id = get_current_user_id();
2277
2278 return c_ws_plugin__s2member_access_cap_times::get_access_cap_times($user_id, $access_caps);
2279 }
2280 }
2281 /**
2282 * A powerful function that can retrieve almost anything
2283 * you need to know about the current User, and/or a particular User.
2284 *
2285 * Scans all properties of the {@link http://codex.wordpress.org/Function_Reference/wp_get_current_user WP_User object}.
2286 * 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.
2287 *
2288 * It can be used to retrieve basic information like `first_name`, `last_name`, `user_email`, `user_login`.
2289 * It can also be used to retrieve User Meta/Options, Role/Capabilities, and even supports
2290 * Custom Registration/Profile Fields configured with s2Member and many other plugins.
2291 *
2292 * ———— Here Are A Few Examples ————
2293 * ```
2294 * <!php
2295 * $user_login = get_user_field ("user_login"); # Username for the current User.
2296 * $user_email = get_user_field ("user_email"); # Email Address for the current User.
2297 * $first_name = get_user_field ("first_name"); # First Name for the current User.
2298 * $last_name = get_user_field ("last_name"); # Last Name for the current User.
2299 * $full_name = get_user_field ("full_name"); # First and Last Name for the current User.
2300 * $display_name = get_user_field ("display_name"); # Display Name for the current User.
2301 * !>
2302 * ```
2303 * ———— Shortcode Equivalents ————
2304 * ```
2305 * [s2Get user_field="user_login" /] # Username for the current User.
2306 * [s2Get user_field="user_email" /] # Email Address for the current User.
2307 * [s2Get user_field="first_name" /] # First Name for the current User.
2308 * [s2Get user_field="last_name" /] # Last Name for the current User.
2309 * [s2Get user_field="full_name" /] # First and Last Name for the current User.
2310 * [s2Get user_field="display_name" /] # Display Name for the current User.
2311 * ```
2312 * ———— More Examples With s2Member Fields ————
2313 * ```
2314 * <!php
2315 * $s2member_custom = get_user_field ("s2member_custom"); # Custom String value for the current User.
2316 * $s2member_subscr_id = get_user_field ("s2member_subscr_id"); # Paid Subscr. ID for the current User.
2317 * $s2member_subscr_or_wp_id = get_user_field ("s2member_subscr_or_wp_id"); # Paid Subscr. ID, else WordPress User ID.
2318 * $s2member_subscr_gateway = get_user_field ("s2member_subscr_gateway"); # Paid Subscr. Gateway Code for the current User.
2319 * $s2member_registration_ip = get_user_field ("s2member_registration_ip"); # IP the current User had during registration.
2320 * $s2member_custom_fields = get_user_field ("s2member_custom_fields"); # Associative array of all Custom Registration/Profile Fields.
2321 * $s2member_file_download_access_log = get_user_field ("s2member_file_download_access_log"); # Associative array of all File Downloads by the current User, in the current Period *(Period is based on a specific User's `allowed_days`, configured in your Basic Download Restrictions, at the User's current Membership Level)*.
2322 * $s2member_file_download_access_arc = get_user_field ("s2member_file_download_access_arc"); # Associative array of all File Downloads by the current User, in previous Periods *(Periods are based on a specific User's `allowed_days`, configured in your Basic Download Restrictions, at the User's Membership Levels in the past)*.
2323 * $s2member_auto_eot_time = get_user_field ("s2member_auto_eot_time"); # Auto EOT-Time for the current User (when applicable).
2324 * $s2member_last_payment_time = get_user_field ("s2member_last_payment_time"); # Timestamp. Last time an actual payment was received by s2Member.
2325 * $s2member_paid_registration_times = get_user_field ("s2member_paid_registration_times"); # Timestamps. Associative array of all Paid Registration Times.
2326 * $s2member_access_role = get_user_field ("s2member_access_role"); # A WordPress Role ID (i.e., s2member_level[0-9]+, administrator, editor, author, contributor, subscriber).
2327 * $s2member_access_level = get_user_field ("s2member_access_level"); # An s2Member Membership Access Level number.
2328 * $s2member_access_label = get_user_field ("s2member_access_label"); # An s2Member Membership Access Label (i.e., Bronze, Gold, Silver, Platinum, or whatever is configured).
2329 * $s2member_access_ccaps = get_user_field ("s2member_access_ccaps"); # An array of Custom Capabilities the current User has (i.e., music,videos).
2330 * $s2member_login_counter = get_user_field ("s2member_login_counter"); # Number of times the User has logged into your site.
2331 * !>
2332 * ```
2333 * ———— Practical Shortcode Equivalents ————
2334 * ```
2335 * [s2Get user_field="s2member_custom" /] # Custom String value for the current User.
2336 * [s2Get user_field="s2member_subscr_id" /] # Paid Subscr. ID for the current User.
2337 * [s2Get user_field="s2member_subscr_or_wp_id" /] # Paid Subscr. ID, else WordPress User ID.
2338 * [s2Get user_field="s2member_subscr_gateway" /] # Paid Subscr. Gateway Code for the current User.
2339 * [s2Get user_field="s2member_registration_ip" /] # IP Address the current User had during registration.
2340 * [s2Get user_field="s2member_access_role" /] # A WordPress Role ID (i.e., s2member_level[0-9]+, administrator, editor, author, contributor, subscriber).
2341 * [s2Get user_field="s2member_access_level" /] # An s2Member Membership Access Level number.
2342 * [s2Get user_field="s2member_access_label" /] # An s2Member Membership Access Label (i.e., Bronze, Gold, Silver, Platinum, or whatever is configured).
2343 * [s2Get user_field="s2member_login_counter" /] # Number of times the User has logged into your site.
2344 * ```
2345 * ———— Pulling Data From Your Own Custom Fields ————
2346 * ```
2347 * <!php
2348 * $my_field_data = get_user_field ("my_field_id"); # The Unique Field ID you configured with s2Member.
2349 * !>
2350 * ```
2351 * ———— Shortcode Equivalent ————
2352 * ```
2353 * [s2Get user_field="my_field_id" /] # The Unique Field ID you configured with s2Member.
2354 * ```
2355 * ———— Pulling Data For A Particular User ID ————
2356 * ```
2357 * <!php
2358 * $user_login = get_user_field ("user_login", 123); # Username for the User with ID #123.
2359 * $user_email = get_user_field ("user_email", 123); # Email Address for the User with ID #123.
2360 * $first_name = get_user_field ("first_name", 123); # First Name for the User with ID #123.
2361 * $last_name = get_user_field ("last_name", 123); # Last Name for the User with ID #123.
2362 * $full_name = get_user_field ("full_name", 123); # First and Last Name for the User with ID #123.
2363 * $display_name = get_user_field ("display_name", 123); # Display Name for the User with ID #123.
2364 * !>
2365 * ```
2366 * ———— Shortcode Equivalents ————
2367 * ```
2368 * [s2Get user_field="user_login" user_id="123" /] # Username for the User with ID #123.
2369 * [s2Get user_field="user_email" user_id="123" /] # Email Address for the User with ID #123.
2370 * [s2Get user_field="first_name" user_id="123" /] # First Name for the User with ID #123.
2371 * [s2Get user_field="last_name" user_id="123" /] # Last Name for the User with ID #123.
2372 * [s2Get user_field="full_name" user_id="123" /] # First and Last Name for the User with ID #123.
2373 * [s2Get user_field="display_name" user_id="123" /] # Display Name for the User with ID #123.
2374 * ```
2375 * ———— Finding A User ID, Based On Username ————
2376 * ```
2377 * <!php
2378 * $user = new WP_User("johndoe22");
2379 * $user_id = $user->ID;
2380 * !>
2381 * ```
2382 * ———— Finding A Username, Based On User ID ————
2383 * ```
2384 * <!php
2385 * $user = new WP_User(123);
2386 * $user_login = $user->user_login;
2387 * # Or you could just use this alternate method.
2388 * $user_login = get_user_field ("user_login", 123);
2389 * !>
2390 * ```
2391 *
2392 * ———— Alternative Using ``get_user_option()`` Native To WordPress ————
2393 * Most of the s2Member fields are stored in the `usermeta` table (a WordPress standard),
2394 * so they could also be retrieved with {@link http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()} if you prefer,
2395 * 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*.
2396 * ```
2397 * <!php
2398 * $s2member_custom = get_user_option ("s2member_custom"); # Custom String value for the current User.
2399 * $s2member_subscr_id = get_user_option ("s2member_subscr_id"); # Paid Subscr. ID for the current User.
2400 * $s2member_subscr_gateway = get_user_option ("s2member_subscr_gateway"); # Paid Subscr. Gateway Code for the current User.
2401 * $s2member_registration_ip = get_user_option ("s2member_registration_ip"); # IP the current User had during registration.
2402 * $s2member_custom_fields = get_user_option ("s2member_custom_fields"); # Associative array of all Custom Registration/Profile Fields.
2403 * $s2member_file_download_access_log = get_user_option ("s2member_file_download_access_log"); # Associative array of all File Downloads by the current User, in the current Period *(Period is based on a specific User's `allowed_days`, configured in your Basic Download Restrictions, at the User's current Membership Level)*.
2404 * $s2member_file_download_access_arc = get_user_option ("s2member_file_download_access_arc"); # Associative array of all File Downloads by the current User, in previous Periods *(Periods are based on a specific User's `allowed_days`, configured in your Basic Download Restrictions, at the User's Membership Levels in the past)*.
2405 * $s2member_auto_eot_time = get_user_option ("s2member_auto_eot_time"); # Auto EOT-Time for the current User (when applicable).
2406 * $s2member_last_payment_time = get_user_option ("s2member_last_payment_time"); # Timestamp. Last time an actual payment was received by s2Member.
2407 * $s2member_paid_registration_times = get_user_option ("s2member_paid_registration_times"); # Timestamps. Associative array of all Paid Registration Times.
2408 * $s2member_login_counter = get_user_option ("s2member_login_counter"); # Number of times the User has logged into your site.
2409 * !>
2410 * ```
2411 * ———— Practical Shortcode Equivalents ————
2412 * ```
2413 * [s2Get user_option="s2member_custom" /] # Custom String value for the current User.
2414 * [s2Get user_option="s2member_subscr_id" /] # Paid Subscr. ID for the current User.
2415 * [s2Get user_option="s2member_subscr_gateway" /] # Paid Subscr. Gateway Code for the current User.
2416 * [s2Get user_option="s2member_registration_ip" /] # IP the current User had during registration.
2417 * [s2Get user_option="s2member_login_counter" /] # Number of times the User has logged in.
2418 * ```
2419 *
2420 * @package s2Member\API_Functions
2421 * @since 3.5
2422 *
2423 * @param string $field_id Required. A unique Custom Registration/Profile Field ID, that you configured with s2Member.
2424 * Or, this could be set to any property that exists on the WP_User object for a particular User;
2425 * ( i.e., `id`, `ID`, `user_login`, `user_email`, `first_name`, `last_name`, `display_name`, `ip`, `IP`,
2426 * `s2member_registration_ip`, `s2member_custom`, `s2member_subscr_id`, `s2member_subscr_or_wp_id`,
2427 * `s2member_subscr_gateway`, `s2member_custom_fields`, `s2member_file_download_access_[log|arc]`,
2428 * `s2member_auto_eot_time`, `s2member_last_payment_time`, `s2member_paid_registration_times`,
2429 * `s2member_access_role`, `s2member_access_level`, `s2member_access_label`,
2430 * `s2member_access_ccaps`, `s2member_login_counter`, etc, etc. ).
2431 * @param int $user_id Optional. Defaults to the current User's ID.
2432 * @return mixed The value of the requested field, or false if the field does not exist.
2433 *
2434 * @see s2Member\API_Functions\get_s2member_custom_fields()
2435 * @see s2Member\API_Functions\s2member_registration_time()
2436 * @see s2Member\API_Functions\s2member_paid_registration_time()
2437 *
2438 * @see http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()
2439 * @see http://codex.wordpress.org/Function_Reference/update_user_option update_user_option()
2440 * @see http://codex.wordpress.org/Function_Reference/wp_get_current_user wp_get_current_user()
2441 */
2442 if(!function_exists("get_user_field"))
2443 {
2444 function get_user_field($field_id = FALSE, $user_id = FALSE, $args = array())
2445 {
2446 return c_ws_plugin__s2member_utils_users::get_user_field($field_id, $user_id, $args);
2447 }
2448 }
2449 /**
2450 * Custom Registration/Profile Field configuration.
2451 *
2452 * Provides information about the configuration of each Custom Registration/Profile Field.
2453 * Returns an associative array with all Custom Field configurations *(and User values too, if ``$user_id`` is passed in)*.
2454 *
2455 * ———— PHP Code Sample ————
2456 * ```
2457 * <!php
2458 * $fields = get_s2member_custom_fields();
2459 * print_r($fields["my_field_id"]["config"]); # The Unique Field ID you configured with s2Member.
2460 * !>
2461 * ```
2462 * ———— PHP Code Sample (Specific User) ————
2463 * ```
2464 * <!php
2465 * $fields = get_s2member_custom_fields(123);
2466 * echo $fields["my_field_id"]["user_value"]; # The Unique Field ID you configured with s2Member.
2467 * print_r($fields["my_field_id"]["config"]); # The Unique Field ID you configured with s2Member.
2468 * !>
2469 * ```
2470 * ———— Shortcode Alternative (Specific User) ————
2471 * ```
2472 * [s2Get user_field="my_field_id" /] # The Unique Field ID you configured with s2Member.
2473 * ```
2474 *
2475 * @package s2Member\API_Functions
2476 * @since 110912
2477 *
2478 * @param int|string $user_id Optional. If supplied, the `user_value` for each Custom Field will be included too.
2479 * @return array An associative array with all Custom Field configurations *(and User values too, if ``$user_id`` is supplied)*.
2480 *
2481 * @see s2Member\API_Functions\get_user_field()
2482 * @see s2Member\API_Functions\s2member_registration_time()
2483 * @see s2Member\API_Functions\s2member_paid_registration_time()
2484 *
2485 * @see http://codex.wordpress.org/Function_Reference/get_user_option get_user_option()
2486 * @see http://codex.wordpress.org/Function_Reference/update_user_option update_user_option()
2487 * @see http://codex.wordpress.org/Function_Reference/wp_get_current_user wp_get_current_user()
2488 */
2489 if(!function_exists("get_s2member_custom_fields"))
2490 {
2491 function get_s2member_custom_fields($user_id = FALSE)
2492 {
2493 $fields = ($user_id) ? get_user_option("s2member_custom_fields", $user_id) : false;
2494
2495 if(!$custom_fields = json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true)) return array();
2496
2497 foreach($custom_fields as $field)
2498 {
2499 if /* Should we try to fill the User's value for this Custom Field? */($user_id)
2500 $s2member_custom_fields[$field["id"]]["user_value"] = (isset($fields[$field["id"]])) ? $fields[$field["id"]] : false;
2501 $s2member_custom_fields[$field["id"]]["config"] = /* Copy configuration into config element. */ $field;
2502 }
2503 return (isset($s2member_custom_fields)) ? (array)$s2member_custom_fields : array();
2504 }
2505 }
2506 /**
2507 * Can be used to auto-fill the `invoice` for PayPal Button Codes, with a unique Code~IP combination.
2508 *
2509 * ———— PHP Code Sample ————
2510 * ```
2511 * <!php echo s2member_value_for_pp_inv(); !>
2512 * ```
2513 * ———— Shortcode & JavaScript Equivalents ————
2514 * ```
2515 * [s2Get constant="S2MEMBER_VALUE_FOR_PP_INV" /]
2516 *
2517 * <script type="text/javascript">
2518 * document.write(s2member_value_for_pp_inv_gen());
2519 * </script>
2520 * ```
2521 *
2522 * @package s2Member\API_Functions
2523 * @since 110720
2524 *
2525 * @return string A unique Invoice.
2526 *
2527 * @see s2Member\API_Constants\S2MEMBER_VALUE_FOR_PP_INV
2528 *
2529 * @todo Create a true Shortcode equivalent function.
2530 */
2531 if(!function_exists("s2member_value_for_pp_inv"))
2532 {
2533 function s2member_value_for_pp_inv()
2534 {
2535 return uniqid()."~".c_ws_plugin__s2member_utils_ip::current();
2536 }
2537 }
2538 /**
2539 * Shortens a long URL, based on s2Member configuration.
2540 *
2541 * ———— PHP Code Samples ————
2542 * ```
2543 * <!php echo s2member_shorten_url("https://www.example.com/?s2member_register=..."); !>
2544 * <!php echo s2member_shorten_url("https://www.example.com/a-long-url/", "bitly"); !>
2545 * ```
2546 * ———— Shortcode Equivalent ————
2547 * ```
2548 * There is NO Shortcode equivalent for this (yet).
2549 * ```
2550 *
2551 * @package s2Member\API_Functions
2552 * @since 111004
2553 *
2554 * @param string $url A full/long URL to be shortened. Built-in s2Member shortening supports `s2member_register` and `s2member_sp_access` URLs only.
2555 * @param string $api_sp Optional. A specific URL shortening API to use. Defaults to that which is configured in the s2Member Dashboard. Normally `s2member` by default.
2556 * @param bool $try_backups Defaults to true. If a failure occurs with the first API, we'll try others until we have success.
2557 * @param int $expiration Optional. Transient expiration, in seconds, for built-in s2Member short links.
2558 * @return str|bool The shortened URL on success, else false on failure.
2559 *
2560 * @todo Create a Shortcode equivalent for this function.
2561 */
2562 if(!function_exists("s2member_shorten_url"))
2563 {
2564 function s2member_shorten_url($url = FALSE, $api_sp = FALSE, $try_backups = TRUE, $expiration = 0)
2565 {
2566 return c_ws_plugin__s2member_utils_urls::shorten($url, $api_sp, $try_backups, $expiration);
2567 }
2568 }
2569 /**
2570 * Two-way RIJNDAEL 256 encryption/decryption, with a URL-safe base64 wrapper.
2571 *
2572 * Falls back on XOR encryption/decryption when/if mcrypt is not available.
2573 *
2574 * ———— PHP Code Samples ————
2575 * ```
2576 * <!php $encrypted = s2member_encrypt("hello"); !>
2577 * <!php $decrypted = s2member_decrypt($encrypted); !>
2578 * ```
2579 * ———— Shortcode Equivalent ————
2580 * ```
2581 * There is NO Shortcode equivalent for this (yet).
2582 * ```
2583 *
2584 * @package s2Member\API_Functions
2585 * @since 111106
2586 *
2587 * @param string $string A string of data to encrypt.
2588 * @param string $key Optional. Key used for encryption. Defaults to the one configured for s2Member. Short of that, defaults to: ``wp_salt()``.
2589 * @param bool $w_md5_cs Optional. Defaults to true. When true, an MD5 checksum is used in the encrypted string *(recommended)*.
2590 * @return string Encrypted string.
2591 *
2592 * @see s2Member\API_Functions\s2member_decrypt()
2593 * @see s2Member\API_Functions\s2member_xencrypt()
2594 * @see s2Member\API_Functions\s2member_xdecrypt()
2595 *
2596 * @todo Create a Shortcode equivalent for this function.
2597 */
2598 if(!function_exists("s2member_encrypt"))
2599 {
2600 function s2member_encrypt($string = FALSE, $key = FALSE, $w_md5_cs = TRUE)
2601 {
2602 return c_ws_plugin__s2member_utils_encryption::encrypt($string, $key, $w_md5_cs);
2603 }
2604 }
2605 /**
2606 * Two-way RIJNDAEL 256 encryption/decryption, with a URL-safe base64 wrapper.
2607 *
2608 * Falls back on XOR encryption/decryption when/if mcrypt is not available.
2609 *
2610 * ———— PHP Code Samples ————
2611 * ```
2612 * <!php $encrypted = s2member_encrypt("hello"); !>
2613 * <!php $decrypted = s2member_decrypt($encrypted); !>
2614 * ```
2615 * ———— Shortcode Equivalent ————
2616 * ```
2617 * There is NO Shortcode equivalent for this (yet).
2618 * ```
2619 *
2620 * @package s2Member\API_Functions
2621 * @since 111106
2622 *
2623 * @param string $base64 A string of data to decrypt. Should still be base64 encoded.
2624 * @param string $key Optional. Key used originally for encryption. Defaults to the one configured for s2Member. Short of that, defaults to: ``wp_salt()``.
2625 * @return string Decrypted string.
2626 *
2627 * @see s2Member\API_Functions\s2member_encrypt()
2628 * @see s2Member\API_Functions\s2member_xencrypt()
2629 * @see s2Member\API_Functions\s2member_xdecrypt()
2630 *
2631 * @todo Create a Shortcode equivalent for this function.
2632 */
2633 if(!function_exists("s2member_decrypt"))
2634 {
2635 function s2member_decrypt($base64 = FALSE, $key = FALSE)
2636 {
2637 return c_ws_plugin__s2member_utils_encryption::decrypt($base64, $key);
2638 }
2639 }
2640 /**
2641 * Two-way XOR encryption/decryption, with a URL-safe base64 wrapper.
2642 *
2643 * ———— PHP Code Samples ————
2644 * ```
2645 * <!php $encrypted = s2member_xencrypt("hello"); !>
2646 * <!php $decrypted = s2member_xdecrypt($encrypted); !>
2647 * ```
2648 * ———— Shortcode Equivalent ————
2649 * ```
2650 * There is NO Shortcode equivalent for this (yet).
2651 * ```
2652 *
2653 * @package s2Member\API_Functions
2654 * @since 111106
2655 *
2656 * @param string $string A string of data to encrypt.
2657 * @param string $key Optional. Key used for encryption. Defaults to the one configured for s2Member. Short of that, defaults to: ``wp_salt()``.
2658 * @param bool $w_md5_cs Optional. Defaults to true. When true, an MD5 checksum is used in the encrypted string *(recommended)*.
2659 * @return string Encrypted string.
2660 *
2661 * @see s2Member\API_Functions\s2member_xdecrypt()
2662 * @see s2Member\API_Functions\s2member_encrypt()
2663 * @see s2Member\API_Functions\s2member_decrypt()
2664 *
2665 * @todo Create a Shortcode equivalent for this function.
2666 */
2667 if(!function_exists("s2member_xencrypt"))
2668 {
2669 function s2member_xencrypt($string = FALSE, $key = FALSE, $w_md5_cs = TRUE)
2670 {
2671 return c_ws_plugin__s2member_utils_encryption::xencrypt($string, $key, $w_md5_cs);
2672 }
2673 }
2674 /**
2675 * Two-way XOR encryption/decryption, with a URL-safe base64 wrapper.
2676 *
2677 * ———— PHP Code Samples ————
2678 * ```
2679 * <!php $encrypted = s2member_xencrypt("hello"); !>
2680 * <!php $decrypted = s2member_xdecrypt($encrypted); !>
2681 * ```
2682 * ———— Shortcode Equivalent ————
2683 * ```
2684 * There is NO Shortcode equivalent for this (yet).
2685 * ```
2686 *
2687 * @package s2Member\API_Functions
2688 * @since 111106
2689 *
2690 * @param string $base64 A string of data to decrypt. Should still be base64 encoded.
2691 * @param string $key Optional. Key used originally for encryption. Defaults to the one configured for s2Member. Short of that, defaults to: ``wp_salt()``.
2692 * @return string Decrypted string.
2693 *
2694 * @see s2Member\API_Functions\s2member_xencrypt()
2695 * @see s2Member\API_Functions\s2member_encrypt()
2696 * @see s2Member\API_Functions\s2member_decrypt()
2697 *
2698 * @todo Create a Shortcode equivalent for this function.
2699 */
2700 if(!function_exists("s2member_xdecrypt"))
2701 {
2702 function s2member_xdecrypt($base64 = FALSE, $key = FALSE)
2703 {
2704 return c_ws_plugin__s2member_utils_encryption::xdecrypt($base64, $key);
2705 }
2706 }
2707 /**
2708 * Gets login IPs for a particular username.
2709 *
2710 * ———— PHP Code Samples ————
2711 * ```
2712 * <!php print_r($ips = s2member_login_ips_for("johndoe22")); !>
2713 * ```
2714 * ———— Shortcode Equivalent ————
2715 * ```
2716 * There is NO Shortcode equivalent for this (yet).
2717 * ```
2718 *
2719 * @package s2Member\API_Functions
2720 * @since 120728
2721 *
2722 * @param string $username A username.
2723 * @return array An associative array of all IPs associated with a particular username, over the last 30 days.
2724 * Array keys are IP addresses; array values are UTC timestamps.
2725 *
2726 * @todo Create a Shortcode equivalent for this function.
2727 */
2728 if(!function_exists("s2member_login_ips_for"))
2729 {
2730 function s2member_login_ips_for($username)
2731 {
2732 $ips = get_transient('s2m_ipr_'.md5('s2member_ip_restrictions_'.strtolower($username).'_entries'));
2733 return (is_array($ips)) ? $ips : array();
2734 }
2735 }
2736
2737 /**
2738 * Auto EOT time, else NPR (next payment time).
2739 *
2740 * ———— PHP Code Samples ————
2741 * ```
2742 * <!php print_r($eot = s2member_eot()); !>
2743 * ```
2744 * ———— Shortcode Equivalent ————
2745 * ```
2746 * [s2Eot /]
2747 * ```
2748 *
2749 * @package s2Member\API_Functions
2750 * @since 150713
2751 *
2752 * @param string|int $user_id Defaults to the current user ID.
2753 * @param bool $check_gateway Defaults to a true value. If this is false, it is only possible to return a fixed EOT time.
2754 * In other words, if this is false and there is no EOT time, empty values will be returned. Be careful with this, because not checking
2755 * the payment gateway can result in an inaccurate return value. Only set to false if you want to limit the check to a fixed hard-coded EOT time.
2756 * @param string $favor Defaults to a value of `fixed`; i.e., if a fixed EOT time is available, that is returned in favor of a next payment time.
2757 * You can set this to `next` if you'd like to favor a next payment time (when applicable) instead of returning a fixed EOT time.
2758 *
2759 * @return array An associative array of EOT details; with the following elements.
2760 *
2761 * - `type` One of `fixed` (a fixed EOT time), `next` (next payment time; i.e., ongoing recurring subscription), or an empty string if there is no EOT for the user.
2762 * - `time` The timestamp (UTC time) that represents the EOT (End Of Term); else `0` if there is no EOT time.
2763 * - `tense` One of `past`, `future`, or an empty string if there is no EOT time. If time is now (or earlier) this will be `past`. If time is in the future, this will be `future`.
2764 * - `debug` A string of details that explain to a developer what was returned. For debugging only.
2765 */
2766 if(!function_exists('s2member_eot'))
2767 {
2768 function s2member_eot($user_id = 0, $check_gateway = true, $favor = 'fixed')
2769 {
2770 return c_ws_plugin__s2member_utils_users::get_user_eot($user_id, $check_gateway, $favor);
2771 }
2772 }
2773
2774 /**
2775 * Conditional to determine if the current User has a specific gateway set in his profile.
2776 *
2777 * ———— PHP Code Sample ————
2778 * ```
2779 * <!php
2780 * if(current_user_gateway_is("stripe"))
2781 * echo "Current user's payment gateway is set to Stripe (e.g. last paid through s2's Stripe pro-form)";
2782 * !>
2783 * ```
2784 *
2785 * ———— Shortcode Conditional Equivalent ————
2786 * ```
2787 * [s2If current_user_gateway_is(stripe)]
2788 * Current user's payment gateway is set to Stripe (e.g. last paid through s2's Stripe pro-form)
2789 * [/s2If]
2790 * ```
2791 *
2792 * @package s2Member\API_Functions
2793 * @since 220316
2794 *
2795 * @param string $gateway A gateway ID *( e.g. `stripe`, `paypal`, `authnet`, `clickbank` )*.
2796 * @return bool True if the specific User has the specified gateway, else false.
2797 */
2798 if (!function_exists("current_user_gateway_is")) {
2799 function current_user_gateway_is($gateway) {
2800 return ($gateway === S2MEMBER_CURRENT_USER_SUBSCR_GATEWAY);
2801 }
2802 }
2803
2804 /**
2805 * Conditional to determine if the current User's EOT is closer than a number of days.
2806 *
2807 * ———— PHP Code Sample ————
2808 * ```
2809 * <!php
2810 * if(current_user_days_to_eot_less_than(31))
2811 * echo "Renew your membership";
2812 * !>
2813 * ```
2814 *
2815 * ———— Shortcode Conditional Equivalent ————
2816 * ```
2817 * [s2If current_user_days_to_eot_less_than(31)]
2818 * Renew your membership.
2819 * [/s2If]
2820 * ```
2821 *
2822 * @package s2Member\API_Functions
2823 * @since 220707
2824 *
2825 * @param int $less_than Days from today, to check if the user's EOT time falls within that number of coming days.
2826 * @return bool True if the current User's EOT is closer than $less_than, else false.
2827 */
2828 if (!function_exists('current_user_days_to_eot_less_than')) {
2829 function current_user_days_to_eot_less_than($less_than) {
2830 $eot_time = get_user_field('s2member_auto_eot_time');
2831 if (empty($eot_time)) {
2832 return false;
2833 }
2834 $now = time();
2835 $time_diff = ((int) $eot_time - $now);
2836 $days_left = round($time_diff / (60 * 60 * 24));
2837 $less_than = (int) $less_than;
2838 return ($days_left < $less_than);
2839 }
2840 }