本文整理汇总了PHP中c_ws_plugin__s2member_user_access::user_access_role_to_level方法的典型用法代码示例。如果您正苦于以下问题:PHP c_ws_plugin__s2member_user_access::user_access_role_to_level方法的具体用法?PHP c_ws_plugin__s2member_user_access::user_access_role_to_level怎么用?PHP c_ws_plugin__s2member_user_access::user_access_role_to_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c_ws_plugin__s2member_user_access
的用法示例。
在下文中一共展示了c_ws_plugin__s2member_user_access::user_access_role_to_level方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: auto_process_list_server_removals
/**
* Listens to Collective EOT/MOD Events processed internally by s2Member.
*
* This is only applicable when ``['custom_reg_auto_opt_outs']`` contains related Event(s).
*
* @package s2Member\List_Servers
* @since 3.5
*
* @attaches-to ``add_action('ws_plugin__s2member_during_collective_mods');``
* @attaches-to ``add_action('ws_plugin__s2member_during_collective_eots');``
*
* @param int|string $user_id Required. A WordPress User ID, numeric string or integer.
* @param array $vars Required. An array of defined variables passed by the calling Hook.
* @param string $event Required. A specific event that triggered this call from the Action Hook.
* @param string $event_spec Required. A specific event specification *(a broader classification)*.
* @param string $mod_new_role Required if ``$event_spec === 'modification'`` (but can be empty). Role the User is being modified to.
* @param string $mod_new_user Optional. If ``$event_spec === 'modification'``, the new User object with current details.
* @param string $mod_old_user Optional. If ``$event_spec === 'modification'``, the old/previous User obj with old details.
*/
public static function auto_process_list_server_removals($user_id, $vars, $event, $event_spec, $mod_new_role = NULL, $mod_new_user = NULL, $mod_old_user = NULL)
{
global $current_site, $current_blog;
// For Multisite support.
static $auto_processed = array();
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_before_auto_process_list_server_removals', get_defined_vars());
unset($__refs, $__v);
$custom_reg_auto_op_outs = c_ws_plugin__s2member_utils_strings::wrap_deep($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_auto_opt_outs'], '/^', '$/i');
if (c_ws_plugin__s2member_list_servers::list_servers_integrated() && $user_id && is_numeric($user_id) && !in_array($user_id, $auto_processed) && is_array($vars) && is_string($event = (string) $event) && is_string($event_spec = (string) $event_spec) && (c_ws_plugin__s2member_utils_arrays::in_regex_array($event, $custom_reg_auto_op_outs) || c_ws_plugin__s2member_utils_arrays::in_regex_array($event_spec, $custom_reg_auto_op_outs)) && is_object($user = $_user = new WP_User($user_id)) && !empty($user->ID)) {
$mod_new_role = $event_spec === 'modification' && $mod_new_role && is_string($mod_new_role) ? $mod_new_role : FALSE;
// Might be empty(i.e. they now have NO Role).
$mod_new_user = $event_spec === 'modification' && $mod_new_user && is_object($mod_new_user) && !empty($mod_new_user->ID) && $mod_new_user->ID === $_user->ID ? $mod_new_user : FALSE;
$mod_old_user = $event_spec === 'modification' && $mod_old_user && is_object($mod_old_user) && !empty($mod_old_user->ID) && $mod_old_user->ID === $_user->ID ? $mod_old_user : FALSE;
$user = $event_spec === 'modification' && $mod_old_user ? $mod_old_user : $_user;
// Now, should we switch over to the old/previous User object ``$mod_old_user`` here? Or, should we use the one pulled by this routine with the User's ID?
if (($event_spec !== 'modification' || $event_spec === 'modification' && (string) $mod_new_role !== c_ws_plugin__s2member_user_access::user_access_role($user) && strtotime($user->user_registered) < strtotime('-10 seconds') && ($event !== 'user-role-change' || $event === 'user-role-change' && !empty($vars['_p']['ws_plugin__s2member_custom_reg_auto_opt_out_transitions']))) && ($auto_processed[$user->ID] = TRUE)) {
$removed = c_ws_plugin__s2member_list_servers::process_list_server_removals(c_ws_plugin__s2member_user_access::user_access_role($user), c_ws_plugin__s2member_user_access::user_access_level($user), $user->user_login, FALSE, $user->user_email, $user->first_name, $user->last_name, FALSE, TRUE, $user->ID);
if ($event_spec === 'modification' && $mod_new_role && ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_auto_opt_out_transitions'] === '2' || $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_auto_opt_out_transitions'] === '1' && $removed)) {
$user = $event_spec === 'modification' && $mod_new_user ? $mod_new_user : $_user;
// Now, should we switch over to a new/current User object ``$mod_new_user`` here? (which may contain newly updated details). Or, should we simply use the User object pulled by this routine with the User's ID?
$transitioned = c_ws_plugin__s2member_list_servers::process_list_servers($mod_new_role, c_ws_plugin__s2member_user_access::user_access_role_to_level($mod_new_role), $user->user_login, FALSE, $user->user_email, $user->first_name, $user->last_name, FALSE, TRUE, $removed ? FALSE : TRUE, $user->ID);
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_during_auto_process_list_server_removal_transitions', get_defined_vars());
unset($__refs, $__v);
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_during_auto_process_list_server_removals', get_defined_vars());
unset($__refs, $__v);
}
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_after_auto_process_list_server_removals', get_defined_vars());
unset($__refs, $__v);
}
示例2: users_list_update_cols
/**
* Saves Custom Fields after an admin updates Profile.
*
* @package s2Member\Users_List
* @since 3.5
*
* @attaches-to ``add_action("edit_user_profile_update");``
* @attaches-to ``add_action("personal_options_update");``
*
* @param int|str $user_id Expects a numeric WordPress User ID passed in by the Action Hook.
* @return null
*/
public static function users_list_update_cols($user_id = FALSE)
{
global $current_site, $current_blog;
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_before_users_list_update_cols", get_defined_vars());
unset($__refs, $__v);
$user = new WP_User($user_id);
$current_user = is_user_logged_in() ? wp_get_current_user() : false;
if (is_object($user) && !empty($user->ID) && ($user_id = $user->ID) && is_object($current_user) && !empty($current_user->ID)) {
if (current_user_can("edit_users") && (!is_multisite() || is_super_admin() || is_user_member_of_blog($user_id))) {
if (!empty($_POST) && is_array($_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)))) {
$old_user = unserialize(serialize($user));
$old_role = c_ws_plugin__s2member_user_access::user_access_role($old_user);
$role = isset($_p["role"]) && $_p["role"] !== $old_role ? $_p["role"] : $old_role;
$level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role);
$user->roles = isset($_p["role"]) && $_p["role"] !== $old_role ? array($_p["role"]) : $old_user->roles;
$user->user_email = isset($_p["email"]) && is_email($_p["email"]) && $_p["email"] !== $old_user->user_email && !email_exists($_p["email"]) ? $_p["email"] : $old_user->user_email;
$user->first_name = isset($_p["first_name"]) && $_p["first_name"] !== $old_user->first_name ? $_p["first_name"] : $old_user->first_name;
$user->last_name = isset($_p["last_name"]) && $_p["last_name"] !== $old_user->last_name ? $_p["last_name"] : $old_user->last_name;
$auto_eot_time = !empty($_p["ws_plugin__s2member_profile_s2member_auto_eot_time"]) ? strtotime($_p["ws_plugin__s2member_profile_s2member_auto_eot_time"]) : "";
if ($role !== $old_role) {
// In this case, we need to fire Hook: `ws_plugin__s2member_during_collective_mods`.
do_action("ws_plugin__s2member_during_collective_mods", $user_id, get_defined_vars(), "user-role-change", "modification", $role, $user, $old_user);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_originating_blog"]) && is_multisite() && is_super_admin()) {
update_user_meta($user_id, "s2member_originating_blog", $_p["ws_plugin__s2member_profile_s2member_originating_blog"]);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_subscr_gateway"])) {
update_user_option($user_id, "s2member_subscr_gateway", $_p["ws_plugin__s2member_profile_s2member_subscr_gateway"]);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_subscr_id"])) {
update_user_option($user_id, "s2member_subscr_id", $_p["ws_plugin__s2member_profile_s2member_subscr_id"]);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_custom"])) {
update_user_option($user_id, "s2member_custom", $_p["ws_plugin__s2member_profile_s2member_custom"]);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_registration_ip"])) {
update_user_option($user_id, "s2member_registration_ip", $_p["ws_plugin__s2member_profile_s2member_registration_ip"]);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_notes"])) {
update_user_option($user_id, "s2member_notes", $_p["ws_plugin__s2member_profile_s2member_notes"]);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_auto_eot_time"]) && isset($auto_eot_time)) {
update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time);
}
if (isset($_p["ws_plugin__s2member_profile_s2member_ccaps"])) {
foreach ($user->allcaps as $cap => $cap_enabled) {
if (preg_match("/^access_s2member_ccap_/", $cap)) {
$user->remove_cap($ccap = $cap);
}
}
if (!empty($_p["ws_plugin__s2member_profile_s2member_ccaps"])) {
foreach (preg_split("/[\r\n\t\\s;,]+/", $_p["ws_plugin__s2member_profile_s2member_ccaps"]) as $ccap) {
if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) {
$user->add_cap("access_s2member_ccap_" . $ccap);
}
}
}
}
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) {
foreach (json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) {
$field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
$field_id_class = preg_replace("/_/", "-", $field_var);
if (isset($_p["ws_plugin__s2member_profile_" . $field_var])) {
if (is_array($_p["ws_plugin__s2member_profile_" . $field_var]) && !empty($_p["ws_plugin__s2member_profile_" . $field_var]) || is_string($_p["ws_plugin__s2member_profile_" . $field_var]) && strlen($_p["ws_plugin__s2member_profile_" . $field_var])) {
$fields[$field_var] = $_p["ws_plugin__s2member_profile_" . $field_var];
} else {
unset($fields[$field_var]);
}
} else {
unset($fields[$field_var]);
}
}
}
if (!empty($fields)) {
update_user_option($user_id, "s2member_custom_fields", $fields);
} else {
delete_user_option($user_id, "s2member_custom_fields");
}
if ($level > 0) {
$pr_times = get_user_option("s2member_paid_registration_times", $user_id);
$pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"];
$pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level];
update_user_option($user_id, "s2member_paid_registration_times", $pr_times);
// Update now.
}
//.........这里部分代码省略.........
示例3: handle_profile_modifications
//.........这里部分代码省略.........
$userdata['user_email'] = $_p['ws_plugin__s2member_profile_email'];
if (strcasecmp($userdata['user_email'], $user->user_email) !== 0) {
$email_change = TRUE;
}
}
}
if (!empty($_p['ws_plugin__s2member_profile_password1'])) {
if ($user->user_login !== 'demo') {
// No pass change on demo!
$userdata['user_pass'] = $_p['ws_plugin__s2member_profile_password1'];
}
}
if (!empty($_p['ws_plugin__s2member_profile_first_name'])) {
$userdata['first_name'] = $_p['ws_plugin__s2member_profile_first_name'];
}
if (!empty($_p['ws_plugin__s2member_profile_display_name'])) {
$userdata['display_name'] = $_p['ws_plugin__s2member_profile_display_name'];
}
if (!empty($_p['ws_plugin__s2member_profile_last_name'])) {
$userdata['last_name'] = $_p['ws_plugin__s2member_profile_last_name'];
}
wp_update_user(wp_slash($userdata));
// OK. Now send this array for an update.
if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) {
if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level('auto-detection', 'profile')) {
$fields = array();
// Initialize the array of fields.
$_existing_fields = get_user_option('s2member_custom_fields', $user_id);
foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) {
$field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id']));
$field_id_class = preg_replace('/_/', '-', $field_var);
if (!in_array($field['id'], $fields_applicable) || strpos($field['editable'], 'no') === 0) {
if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) {
$fields[$field_var] = $_existing_fields[$field_var];
} else {
unset($fields[$field_var]);
}
} else {
if ($field['required'] === 'yes' && (!isset($_p['ws_plugin__s2member_profile_' . $field_var]) || !is_array($_p['ws_plugin__s2member_profile_' . $field_var]) && !is_string($_p['ws_plugin__s2member_profile_' . $field_var]) || is_array($_p['ws_plugin__s2member_profile_' . $field_var]) && empty($_p['ws_plugin__s2member_profile_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_' . $field_var]) && !strlen($_p['ws_plugin__s2member_profile_' . $field_var])) || isset($_p['ws_plugin__s2member_profile_' . $field_var]) && c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_' . $field_var]), array($field))) {
if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) {
$fields[$field_var] = $_existing_fields[$field_var];
} else {
unset($fields[$field_var]);
}
} else {
if (isset($_p['ws_plugin__s2member_profile_' . $field_var])) {
if ((is_array($_p['ws_plugin__s2member_profile_' . $field_var]) && !empty($_p['ws_plugin__s2member_profile_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_' . $field_var]) && strlen($_p['ws_plugin__s2member_profile_' . $field_var])) && !c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_' . $field_var]), array($field))) {
$fields[$field_var] = $_p['ws_plugin__s2member_profile_' . $field_var];
} else {
unset($fields[$field_var]);
}
} else {
unset($fields[$field_var]);
}
}
}
}
if (!empty($fields)) {
update_user_option($user_id, 's2member_custom_fields', $fields);
} else {
// Else delete their Custom Fields?
delete_user_option($user_id, 's2member_custom_fields');
}
}
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_during_handle_profile_modifications', get_defined_vars());
unset($__refs, $__v);
clean_user_cache($user_id);
wp_cache_delete($user_id, 'user_meta');
$user = new WP_User($user_id);
// Fresh object.
if (function_exists('setup_userdata')) {
setup_userdata();
}
$role = c_ws_plugin__s2member_user_access::user_access_role($user);
$level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role);
if (!empty($_p['ws_plugin__s2member_profile_opt_in']) && $role && $level >= 0) {
c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $user->user_login, !empty($userdata['user_pass']) ? $userdata['user_pass'] : '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, TRUE, $user_id);
} else {
if ($role && $level >= 0 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in']) {
c_ws_plugin__s2member_list_servers::process_list_server_removals($role, $level, $user->user_login, !empty($userdata['user_pass']) ? $userdata['user_pass'] : '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, $user_id);
}
}
$lwp = c_ws_plugin__s2member_login_redirects::login_redirection_url($user);
$lwp = !$lwp ? get_page_link($GLOBALS['WS_PLUGIN__']['s2member']['o']['login_welcome_page']) : $lwp;
if (empty($_p['ws_plugin__s2member_sc_profile_save'])) {
echo '<script type="text/javascript">' . "\n";
echo "if(window.parent && window.parent != window) { window.parent.alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq(_x('Profile updated successfully.', 's2member-front', 's2member')) . "'); window.parent.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq($lwp) . "'; }";
echo "else if(window.opener) { window.alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq(_x('Profile updated successfully.', 's2member-front', 's2member')) . "'); window.opener.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq($lwp) . "'; window.close(); }";
echo "else { alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq(_x('Profile updated successfully.', 's2member-front', 's2member')) . "'); window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq($lwp) . "'; }";
echo '</script>' . "\n";
exit;
}
}
}
do_action('ws_plugin__s2member_after_handle_profile_modifications', get_defined_vars());
}
示例4: modify_user
/**
* Modifies an existing User.
*
* @package s2Member\API_Remote_Ops
* @since 110713
*
* @param array An input array of Remote Operation parameters.
* @return str Returns a serialized array with an `ID` element object on success,
* else returns a string beginning with `Error:` on failure; which will include details regarding the error.
*/
public static function modify_user($op = NULL)
{
if (!empty($op["op"]) && $op["op"] === "modify_user" && !empty($op["data"]) && is_array($op["data"])) {
if (!empty($op["data"]["user_id"]) && ($_user = new WP_User((int) $op["data"]["user_id"])) && !empty($_user->ID)) {
$user = $_user;
} else {
if (!empty($op["data"]["user_login"]) && ($_user = new WP_User((string) $op["data"]["user_login"])) && !empty($_user->ID)) {
$user = $_user;
} else {
return "Error: Modification failed. Unable to obtain WP_User object instance with data supplied (i.e. ID/Username not found).";
}
}
if (is_multisite() && !is_user_member_of_blog($user->ID)) {
return "Error: Modification failed. Unable to obtain WP_User object instance with data supplied (i.e. ID/Username not a part of this Blog).";
}
if (is_super_admin($user->ID) || $user->has_cap("administrator")) {
return "Error: Modification failed. This API will not modify Administrators.";
}
$userdata["ID"] = $user->ID;
if (!empty($op["data"]["user_email"])) {
if (is_email((string) $op["data"]["user_email"]) && !email_exists((string) $op["data"]["user_email"])) {
$userdata["user_email"] = (string) $op["data"]["user_email"];
}
}
if (!empty($op["data"]["user_pass"])) {
if ($user->user_login !== "demo") {
$userdata["user_pass"] = (string) $op["data"]["user_pass"];
}
}
if (!empty($op["data"]["first_name"])) {
$userdata["first_name"] = (string) $op["data"]["first_name"];
}
if (!empty($op["data"]["display_name"])) {
$userdata["display_name"] = (string) $op["data"]["display_name"];
}
if (!empty($op["data"]["last_name"])) {
$userdata["last_name"] = (string) $op["data"]["last_name"];
}
if (isset($op["data"]["s2member_level"]) && (int) $op["data"]["s2member_level"] === 0) {
if (c_ws_plugin__s2member_user_access::user_access_role($user) !== get_option("default_role")) {
$userdata["role"] = get_option("default_role");
}
} else {
if (!empty($op["data"]["s2member_level"]) && (int) $op["data"]["s2member_level"] > 0) {
if (c_ws_plugin__s2member_user_access::user_access_role($user) !== "s2member_level" . (int) $op["data"]["s2member_level"]) {
$userdata["role"] = "s2member_level" . (int) $op["data"]["s2member_level"];
}
}
}
wp_update_user($userdata);
$old_user = unserialize(serialize($user));
$user = new WP_User($user->ID);
$role = c_ws_plugin__s2member_user_access::user_access_role($user);
$level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role);
if (!empty($op["data"]["auto_opt_out_transition"])) {
$_p["ws_plugin__s2member_custom_reg_auto_opt_out_transitions"] = TRUE;
}
if (!empty($userdata["role"])) {
do_action("ws_plugin__s2member_during_collective_mods", $user->ID, get_defined_vars(), "user-role-change", "modification", $role, $user, $old_user);
}
if (!empty($op["data"]["s2member_ccaps"]) && preg_match("/^-all/", str_replace("+", "", (string) $op["data"]["s2member_ccaps"]))) {
foreach ($user->allcaps as $cap => $cap_enabled) {
if (preg_match("/^access_s2member_ccap_/", $cap)) {
$user->remove_cap($ccap = $cap);
}
}
}
if (!empty($op["data"]["s2member_ccaps"]) && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", (string) $op["data"]["s2member_ccaps"]))) {
foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", (string) $op["data"]["s2member_ccaps"]))) as $ccap) {
if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) {
$user->add_cap("access_s2member_ccap_" . $ccap);
}
}
}
if (isset($op["data"]["s2member_originating_blog"]) && is_multisite()) {
update_user_meta($user->ID, "s2member_originating_blog", (int) $op["data"]["s2member_originating_blog"]);
}
if (isset($op["data"]["s2member_subscr_gateway"])) {
update_user_option($user->ID, "s2member_subscr_gateway", (string) $op["data"]["s2member_subscr_gateway"]);
}
if (isset($op["data"]["s2member_subscr_id"])) {
update_user_option($user->ID, "s2member_subscr_id", (string) $op["data"]["s2member_subscr_id"]);
}
if (isset($op["data"]["s2member_custom"])) {
update_user_option($user->ID, "s2member_custom", (string) $op["data"]["s2member_custom"]);
}
if (isset($op["data"]["s2member_registration_ip"])) {
update_user_option($user->ID, "s2member_registration_ip", (string) $op["data"]["s2member_registration_ip"]);
}
if (isset($op["data"]["s2member_notes"])) {
//.........这里部分代码省略.........
示例5: auto_process_list_server_removals
/**
* Listens to Collective EOT/MOD Events processed internally by s2Member.
*
* This is only applicable when ``["custom_reg_auto_opt_outs"]`` contains related Event(s).
*
* @package s2Member\List_Servers
* @since 3.5
*
* @attaches-to ``add_action("ws_plugin__s2member_during_collective_mods");``
* @attaches-to ``add_action("ws_plugin__s2member_during_collective_eots");``
*
* @param int|str $user_id Required. A WordPress User ID, numeric string or integer.
* @param array $vars Required. An array of defined variables passed by the calling Hook.
* @param str $event Required. A specific event that triggered this call from the Action Hook.
* @param str $event_spec Required. A specific event specification *(a broader classification)*.
* @param str $mod_new_role Required if ``$event_spec === "modification"`` (but can be empty). Role the User is being modified to.
* @param str $mod_new_user Optional. If ``$event_spec === "modification"``, the new User object with current details.
* @param str $mod_old_user Optional. If ``$event_spec === "modification"``, the old/previous User obj with old details.
* @return null This function does not have a return value.
*/
public static function auto_process_list_server_removals($user_id = FALSE, $vars = FALSE, $event = FALSE, $event_spec = FALSE, $mod_new_role = FALSE, $mod_new_user = FALSE, $mod_old_user = FALSE)
{
global $current_site, $current_blog;
static $auto_processed = array();
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_before_auto_process_list_server_removals", get_defined_vars());
unset($__refs, $__v);
$custom_reg_auto_op_outs = c_ws_plugin__s2member_utils_strings::wrap_deep($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_auto_opt_outs"], "/^", "\$/i");
if (c_ws_plugin__s2member_list_servers::list_servers_integrated() && $user_id && is_numeric($user_id) && !in_array($user_id, $auto_processed) && is_array($vars) && is_string($event = (string) $event) && is_string($event_spec = (string) $event_spec) && (c_ws_plugin__s2member_utils_arrays::in_regex_array($event, $custom_reg_auto_op_outs) || c_ws_plugin__s2member_utils_arrays::in_regex_array($event_spec, $custom_reg_auto_op_outs)) && is_object($user = $_user = new WP_User($user_id)) && !empty($user->ID)) {
$mod_new_role = $event_spec === "modification" && $mod_new_role && is_string($mod_new_role) ? $mod_new_role : false;
$mod_new_user = $event_spec === "modification" && $mod_new_user && is_object($mod_new_user) && !empty($mod_new_user->ID) && $mod_new_user->ID === $_user->ID ? $mod_new_user : false;
$mod_old_user = $event_spec === "modification" && $mod_old_user && is_object($mod_old_user) && !empty($mod_old_user->ID) && $mod_old_user->ID === $_user->ID ? $mod_old_user : false;
$user = $event_spec === "modification" && $mod_old_user ? $mod_old_user : $_user;
// Now, should we switch over to the old/previous User object ``$mod_old_user`` here? Or, should we use the one pulled by this routine with the User's ID?
if (($event_spec !== "modification" || $event_spec === "modification" && (string) $mod_new_role !== c_ws_plugin__s2member_user_access::user_access_role($user) && strtotime($user->user_registered) < strtotime("-10 seconds") && ($event !== "user-role-change" || $event === "user-role-change" && !empty($vars["_p"]["ws_plugin__s2member_custom_reg_auto_opt_out_transitions"]))) && ($auto_processed[$user->ID] = true)) {
$removed = c_ws_plugin__s2member_list_servers::process_list_server_removals(c_ws_plugin__s2member_user_access::user_access_role($user), c_ws_plugin__s2member_user_access::user_access_level($user), $user->user_login, false, $user->user_email, $user->first_name, $user->last_name, false, true, $user->ID);
if ($event_spec === "modification" && $mod_new_role && ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_auto_opt_out_transitions"] === "2" || $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_auto_opt_out_transitions"] === "1" && $removed)) {
$user = $event_spec === "modification" && $mod_new_user ? $mod_new_user : $_user;
// Now, should we switch over to a new/current User object ``$mod_new_user`` here? (which may contain newly updated details). Or, should we simply use the User object pulled by this routine with the User's ID?
$transitioned = c_ws_plugin__s2member_list_servers::process_list_servers($mod_new_role, c_ws_plugin__s2member_user_access::user_access_role_to_level($mod_new_role), $user->user_login, false, $user->user_email, $user->first_name, $user->last_name, false, true, $removed ? false : true, $user->ID);
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_during_auto_process_list_server_removal_transitions", get_defined_vars());
unset($__refs, $__v);
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_during_auto_process_list_server_removals", get_defined_vars());
unset($__refs, $__v);
}
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_after_auto_process_list_server_removals", get_defined_vars());
unset($__refs, $__v);
return;
}
示例6: modify_user
/**
* Modifies an existing User.
*
* @package s2Member\API_Remote_Ops
* @since 110713
*
* @param array $op An input array of Remote Operation parameters.
*
* @return string Returns a serialized array with an `ID` element object on success,
* else returns a string beginning with `Error:` on failure; which will include details regarding the error.
*/
public static function modify_user($op = NULL)
{
if (!empty($op['op']) && $op['op'] === 'modify_user' && !empty($op['data']) && is_array($op['data'])) {
if (!empty($op['data']['user_id']) && ($_user = new WP_User((int) $op['data']['user_id'])) && !empty($_user->ID)) {
$user = $_user;
} else {
if (!empty($op['data']['user_login']) && ($_user = new WP_User((string) $op['data']['user_login'])) && !empty($_user->ID)) {
$user = $_user;
} else {
return 'Error: Modification failed. Unable to obtain WP_User object instance with data supplied (i.e., ID/Username not found).';
}
}
if (is_multisite() && !is_user_member_of_blog($user->ID)) {
return 'Error: Modification failed. Unable to obtain WP_User object instance with data supplied (i.e., ID/Username not a part of this Blog).';
}
if (is_super_admin($user->ID) || $user->has_cap('administrator')) {
return 'Error: Modification failed. This API will not modify Administrators.';
}
$userdata['ID'] = $user->ID;
// Needed for database update.
if (!empty($op['data']['user_email'])) {
if (is_email((string) $op['data']['user_email']) && !email_exists((string) $op['data']['user_email'])) {
$userdata['user_email'] = (string) $op['data']['user_email'];
}
}
if (!empty($op['data']['user_pass'])) {
if ($user->user_login !== 'demo') {
$userdata['user_pass'] = (string) $op['data']['user_pass'];
}
}
if (!empty($op['data']['first_name'])) {
$userdata['first_name'] = (string) $op['data']['first_name'];
}
if (!empty($op['data']['display_name'])) {
$userdata['display_name'] = (string) $op['data']['display_name'];
}
if (!empty($op['data']['last_name'])) {
$userdata['last_name'] = (string) $op['data']['last_name'];
}
if (isset($op['data']['s2member_level']) && (int) $op['data']['s2member_level'] === 0) {
if (c_ws_plugin__s2member_user_access::user_access_role($user) !== get_option('default_role')) {
$userdata['role'] = get_option('default_role');
}
} else {
if (!empty($op['data']['s2member_level']) && (int) $op['data']['s2member_level'] > 0) {
if (c_ws_plugin__s2member_user_access::user_access_role($user) !== 's2member_level' . (int) $op['data']['s2member_level']) {
$userdata['role'] = 's2member_level' . (int) $op['data']['s2member_level'];
}
}
}
wp_update_user(wp_slash($userdata));
// OK. Now send this array for an update.
$old_user = unserialize(serialize($user));
// Copy existing user obj.
$user = new WP_User($user->ID);
// Update our object instance.
$role = c_ws_plugin__s2member_user_access::user_access_role($user);
$level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role);
if (!empty($op['data']['auto_opt_out_transition'])) {
$_p['ws_plugin__s2member_custom_reg_auto_opt_out_transitions'] = TRUE;
}
if (!empty($userdata['role'])) {
do_action('ws_plugin__s2member_during_collective_mods', $user->ID, get_defined_vars(), 'user-role-change', 'modification', $role, $user, $old_user);
}
if (!empty($op['data']['s2member_ccaps']) && preg_match('/^-all/', str_replace('+', '', (string) $op['data']['s2member_ccaps']))) {
foreach ($user->allcaps as $cap => $cap_enabled) {
if (preg_match('/^access_s2member_ccap_/', $cap)) {
$user->remove_cap($ccap = $cap);
}
}
}
if (!empty($op['data']['s2member_ccaps']) && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', (string) $op['data']['s2member_ccaps']))) {
foreach (preg_split('/[\\r\\n\\t\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', (string) $op['data']['s2member_ccaps']))) as $ccap) {
if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) {
$user->add_cap('access_s2member_ccap_' . $ccap);
}
}
}
if (isset($op['data']['s2member_originating_blog']) && is_multisite()) {
update_user_meta($user->ID, 's2member_originating_blog', (int) $op['data']['s2member_originating_blog']);
}
if (isset($op['data']['s2member_subscr_gateway'])) {
update_user_option($user->ID, 's2member_subscr_gateway', (string) $op['data']['s2member_subscr_gateway']);
}
if (isset($op['data']['s2member_subscr_id'])) {
update_user_option($user->ID, 's2member_subscr_id', (string) $op['data']['s2member_subscr_id']);
}
if (isset($op['data']['s2member_custom'])) {
update_user_option($user->ID, 's2member_custom', (string) $op['data']['s2member_custom']);
//.........这里部分代码省略.........
示例7: handle_profile_modifications_4bp
/**
* Handles Profile modifications for Custom Fields *(created with s2Member)*; integrated with BuddyPress.
*
* @package s2Member\Profiles
* @since 3.5
*
* @attaches-to ``add_action('xprofile_updated_profile');``
*/
public static function handle_profile_modifications_4bp()
{
global $current_user;
// We'll need to update this global object.
$user =& $current_user;
// Shorter reference to the ``$current_user`` object.
do_action('ws_plugin__s2member_before_handle_profile_modifications_4bp', get_defined_vars());
if (!empty($_POST['ws_plugin__s2member_profile_4bp_save']) && is_user_logged_in() && is_object($user) && !empty($user->ID) && ($user_id = $user->ID)) {
if (($nonce = $_POST['ws_plugin__s2member_profile_4bp_save']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-profile-4bp-save')) {
$GLOBALS['ws_plugin__s2member_profile_4bp_saved'] = TRUE;
// Global flag as having been saved/updated successfully.
$_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST));
// Clean ``$_POST`` vars.
if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) {
if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level('auto-detection', 'profile')) {
$fields = array();
// Initialize the array of fields.
$_existing_fields = get_user_option('s2member_custom_fields', $user_id);
foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) {
$field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id']));
$field_id_class = preg_replace('/_/', '-', $field_var);
if (!in_array($field['id'], $fields_applicable) || strpos($field['editable'], 'no') === 0) {
if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) {
$fields[$field_var] = $_existing_fields[$field_var];
} else {
unset($fields[$field_var]);
}
} else {
if ($field['required'] === 'yes' && (!isset($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || !is_array($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && !is_string($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || is_array($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && empty($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && !strlen($_p['ws_plugin__s2member_profile_4bp_' . $field_var])) || isset($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_4bp_' . $field_var]), array($field))) {
if (isset($_existing_fields[$field_var]) && (is_array($_existing_fields[$field_var]) && !empty($_existing_fields[$field_var]) || is_string($_existing_fields[$field_var]) && strlen($_existing_fields[$field_var]))) {
$fields[$field_var] = $_existing_fields[$field_var];
} else {
unset($fields[$field_var]);
}
} else {
if (isset($_p['ws_plugin__s2member_profile_4bp_' . $field_var])) {
if ((is_array($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && !empty($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) || is_string($_p['ws_plugin__s2member_profile_4bp_' . $field_var]) && strlen($_p['ws_plugin__s2member_profile_4bp_' . $field_var])) && !c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_4bp_' . $field_var]), array($field))) {
$fields[$field_var] = $_p['ws_plugin__s2member_profile_4bp_' . $field_var];
} else {
unset($fields[$field_var]);
}
} else {
unset($fields[$field_var]);
}
}
}
}
if (!empty($fields)) {
update_user_option($user_id, 's2member_custom_fields', $fields);
} else {
// Else delete their Custom Fields?
delete_user_option($user_id, 's2member_custom_fields');
}
}
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_during_handle_profile_modifications_4bp', get_defined_vars());
unset($__refs, $__v);
clean_user_cache($user_id);
wp_cache_delete($user_id, 'user_meta');
$user = new WP_User($user_id);
// Fresh object.
if (function_exists('setup_userdata')) {
setup_userdata();
}
$role = c_ws_plugin__s2member_user_access::user_access_role($user);
$level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role);
if (!empty($_p['ws_plugin__s2member_profile_4bp_opt_in']) && $role && $level >= 0) {
c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $user->user_login, '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, TRUE, $user_id);
} else {
if ($role && $level >= 0 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in']) {
c_ws_plugin__s2member_list_servers::process_list_server_removals($role, $level, $user->user_login, '', $user->user_email, $user->first_name, $user->last_name, $_SERVER['REMOTE_ADDR'], TRUE, $user_id);
}
}
}
}
do_action('ws_plugin__s2member_after_handle_profile_modifications_4bp', get_defined_vars());
}
示例8: auto_process_list_server_removals
/**
* Listens to Collective EOT/MOD events processed by s2Member.
*
* @since 3.5
* @package s2Member\List_Servers
*
* @attaches-to `add_action('ws_plugin__s2member_during_collective_mods');`.
* @attaches-to `add_action('ws_plugin__s2member_during_collective_eots');`.
*
* @param int|string $user_id Required. A WordPress User ID, numeric string or integer.
* @param array $vars Required. An array of defined variables passed by the calling hook.
* @param string $event Required. A specific event that triggered this call from the action hook.
* @param string $event_spec Required. A specific event specification *(a broader classification)*.
* @param string $mod_new_role Required if `$event_spec === 'modification'`; but can be empty. User role.
* @param string $mod_new_user Optional. If `$event_spec === 'modification'`, the new user object with current details.
* @param string $mod_old_user Optional. If `$event_spec === 'modification'`, the old/previous user obj with old details.
*
* @note This is only applicable when `['custom_reg_auto_opt_outs']` contains related Event(s).
*/
public static function auto_process_list_server_removals($user_id, $vars, $event, $event_spec, $mod_new_role = NULL, $mod_new_user = NULL, $mod_old_user = NULL)
{
static $auto_processed = array();
// Static cache.
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_before_auto_process_list_server_removals', get_defined_vars());
unset($__refs, $__v);
// Allows vars to be modified by reference.
if (c_ws_plugin__s2member_list_servers::list_servers_integrated()) {
if ($user_id && is_numeric($user_id) && !isset($auto_processed[$user_id])) {
if (is_array($vars) && is_string($event = (string) $event) && is_string($event_spec = (string) $event_spec)) {
if ($custom_reg_auto_op_outs = c_ws_plugin__s2member_utils_strings::wrap_deep($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_auto_opt_outs'], '/^', '$/i')) {
if (c_ws_plugin__s2member_utils_arrays::in_regex_array($event, $custom_reg_auto_op_outs) || c_ws_plugin__s2member_utils_arrays::in_regex_array($event_spec, $custom_reg_auto_op_outs)) {
if (is_object($dynamic_user = $user_now = new WP_User($user_id)) && $dynamic_user->exists() && !empty($dynamic_user->ID)) {
$mod_new_role = $event_spec === 'modification' && is_string($mod_new_role) ? $mod_new_role : '';
// Might be empty.
$mod_new_user = $event_spec === 'modification' && !empty($mod_new_user->ID) && $mod_new_user->ID === $dynamic_user->ID ? $mod_new_user : NULL;
$mod_old_user = $event_spec === 'modification' && !empty($mod_old_user->ID) && $mod_old_user->ID === $dynamic_user->ID ? $mod_old_user : NULL;
$dynamic_user = $event_spec === 'modification' && $mod_old_user ? $mod_old_user : $user_now;
// Use old user when applicable.
if ($event_spec !== 'modification' || $event_spec === 'modification' && $mod_new_role !== c_ws_plugin__s2member_user_access::user_access_role($dynamic_user) && strtotime($dynamic_user->user_registered) < strtotime('-10 seconds') && ($event !== 'user-role-change' || $event === 'user-role-change' && !empty($vars['_p']['ws_plugin__s2member_custom_reg_auto_opt_out_transitions']))) {
$auto_processed[$dynamic_user->ID] = -1;
// Flag as auto-processed!
$auto_removal_success = c_ws_plugin__s2member_list_servers::process_list_server_removals(c_ws_plugin__s2member_user_access::user_access_role($dynamic_user), c_ws_plugin__s2member_user_access::user_access_level($dynamic_user), $dynamic_user->user_login, '', $dynamic_user->user_email, $dynamic_user->first_name, $dynamic_user->last_name, '', TRUE, $dynamic_user->ID);
if ($event_spec === 'modification' && $mod_new_role && ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_auto_opt_out_transitions'] === '2' || $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_auto_opt_out_transitions'] === '1' && $auto_removal_success)) {
$dynamic_user = $event_spec === 'modification' && $mod_new_user ? $mod_new_user : $user_now;
// New user; when applicable.
$auto_transition_success = c_ws_plugin__s2member_list_servers::process_list_servers($mod_new_role, c_ws_plugin__s2member_user_access::user_access_role_to_level($mod_new_role), $dynamic_user->user_login, '', $dynamic_user->user_email, $dynamic_user->first_name, $dynamic_user->last_name, '', TRUE, $auto_removal_success ? FALSE : TRUE, $dynamic_user->ID);
do_action('ws_plugin__s2member_during_auto_process_list_server_removal_transitions', get_defined_vars());
}
do_action('ws_plugin__s2member_during_auto_process_list_server_removals', get_defined_vars());
}
}
}
}
}
}
}
do_action('ws_plugin__s2member_after_auto_process_list_server_removals', get_defined_vars());
}