/** * For Multisite Networks, this function is used to add a User to an existing Blog; and to simulate ``wp_create_user()`` behavior. * * The ``$user_id`` value will be returned by this function, just like ``wp_create_user()`` does. * This function will fire the Hook `user_register`. * * @package s2Member\Registrations * @since 3.5 * * @param str $user_login Expects the User's Username. * @param str $user_email Expects the User's Email Address. * @param str $user_pass Expects the User's plain text Password. * @param int|str $user_id Optional. A numeric WordPress User ID. * If unspecified, a lookup is performed with ``$user_login`` and ``$user_email``. * @return int|false Returns numeric ``$user_id`` on success, else false on failure. */ public static function ms_create_existing_user($user_login = FALSE, $user_email = FALSE, $user_pass = FALSE, $user_id = FALSE) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_before_ms_create_existing_user", get_defined_vars()); unset($__refs, $__v); if (is_multisite()) { if (($user_id || ($user_id = c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($user_login, $user_email))) && $user_pass) { $role = get_option("default_role"); // Use default Role. add_existing_user_to_blog(array("user_id" => $user_id, "role" => $role)); // Add User. wp_update_user(array("ID" => $user_id, "user_pass" => $user_pass)); // Update to ``$user_pass``. do_action("ws_plugin__s2member_during_ms_create_existing_user", get_defined_vars()); do_action("user_register", $user_id); // So s2Member knows a User is registering. return apply_filters("ws_plugin__s2member_ms_create_existing_user", $user_id, get_defined_vars()); } } return apply_filters("ws_plugin__s2member_ms_create_existing_user", false, get_defined_vars()); }
/** * Handles the importation of Users/Members. * * @package s2Member\Imports * @since 110815 * * @return null */ public static function import_users() { if (!empty($_POST["ws_plugin__s2member_pro_import_users"]) && ($nonce = $_POST["ws_plugin__s2member_pro_import_users"]) && wp_verify_nonce($nonce, "ws-plugin--s2member-pro-import-users") && current_user_can("create_users")) { global $wpdb; global $current_site, $current_blog; @set_time_limit(0); @ini_set("memory_limit", apply_filters("admin_memory_limit", WP_MAX_MEMORY_LIMIT)); remove_all_actions("profile_update") . remove_all_actions("user_register"); remove_all_actions("added_existing_user") . remove_all_actions("add_user_to_blog"); if (!empty($_FILES["ws_plugin__s2member_pro_import_users_file"]) && empty($_FILES["ws_plugin__s2member_pro_import_users_file"]["error"])) { $file = fopen($_FILES["ws_plugin__s2member_pro_import_users_file"]["tmp_name"], "r"); } else { if (!empty($_POST["ws_plugin__s2member_pro_import_users_direct_input"])) { fwrite($file = tmpfile(), trim(stripslashes($_POST["ws_plugin__s2member_pro_import_users_direct_input"]))) . fseek($file, 0); } } if (isset($file) && is_resource($file) && !($imported = 0)) { $custom_field_vars = array(); if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], TRUE) as $field) { $custom_field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $custom_field_vars[] = $custom_field_var; } } sort($custom_field_vars, SORT_STRING); while (($data = version_compare(PHP_VERSION, "5.3", ">=") ? fgetcsv($file, 0, ",", '"', '"') : fgetcsv($file, 0, ",", '"')) !== false) { $line = (int) $line + 1; $data = c_ws_plugin__s2member_utils_strings::trim_deep($data); $data = stripslashes_deep($data); if ($line === 1 && strtoupper($data[0]) === "ID") { $line = $line - 1; continue; } if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { $ID = $data[0]; $user_login = is_multisite() ? strtolower($data[1]) : $data[1]; $user_login = preg_replace("/\\s+/", "", sanitize_user($user_login, is_multisite())); $user_pass = (string) ""; $first_name = $data[2]; $last_name = $data[3]; $display_name = $data[4]; $user_email = sanitize_email($data[5]); $user_url = $data[6]; $role = $data[7]; $custom_capabilities = $data[8]; $user_registered = $data[9] ? date("Y-m-d H:i:s", strtotime($data[9])) : ""; $paid_registration_times = $data[10] ? maybe_unserialize($data[10]) : ""; $last_payment_time = $data[11] ? strtotime($data[11]) : ""; $auto_eot_time = $data[12] ? strtotime($data[12]) : ""; $custom = $data[13]; $subscr_id = $data[14]; $subscr_gateway = strtolower($data[15]); $custom_fields = array(); if (count($data) > 16) { for ($i = 16, $j = 0; $i < count($data); $i++, $j++) { if (isset($custom_field_vars[$j])) { $custom_fields[$custom_field_vars[$j]] = maybe_unserialize($data[$i]); } } } } else { $ID = $data[0]; $user_login = is_multisite() ? strtolower($data[1]) : $data[1]; $user_login = preg_replace("/\\s+/", "", sanitize_user($user_login, is_multisite())); $user_pass = $data[2]; $first_name = $data[3]; $last_name = $data[4]; $display_name = $data[5]; $user_email = sanitize_email($data[6]); $user_url = $data[7]; $role = $data[8]; $custom_capabilities = $data[9]; $user_registered = $data[10] ? date("Y-m-d H:i:s", strtotime($data[10])) : ""; $paid_registration_times = $data[11] ? maybe_unserialize($data[11]) : ""; $last_payment_time = $data[12] ? strtotime($data[12]) : ""; $auto_eot_time = $data[13] ? strtotime($data[13]) : ""; $custom = $data[14]; $subscr_id = $data[15]; $subscr_gateway = strtolower($data[16]); $custom_fields = array(); if (count($data) > 17) { for ($i = 17, $j = 0; $i < count($data); $i++, $j++) { if (isset($custom_field_vars[$j])) { $custom_fields[$custom_field_vars[$j]] = maybe_unserialize($data[$i]); } } } } $role = is_numeric($role) ? $role == 0 ? "subscriber" : "s2member_level" . $role : $role; if ($paid_registration_times && !is_array($paid_registration_times)) { $paid_registration_times = array("level" => strtotime($paid_registration_times)); } $paid_registration_times = !$paid_registration_times || !is_array($paid_registration_times) ? array() : $paid_registration_times; $user_details = compact("ID", "user_login", "user_pass", "first_name", "last_name", "display_name", "user_email", "user_url", "role", "user_registered"); if (empty($user_details["user_pass"])) { // If there was NO Password given. unset($user_details["user_pass"]); } // Unset the Password array element. if ($ID) { if (is_object($user = new WP_User($ID)) && $user->ID) { if (!is_multisite() || is_user_member_of_blog($ID)) { if ((!is_multisite() || !is_super_admin($ID)) && !$user->has_cap("administrator")) { if (strtolower($role) !== "administrator") { if ($user_email && is_email($user_email)) { if ($user_login) { if (validate_username($user_login)) { if (($_same_email = strtolower($user_email) === strtolower($user->user_email)) || !email_exists($user_email)) { if (($_same_login = strtolower($user_login) === strtolower($user->user_login)) || !username_exists($user_login)) { if (!is_multisite() || $_same_email && $_same_login || ($_ = wpmu_validate_user_signup($user_login, $user_email)) && (!is_wp_error($_["errors"]) || !$_["errors"]->get_error_code())) { if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { unset($user_details["user_login"], $user_details["user_pass"]); } if ($user_id = wp_update_user($user_details)) { $user = new WP_User($ID); // Refresh object value. update_user_option($user_id, "s2member_custom", $custom); update_user_option($user_id, "s2member_subscr_id", $subscr_id); update_user_option($user_id, "s2member_subscr_gateway", $subscr_gateway); update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time); update_user_option($user_id, "s2member_paid_registration_times", $paid_registration_times); update_user_option($user_id, "s2member_last_payment_time", $last_payment_time); update_user_option($user_id, "s2member_custom_fields", $custom_fields); foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } if ($custom_capabilities && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $custom_capabilities))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $custom_capabilities))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_s2member_ccap_" . $ccap); } } } $imported = $imported + 1; } else { $errors[] = "Line #" . $line . ". User ID# <code>" . $ID . "</code> could NOT be updated. Unknown error, please try again."; } } else { $errors[] = "Line #" . $line . ". Network. The Username and/or Email (<code>" . esc_html($user_login) . "</code> / <code>" . esc_html($user_email) . "</code>) are in conflict w/ Network rules."; } } else { $errors[] = "Line #" . $line . ". Conflicting. The Username (<code>" . esc_html($user_login) . "</code>), already exists."; } } else { $errors[] = "Line #" . $line . ". Conflicting. The Email address (<code>" . esc_html($user_email) . "</code>), already exists."; } } else { $errors[] = "Line #" . $line . ". Invalid Username (<code>" . esc_html($user_login) . "</code>). Lowercase alphanumerics are required."; } } else { $errors[] = "Line #" . $line . ". Missing Username; please try again."; } // We have two separate errors for Usernames. This provides clarity. } else { $errors[] = "Line #" . $line . ". Missing or invalid Email address (<code>" . esc_html($user_email) . "</code>); please try again."; } } else { $errors[] = "Line #" . $line . ". User ID# <code>" . $ID . "</code> cannot be updated to an Administrator. Bypassing this line for security."; } } else { $errors[] = "Line #" . $line . ". User ID# <code>" . $ID . "</code> belongs to an Administrator. Bypassing this line for security."; } } else { $errors[] = "Line #" . $line . ". User ID# <code>" . $ID . "</code> does NOT belong to an existing User on this site."; } } else { $errors[] = "Line #" . $line . ". User ID# <code>" . $ID . "</code> does NOT belong to an existing User."; } } else { if (is_multisite() && ($user_id = c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($user_login, $user_email)) && !is_super_admin($user_id)) { if (strtolower($role) !== "administrator") { if (add_existing_user_to_blog(array("user_id" => $user_id, "role" => $role))) { if (is_object($user = new WP_User($user_id)) && $user->ID) { update_user_option($user_id, "s2member_custom", $custom); update_user_option($user_id, "s2member_subscr_id", $subscr_id); update_user_option($user_id, "s2member_subscr_gateway", $subscr_gateway); update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time); update_user_option($user_id, "s2member_paid_registration_times", $paid_registration_times); update_user_option($user_id, "s2member_last_payment_time", $last_payment_time); update_user_option($user_id, "s2member_custom_fields", $custom_fields); foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } if ($custom_capabilities && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $custom_capabilities))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $custom_capabilities))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_s2member_ccap_" . $ccap); } } } $imported = $imported + 1; } else { $errors[] = "Line #" . $line . ". Unknown object error, please try again."; } } else { $errors[] = "Line #" . $line . ". Unknown User/site addition error, please try again."; } } else { $errors[] = "Line #" . $line . ". Role cannot be Administrator. Bypassing this line for security."; } } else { if (strtolower($role) !== "administrator") { if ($user_email && is_email($user_email)) { if ($user_login) { if (validate_username($user_login)) { if (!email_exists($user_email)) { if (!username_exists($user_login)) { if (!is_multisite() || ($_ = wpmu_validate_user_signup($user_login, $user_email)) && (!is_wp_error($_["errors"]) || !$_["errors"]->get_error_code())) { if ($user_id = wp_insert_user($user_details)) { if (is_object($user = new WP_User($user_id)) && $user->ID) { if ($user_pass) { // If we are given an "un-encrypted Password". wp_update_user(array("ID" => $user_id, "user_pass" => $user_pass)); } if (is_multisite()) { // New Users on a Multisite Network need this too. update_user_meta($user_id, "s2member_originating_blog", $current_blog->blog_id); } update_user_option($user_id, "s2member_custom", $custom); update_user_option($user_id, "s2member_subscr_id", $subscr_id); update_user_option($user_id, "s2member_subscr_gateway", $subscr_gateway); update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time); update_user_option($user_id, "s2member_paid_registration_times", $paid_registration_times); update_user_option($user_id, "s2member_last_payment_time", $last_payment_time); update_user_option($user_id, "s2member_custom_fields", $custom_fields); foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } if ($custom_capabilities && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $custom_capabilities))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $custom_capabilities))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_s2member_ccap_" . $ccap); } } } $imported = $imported + 1; } else { $errors[] = "Line #" . $line . ". Unknown object error, please try again."; } } else { $errors[] = "Line #" . $line . ". Unknown insertion error, please try again."; } } else { $errors[] = "Line #" . $line . ". Network. The Username and/or Email (<code>" . esc_html($user_login) . "</code> / <code>" . esc_html($user_email) . "</code>) are in conflict w/ Network rules."; } } else { $errors[] = "Line #" . $line . ". Conflicting. The Username (<code>" . esc_html($user_login) . "</code>), already exists."; } } else { $errors[] = "Line #" . $line . ". Conflicting. The Email address (<code>" . esc_html($user_email) . "</code>), already exists."; } } else { $errors[] = "Line #" . $line . ". Invalid Username (<code>" . esc_html($user_login) . "</code>). Lowercase alphanumerics are required."; } } else { $errors[] = "Line #" . $line . ". Missing Username; please try again."; } // We have two separate errors for Usernames. This provides clarity. } else { $errors[] = "Line #" . $line . ". Missing or invalid Email address (<code>" . esc_html($user_email) . "</code>); please try again."; } } else { $errors[] = "Line #" . $line . ". Role cannot be Administrator. Bypassing this line for security."; } } } } fclose($file); } else { $errors[] = "No data was received. Please try again."; } // The upload failed, or it was empty. c_ws_plugin__s2member_admin_notices::display_admin_notice('Operation complete. Users/Members imported: <code>' . (int) $imported . '</code>.'); if (!empty($errors)) { // Here is where a detailed error log will be returned to the Site Owner; as a way of clarifying what just happened during importation. c_ws_plugin__s2member_admin_notices::display_admin_notice('<strong>The following errors were encountered during importation:</strong><ul style="font-size:80%; list-style:disc outside; margin-left:25px;"><li>' . implode("</li><li>", $errors) . '</li></ul>', true); } } return; }
/** * Handles the importation of Users/Members. * * @package s2Member\Imports * @since 110815 */ public static function import_users() { if (!empty($_POST['ws_plugin__s2member_pro_import_users']) && ($nonce = $_POST['ws_plugin__s2member_pro_import_users']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-pro-import-users') && current_user_can('create_users')) { global $wpdb; // Global database object reference. /** @var \wpdb $wpdb This line for IDEs that need a reference. */ global $current_site, $current_blog; // Multisite Networking. @set_time_limit(0); // Make time for processing large import files. @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); remove_all_actions('profile_update') . remove_all_actions('user_register'); remove_all_actions('added_existing_user') . remove_all_actions('add_user_to_blog'); if (!empty($_FILES['ws_plugin__s2member_pro_import_users_file']) && empty($_FILES['ws_plugin__s2member_pro_import_users_file']['error'])) { $file = fopen($_FILES['ws_plugin__s2member_pro_import_users_file']['tmp_name'], 'r'); } else { if (!empty($_POST['ws_plugin__s2member_pro_import_users_direct_input'])) { fwrite($file = tmpfile(), trim(stripslashes($_POST['ws_plugin__s2member_pro_import_users_direct_input']))) . fseek($file, 0); } } $imported = $line = $line_index = 0; // Initialize these counters. $headers = array(); // Initialize the array of CSV import file headers. $user_keys = array(); // Initialize array of user keys. if (is_object($_user_row = $wpdb->get_row("SELECT * FROM `" . $wpdb->users . "` LIMIT 1"))) { foreach (array_keys((array) $_user_row) as $_user_key) { $user_keys[] = $_user_key; } } unset($_user_row, $_user_key); // Housekeeping. $user_keys = array_unique($user_keys); // Only unique keys please. if (isset($file) && is_resource($file)) { while (($_csv_data = version_compare(PHP_VERSION, '5.3', '>=') ? fgetcsv($file, 0, ',', '"', '"') : fgetcsv($file, 0, ',', '"')) !== FALSE) { $line_index = (int) $line_index + 1; // CSV lines. $line = (int) $line + 1; // CSV lines. $_csv_data = c_ws_plugin__s2member_utils_strings::trim_deep($_csv_data); if ($line_index === 1 && isset($_csv_data[0])) { $line = $line - 1; foreach ($_csv_data as $_header) { $headers[] = $_header; } unset($_header); // Housekeeping. continue; // We've got the headers now; let's move to the next line. } if ($line_index >= 1 && (!$headers || !in_array('ID', $headers, TRUE) && !in_array('user_login', $headers, TRUE))) { $errors[] = 'Line #' . $line . '. Missing first-line CSV headers; please try again.' . ' Please note that your CSV headers MUST contain (at a minimum), one of: "ID", or "user_login"'; break; // Stop here; we have no headers in this importation. } $_user_ID_key = array_search('ID', $headers); $_user_id = $_user_ID_key !== FALSE && !empty($_csv_data[$_user_ID_key]) ? (int) $_csv_data[$_user_ID_key] : 0; unset($_user_ID_key); // Housekeeping. $_user_login_key = array_search('user_login', $headers); $_user_login = $_user_login_key !== FALSE && !empty($_csv_data[$_user_login_key]) ? $_csv_data[$_user_login_key] : ''; unset($_user_login_key); // Housekeeping. $_user_pass_key = array_search('user_pass', $headers); $_user_pass = $_user_pass_key !== FALSE && !empty($_csv_data[$_user_pass_key]) ? $_csv_data[$_user_pass_key] : ''; unset($_user_pass_key); // Housekeeping. $_user_email_key = array_search('user_email', $headers); $_user_email = $_user_email_key !== FALSE && !empty($_csv_data[$_user_email_key]) ? $_csv_data[$_user_email_key] : ''; unset($_user_email_key); // Housekeeping. $_user_role_key = array_search('role', $headers); $_user_role = $_user_role_key !== FALSE && !empty($_csv_data[$_user_role_key]) ? $_csv_data[$_user_role_key] : ''; $_user_role = is_numeric($_user_role) ? $_user_role == 0 ? 'subscriber' : 's2member_level' . $_user_role : $_user_role; unset($_user_role_key); // Housekeeping. $_user_ccaps_key = array_search('ccaps', $headers); $_user_ccaps = $_user_ccaps_key !== FALSE && !empty($_csv_data[$_user_ccaps_key]) ? $_csv_data[$_user_ccaps_key] : ''; unset($_user_ccaps_key); // Housekeeping. if ($_user_login) { if (is_multisite()) { $_user_login = strtolower($_user_login); } $_user_login = sanitize_user($_user_login, is_multisite()); } if ($_user_email) { $_user_email = sanitize_email($_user_email); } $_user_id_exists_but_not_on_blog = 0; // Initialize. if (!$_user_id && $_user_login && $_user_email && is_multisite()) { $_user_id = $_user_id_exists_but_not_on_blog = c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($_user_login, $_user_email); } if (strcasecmp($_user_role, 'administrator') === 0) { $errors[] = 'Line #' . $line . '. Users cannot be updated to an Administrator. Bypassing this line for security.'; continue; // Skip this line. } if ($_user_email && !is_email($_user_email)) { $errors[] = 'Line #' . $line . '. Invalid email address (<code>' . esc_html($_user_email) . '</code>); please try again.'; continue; // Skip this line. } if ($_user_login && !validate_username($_user_login)) { $errors[] = 'Line #' . $line . '. Invalid username (<code>' . esc_html($_user_login) . '</code>).'; continue; // Skip this line. } if ($_user_id) { if (!is_object($_user = new WP_User($_user_id)) || !$_user->ID) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> does NOT belong to an existing User.'; continue; // Skip this line. } if (is_super_admin($_user_id) || $_user->has_cap('administrator')) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> belongs to an Administrator. Bypassing this line for security.'; continue; // Skip this line. } if (is_multisite() && $_user_id_exists_but_not_on_blog && add_existing_user_to_blog(array('user_id' => $_user_id, 'role' => 'subscriber')) !== TRUE) { $errors[] = 'Line #' . $line . '. Unknown user/site addition error, please try again.'; continue; // Skip this line. } if (is_multisite() && !is_user_member_of_blog($_user_id)) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> does NOT belong to an existing User on this site.'; continue; // Skip this line. } if ($_user_email && strcasecmp($_user_email, $_user->user_email) !== 0 && email_exists($_user_email)) { $errors[] = 'Line #' . $line . '. Conflicting; the email address (<code>' . esc_html($_user_email) . '</code>), already exists.'; continue; // Skip this line. } if ($_user_login && strcasecmp($_user_login, $_user->user_login) !== 0 && username_exists($_user_login)) { $errors[] = 'Line #' . $line . '. Conflicting; the username (<code>' . esc_html($_user_login) . '</code>), already exists.'; continue; // Skip this line. } /** @var WP_Error $_email_login_validation */ if (is_multisite() && strcasecmp($_user_email, $_user->user_email) !== 0 && strcasecmp($_user_login, $_user->user_login) !== 0) { if (is_wp_error($_email_login_validation = wpmu_validate_user_signup($_user_login, $_user_email))) { if ($_email_login_validation->get_error_code()) { $errors[] = 'Line #' . $line . '. Network. The email and/or username (<code>' . esc_html($_user_email) . '</code> / <code>' . esc_html($_user_login) . '</code>) are in conflict w/ network rules.'; continue; // Skip this line. } } } unset($_email_login_validation); // Housekeeping. $_wp_update_user = array(); foreach ($user_keys as $_user_key) { if (($_user_data_key = array_search($_user_key, $headers)) !== FALSE && isset($_csv_data[$_user_data_key])) { $_wp_update_user[$_user_key] = $_csv_data[$_user_data_key]; } } unset($_user_key, $_user_data_key); // Housekeeping. if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { unset($_wp_update_user['user_login'], $_wp_update_user['user_pass']); } if (!wp_update_user(wp_slash($_wp_update_user))) { $errors[] = 'Line #' . $line . '. User ID# <code>' . esc_html($_user_id) . '</code> could NOT be updated. Unknown error, please try again.'; continue; // Skip this line. } unset($_wp_update_user); // Housekeeping. clean_user_cache($_user_id); wp_cache_delete($_user_id, 'user_meta'); $_user = new WP_User($_user_id); $imported = $imported + 1; } else { if (!$_user_email) { $errors[] = 'Line #' . $line . '. Missing email address.'; continue; // Skip this line. } if (email_exists($_user_email)) { $errors[] = 'Line #' . $line . '. Conflicting; the email address (<code>' . esc_html($_user_email) . '</code>), already exists.'; continue; // Skip this line. } if (!$_user_login) { $errors[] = 'Line #' . $line . '. Missing user login (i.e., username).'; continue; // Skip this line. } if (username_exists($_user_login)) { $errors[] = 'Line #' . $line . '. Conflicting; the username (<code>' . esc_html($_user_login) . '</code>), already exists.'; continue; // Skip this line. } /** @var WP_Error $_email_login_validation */ if (is_multisite() && is_wp_error($_email_login_validation = wpmu_validate_user_signup($_user_login, $_user_email))) { if ($_email_login_validation->get_error_code()) { $errors[] = 'Line #' . $line . '. Network. The email and/or username (<code>' . esc_html($_user_email) . '</code> / <code>' . esc_html($_user_login) . '</code>) are in conflict w/ network rules.'; continue; // Skip this line. } } unset($_email_login_validation); // Housekeeping. if (!($_user_id = wp_insert_user(wp_slash(array('user_login' => $_user_login, 'user_pass' => $_user_pass ? $_user_pass : wp_generate_password(12, FALSE), 'user_email' => $_user_email)))) || is_wp_error($_user_id)) { $errors[] = 'Line #' . $line . '. Unknown insertion error, please try again.'; continue; // Skip this line. } $_wp_update_user = array('ID' => $_user_id); foreach ($user_keys as $_user_key) { if (($_user_data_key = array_search($_user_key, $headers)) !== FALSE && isset($_csv_data[$_user_data_key])) { $_wp_update_user[$_user_key] = $_csv_data[$_user_data_key]; } } unset($_user_key, $_user_data_key); // Housekeeping. if (!wp_update_user(wp_slash($_wp_update_user))) { $errors[] = 'Line #' . $line . '. Post insertion update failed on User ID# <code>' . esc_html($_user_id) . '</code>. Unknown error, please try again.'; continue; // Skip this line. } unset($_wp_update_user); // Housekeeping. if (is_multisite()) { // New Users on a Multisite Network need this too. update_user_meta($_user_id, 's2member_originating_blog', $current_blog->blog_id); } clean_user_cache($_user_id); wp_cache_delete($_user_id, 'user_meta'); $_user = new WP_User($_user_id); $imported = $imported + 1; } if ($_user_role) { $_user->set_role($_user_role); } if ($_user_ccaps) { foreach ($_user->allcaps as $_cap => $_cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $_cap)) { $_user->remove_cap($_cap); } } unset($_cap, $_cap_enabled); // Housekeeping. if (preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $_user_ccaps))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $_user_ccaps))) as $_ccap) { if (strlen($_ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $_ccap))))) { $_user->add_cap('access_s2member_ccap_' . $_ccap); } } } } $_user_custom_fields = get_user_option('s2member_custom_fields', $_user_id); $_user_custom_fields = is_array($_user_custom_fields) ? $_user_custom_fields : array(); foreach ($headers as $_index => $_header) { if (strpos($_header, 'meta_key__') === 0) { if (isset($_csv_data[$_index])) { $_new_meta_value = $_csv_data[$_index]; $_user_meta_key = substr($_header, strlen('meta_key__')); if ($_user_meta_key === $wpdb->prefix . 'capabilities' && ($_user_role || $_user_ccaps)) { continue; } // Already handled via `role` and `ccaps`. if ($_user_meta_key === $wpdb->prefix . 'capabilities' && stripos($_new_meta_value, 'administrator') !== FALSE) { continue; } // Do not allow this for security purposes. if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { if (strpos($_user_meta_key, $wpdb->prefix) !== 0 && !in_array($_user_meta_key, array('first_name', 'last_name', 'nickname', 'description'), TRUE)) { continue; } } // Child sites may NOT update meta data for other child blogs. switch ($_user_meta_key) { case $wpdb->prefix . 'capabilities': case $wpdb->prefix . 's2member_sp_references': case $wpdb->prefix . 's2member_ipn_signup_vars': case $wpdb->prefix . 's2member_access_cap_times': case $wpdb->prefix . 's2member_paid_registration_times': case $wpdb->prefix . 's2member_file_download_access_arc': case $wpdb->prefix . 's2member_file_download_access_log': if (isset($_new_meta_value[0])) { // This handles JSON-decoding for known array values. if (!is_null($_new_meta_value_decoded = json_decode($_new_meta_value, TRUE))) { $_new_meta_value = maybe_serialize($_new_meta_value_decoded); } } break; } $_existing_meta_row = $wpdb->get_row("SELECT * FROM `" . $wpdb->usermeta . "` WHERE `user_id` = '" . esc_sql($_user_id) . "' AND `meta_key` = '" . esc_sql($_user_meta_key) . "' AND `meta_value` = '" . esc_sql($_new_meta_value) . "' LIMIT 1"); if (is_object($_existing_meta_row)) { continue; } // No need to update this; it is still the same value. $_existing_meta_rows = $wpdb->get_results("SELECT * FROM `" . $wpdb->usermeta . "` WHERE `user_id` = '" . esc_sql($_user_id) . "' AND `meta_key` = '" . esc_sql($_user_meta_key) . "' LIMIT 2"); if ($_existing_meta_rows && count($_existing_meta_rows) > 1) { continue; } // We don't update multivalue keys. This can cause database corruption via CSV import files. $_existing_meta_row = $_existing_meta_rows ? $_existing_meta_rows[0] : NULL; /** @var object $_existing_meta_row This line is for IDEs; so they don't choke. */ if (is_object($_existing_meta_row) && $_new_meta_value !== $_existing_meta_row->meta_value) { $wpdb->update($wpdb->usermeta, array('meta_value' => $_new_meta_value), array('umeta_id' => $_existing_meta_row->umeta_id)); } else { if (!is_object($_existing_meta_row)) { $wpdb->insert($wpdb->usermeta, array('user_id' => $_user_id, 'meta_key' => $_user_meta_key, 'meta_value' => $_new_meta_value)); } } } } else { if (strpos($_header, 'custom_field_key__') === 0) { if (isset($_csv_data[$_index])) { $_new_custom_field_value = $_csv_data[$_index]; if (!is_null($_new_custom_field_value_decoded = json_decode($_new_custom_field_value, TRUE))) { $_new_custom_field_value = $_new_custom_field_value_decoded; } $_user_custom_field_key = substr($_header, strlen('custom_field_key__')); $_user_custom_fields[$_user_custom_field_key] = $_new_custom_field_value; } } } } update_user_option($_user_id, 's2member_custom_fields', $_user_custom_fields); unset($_user_custom_fields, $_index, $_header); // Housekeeping. unset($_new_meta_value, $_new_meta_value_decoded, $_user_meta_key, $_existing_meta_rows, $_existing_meta_row); unset($_new_custom_field_value, $_new_custom_field_value_decoded, $_user_custom_field_key); } fclose($file); // Close the file resource handle now. unset($_csv_data, $_user, $_user_id, $_user_login, $_user_email); unset($_user_id_exists_but_not_on_blog, $_user_role, $_user_ccaps); } else { $errors[] = 'No data was received. Please try again.'; } // The upload failed, or it was empty. c_ws_plugin__s2member_admin_notices::display_admin_notice('Operation complete. Users/Members imported: <code>' . (int) $imported . '</code>.'); if (!empty($errors)) { // Here is where a detailed error log will be returned to the Site Owner; as a way of clarifying what just happened during importation. c_ws_plugin__s2member_admin_notices::display_admin_notice('<strong>The following errors were encountered during importation:</strong><ul style="font-size:80%; list-style:disc outside; margin-left:25px;"><li>' . implode('</li><li>', $errors) . '</li></ul>', TRUE); } } }
/** * For Multisite Networks, this function is used to add a User to an existing Blog; and to simulate ``wp_create_user()`` behavior. * * The ``$user_id`` value will be returned by this function, just like ``wp_create_user()`` does. * This function will fire the Hook `user_register`. * * @package s2Member\Registrations * @since 3.5 * * @param string $user_login Expects the User's Username. * @param string $user_email Expects the User's Email Address. * @param string $user_pass Expects the User's plain text Password. * @param int|string $user_id Optional. A numeric WordPress User ID. * If unspecified, a lookup is performed with ``$user_login`` and ``$user_email``. * * @return int|false Returns numeric ``$user_id`` on success, else false on failure. */ public static function ms_create_existing_user($user_login = '', $user_email = '', $user_pass = '', $user_id = '') { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_ms_create_existing_user', get_defined_vars()); unset($__refs, $__v); // Housekeeping. if (is_multisite()) { if (($user_id || ($user_id = c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($user_login, $user_email))) && $user_pass) { $role = get_option('default_role'); // Use default Role. add_existing_user_to_blog(array('user_id' => $user_id, 'role' => $role)); // Add User. wp_update_user(wp_slash(array('ID' => $user_id, 'user_pass' => $user_pass))); // Update to ``$user_pass``. do_action('ws_plugin__s2member_during_ms_create_existing_user', get_defined_vars()); do_action('user_register', $user_id); // So s2Member knows a User is registering. return apply_filters('ws_plugin__s2member_ms_create_existing_user', $user_id, get_defined_vars()); } } return apply_filters('ws_plugin__s2member_ms_create_existing_user', FALSE, get_defined_vars()); }
/** * Determines whether or not a Username/Email is already in the database for this Blog. * * This is an alias for: `c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog()`. * * Returns the WordPress User ID if they exist. * * @package s2Member\Utilities * @since 3.5 * * @param str $user_login A User's Username. * @param str $user_email A User's Email Address. * @param int|str $blog_id A numeric WordPress Blog ID. * @return int|bool If exists *(but not on Blog)*, a WordPress User ID, else false. */ public static function ms_user_login_email_can_join_blog($user_login = FALSE, $user_email = FALSE, $blog_id = FALSE) { return c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($user_login, $user_email, $blog_id); }
/** * Handles the importation of Users/Members. * * @package s2Member\Imports * @since 110815 */ public static function import_users() { if (!empty($_POST['ws_plugin__s2member_pro_import_simple_users']) && ($nonce = $_POST['ws_plugin__s2member_pro_import_simple_users']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-pro-import-users') && current_user_can('create_users')) { global $wpdb; // Global database object reference. global $current_site, $current_blog; // Multisite Networking. @set_time_limit(0); // Make time for processing large import files. @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); remove_all_actions('profile_update') . remove_all_actions('user_register'); remove_all_actions('added_existing_user') . remove_all_actions('add_user_to_blog'); if (!empty($_FILES['ws_plugin__s2member_pro_import_users_file']) && empty($_FILES['ws_plugin__s2member_pro_import_users_file']['error'])) { $file = fopen($_FILES['ws_plugin__s2member_pro_import_users_file']['tmp_name'], 'r'); } else { if (!empty($_POST['ws_plugin__s2member_pro_import_users_direct_input'])) { fwrite($file = tmpfile(), trim(stripslashes($_POST['ws_plugin__s2member_pro_import_users_direct_input']))) . fseek($file, 0); } } $imported = $line = 0; // Initialize these counters. if (isset($file) && is_resource($file)) { $custom_field_vars = array(); // Initialize this array. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $custom_field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $custom_field_vars[] = $custom_field_var; } } sort($custom_field_vars, SORT_STRING); // Always sort this array. while (($data = version_compare(PHP_VERSION, '5.3', '>=') ? fgetcsv($file, 0, ',', '"', '"') : fgetcsv($file, 0, ',', '"')) !== FALSE) { $line = (int) $line + 1; // CSV lines. $data = c_ws_plugin__s2member_utils_strings::trim_deep($data); $data = stripslashes_deep($data); if ($line === 1 && strtoupper($data[0]) === 'ID') { $line = $line - 1; continue; } if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { $ID = $data[0]; $user_login = is_multisite() ? strtolower($data[1]) : $data[1]; $user_login = sanitize_user($user_login, is_multisite()); $user_pass = (string) ''; $first_name = $data[2]; $last_name = $data[3]; $display_name = $data[4]; $user_email = sanitize_email($data[5]); $user_url = $data[6]; $role = $data[7]; $custom_capabilities = $data[8]; $user_registered = $data[9] ? date('Y-m-d H:i:s', strtotime($data[9])) : ''; $paid_registration_times = $data[10] ? maybe_unserialize($data[10]) : ''; $last_payment_time = $data[11] ? strtotime($data[11]) : ''; $auto_eot_time = $data[12] ? strtotime($data[12]) : ''; $custom = $data[13]; $subscr_id = $data[14]; $subscr_gateway = strtolower($data[15]); $custom_fields = array(); // Initialize. if (count($data) > 16) { // Now loop through Custom Fields. for ($i = 16, $j = 0; $i < count($data); $i++, $j++) { if (isset($custom_field_vars[$j])) { // A field in this position? $custom_fields[$custom_field_vars[$j]] = maybe_unserialize($data[$i]); } } } } else { $ID = $data[0]; $user_login = is_multisite() ? strtolower($data[1]) : $data[1]; $user_login = sanitize_user($user_login, is_multisite()); $user_pass = $data[2]; $first_name = $data[3]; $last_name = $data[4]; $display_name = $data[5]; $user_email = sanitize_email($data[6]); $user_url = $data[7]; $role = $data[8]; $custom_capabilities = $data[9]; $user_registered = $data[10] ? date('Y-m-d H:i:s', strtotime($data[10])) : ''; $paid_registration_times = $data[11] ? maybe_unserialize($data[11]) : ''; $last_payment_time = $data[12] ? strtotime($data[12]) : ''; $auto_eot_time = $data[13] ? strtotime($data[13]) : ''; $custom = $data[14]; $subscr_id = $data[15]; $subscr_gateway = strtolower($data[16]); $custom_fields = array(); // Initialize. if (count($data) > 17) { // Now loop through Custom Fields. for ($i = 17, $j = 0; $i < count($data); $i++, $j++) { if (isset($custom_field_vars[$j])) { // A field in this position? $custom_fields[$custom_field_vars[$j]] = maybe_unserialize($data[$i]); } } } } $role = is_numeric($role) ? $role == 0 ? 'subscriber' : 's2member_level' . $role : $role; if ($paid_registration_times && !is_array($paid_registration_times)) { $paid_registration_times = array('level' => strtotime($paid_registration_times)); } $paid_registration_times = !$paid_registration_times || !is_array($paid_registration_times) ? array() : $paid_registration_times; $user_details = compact('ID', 'user_login', 'user_pass', 'first_name', 'last_name', 'display_name', 'user_email', 'user_url', 'role', 'user_registered'); if (empty($user_details['user_pass'])) { // If there was NO Password given. unset($user_details['user_pass']); } // Unset the Password array element. if ($ID) { if (is_object($user = new WP_User($ID)) && $user->ID) { if (!is_multisite() || is_user_member_of_blog($ID)) { if ((!is_multisite() || !is_super_admin($ID)) && !$user->has_cap('administrator')) { if (strtolower($role) !== 'administrator') { if ($user_email && is_email($user_email)) { if ($user_login) { if (validate_username($user_login)) { if (($_same_email = strtolower($user_email) === strtolower($user->user_email)) || !email_exists($user_email)) { if (($_same_login = strtolower($user_login) === strtolower($user->user_login)) || !username_exists($user_login)) { if (!is_multisite() || $_same_email && $_same_login || ($_ = wpmu_validate_user_signup($user_login, $user_email)) && (!is_wp_error($_['errors']) || !$_['errors']->get_error_code())) { if (is_multisite() && c_ws_plugin__s2member_utils_conds::is_multisite_farm() && !is_main_site()) { unset($user_details['user_login'], $user_details['user_pass']); } if ($user_id = wp_update_user(wp_slash($user_details))) { $user = new WP_User($ID); // Refresh object value. update_user_option($user_id, 's2member_custom', $custom); update_user_option($user_id, 's2member_subscr_id', $subscr_id); update_user_option($user_id, 's2member_subscr_gateway', $subscr_gateway); update_user_option($user_id, 's2member_auto_eot_time', $auto_eot_time); update_user_option($user_id, 's2member_paid_registration_times', $paid_registration_times); update_user_option($user_id, 's2member_last_payment_time', $last_payment_time); update_user_option($user_id, 's2member_custom_fields', $custom_fields); foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } if ($custom_capabilities && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $custom_capabilities))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $custom_capabilities))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) { $user->add_cap('access_s2member_ccap_' . $ccap); } } } $imported = $imported + 1; } else { $errors[] = 'Line #' . $line . '. User ID# <code>' . $ID . '</code> could NOT be updated. Unknown error, please try again.'; } } else { $errors[] = 'Line #' . $line . '. Network. The Username and/or Email (<code>' . esc_html($user_login) . '</code> / <code>' . esc_html($user_email) . '</code>) are in conflict w/ Network rules.'; } } else { $errors[] = 'Line #' . $line . '. Conflicting. The Username (<code>' . esc_html($user_login) . '</code>), already exists.'; } } else { $errors[] = 'Line #' . $line . '. Conflicting. The Email address (<code>' . esc_html($user_email) . '</code>), already exists.'; } } else { $errors[] = 'Line #' . $line . '. Invalid Username (<code>' . esc_html($user_login) . '</code>). Lowercase alphanumerics are required.'; } } else { $errors[] = 'Line #' . $line . '. Missing Username; please try again.'; } // We have two separate errors for Usernames. This provides clarity. } else { $errors[] = 'Line #' . $line . '. Missing or invalid Email address (<code>' . esc_html($user_email) . '</code>); please try again.'; } } else { $errors[] = 'Line #' . $line . '. User ID# <code>' . $ID . '</code> cannot be updated to an Administrator. Bypassing this line for security.'; } } else { $errors[] = 'Line #' . $line . '. User ID# <code>' . $ID . '</code> belongs to an Administrator. Bypassing this line for security.'; } } else { $errors[] = 'Line #' . $line . '. User ID# <code>' . $ID . '</code> does NOT belong to an existing User on this site.'; } } else { $errors[] = 'Line #' . $line . '. User ID# <code>' . $ID . '</code> does NOT belong to an existing User.'; } } else { if (is_multisite() && ($user_id = c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($user_login, $user_email)) && !is_super_admin($user_id)) { if (strtolower($role) !== 'administrator') { if (add_existing_user_to_blog(array('user_id' => $user_id, 'role' => $role))) { if (is_object($user = new WP_User($user_id)) && $user->ID) { update_user_option($user_id, 's2member_custom', $custom); update_user_option($user_id, 's2member_subscr_id', $subscr_id); update_user_option($user_id, 's2member_subscr_gateway', $subscr_gateway); update_user_option($user_id, 's2member_auto_eot_time', $auto_eot_time); update_user_option($user_id, 's2member_paid_registration_times', $paid_registration_times); update_user_option($user_id, 's2member_last_payment_time', $last_payment_time); update_user_option($user_id, 's2member_custom_fields', $custom_fields); foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } if ($custom_capabilities && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $custom_capabilities))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $custom_capabilities))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) { $user->add_cap('access_s2member_ccap_' . $ccap); } } } $imported = $imported + 1; } else { $errors[] = 'Line #' . $line . '. Unknown object error, please try again.'; } } else { $errors[] = 'Line #' . $line . '. Unknown User/site addition error, please try again.'; } } else { $errors[] = 'Line #' . $line . '. Role cannot be Administrator. Bypassing this line for security.'; } } else { if (strtolower($role) !== 'administrator') { if ($user_email && is_email($user_email)) { if ($user_login) { if (validate_username($user_login)) { if (!email_exists($user_email)) { if (!username_exists($user_login)) { if (!is_multisite() || ($_ = wpmu_validate_user_signup($user_login, $user_email)) && (!is_wp_error($_['errors']) || !$_['errors']->get_error_code())) { if ($user_id = wp_insert_user(wp_slash(empty($user_details['user_pass']) ? array_merge($user_details, array('user_pass' => wp_generate_password(12, FALSE))) : $user_details))) { if (is_object($user = new WP_User($user_id)) && $user->ID) { if ($user_pass) { // If we are given an 'un-encrypted Password'. wp_update_user(wp_slash(array('ID' => $user_id, 'user_pass' => $user_pass))); } if (is_multisite()) { // New Users on a Multisite Network need this too. update_user_meta($user_id, 's2member_originating_blog', $current_blog->blog_id); } update_user_option($user_id, 's2member_custom', $custom); update_user_option($user_id, 's2member_subscr_id', $subscr_id); update_user_option($user_id, 's2member_subscr_gateway', $subscr_gateway); update_user_option($user_id, 's2member_auto_eot_time', $auto_eot_time); update_user_option($user_id, 's2member_paid_registration_times', $paid_registration_times); update_user_option($user_id, 's2member_last_payment_time', $last_payment_time); update_user_option($user_id, 's2member_custom_fields', $custom_fields); foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } if ($custom_capabilities && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $custom_capabilities))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $custom_capabilities))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) { $user->add_cap('access_s2member_ccap_' . $ccap); } } } $imported = $imported + 1; } else { $errors[] = 'Line #' . $line . '. Unknown object error, please try again.'; } } else { $errors[] = 'Line #' . $line . '. Unknown insertion error, please try again.'; } } else { $errors[] = 'Line #' . $line . '. Network. The Username and/or Email (<code>' . esc_html($user_login) . '</code> / <code>' . esc_html($user_email) . '</code>) are in conflict w/ Network rules.'; } } else { $errors[] = 'Line #' . $line . '. Conflicting. The Username (<code>' . esc_html($user_login) . '</code>), already exists.'; } } else { $errors[] = 'Line #' . $line . '. Conflicting. The Email address (<code>' . esc_html($user_email) . '</code>), already exists.'; } } else { $errors[] = 'Line #' . $line . '. Invalid Username (<code>' . esc_html($user_login) . '</code>). Lowercase alphanumerics are required.'; } } else { $errors[] = 'Line #' . $line . '. Missing Username; please try again.'; } // We have two separate errors for Usernames. This provides clarity. } else { $errors[] = 'Line #' . $line . '. Missing or invalid Email address (<code>' . esc_html($user_email) . '</code>); please try again.'; } } else { $errors[] = 'Line #' . $line . '. Role cannot be Administrator. Bypassing this line for security.'; } } } } fclose($file); // Close the file resource handle now. } else { $errors[] = 'No data was received. Please try again.'; } // The upload failed, or it was empty. c_ws_plugin__s2member_admin_notices::display_admin_notice('Operation complete. Users/Members imported: <code>' . (int) $imported . '</code>.'); if (!empty($errors)) { // Here is where a detailed error log will be returned to the Site Owner; as a way of clarifying what just happened during importation. c_ws_plugin__s2member_admin_notices::display_admin_notice('<strong>The following errors were encountered during importation:</strong><ul style="font-size:80%; list-style:disc outside; margin-left:25px;"><li>' . implode('</li><li>', $errors) . '</li></ul>', TRUE); } } }