| 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 a demotion Role to be passed by the caller. |
| 74 |
* @return string Demotion Role, 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 |
return apply_filters("ws_plugin__s2member_force_demotion_role", ($demotion_role = "subscriber"), get_defined_vars ()); |
| 81 |
} |
| 82 |
/** |
| 83 |
* Allows new Users to be created on a Multisite Network. |
| 84 |
* |
| 85 |
* @package s2Member\Option_Forces |
| 86 |
* @since 3.5 |
| 87 |
* |
| 88 |
* @attaches-to ``add_filter("pre_site_option_add_new_users");`` |
| 89 |
* |
| 90 |
* @param int|string $allow Numeric string (`1`) or (`0`), expected by the Filter. |
| 91 |
* @return string Numeric (`1`) or (`0`) indicating true or false. Forces to (`1`) true. |
| 92 |
*/ |
| 93 |
public static function mms_allow_new_users ($allow = FALSE) |
| 94 |
{ |
| 95 |
do_action("ws_plugin__s2member_before_mms_allow_new_users", get_defined_vars ()); |
| 96 |
|
| 97 |
return apply_filters("ws_plugin__s2member_mms_allow_new_users", ($allow = "1"), get_defined_vars ()); |
| 98 |
} |
| 99 |
/** |
| 100 |
* Forces a Multisite Dashboard Blog to be the Main Site. |
| 101 |
* |
| 102 |
* @package s2Member\Option_Forces |
| 103 |
* @since 3.5 |
| 104 |
* |
| 105 |
* @attaches-to ``add_filter("pre_site_option_dashboard_blog");`` |
| 106 |
* |
| 107 |
* @param int|string $dashboard_blog Numeric Dashboard Blog ID passed through by the Filter. |
| 108 |
* @return int|str Numeric Dashboard Blog ID, as configured by s2Member. Forces to the Main Site. |
| 109 |
*/ |
| 110 |
public static function mms_dashboard_blog ($dashboard_blog = FALSE) |
| 111 |
{ |
| 112 |
global /* For Multisite support. */ $current_site, $current_blog; |
| 113 |
|
| 114 |
do_action("ws_plugin__s2member_before_mms_dashboard_blog", get_defined_vars ()); |
| 115 |
|
| 116 |
$main_site = ((is_multisite ()) ? $current_site->blog_id : "1"); // Forces the Main Site. |
| 117 |
|
| 118 |
return apply_filters("ws_plugin__s2member_mms_dashboard_blog", ($dashboard_blog = $main_site), get_defined_vars ()); |
| 119 |
} |
| 120 |
/** |
| 121 |
* Allows access to the Registration Form. |
| 122 |
* |
| 123 |
* @package s2Member\Option_Forces |
| 124 |
* @since 3.5 |
| 125 |
* |
| 126 |
* @attaches-to ``add_filter("pre_option_users_can_register");`` |
| 127 |
* |
| 128 |
* @param int|string $users_can_register Numeric (`1`) or (`0`), indicating true or false; passed through by the Filter. |
| 129 |
* @return string Numeric value of (`1`) or (`0`), indicating true or false; depending on several factors. |
| 130 |
*/ |
| 131 |
public static function check_register_access ($users_can_register = FALSE) |
| 132 |
{ |
| 133 |
global $wpdb; // Global database object reference |
| 134 |
|
| 135 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 136 |
do_action("ws_plugin__s2member_before_check_register_access", get_defined_vars ()); |
| 137 |
unset($__refs, $__v); |
| 138 |
|
| 139 |
$by_default = $users_can_register = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["allow_subscribers_in"]; |
| 140 |
|
| 141 |
if (is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm () && is_main_site ()) |
| 142 |
return apply_filters("ws_plugin__s2member_check_register_access", ($users_can_register = "0"), get_defined_vars ()); |
| 143 |
|
| 144 |
else if (!is_admin () && !$users_can_register) // Do NOT run these security checks on option pages; it's confusing. |
| 145 |
if (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm () || !is_main_site () || current_user_can ("create_users") || is_super_admin ()) |
| 146 |
{ |
| 147 |
if (current_user_can ("create_users") || (is_multisite () && is_super_admin ()) || c_ws_plugin__s2member_register_access::reg_cookies_ok ()) |
| 148 |
{ |
| 149 |
return apply_filters("ws_plugin__s2member_check_register_access", ($users_can_register = "1"), get_defined_vars ()); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
return apply_filters("ws_plugin__s2member_check_register_access", $users_can_register, get_defined_vars ()); |
| 154 |
} |
| 155 |
/** |
| 156 |
* Allows access to the main Multisite Registration Form. |
| 157 |
* |
| 158 |
* @package s2Member\Option_Forces |
| 159 |
* @since 3.5 |
| 160 |
* |
| 161 |
* @attaches-to ``add_filter("pre_site_option_registration");`` |
| 162 |
* |
| 163 |
* @param string $users_can_register Expects *( `none`, `all`, `blog`, `user` )*, passed through by the Filter. |
| 164 |
* @return string One of `none|all|user`; depending on several factors. |
| 165 |
*/ |
| 166 |
public static function check_mms_register_access ($users_can_register = FALSE) |
| 167 |
{ |
| 168 |
global $wpdb; // Global database object reference |
| 169 |
global /* For Multisite support. */ $current_site, $current_blog; |
| 170 |
|
| 171 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 172 |
do_action("ws_plugin__s2member_before_check_register_access", get_defined_vars ()); |
| 173 |
unset($__refs, $__v); |
| 174 |
|
| 175 |
$by_default = $users_can_register = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_grants"]; |
| 176 |
|
| 177 |
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 ()) |
| 178 |
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 ()); |
| 179 |
|
| 180 |
else if (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm ()) // Blog Farm? |
| 181 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "none"), get_defined_vars ()); |
| 182 |
|
| 183 |
else if (!is_network_admin () && $users_can_register !== "all") // Do NOT run these checks on Network option pages; it's confusing. |
| 184 |
{ |
| 185 |
if ((is_main_site () && current_user_can ("create_users")) || is_super_admin ()) // Creates Users on the Main Site? |
| 186 |
{ |
| 187 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "all"), get_defined_vars ()); |
| 188 |
} |
| 189 |
|
| 190 |
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")) |
| 191 |
{ |
| 192 |
$mms_options = c_ws_plugin__s2member_utilities::mms_options (); |
| 193 |
$blogs_allowed = (int)@$mms_options["mms_registration_blogs_level" . c_ws_plugin__s2member_user_access::user_access_level ($user)]; |
| 194 |
$user_blogs = (is_array($blogs = get_blogs_of_user ($user->ID))) ? count ($blogs) - 1 : 0; |
| 195 |
|
| 196 |
$user_blogs = ($user_blogs >= 0) ? $user_blogs : 0; // NOT less than zero. |
| 197 |
$blogs_allowed = ($blogs_allowed >= 0) ? $blogs_allowed : 0; |
| 198 |
|
| 199 |
if ($user_blogs < $blogs_allowed) // Are they within their limit? |
| 200 |
{ |
| 201 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "all"), get_defined_vars ()); |
| 202 |
} |
| 203 |
} |
| 204 |
else if (!is_user_logged_in () && is_main_site () && ($reg_cookies = c_ws_plugin__s2member_register_access::reg_cookies_ok ()) && extract ($reg_cookies)) |
| 205 |
{ |
| 206 |
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]])) |
| 207 |
{ |
| 208 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "all"), get_defined_vars ()); |
| 209 |
} |
| 210 |
else // Otherwise, we MUST allow them to at least create an account; they paid for it! Defaults to `user`. |
| 211 |
{ |
| 212 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "user"), get_defined_vars ()); |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
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. |
| 218 |
{ |
| 219 |
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) |
| 220 |
{ |
| 221 |
$mms_options = c_ws_plugin__s2member_utilities::mms_options (); |
| 222 |
$blogs_allowed = (int)@$mms_options["mms_registration_blogs_level" . c_ws_plugin__s2member_user_access::user_access_level ($user)]; |
| 223 |
$user_blogs = (is_array($blogs = get_blogs_of_user ($user->ID))) ? count ($blogs) - 1 : 0; |
| 224 |
|
| 225 |
$user_blogs = ($user_blogs >= 0) ? $user_blogs : 0; // NOT less than zero. |
| 226 |
$blogs_allowed = ($blogs_allowed >= 0) ? $blogs_allowed : 0; |
| 227 |
|
| 228 |
if ($user_blogs >= $blogs_allowed) // Are they at their limit? |
| 229 |
{ |
| 230 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", ($users_can_register = "none"), get_defined_vars ()); |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
return apply_filters("ws_plugin__s2member_check_mms_register_access", $users_can_register, get_defined_vars ()); |
| 236 |
} |
| 237 |
/** |
| 238 |
* Register access in BuddyPress, for Multisite compatibility. |
| 239 |
* |
| 240 |
* BuddyPress bypasses the default Filter `pre_site_option_registration`, and instead uses: ``bp_core_get_root_options()``. |
| 241 |
* |
| 242 |
* @package s2Member\Option_Forces |
| 243 |
* @since 3.5 |
| 244 |
* |
| 245 |
* @attaches-to ``add_filter("bp_core_get_root_options");`` |
| 246 |
* @attaches-to ``add_filter("bp_core_get_site_options");`` **(before BuddyPress v1.5)**. |
| 247 |
* |
| 248 |
* @param array $site_options Expects array of BuddyPress site options. |
| 249 |
* @return array Site options array, after having been Filtered by this routine. |
| 250 |
*/ |
| 251 |
public static function check_bp_mms_register_access ($site_options = FALSE) |
| 252 |
{ |
| 253 |
if (is_multisite ()) // Only if Multisite Networking is enabled. Pointless otherwise. |
| 254 |
$site_options["registration"] = c_ws_plugin__s2member_option_forces::check_mms_register_access ($site_options["registration"]); |
| 255 |
|
| 256 |
return apply_filters("ws_plugin__s2member_check_bp_mms_register_access", $site_options, get_defined_vars ()); |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
|