PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/functions/api-functions.inc.php

https://gitlab.com/Gashler/dp
PHP | 1102 lines | 137 code | 24 blank | 941 comment | 71 complexity | 1ef5731d54452dbc4c9091ecca69ad7a MD5 | raw file
  1. <?php
  2. /**
  3. * Core API Functions *(for site owners)*.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\API_Functions
  15. * @since 3.5
  16. */
  17. if(realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19. /**
  20. * Conditional to determine if the current User is NOT logged in.
  21. *
  22. * Counterpart {@link http://codex.wordpress.org/Function_Reference/is_user_logged_in is_user_logged_in()} already exists in the WordPress® core.
  23. *
  24. * ———— Code Sample Using Both Functions ————
  25. * ```
  26. * <!php
  27. * if(is_user_logged_in())
  28. * echo 'You ARE logged in.';
  29. *
  30. * else if(is_user_not_logged_in())
  31. * echo 'You are NOT logged in.';
  32. * !>
  33. * ```
  34. * ———— Shortcode Conditional Equivalent ————
  35. * ```
  36. * [s2If is_user_logged_in()]
  37. * You ARE logged in.
  38. * [/s2If]
  39. * [s2If is_user_not_logged_in()]
  40. * You are NOT logged in.
  41. * [/s2If]
  42. * ```
  43. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  44. *
  45. * @package s2Member\API_Functions
  46. * @since 3.5
  47. *
  48. * @return bool True if the current User is NOT logged in, else false.
  49. *
  50. * @see http://codex.wordpress.org/Function_Reference/is_user_logged_in is_user_logged_in()
  51. */
  52. if(!function_exists("is_user_not_logged_in"))
  53. {
  54. function is_user_not_logged_in()
  55. {
  56. return (!is_user_logged_in());
  57. }
  58. }
  59. /**
  60. * Conditional to determine if a specific User is/has a specific Role.
  61. *
  62. * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress® core.
  63. *
  64. * ———— Code Sample Using Both Functions ————
  65. * ```
  66. * <!php
  67. * if(user_is(123, "subscriber"))
  68. * echo 'User ID# 123 is a Free Subscriber at Level #0.';
  69. *
  70. * else if(user_is(123, "s2member_level1"))
  71. * echo 'User ID# 123 is a Member at Level #1.';
  72. *
  73. * else if(user_can(123, "access_s2member_level2"))
  74. * echo 'User ID# 123 has access to content protected at Level #2.';
  75. * # But, (important) they could actually be a Level #3 or #4 Member;
  76. * # because Membership Levels provide incremental access.
  77. * !>
  78. * ```
  79. *
  80. * ———— Shortcode Conditional Equivalent ————
  81. * ```
  82. * [s2If user_is(123, subscriber)]
  83. * User ID# 123 is a Free Subscriber at Level #0.
  84. * [/s2If]
  85. * [s2If user_is(123, s2member_level1)]
  86. * User ID# 123 is a Member at Level #1.
  87. * [/s2If]
  88. * [s2If user_can(123, access_s2member_level2)]
  89. * User ID# 123 has access to content protected at Level #2.
  90. * [/s2If]
  91. * ```
  92. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  93. *
  94. * ———— Membership Levels Provide Incremental Access ————
  95. *
  96. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  97. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  98. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  99. * o A Member with Level 1 access, will also be able to access Level 0.
  100. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  101. * o A public Visitor will have NO access to protected content.
  102. *
  103. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  104. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  105. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  106. *
  107. * @package s2Member\API_Functions
  108. * @since 110524RC
  109. *
  110. * @param int|str $id A numeric WordPress® User ID.
  111. * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  112. * @return bool True if the specific User is/has the specified Role, else false.
  113. *
  114. * @see s2Member\API_Functions\user_is()
  115. * @see s2Member\API_Functions\user_is_not()
  116. *
  117. * @see s2Member\API_Functions\current_user_is()
  118. * @see s2Member\API_Functions\current_user_is_not()
  119. * @see s2Member\API_Functions\current_user_is_for_blog()
  120. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  121. *
  122. * @see s2Member\API_Functions\user_cannot()
  123. * @see s2Member\API_Functions\current_user_cannot()
  124. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  125. *
  126. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  127. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  128. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  129. */
  130. if(!function_exists("user_is"))
  131. {
  132. function user_is($id = FALSE, $role = FALSE)
  133. {
  134. $role = ($role === "s2member_level0") ? "subscriber" : preg_replace("/^access_/i", "", $role);
  135. if(($role === "super_administrator" || $role === "administrator") && is_multisite() && is_super_admin($id))
  136. return /* Return true, Super Admins are always considered an Admnistrator, for all Blogs. */ true;
  137. else if /* Else return false for Super Admins here. */(is_multisite() && is_super_admin($id))
  138. return /* Super Admins can access all Capabilities, so the default handling would fail. */ false;
  139. return user_can($id, $role);
  140. }
  141. }
  142. /**
  143. * Conditional to determine if a specific User is/does NOT have a specific Role.
  144. *
  145. * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress® core.
  146. *
  147. * ———— Code Sample Using Three Functions ————
  148. * ```
  149. * <!php
  150. * if(user_is(123, "subscriber"))
  151. * echo 'User ID# 123 is a Free Subscriber at Level #0.';
  152. *
  153. * else if(user_is(123, "s2member_level1"))
  154. * echo 'User ID# 123 is a Member at Level #1.';
  155. *
  156. * else if(user_can(123, "access_s2member_level2") && user_is_not(123, "s2member_level2"))
  157. * echo 'User ID# 123 has access to content protected at Level #2, but they are NOT a Level #2 Member.';
  158. * # So, (important) they could actually be a Level #3 or #4 Member;
  159. * # because Membership Levels provide incremental access.
  160. * !>
  161. * ```
  162. * ———— Shortcode Conditional Equivalent ————
  163. * ```
  164. * [s2If user_is(123, subscriber)]
  165. * User ID# 123 is a Free Subscriber at Level #0.
  166. * [/s2If]
  167. * [s2If user_is(123, s2member_level1)]
  168. * User ID# 123 is a Member at Level #1.
  169. * [/s2If]
  170. * [s2If user_can(123, access_s2member_level2) AND user_is_not(123, s2member_level2)]
  171. * User ID# 123 has access to content protected at Level #2, but they are NOT a Level #2 Member.
  172. * [/s2If]
  173. * ```
  174. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  175. *
  176. * ———— Membership Levels Provide Incremental Access ————
  177. *
  178. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  179. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  180. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  181. * o A Member with Level 1 access, will also be able to access Level 0.
  182. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  183. * o A public Visitor will have NO access to protected content.
  184. *
  185. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  186. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  187. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  188. *
  189. * @package s2Member\API_Functions
  190. * @since 110524RC
  191. *
  192. * @param int|str $id A numeric WordPress® User ID.
  193. * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  194. * @return bool True if the specific User is/does NOT have the specified Role, else false.
  195. *
  196. * @see s2Member\API_Functions\user_is()
  197. * @see s2Member\API_Functions\user_is_not()
  198. *
  199. * @see s2Member\API_Functions\current_user_is()
  200. * @see s2Member\API_Functions\current_user_is_not()
  201. * @see s2Member\API_Functions\current_user_is_for_blog()
  202. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  203. *
  204. * @see s2Member\API_Functions\user_cannot()
  205. * @see s2Member\API_Functions\current_user_cannot()
  206. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  207. *
  208. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  209. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  210. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  211. */
  212. if(!function_exists("user_is_not"))
  213. {
  214. function user_is_not($id = FALSE, $role = FALSE)
  215. {
  216. return (!user_is($id, $role));
  217. }
  218. }
  219. /**
  220. * Conditional to determine if the current User is/has a specific Role.
  221. *
  222. * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress® core.
  223. *
  224. * ———— Code Sample Using Both Functions ————
  225. * ```
  226. * <!php
  227. * if(current_user_is("subscriber"))
  228. * echo 'You ARE a Free Subscriber at Level #0.';
  229. *
  230. * else if(current_user_is("s2member_level1"))
  231. * echo 'You ARE a Member at Level #1.';
  232. *
  233. * else if(current_user_can("access_s2member_level2"))
  234. * echo 'You DO have access to content protected at Level #2.';
  235. * # But, (important) they could actually be a Level #3 or #4 Member;
  236. * # because Membership Levels provide incremental access.
  237. * !>
  238. * ```
  239. *
  240. * ———— Shortcode Conditional Equivalent ————
  241. * ```
  242. * [s2If current_user_is(subscriber)]
  243. * You ARE a Free Subscriber at Level #0.
  244. * [/s2If]
  245. * [s2If current_user_is(s2member_level1)]
  246. * You ARE a Member at Level #1.
  247. * [/s2If]
  248. * [s2If current_user_can(access_s2member_level2)]
  249. * You DO have access to content protected at Level #2.
  250. * [/s2If]
  251. * ```
  252. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  253. *
  254. * ———— Membership Levels Provide Incremental Access ————
  255. *
  256. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  257. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  258. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  259. * o A Member with Level 1 access, will also be able to access Level 0.
  260. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  261. * o A public Visitor will have NO access to protected content.
  262. *
  263. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  264. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  265. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  266. *
  267. * @package s2Member\API_Functions
  268. * @since 3.5
  269. *
  270. * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  271. * @return bool True if the current User is/has the specified Role, else false.
  272. *
  273. * @see s2Member\API_Functions\user_is()
  274. * @see s2Member\API_Functions\user_is_not()
  275. *
  276. * @see s2Member\API_Functions\current_user_is()
  277. * @see s2Member\API_Functions\current_user_is_not()
  278. * @see s2Member\API_Functions\current_user_is_for_blog()
  279. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  280. *
  281. * @see s2Member\API_Functions\user_cannot()
  282. * @see s2Member\API_Functions\current_user_cannot()
  283. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  284. *
  285. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  286. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  287. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  288. */
  289. if(!function_exists("current_user_is"))
  290. {
  291. function current_user_is($role = FALSE)
  292. {
  293. $role = ($role === "s2member_level0") ? "subscriber" : preg_replace("/^access_/i", "", $role);
  294. if(($role === "super_administrator" || $role === "administrator") && is_multisite() && is_super_admin())
  295. return /* Return true, Super Admins are always considered an Admnistrator, for all Blogs. */ true;
  296. else if /* Else return false for Super Admins here. */(is_multisite() && is_super_admin())
  297. return /* Super Admins can access all Capabilities, so the default handling would fail. */ false;
  298. return current_user_can($role);
  299. }
  300. }
  301. /**
  302. * Conditional to determine if the current User is/does NOT have a specific Role.
  303. *
  304. * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress® core.
  305. *
  306. * ———— Code Sample Using Three Functions ————
  307. * ```
  308. * <!php
  309. * if(current_user_is("subscriber"))
  310. * echo 'You ARE a Free Subscriber at Level #0.';
  311. *
  312. * else if(current_user_is("s2member_level1"))
  313. * echo 'You ARE a Member at Level #1.';
  314. *
  315. * else if(current_user_can("access_s2member_level2") && current_user_is_not("s2member_level2"))
  316. * echo 'You DO have access to content protected at Level #2, but you are NOT a Level #2 Member.';
  317. * # So, (important) they could actually be a Level #3 or #4 Member;
  318. * # because Membership Levels provide incremental access.
  319. * !>
  320. * ```
  321. * ———— Shortcode Conditional Equivalent ————
  322. * ```
  323. * [s2If current_user_is(subscriber)]
  324. * You ARE a Free Subscriber at Level #0.
  325. * [/s2If]
  326. * [s2If current_user_is(s2member_level1)]
  327. * You ARE a Member at Level #1.
  328. * [/s2If]
  329. * [s2If current_user_can(access_s2member_level2) AND current_user_is_not(s2member_level2)]
  330. * You DO have access to content protected at Level #2, but you are NOT a Level #2 Member.
  331. * [/s2If]
  332. * ```
  333. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  334. *
  335. * ———— Membership Levels Provide Incremental Access ————
  336. *
  337. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  338. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  339. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  340. * o A Member with Level 1 access, will also be able to access Level 0.
  341. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  342. * o A public Visitor will have NO access to protected content.
  343. *
  344. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  345. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  346. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  347. *
  348. * @package s2Member\API_Functions
  349. * @since 3.5
  350. *
  351. * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  352. * @return bool True if the current User is/does NOT have the specified Role, else false.
  353. *
  354. * @see s2Member\API_Functions\user_is()
  355. * @see s2Member\API_Functions\user_is_not()
  356. *
  357. * @see s2Member\API_Functions\current_user_is()
  358. * @see s2Member\API_Functions\current_user_is_not()
  359. * @see s2Member\API_Functions\current_user_is_for_blog()
  360. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  361. *
  362. * @see s2Member\API_Functions\user_cannot()
  363. * @see s2Member\API_Functions\current_user_cannot()
  364. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  365. *
  366. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  367. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  368. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  369. */
  370. if(!function_exists("current_user_is_not"))
  371. {
  372. function current_user_is_not($role = FALSE)
  373. {
  374. return (!current_user_is($role));
  375. }
  376. }
  377. /**
  378. * Conditional to determine if the current User is/has a specific Role, on a specific Blog within a Multisite Network.
  379. *
  380. * 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.
  381. *
  382. * ———— Code Sample Using Three Functions ————
  383. * ```
  384. * <!php
  385. * if(current_user_is("subscriber"))
  386. * echo 'You ARE a Free Subscriber at Level #0 (on this Blog).';
  387. *
  388. * else if(current_user_is_for_blog(5, "subscriber"))
  389. * echo 'You ARE a Free Subscriber at Level #0 (on Blog ID 5).';
  390. *
  391. * else if(current_user_is_for_blog(5, "s2member_level1"))
  392. * echo 'You ARE a Member at Level #1 (on Blog ID 5).';
  393. *
  394. * else if(current_user_can_for_blog(5, "access_s2member_level2"))
  395. * echo 'You DO have access to content protected at Level #2 (on Blog ID 5).';
  396. * # But, (important) they could actually be a Level #3 or #4 Member (on Blog ID 5);
  397. * # because Membership Levels provide incremental access.
  398. * !>
  399. * ```
  400. * ———— Shortcode Conditional Equivalent ————
  401. * ```
  402. * [s2If current_user_is(subscriber)]
  403. * You ARE a Free Subscriber at Level #0 (on this Blog).
  404. * [/s2If]
  405. * [s2If current_user_is_for_blog(5, subscriber)]
  406. * You ARE a Free Subscriber at Level #0 (on Blog ID 5).
  407. * [/s2If]
  408. * [s2If current_user_is_for_blog(5, s2member_level1)]
  409. * You ARE a Member at Level #1 (on Blog ID 5).
  410. * [/s2If]
  411. * [s2If current_user_can_for_blog(5, access_s2member_level2)]
  412. * You DO have access to content protected at Level #2 (on Blog ID 5).
  413. * [/s2If]
  414. * ```
  415. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  416. *
  417. * ———— Membership Levels Provide Incremental Access ————
  418. *
  419. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  420. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  421. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  422. * o A Member with Level 1 access, will also be able to access Level 0.
  423. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  424. * o A public Visitor will have NO access to protected content.
  425. *
  426. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  427. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  428. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  429. *
  430. * @package s2Member\API_Functions
  431. * @since 3.5
  432. *
  433. * @param int|str $blog_id A WordPress® Blog ID *(must be numeric)*.
  434. * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  435. * @return bool True if the current User is/has the specified Role, on the specified Blog, else false.
  436. *
  437. * @see s2Member\API_Functions\user_is()
  438. * @see s2Member\API_Functions\user_is_not()
  439. *
  440. * @see s2Member\API_Functions\current_user_is()
  441. * @see s2Member\API_Functions\current_user_is_not()
  442. * @see s2Member\API_Functions\current_user_is_for_blog()
  443. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  444. *
  445. * @see s2Member\API_Functions\user_cannot()
  446. * @see s2Member\API_Functions\current_user_cannot()
  447. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  448. *
  449. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  450. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  451. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  452. */
  453. if(!function_exists("current_user_is_for_blog"))
  454. {
  455. function current_user_is_for_blog($blog_id = FALSE, $role = FALSE)
  456. {
  457. $role = ($role === "s2member_level0") ? "subscriber" : preg_replace("/^access_/i", "", $role);
  458. if(($role === "super_administrator" || $role === "administrator") && is_multisite() && is_super_admin())
  459. return /* Return true, Super Admins are always considered an Admnistrator, for all Blogs. */ true;
  460. else if /* Else return false for Super Admins here. */(is_multisite() && is_super_admin())
  461. return /* Super Admins can access all Capabilities, so the default handling would fail. */ false;
  462. return current_user_can_for_blog($blog_id, $role);
  463. }
  464. }
  465. /**
  466. * Conditional to determine if the current User is/does NOT have a specific Role, on a specific Blog within a Multisite Network.
  467. *
  468. * 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.
  469. *
  470. * ———— Code Sample Using Three Functions ————
  471. * ```
  472. * <!php
  473. * if(current_user_is_for_blog(5, "subscriber"))
  474. * echo 'You ARE a Free Subscriber at Level #0 (on Blog ID 5).';
  475. *
  476. * else if(current_user_can_for_blog(5, "access_s2member_level1") && current_user_is_not_for_blog(5, "s2member_level1"))
  477. * 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).';
  478. * # So, (important) they could actually be a Level #2 or #3 or #4 Member (on Blog ID 5);
  479. * # because Membership Levels provide incremental access.
  480. * !>
  481. * ```
  482. * ———— Shortcode Conditional Equivalent ————
  483. * ```
  484. * [s2If current_user_is_for_blog(5, subscriber)]
  485. * You ARE a Free Subscriber at Level #0 (on Blog ID 5).
  486. * [/s2If]
  487. * [s2If current_user_can_for_blog(5, access_s2member_level1) AND current_user_is_not_for_blog(5, s2member_level1)]
  488. * 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).
  489. * [/s2If]
  490. * ```
  491. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  492. *
  493. * ———— Membership Levels Provide Incremental Access ————
  494. *
  495. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  496. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  497. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  498. * o A Member with Level 1 access, will also be able to access Level 0.
  499. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  500. * o A public Visitor will have NO access to protected content.
  501. *
  502. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  503. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  504. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  505. *
  506. * @package s2Member\API_Functions
  507. * @since 3.5
  508. *
  509. * @param int|str $blog_id A WordPress® Blog ID *(must be numeric)*.
  510. * @param str $role A WordPress® Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  511. * @return bool True if the current User is/does NOT have the specified Role, on the specified Blog, else false.
  512. *
  513. * @see s2Member\API_Functions\user_is()
  514. * @see s2Member\API_Functions\user_is_not()
  515. *
  516. * @see s2Member\API_Functions\current_user_is()
  517. * @see s2Member\API_Functions\current_user_is_not()
  518. * @see s2Member\API_Functions\current_user_is_for_blog()
  519. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  520. *
  521. * @see s2Member\API_Functions\user_cannot()
  522. * @see s2Member\API_Functions\current_user_cannot()
  523. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  524. *
  525. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  526. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  527. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  528. */
  529. if(!function_exists("current_user_is_not_for_blog"))
  530. {
  531. function current_user_is_not_for_blog($blog_id = FALSE, $role = FALSE)
  532. {
  533. return (!current_user_is_for_blog($blog_id, $role));
  534. }
  535. }
  536. /**
  537. * Conditional to determine if a specific User does NOT have a specific Capability or Role.
  538. *
  539. * Another function {@link http://codex.wordpress.org/Function_Reference/user_can user_can()} already exists in the WordPress® core.
  540. *
  541. * ———— Code Sample Using Both Functions ————
  542. * ```
  543. * <!php
  544. * if(user_can(123, "access_s2member_level0"))
  545. * echo 'User ID# 123 CAN access content protected at Level #0.';
  546. *
  547. * else if(user_cannot(123, "access_s2member_level0"))
  548. * echo 'User ID# 123 CANNOT access content at Level #0.';
  549. * !>
  550. * ```
  551. * ———— Shortcode Conditional Equivalent ————
  552. * ```
  553. * [s2If user_can(123, access_s2member_level0)]
  554. * User ID# 123 CAN access content protected at Level #0.
  555. * [/s2If]
  556. * [s2If user_cannot(123, access_s2member_level0)]
  557. * User ID# 123 CANNOT access content at Level #0.
  558. * [/s2If]
  559. * ```
  560. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  561. *
  562. * ———— Membership Levels Provide Incremental Access ————
  563. *
  564. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  565. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  566. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  567. * o A Member with Level 1 access, will also be able to access Level 0.
  568. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  569. * o A public Visitor will have NO access to protected content.
  570. *
  571. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  572. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  573. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  574. *
  575. * @package s2Member\API_Functions
  576. * @since 3.5
  577. *
  578. * @param int|str $id A numeric WordPress® User ID.
  579. * @param str $capability A WordPress® Capability ID *( i.e. `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
  580. * @return bool True if the specific User does NOT have the specified Capability or Role, else false.
  581. *
  582. * @see s2Member\API_Functions\user_is()
  583. * @see s2Member\API_Functions\user_is_not()
  584. *
  585. * @see s2Member\API_Functions\current_user_is()
  586. * @see s2Member\API_Functions\current_user_is_not()
  587. * @see s2Member\API_Functions\current_user_is_for_blog()
  588. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  589. *
  590. * @see s2Member\API_Functions\user_cannot()
  591. * @see s2Member\API_Functions\current_user_cannot()
  592. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  593. *
  594. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  595. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  596. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  597. */
  598. if(!function_exists("user_cannot"))
  599. {
  600. function user_cannot($id = FALSE, $capability = FALSE)
  601. {
  602. return (!user_can($id, $capability));
  603. }
  604. }
  605. /**
  606. * Conditional to determine if the current User does NOT have a specific Capability or Role.
  607. *
  608. * Another function {@link http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()} already exists in the WordPress® core.
  609. *
  610. * ———— Code Sample Using Both Functions ————
  611. * ```
  612. * <!php
  613. * if(current_user_can("access_s2member_level0"))
  614. * echo 'You CAN access content protected at Level #0.';
  615. *
  616. * else if(current_user_cannot("access_s2member_level0"))
  617. * echo 'You CANNOT access content protected at Level #0.';
  618. * !>
  619. * ```
  620. * ———— Shortcode Conditional Equivalent ————
  621. * ```
  622. * [s2If current_user_can(access_s2member_level0)]
  623. * You CAN access content protected at Level #0.
  624. * [/s2If]
  625. * [s2If current_user_cannot(access_s2member_level0)]
  626. * You CANNOT access content protected at Level #0.
  627. * [/s2If]
  628. * ```
  629. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  630. *
  631. * ———— Membership Levels Provide Incremental Access ————
  632. *
  633. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  634. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  635. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  636. * o A Member with Level 1 access, will also be able to access Level 0.
  637. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  638. * o A public Visitor will have NO access to protected content.
  639. *
  640. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  641. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  642. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  643. *
  644. * @package s2Member\API_Functions
  645. * @since 3.5
  646. *
  647. * @param str $capability A WordPress® Capability ID *( i.e. `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
  648. * Or a Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  649. * @return bool True if the current User does NOT have the specified Capability or Role, else false.
  650. *
  651. * @see s2Member\API_Functions\user_is()
  652. * @see s2Member\API_Functions\user_is_not()
  653. *
  654. * @see s2Member\API_Functions\current_user_is()
  655. * @see s2Member\API_Functions\current_user_is_not()
  656. * @see s2Member\API_Functions\current_user_is_for_blog()
  657. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  658. *
  659. * @see s2Member\API_Functions\user_cannot()
  660. * @see s2Member\API_Functions\current_user_cannot()
  661. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  662. *
  663. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  664. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  665. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  666. */
  667. if(!function_exists("current_user_cannot"))
  668. {
  669. function current_user_cannot($capability = FALSE)
  670. {
  671. return (!current_user_can($capability));
  672. }
  673. }
  674. /**
  675. * Conditional to determine if the current User does NOT have a specific Capability or Role, on a specific Blog within a Multisite Network.
  676. *
  677. * 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.
  678. *
  679. * ———— Code Sample Using Both Functions ————
  680. * ```
  681. * <!php
  682. * if(current_user_can_for_blog(5, "access_s2member_level0"))
  683. * echo 'You CAN access content protected at Level #0 (on Blog ID 5).';
  684. *
  685. * else if(current_user_cannot_for_blog(5, "access_s2member_level0"))
  686. * echo 'You CANNOT access content protected at Level #0 (on Blog ID 5).';
  687. * !>
  688. * ```
  689. * ———— Shortcode Conditional Equivalent ————
  690. * ```
  691. * [s2If current_user_can_for_blog(5, access_s2member_level0)]
  692. * You CAN access content protected at Level #0 (on Blog ID 5).
  693. * [/s2If]
  694. * [s2If current_user_cannot_for_blog(5, access_s2member_level0)]
  695. * You CANNOT access content protected at Level #0 (on Blog ID 5).
  696. * [/s2If]
  697. * ```
  698. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  699. *
  700. * ———— Membership Levels Provide Incremental Access ————
  701. *
  702. * o A Member with Level 4 access, will also be able to access Levels 0, 1, 2, 3.
  703. * o A Member with Level 3 access, will also be able to access Levels 0, 1, 2.
  704. * o A Member with Level 2 access, will also be able to access Levels 0, 1
  705. * o A Member with Level 1 access, will also be able to access Level 0.
  706. * o A Subscriber with Level 0 access, can ONLY access Level 0.
  707. * o A public Visitor will have NO access to protected content.
  708. *
  709. * WordPress® Subscribers are at Membership Level 0. If you're allowing Open Registration, Subscribers will be at Level 0 *(a Free Subscriber)*.
  710. * WordPress® Administrators, Editors, Authors, and Contributors have Level 4 access, with respect to s2Member.
  711. * All of their other {@link http://codex.wordpress.org/Roles_and_Capabilities Roles/Capabilities} are left untouched.
  712. *
  713. * @package s2Member\API_Functions
  714. * @since 3.5
  715. *
  716. * @param int|str $blog_id A WordPress® Blog ID *(must be numeric)*.
  717. * @param str $capability A WordPress® Capability ID *( i.e. `access_s2member_level[0-9]+`, `access_s2member_ccap_music` )*.
  718. * Or a Role ID *( i.e. `s2member_level[0-9]+`, `administrator`, `editor`, `author`, `contributor`, `subscriber` )*.
  719. * @return bool True if the current User does NOT have the specified Capability or Role, else false.
  720. *
  721. * @see s2Member\API_Functions\user_is()
  722. * @see s2Member\API_Functions\user_is_not()
  723. *
  724. * @see s2Member\API_Functions\current_user_is()
  725. * @see s2Member\API_Functions\current_user_is_not()
  726. * @see s2Member\API_Functions\current_user_is_for_blog()
  727. * @see s2Member\API_Functions\current_user_is_not_for_blog()
  728. *
  729. * @see s2Member\API_Functions\user_cannot()
  730. * @see s2Member\API_Functions\current_user_cannot()
  731. * @see s2Member\API_Functions\current_user_cannot_for_blog()
  732. *
  733. * @see http://codex.wordpress.org/Function_Reference/user_can user_can()
  734. * @see http://codex.wordpress.org/Function_Reference/current_user_can current_user_can()
  735. * @see http://codex.wordpress.org/Function_Reference/current_user_can_for_blog current_user_can_for_blog()
  736. */
  737. if(!function_exists("current_user_cannot_for_blog"))
  738. {
  739. function current_user_cannot_for_blog($blog_id = FALSE, $capability = FALSE)
  740. {
  741. return (!current_user_can_for_blog($blog_id, $capability));
  742. }
  743. }
  744. /**
  745. * Conditional to determine if a specific Category, Tag, Post, Page, URL or URI is protected by s2Member;
  746. * without considering the current User's Role/Capabilites.
  747. *
  748. * ———— Extra Detail On Function Parameters ————
  749. *
  750. * **Parameter $what (int|str Optional).**
  751. * Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
  752. * 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.
  753. *
  754. * o If you pass in an ID, s2Member will check everything, including your configured URI Restrictions against the ID.
  755. * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
  756. * So using an ID results in an all-inclusive scan against your configured Restrictions,
  757. * including any URI Restrictions that you may have configured.
  758. *
  759. * o If you pass in a URL or URI, s2Member will ONLY check URI Restrictions, because it has no ID to work with.
  760. * This is useful though. Some protected content is not associated with an ID. In those cases, URI Restrictions are all the matter.
  761. *
  762. * o Note: when passing in a URL or URI, the $type parameter must be set to `URI` or `uri`. Case insensitive.
  763. *
  764. * **Parameter $type (str Optional).**
  765. * One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e. a Post or Page)*.
  766. *
  767. * **Parameter $check_user (bool Optional).**
  768. * Consider the current User? Defaults to false.
  769. *
  770. * o In other words, by default, this Conditional function is only checking to see if the content is protected, and that's it.
  771. * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
  772. * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_permitted_by_s2member()}.
  773. *
  774. * ———— Code Sample Using Function Parameters ————
  775. * ```
  776. * <!php
  777. * if(is_protected_by_s2member(123))
  778. * echo 'Post or Page ID #123 is protected by s2Member.';
  779. *
  780. * else if(is_protected_by_s2member(332, "tag"))
  781. * echo 'Tag ID #332 is protected by s2Member.';
  782. *
  783. * else if(is_protected_by_s2member(554, "category"))
  784. * echo 'Category ID #554 is protected by s2Member.';
  785. *
  786. * else if(is_protected_by_s2member("http://example.com/members/", "uri"))
  787. * echo 'This URL is protected by URI Restrictions.';
  788. *
  789. * else if(is_protected_by_s2member("/members/", "uri"))
  790. * echo 'This URI is protected by URI Restrictions.';
  791. * !>
  792. * ```
  793. * ———— Shortcode Conditional Equivalent ————
  794. * ```
  795. * [s2If is_protected_by_s2member(123)]
  796. * Post or Page ID #123 is protected by s2Member.
  797. * [/s2If]
  798. * [s2If is_protected_by_s2member(332, tag)]
  799. * Tag ID #332 is protected by s2Member.
  800. * [/s2If]
  801. * [s2If is_protected_by_s2member(554, category)]
  802. * Category ID #554 is protected by s2Member.
  803. * [/s2If]
  804. * [s2If is_protected_by_s2member(http://example.com/members/, uri)]
  805. * This URL is protected by URI Restrictions.
  806. * [/s2If]
  807. * [s2If is_protected_by_s2member(/members/, uri)]
  808. * This URI is protected by URI Restrictions.
  809. * [/s2If]
  810. * ```
  811. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  812. *
  813. * @package s2Member\API_Functions
  814. * @since 3.5
  815. *
  816. * @param int|str $what Optional. Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
  817. * 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.
  818. * @param str $type Optional. One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e. a Post or Page)*.
  819. * @param bool $check_user Optional. Consider the current User? Defaults to false.
  820. * @return array|bool A non-empty array *(meaning true)*, or false if the content is not protected *(i.e. available publicly)*.
  821. * When/if content IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
  822. * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the content.
  823. * In other words, the reason why it's protected; based on your s2Member configuration.
  824. *
  825. * @see s2Member\API_Functions\is_protected_by_s2member()
  826. * @see s2Member\API_Functions\is_permitted_by_s2member()
  827. *
  828. * @see s2Member\API_Functions\is_category_protected_by_s2member()
  829. * @see s2Member\API_Functions\is_category_permitted_by_s2member()
  830. *
  831. * @see s2Member\API_Functions\is_tag_protected_by_s2member()
  832. * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
  833. *
  834. * @see s2Member\API_Functions\is_post_protected_by_s2member()
  835. * @see s2Member\API_Functions\is_post_permitted_by_s2member()
  836. *
  837. * @see s2Member\API_Functions\is_page_protected_by_s2member()
  838. * @see s2Member\API_Functions\is_page_permitted_by_s2member()
  839. *
  840. * @see s2Member\API_Functions\is_uri_protected_by_s2member()
  841. * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
  842. *
  843. * @see s2Member\API_Functions\attach_s2member_query_filters()
  844. * @see s2Member\API_Functions\detach_s2member_query_filters()
  845. */
  846. if(!function_exists("is_protected_by_s2member"))
  847. {
  848. function is_protected_by_s2member($what = FALSE, $type = FALSE, $check_user = FALSE)
  849. {
  850. global /* Global reference to $post in The Loop. */ $post;
  851. $what = ($what) ? $what : ((is_object($post) && $post->ID) ? $post->ID : false);
  852. $type = ($type) ? strtolower($type) : "singular";
  853. if($type === "category" && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($what, $check_user)))
  854. return /* A non-empty array with ["s2member_level_req"]. */ $array;
  855. else if($type === "tag" && ($array = c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access($what, $check_user)))
  856. return /* A non-empty array with ["s2member_level_req"]. */ $array;
  857. else if(($type === "post" || $type === "singular") && ($array = c_ws_plugin__s2member_posts_sp::check_specific_post_level_access($what, $check_user)))
  858. return /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */ $array;
  859. else if(($type === "page" || $type === "singular") && ($array = c_ws_plugin__s2member_pages_sp::check_specific_page_level_access($what, $check_user)))
  860. return /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */$array;
  861. else if($type === "uri" && ($array = c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access($what, $check_user)))
  862. return /* A non-empty array with ["s2member_level_req"]. */ $array;
  863. return false;
  864. }
  865. }
  866. /**
  867. * Conditional to determine if a specific Category, Tag, Post, Page, URL or URI is permitted by s2Member,
  868. * with consideration given to the current User's Role/Capabilites.
  869. *
  870. * This function is similar to {@link s2Member\API_Functions\is_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
  871. * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_protected_by_s2member()} does; it only returns true|false.
  872. *
  873. * ———— Extra Detail On Function Parameters ————
  874. *
  875. * **Parameter $what (int|str Optional).**
  876. * Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
  877. * 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.
  878. *
  879. * o If you pass in an ID, s2Member will check everything, including your configured URI Restrictions against the ID.
  880. * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
  881. * So using an ID results in an all-inclusive scan against your configured Restrictions,
  882. * including any URI Restrictions that you may have configured.
  883. *
  884. * o If you pass in a URL or URI, s2Member will ONLY check URI Restrictions, because it has no ID to work with.
  885. * This is useful though. Some protected content is not associated with an ID. In those cases, URI Restrictions are all the matter.
  886. *
  887. * o Note: when passing in a URL or URI, the $type parameter must be set to `URI` or `uri`. Case insensitive.
  888. *
  889. * **Parameter $type (str Optional).**
  890. * One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e. a Post or Page)*.
  891. *
  892. * ———— Code Sample Using Function Parameters ————
  893. * ```
  894. * <!php
  895. * if(is_permitted_by_s2member(123))
  896. * echo 'Post or Page ID #123 is permitted by s2Member.';
  897. *
  898. * else if(is_permitted_by_s2member(332, "tag"))
  899. * echo 'Tag ID #332 is permitted by s2Member.';
  900. *
  901. * else if(is_permitted_by_s2member(554, "category"))
  902. * echo 'Category ID #554 is permitted by s2Member.';
  903. *
  904. * else if(is_permitted_by_s2member("http://example.com/members/", "uri"))
  905. * echo 'This URL is permitted by s2Member.';
  906. *
  907. * else if(is_permitted_by_s2member("/members/", "uri"))
  908. * echo 'This URI is permitted by s2Member.';
  909. * !>
  910. * ```
  911. * ———— Shortcode Conditional Equivalent ————
  912. * ```
  913. * [s2If is_permitted_by_s2member(123)]
  914. * Post or Page ID #123 is permitted by s2Member.
  915. * [/s2If]
  916. * [s2If is_permitted_by_s2member(332, tag)]
  917. * Tag ID #332 is permitted by s2Member.
  918. * [/s2If]
  919. * [s2If is_permitted_by_s2member(554, category)]
  920. * Category ID #554 is permitted by s2Member.
  921. * [/s2If]
  922. * [s2If is_permitted_by_s2member(http://example.com/members/, uri)]
  923. * This URL is permitted by s2Member.
  924. * [/s2If]
  925. * [s2If is_permitted_by_s2member(/members/, uri)]
  926. * This URI is permitted by s2Member.
  927. * [/s2If]
  928. * ```
  929. * *but please note, `else if()` logic is not possible with `[s2If /]`.*
  930. *
  931. * @package s2Member\API_Functions
  932. * @since 3.5
  933. *
  934. * @param int|str $what Optional. Defaults to the current $post ID when called from within {@link http://codex.wordpress.org/The_Loop The Loop}.
  935. * 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.
  936. * @param str $type Optional. One of `category`, `tag`, `post`, `page`, `singular` or `uri`. Defaults to `singular` *(i.e. a Post or Page)*.
  937. * @return bool True if the current User IS permitted, else false if the content is NOT available to the current User;
  938. * based on your configuration of s2Member, and based on the current User's Role/Capabilities.
  939. *
  940. * @see s2Member\API_Functions\is_protected_by_s2member()
  941. * @see s2Member\API_Functions\is_permitted_by_s2member()
  942. *
  943. * @see s2Member\API_Functions\is_category_protected_by_s2member()
  944. * @see s2Member\API_Functions\is_category_permitted_by_s2member()
  945. *
  946. * @see s2Member\API_Functions\is_tag_protected_by_s2member()
  947. * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
  948. *
  949. * @see s2Member\API_Functions\is_post_protected_by_s2member()
  950. * @see s2Member\API_Functions\is_post_permitted_by_s2member()
  951. *
  952. * @see s2Member\API_Functions\is_page_protected_by_s2member()
  953. * @see s2Member\API_Functions\is_page_permitted_by_s2member()
  954. *
  955. * @see s2Member\API_Functions\is_uri_protected_by_s2member()
  956. * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
  957. *
  958. * @see s2Member\API_Functions\attach_s2member_query_filters()
  959. * @see s2Member\API_Functions\detach_s2member_query_filters()
  960. */
  961. if(!function_exists("is_permitted_by_s2member"))
  962. {
  963. function is_permitted_by_s2member($what = FALSE, $type = FALSE)
  964. {
  965. global /* Global reference to $post in The Loop. */ $post;
  966. $what = ($what) ? $what : ((is_object($post) && $post->ID) ? $post->ID : false);
  967. $type = ($type) ? strtolower($type) : "singular";
  968. if($type === "category" && c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($what, true))
  969. return false;
  970. else if($type === "tag" && c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access($what, true))
  971. return false;
  972. else if(($type === "post" || $type === "singular") && c_ws_plugin__s2member_posts_sp::check_specific_post_level_access($what, true))
  973. return false;
  974. else if(($type === "page" || $type === "singular") && c_ws_plugin__s2member_pages_sp::check_specific_page_level_access($what, true))
  975. return false;
  976. else if($type === "uri" && c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access($what, true))
  977. return false;
  978. return true;
  979. }
  980. }
  981. /**
  982. * Conditional to determine if a specific Category is protected by s2Member;
  983. * without considering the current User's Role/Capabilites.
  984. *
  985. * ———— Extra Detail On Function Parameters ————
  986. *
  987. * **Parameter $cat_id (int Required).** This should be a WordPress® Category ID.
  988. *
  989. * o s2Member will check everything, including your configured URI Restrictions against the ID.
  990. * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
  991. * So using an ID results in an all-inclusive scan against your configured Restrictions,
  992. * including any URI Restrictions that you may have configured.
  993. *
  994. * **Parameter $check_user (bool Optional).**
  995. * Consider the current User? Defaults to false.
  996. *
  997. * o In other words, by default, this Conditional function is only checking to see if the Category is protected, and that's it.
  998. * o So this function does NOT consider the current User's Role or Capabilities. If you set $check_user to true, it will.
  999. * o When $check_user is true, this function behaves like {@link s2Member\API_Functions\is_category_permitted_by_s2member()}.
  1000. *
  1001. * ———— Code Sample Using Function Parameters ————
  1002. * ```
  1003. * <!php
  1004. * if(is_category_protected_by_s2member(123))
  1005. * echo 'Category ID #123 is protected by s2Member.';
  1006. * !>
  1007. * ```
  1008. * ———— Shortcode Conditional Equivalent ————
  1009. * ```
  1010. * [s2If is_category_protected_by_s2member(123)]
  1011. * Category ID #123 is protected by s2Member.
  1012. * [/s2If]
  1013. * ```
  1014. *
  1015. * @package s2Member\API_Functions
  1016. * @since 3.5
  1017. *
  1018. * @param int $cat_id Required. This should be a WordPress® Category ID.
  1019. * @param bool $check_user Optional. Consider the current User? Defaults to false.
  1020. * @return array|bool A non-empty array *(meaning true)*, or false if the Category is not protected *(i.e. available publicly)*.
  1021. * When/if the Category IS protected, the return array will include one of these keys ``["s2member_(level|sp|ccap)_req"]``
  1022. * indicating the Level #, Specific Post/Page ID #, or Custom Capability required to access the Category.
  1023. * In other words, the reason why it's protected; based on your s2Member configuration.
  1024. *
  1025. * @see s2Member\API_Functions\is_protected_by_s2member()
  1026. * @see s2Member\API_Functions\is_permitted_by_s2member()
  1027. *
  1028. * @see s2Member\API_Functions\is_category_protected_by_s2member()
  1029. * @see s2Member\API_Functions\is_category_permitted_by_s2member()
  1030. *
  1031. * @see s2Member\API_Functions\is_tag_protected_by_s2member()
  1032. * @see s2Member\API_Functions\is_tag_permitted_by_s2member()
  1033. *
  1034. * @see s2Member\API_Functions\is_post_protected_by_s2member()
  1035. * @see s2Member\API_Functions\is_post_permitted_by_s2member()
  1036. *
  1037. * @see s2Member\API_Functions\is_page_protected_by_s2member()
  1038. * @see s2Member\API_Functions\is_page_permitted_by_s2member()
  1039. *
  1040. * @see s2Member\API_Functions\is_uri_protected_by_s2member()
  1041. * @see s2Member\API_Functions\is_uri_permitted_by_s2member()
  1042. *
  1043. * @see s2Member\API_Functions\attach_s2member_query_filters()
  1044. * @see s2Member\API_Functions\detach_s2member_query_filters()
  1045. */
  1046. if(!function_exists("is_category_protected_by_s2member"))
  1047. {
  1048. function is_category_protected_by_s2member($cat_id = FALSE, $check_user = FALSE)
  1049. {
  1050. if($cat_id && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access($cat_id, $check_user)))
  1051. return /* A non-empty array with ["s2member_level_req"]. */ $array;
  1052. return false;
  1053. }
  1054. }
  1055. /**
  1056. * Conditional to determine if a specific Category is permitted by s2Member,
  1057. * with consideration given to the current User's Role/Capabilites.
  1058. *
  1059. * This function is similar to {@link s2Member\API_Functions\is_category_protected_by_s2member()}, except this function considers the current User's Role/Capabilites.
  1060. * Also, this function does NOT return the array like {@link s2Member\API_Functions\is_category_protected_by_s2member()} does; it only returns true|false.
  1061. *
  1062. * ———— Extra Detail On Function Parameters ————
  1063. *
  1064. * **Parameter $cat_id (int Required).** This should be a WordPress® Category ID.
  1065. *
  1066. * o s2Member will check everything, including your configured URI Restrictions against the ID.
  1067. * In other words, s2Member is capable of determining a URI based on the ID that you pass in.
  1068. * So using an ID results in an all-inclusive scan against your configured Restrictions,
  1069. * including any URI Restrictions that you may have configured.
  1070. *
  1071. * ———— Code Sample Using Function Parameters ————
  1072. * ```
  1073. * <!php
  1074. * if(is_category_permitted_by_s2member(123))
  1075. * echo 'Category ID #123 is permitted by s2Member.';
  1076. * !>
  1077. * ```
  1078. *