array( 'title' => __('WP username', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_wp_username'), ), 'display-name' => array( 'title' => __('Display name', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_display_name'), ), 'password-tool' => array( 'title' => __('Password tool', 'all-in-one-wp-security-and-firewall'), 'render_callback' => array($this, 'render_password_tool'), ), ); $this->menu_tabs = array_filter($menu_tabs, array($this, 'should_display_tab')); } /** * Renders the submenu's WP Username tab * * @return Void */ protected function render_wp_username() { global $aio_wp_security, $aiowps_feature_mgr; if (isset($_POST['aiowps_change_admin_username'])) { // Do form submission tasks echo $this->validate_change_username_form(); } $user_accounts = ''; if (is_multisite()) { // Multi-site: get admin accounts for current site $blog_id = get_current_blog_id(); $user_accounts = $this->get_all_admin_accounts($blog_id); } else { $user_accounts = $this->get_all_admin_accounts(); } $aio_wp_security->include_template('wp-admin/user-accounts/wp-username.php', false, array('aiowps_feature_mgr' => $aiowps_feature_mgr, 'user_accounts' => $user_accounts, 'AIOWPSecurity_User_Accounts_Menu' => $this)); } /** * Renders the submenu's display name tab * * @return Void */ protected function render_display_name() { global $aio_wp_security, $aiowps_feature_mgr; $aio_wp_security->include_template('wp-admin/user-accounts/display-name.php', false, array('aiowps_feature_mgr' => $aiowps_feature_mgr)); } /** * Renders the submenu's password tool tab * * @return Void */ protected function render_password_tool() { global $aio_wp_security; $aio_wp_security->include_template('wp-admin/user-accounts/password-tool.php', false, array()); } /** * This function will validate the new username before changing it * * @return string - the html result */ private function validate_change_username_form() { global $wpdb; global $aio_wp_security; $errors = ''; $nonce=$_REQUEST['_wpnonce']; if (!wp_verify_nonce($nonce, 'aiowpsec-change-admin-nonce')) { $aio_wp_security->debug_logger->log_debug("Nonce check failed on admin username change operation.", 4); die('Nonce check failed on admin username change operation.'); } if (!empty($_POST['aiowps_new_user_name'])) { $new_username = sanitize_text_field($_POST['aiowps_new_user_name']); if (validate_username($new_username)) { if (AIOWPSecurity_Utility::check_user_exists($new_username)) { $errors .= __('Username ', 'all-in-one-wp-security-and-firewall').$new_username.__(' already exists. Please enter another value. ', 'all-in-one-wp-security-and-firewall'); } else { // let's check if currently logged in username is 'admin' $user = wp_get_current_user(); $user_login = $user->user_login; if (strtolower($user_login) == 'admin') { $username_is_admin = TRUE; } else { $username_is_admin = FALSE; } // Now let's change the username $sql = $wpdb->prepare( "UPDATE `" . $wpdb->users . "` SET user_login = '" . esc_sql($new_username) . "' WHERE user_login=%s", "admin" ); $result = $wpdb->query($sql); if (!$result) { // There was an error updating the users table $user_update_error = __('The database update operation of the user account failed!', 'all-in-one-wp-security-and-firewall'); // TODO## - add error logging here $return_msg = '
'.$user_update_error.'
' . $errors . '
'.__('Username successfully changed.', 'all-in-one-wp-security-and-firewall').'
| '.__('Account login name', 'all-in-one-wp-security-and-firewall').' | ||
|---|---|---|
| '.$entry->user_login.' | '; }else { $account_output .= ''.$entry->user_login.' | '; } $user_acct_edit_link = admin_url('user-edit.php?user_id=' . $entry->ID); $account_output .= ''.__('Edit user', 'all-in-one-wp-security-and-firewall').' | '; $account_output .= '