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

user-securities.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110812, at includes/classes/user-securities.inc.php

137 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * User securities.
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\User_Securities
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit ("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_user_securities"))
21 {
22 /**
23 * User securities.
24 *
25 * @package s2Member\User_Securities
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_user_securities
29 {
30 /**
31 * Initializes a Multisite Filter for `user_has_cap`.
32 *
33 * It's very important that this is NOT attached before WordPress® creates `$current_user` via `$wp->init()`.
34 * This prevents crashes when other plugins attempt to call upon `current_user_can()` before WordPress is initialized.
35 * For instance, some plugins attempt to use `current_user_can()` on the `plugins_loaded` Hook, which they should not do.
36 *
37 * @package s2Member\User_Securities
38 * @since 3.5
39 *
40 * @attaches-to: ``add_action("init");``
41 *
42 * @return null
43 */
44 public static function initialize () /* Initializes the Filter for `user_has_cap`. */
45 {
46 add_filter ("user_has_cap", "c_ws_plugin__s2member_user_securities::ms_user_capabilities", 10, 3);
47 }
48 /**
49 * Alters `WP_User->has_cap()` on a Multisite Blog Farm.
50 *
51 * @package s2Member\User_Securities
52 * @since 3.5
53 *
54 * @attaches-to: ``add_filter("user_has_cap");``
55 *
56 * @param array $capabilities Expects an array of Capabilities passed in by the Filter.
57 * This array contains all of the Capabilities that the User has *( i.e. ``$user->allcaps`` )*.
58 * @param array $caps_map An array of Capabilities mapped out by the ``map_meta_cap`` function.
59 * @param array $args Array of arguments originally passed through the ``has_cap()`` function.
60 * However, WordPress® modifies this array of arguments in the following way.
61 * Argument `[0]` is the Capability test string itself *( this is normal )*.
62 * Argument `[1]` is added by WordPress®; it's the ID of the User.
63 * Other arguments starting from array index `[2]` are normal.
64 * @return array An array of Capabilities.
65 */
66 public static function ms_user_capabilities ($capabilities = FALSE, $caps_map = FALSE, $args = FALSE)
67 {
68 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
69 do_action ("ws_plugin__s2member_before_ms_user_capabilities", get_defined_vars ());
70 unset ($__refs, $__v); /* Unset defined __refs, __v. */
71 /**/
72 if (is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm () && (is_super_admin () || !empty ($capabilities["administrator"])) && !empty ($args[0]) && ($args[0] === "edit_user" || $args[0] === "edit_users"))
73 if ($args[0] === "edit_users" || ($args[0] === "edit_user" && !empty ($args[2]) && ((!empty ($args[1]) && (int)$args[1] === (int)$args[2]) || is_user_member_of_blog ($args[2]))))
74 $capabilities = array_merge ((array)$capabilities, array ("edit_users" => 1, "do_not_allow" => 1));
75 /**/
76 return apply_filters ("ws_plugin__s2member_ms_user_capabilities", $capabilities, get_defined_vars ());
77 }
78 /**
79 * Alters this Filter inside `/wp-admin/user-edit.php`.
80 *
81 * @package s2Member\User_Securities
82 * @since 3.5
83 *
84 * @attaches-to: ``add_filter("enable_edit_any_user_configuration");``
85 *
86 * @param bool $allow Expects boolean value passed through by the Filter.
87 * @return bool True if the current User is allowed to edit any User, else existing value.
88 */
89 public static function ms_allow_edits ($allow = FALSE)
90 {
91 global $user_id; /* Available inside `/wp-admin/user-edit.php`. */
92 /**/
93 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
94 do_action ("ws_plugin__s2member_before_ms_allow_edits", get_defined_vars ());
95 unset ($__refs, $__v); /* Unset defined __refs, __v. */
96 /**/
97 if (is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm ())
98 if (is_super_admin () || (current_user_can ("administrator") && $user_id && is_user_member_of_blog ($user_id)))
99 $allow = true; /* Yes, allow Administrators to edit User Profiles. */
100 /**/
101 return apply_filters ("ws_plugin__s2member_ms_allow_edits", $allow, get_defined_vars ());
102 }
103 /**
104 * Hides Password fields for Demo Users; and deals with Password fields on Multisite Blog Farms.
105 *
106 * Demo accounts *( where the Username MUST be "demo" )*, will NOT be allowed to change their Password.
107 * Any other restrictions you need to impose must be done through custom programming, using s2Member's Conditionals.
108 * See `s2Member -> API Scripting`.
109 *
110 * @package s2Member\User_Securities
111 * @since 3.5
112 *
113 * @attaches-to: ``add_filter("show_password_fields");``
114 *
115 * @param bool $show Expects boolean value passed through by the Filter.
116 * @param obj $user Expects a `WP_User` object passed through by the Filter.
117 * @return bool False if the Password is locked for this User, else existing value.
118 */
119 public static function hide_password_fields ($show = TRUE, $user = FALSE)
120 {
121 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
122 do_action ("ws_plugin__s2member_before_hide_password_fields", get_defined_vars ());
123 unset ($__refs, $__v); /* Unset defined __refs, __v. */
124 /**/
125 if ($show && is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm ())
126 if (!is_super_admin () && is_object ($user) && $user->ID && is_object ($current_user = wp_get_current_user ()) && $current_user->ID)
127 if ($user->ID !== $current_user->ID)
128 $show = false;
129 /**/
130 if ($show && is_object ($user) && $user->ID && $user->user_login === "demo")
131 $show = false; /* Lock Password on Demos. */
132 /**/
133 return apply_filters ("ws_plugin__s2member_hide_password_fields", $show, get_defined_vars ());
134 }
135 }
136 }
137 ?>