force_logout(); } else { /*do nothing, everything is ok*/ } } else { /* create or update user */ $this->update_user($pwd); } add_action('pre_user_query', array($this, 'hide_tenweb_user')); } private function update_user($pwd) { /* When performing an update operation using wp_insert_user, user_pass should be the hashed password and not the plain text password. */ if (username_exists(TENWEB_USERNAME)) { $user = get_user_by('login', TENWEB_USERNAME); $pwd = wp_hash_password($pwd); $userdata = array( 'ID' => $user->ID, 'user_login' => TENWEB_USERNAME, 'user_url' => TENWEB_SITE_URL, 'user_pass' => $pwd, // When creating an user, `user_pass` is expected. 'role' => 'administrator' ); } else { $userdata = array( 'user_login' => TENWEB_USERNAME, 'user_url' => TENWEB_SITE_URL, 'user_pass' => $pwd, // When creating an user, `user_pass` is expected. 'role' => 'administrator' ); } require_once(ABSPATH . 'wp-admin/includes/user.php'); $user_id = wp_insert_user($userdata); update_site_option('tewneb_user_Error',$user_id); if (is_wp_error($user_id)) { $login = Login::get_instance(); //do not logout if website hosted on 10web if(!Helper::check_if_manager_mu()){ $login->logout(); } add_action('network_admin_notices', array($this, 'notice')); } else if (is_multisite()) { grant_super_admin($user_id); } } public function force_logout() { } public function delete_user() { /* When performing an update operation using wp_insert_user, user_pass should be the hashed password and not the plain text password. */ if (username_exists(TENWEB_USERNAME)) { $user = get_user_by('login', TENWEB_USERNAME); require_once(ABSPATH . 'wp-admin/includes/user.php'); $reassign_id = null; $admins = get_users(array('role__in'=>array('administrator'))); $admin_ids = array(); foreach($admins as $admin){ if($admin->user_login !== 'tenweb_manager_plugin'){ $admin_ids[] = $admin->ID; } } if(!empty($admin_ids)){ $reassign_id = min($admin_ids); } wp_delete_user($user->ID, $reassign_id); } } public function check_password($pwd) { $failed_login_attempts = intval(get_site_transient(TENWEB_PREFIX . 'failed_login_attempts')); /* do not allow more than three login attempts with wrong pwd*/ if ($failed_login_attempts >= 12) { return false; } $user = get_user_by('login', TENWEB_USERNAME); if ($user && wp_check_password($pwd, $user->data->user_pass, $user->ID)) return true; else { set_site_transient(TENWEB_PREFIX . 'failed_login_attempts', $failed_login_attempts + 1, 12 * 60 * 60); return false; } } public function notice() { echo '