Run Username SQL Query from WordPress Child Theme Functions File

Question

Having an admin account, I can change everything except the username (which happens to be the login name). I am therefore wondering how to change the username using the functions file.

Running the below as a SQL query works fine, but how do I “convert” it into a function?

add_action('init','username_query');
function username_query() {
    
    global $wpdb;
    $result = (UPDATE `wp_users` SET `user_login`= 'new-admin-name-here' WHERE `user_login`='old-admin-name-here');

}

Any help is appreciated and yes; I know that the user will be logged out and asked to login again.

0
, Moa Andersen 1 year 2020-07-21T00:10:46-05:00 0 Answers 52 views 0

Leave an answer

Browse
Browse