prefix . "users"; global $user_ID; get_currentuserinfo(); //we get all rows from our table $result = $wpdb->get_results( "SELECT * FROM $table_name WHERE ID=$user_ID"); $nonce = wp_create_nonce( 'admin-username-changer' ); echo ' Simple to-do dashboard widget '; echo '
Current admin username is '.$result[0]->user_login.'

'; echo '
'.wp_nonce_field('auc-noscript').'
'; ///////////////////////////////////////////////////////////////////// //a form submit action that will run if JS is disabled if(isset($_POST['changeUsernameButton'])){ if($_POST['username'] != ''){ if (! check_admin_referer('auc-noscript') ) die("Security check failure"); $username = $_POST['username']; $data = array('user_login'=>$username, 'user_nicename'=>$username, 'display_name'=>$username); $where = array('ID'=>$user_ID); $format = array('%s', '%s', '%s'); $wformat = array('%d'); $update = $wpdb->update( $table_name, $data, $where, $format, $wformat); echo '
Your admin username has been changed to: '.$username.'
'; } else { echo '
Username can not be empty!
'; } } ///////////////////////////////////////////////////////////////////// echo ""; } public static function usernameForm_callback() { if (!check_ajax_referer( "admin-username-changer" ) ) die("Security check failure"); global $wpdb; $table_name = $wpdb->prefix . "users"; $username = $_POST['username']; global $user_ID; get_currentuserinfo(); $data = array('user_login'=>$username, 'user_nicename'=>$username, 'display_name'=>$username); $where = array('ID'=>$user_ID); $format = array('%s', '%s', '%s'); $wformat = array('%d'); $update = $wpdb->update( $table_name, $data, $where, $format, $wformat); echo 'New admin username '.$username.' has been set. Logout and log back in with your shiny brand new username.'; die(); } public static function usernameFormNo_callback() { echo 'You shall not pass! Only admin can use this function.'; die(); } } ?>