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

option-forces.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 260917, at src/includes/classes/option-forces.inc.php

266 lines 12.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreFile
3 /**
4 * Forces WordPress options.
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\Option_Forces
16 * @since 3.5
17 */
18 if(!defined('WPINC')) // MUST have WordPress.
19 exit("Do not access this file directly.");
20
21 if (!class_exists ("c_ws_plugin__s2member_option_forces"))
22 {
23 /**
24 * Forces WordPress options.
25 *
26 * @package s2Member\Option_Forces
27 * @since 3.5
28 */
29 class c_ws_plugin__s2member_option_forces
30 {
31 /**
32 * Forces a default Role for new registrations, NOT tied to an incoming payment.
33 *
34 * @package s2Member\Option_Forces
35 * @since 3.5
36 *
37 * @attaches-to ``add_filter("pre_option_default_role");``
38 *
39 * @param string $default_role Expects a default Role to be passed by the Filter.
40 * @return string Default Role, as configured by s2Member.
41 */
42 public static function force_default_role ($default_role = FALSE)
43 {
44 do_action("ws_plugin__s2member_before_force_default_role", get_defined_vars ());
45
46 return apply_filters("ws_plugin__s2member_force_default_role", ($default_role = "subscriber"), get_defined_vars ());
47 }
48 /**
49 * Forces a default Role for new Multisite registrations (on the Main Site) NOT tied to an incoming payment.
50 *
51 * @package s2Member\Option_Forces
52 * @since 3.5
53 *
54 * @attaches-to ``add_filter("pre_site_option_default_user_role");``
55 *
56 * @param string $default_role Expects a default Role to be passed by the Filter.
57 * @return string Default Role, as configured by s2Member.
58 */
59 public static function force_mms_default_role ($default_role = FALSE)
60 {
61 do_action("ws_plugin__s2member_before_force_mms_default_role", get_defined_vars ());
62
63 return apply_filters("ws_plugin__s2member_force_mms_default_role", ($default_role = "subscriber"), get_defined_vars ());
64 }
65 /**
66 * Forces a specific Role to demote to, whenever a Member is demoted in one way or another.
67 *
68 * Use by the PayPal IPN routines, and also by the Auto-EOT system.
69 *
70 * @package s2Member\Option_Forces
71 * @since 3.5
72 *
73 * @param string $demotion_role Expects the role to demote the user to.
74 * @return string Role users are demoted to, as configured by s2Member.
75 */
76 public static function force_demotion_role ($demotion_role = FALSE)
77 {
78 do_action("ws_plugin__s2member_before_force_demotion_role", get_defined_vars ());
79
80 //260916.1840 Use the administrator's configured EOT destination first; the long-standing filter remains the final developer override.
81 $demotion_role = !empty($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_demotion_to_role"]) ? $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_demotion_to_role"] : "subscriber";
82 //260916.2306 Validate registered-role existence here, after s2Member is fully loaded; doing this in bootstrap option validation can initialize WordPress roles too early.
83 if(in_array($demotion_role, array('administrator', 'editor', 'author', 'contributor', 's2member_pending_deletion'), TRUE) || !get_role($demotion_role))
84 $demotion_role = "subscriber";
85
86 return apply_filters("ws_plugin__s2member_force_demotion_role", $demotion_role, get_defined_vars ());
87 }
88 /**
89 * Allows new Users to be created on a Multisite Network.
90 *
91 * @package s2Member\Option_Forces
92 * @since 3.5
93 *
94 * @attaches-to ``add_filter("pre_site_option_add_new_users");``
95 *
96 * @param int|string $allow Numeric string (`1`) or (`0`), expected by the Filter.
97 * @return string Numeric (`1`) or (`0`) indicating true or false. Forces to (`1`) true.
98 */
99 public static function mms_allow_new_users ($allow = FALSE)
100 {
101 do_action("ws_plugin__s2member_before_mms_allow_new_users", get_defined_vars ());
102
103 return apply_filters("ws_plugin__s2member_mms_allow_new_users", ($allow = "1"), get_defined_vars ());
104 }
105 /**
106 * Forces a Multisite Dashboard Blog to be the Main Site.
107 *
108 * @package s2Member\Option_Forces
109 * @since 3.5
110 *
111 * @attaches-to ``add_filter("pre_site_option_dashboard_blog");``
112 *
113 * @param int|string $dashboard_blog Numeric Dashboard Blog ID passed through by the Filter.
114 * @return int|str Numeric Dashboard Blog ID, as configured by s2Member. Forces to the Main Site.
115 */
116 public static function mms_dashboard_blog ($dashboard_blog = FALSE)
117 {
118 global /* For Multisite support. */ $current_site, $current_blog;
119
120 do_action("ws_plugin__s2member_before_mms_dashboard_blog", get_defined_vars ());
121
122 $main_site = ((is_multisite ()) ? $current_site->blog_id : "1"); // Forces the Main Site.
123
124 return apply_filters("ws_plugin__s2member_mms_dashboard_blog", ($dashboard_blog = $main_site), get_defined_vars ());
125 }
126 /**
127 * Allows access to the Registration Form.
128 *
129 * @package s2Member\Option_Forces
130 * @since 3.5
131 *
132 * @attaches-to ``add_filter("pre_option_users_can_register");``
133 *
134 * @param int|string $users_can_register Numeric (`1`) or (`0`), indicating true or false; passed through by the Filter.
135 * @return string Numeric value of (`1`) or (`0`), indicating true or false; depending on several factors.
136 */
137 public static function check_register_access ($users_can_register = FALSE)
138 {
139 global $wpdb; // Global database object reference
140
141 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
142 do_action("ws_plugin__s2member_before_check_register_access", get_defined_vars ());
143 unset($__refs, $__v);
144
145 $by_default = $users_can_register = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["allow_subscribers_in"];
146
147 if (is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm () && is_main_site ())
148 return apply_filters("ws_plugin__s2member_check_register_access", ($users_can_register = "0"), get_defined_vars ());
149
150 else if (!is_admin () && !$users_can_register) // Do NOT run these security checks on option pages; it's confusing.
151 if (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm () || !is_main_site () || current_user_can ("create_users") || is_super_admin ())
152 {
153 if (current_user_can ("create_users") || (is_multisite () && is_super_admin ()) || c_ws_plugin__s2member_register_access::reg_cookies_ok ())
154 {
155 return apply_filters("ws_plugin__s2member_check_register_access", ($users_can_register = "1"), get_defined_vars ());
156 }
157 }
158
159 return apply_filters("ws_plugin__s2member_check_register_access", $users_can_register, get_defined_vars ());
160 }
161 /**
162 * Allows access to the main Multisite Registration Form.
163 *
164 * @package s2Member\Option_Forces
165 * @since 3.5
166 *
167 * @attaches-to ``add_filter("pre_site_option_registration");``
168 *
169 * @param string $users_can_register Expects *( `none`, `all`, `blog`, `user` )*, passed through by the Filter.
170 * @return string One of `none|all|user`; depending on several factors.
171 */
172 public static function check_mms_register_access ($users_can_register = FALSE)
173 {
174 global $wpdb; // Global database object reference
175 global /* For Multisite support. */ $current_site, $current_blog;
176
177 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
178 do_action("ws_plugin__s2member_before_check_register_access", get_defined_vars ());
179 unset($__refs, $__v);
180
181 $by_default = $users_can_register = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_grants"];
182
183 if (c_ws_plugin__s2member_utils_conds::bp_is_installed () && is_multisite () && /* BP Multisite / but NOT offering Blogs? */ !c_ws_plugin__s2member_utils_conds::is_multisite_farm ())
184 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = ((c_ws_plugin__s2member_option_forces::check_register_access ()) ? "user" : "none")), get_defined_vars ());
185
186 else if (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm ()) // Blog Farm?
187 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "none"), get_defined_vars ());
188
189 else if (!is_network_admin () && $users_can_register !== "all") // Do NOT run these checks on Network option pages; it's confusing.
190 {
191 if ((is_main_site () && current_user_can ("create_users")) || is_super_admin ()) // Creates Users on the Main Site?
192 {
193 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "all"), get_defined_vars ());
194 }
195
196 else if (is_user_logged_in () && is_object ($user = wp_get_current_user ()) && $user->ID && is_object ($user = new WP_User ($user->ID, $current_site->blog_id)) && $user->ID && $user->has_cap ("access_s2member_level1"))
197 {
198 $mms_options = c_ws_plugin__s2member_utilities::mms_options ();
199 $blogs_allowed = (int)@$mms_options["mms_registration_blogs_level" . c_ws_plugin__s2member_user_access::user_access_level ($user)];
200 $user_blogs = (is_array($blogs = get_blogs_of_user ($user->ID))) ? count ($blogs) - 1 : 0;
201
202 $user_blogs = ($user_blogs >= 0) ? $user_blogs : 0; // NOT less than zero.
203 $blogs_allowed = ($blogs_allowed >= 0) ? $blogs_allowed : 0;
204
205 if ($user_blogs < $blogs_allowed) // Are they within their limit?
206 {
207 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "all"), get_defined_vars ());
208 }
209 }
210 else if (!is_user_logged_in () && is_main_site () && ($reg_cookies = c_ws_plugin__s2member_register_access::reg_cookies_ok ()) && extract ($reg_cookies))
211 {
212 if (preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["membership_item_number_w_level_regex"], $item_number, $m) && !empty($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_blogs_level" . $m[1]]))
213 {
214 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "all"), get_defined_vars ());
215 }
216 else // Otherwise, we MUST allow them to at least create an account; they paid for it! Defaults to `user`.
217 {
218 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "user"), get_defined_vars ());
219 }
220 }
221 }
222
223 else if (!is_network_admin () && $users_can_register === "all") // Do NOT run these security checks on option pages; it's confusing to a site owner.
224 {
225 if (is_user_logged_in () && !(is_main_site () && current_user_can ("create_users")) && !is_super_admin () && is_object ($user = wp_get_current_user ()) && $user->ID && is_object ($user = new WP_User ($user->ID, $current_site->blog_id)) && $user->ID)
226 {
227 $mms_options = c_ws_plugin__s2member_utilities::mms_options ();
228 $blogs_allowed = (int)@$mms_options["mms_registration_blogs_level" . c_ws_plugin__s2member_user_access::user_access_level ($user)];
229 $user_blogs = (is_array($blogs = get_blogs_of_user ($user->ID))) ? count ($blogs) - 1 : 0;
230
231 $user_blogs = ($user_blogs >= 0) ? $user_blogs : 0; // NOT less than zero.
232 $blogs_allowed = ($blogs_allowed >= 0) ? $blogs_allowed : 0;
233
234 if ($user_blogs >= $blogs_allowed) // Are they at their limit?
235 {
236 return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "none"), get_defined_vars ());
237 }
238 }
239 }
240
241 return apply_filters("ws_plugin__s2member_check_mms_register_access", $users_can_register, get_defined_vars ());
242 }
243 /**
244 * Register access in BuddyPress, for Multisite compatibility.
245 *
246 * BuddyPress bypasses the default Filter `pre_site_option_registration`, and instead uses: ``bp_core_get_root_options()``.
247 *
248 * @package s2Member\Option_Forces
249 * @since 3.5
250 *
251 * @attaches-to ``add_filter("bp_core_get_root_options");``
252 * @attaches-to ``add_filter("bp_core_get_site_options");`` **(before BuddyPress v1.5)**.
253 *
254 * @param array $site_options Expects array of BuddyPress site options.
255 * @return array Site options array, after having been Filtered by this routine.
256 */
257 public static function check_bp_mms_register_access ($site_options = FALSE)
258 {
259 if (is_multisite ()) // Only if Multisite Networking is enabled. Pointless otherwise.
260 $site_options["registration"] = c_ws_plugin__s2member_option_forces::check_mms_register_access ($site_options["registration"]);
261
262 return apply_filters("ws_plugin__s2member_check_bp_mms_register_access", $site_options, get_defined_vars ());
263 }
264 }
265 }
266