set_role has no effect

You can use wp_update_user to update the role for your newly created user. if ( !username_exists( ‘mytestuser’ ) ) { $user_id = wp_create_user(‘mytestuser’, ‘testpass345′,’[email protected]’); $user_id = wp_update_user( array( ‘ID’ => $user_id, ‘role’ => ‘author’ ) ); } Further reading at WordPress Codex. Or, you can remove the current role and assign a new one: if … Read more

Update user_login to change username

First: The $wpdb object has the names of tables, with prefixes, pre-defined for you. $wpdb->users == ‘wp_users’ $wpdb->posts == ‘wp_posts’ etc. Second: $wpdb-prepare() is essentially a WordPress aware printf, if you pass it more than one argument, you need to have some string/digit replacements %s %d $sql = “UPDATE {$wpdb->users} SET user_login = %s WHERE … Read more

Hide a user from WordPress

You’re wanting to hide a user from WordPress in three places: The user list in the admin The count above that user list The user’s author archive on the front-end As you mentioned, you’ve already solved item 1 and you’ve included the code for that. So, I’ll provide the solutions for items 2 and 3. … Read more

how to get recent registered author id?

I don’t think you need any SQL queries. <?php $args = array( ‘role’ => ‘author’, // authors only ‘orderby’ => ‘registered’, // registered date ‘order’ => ‘DESC’, // last registered goes first ‘number’ => 1 // limit to the last one, not required ); $users = get_users( $args ); $last_user_registered = $users[0]; // the first … Read more

How to edit user_id on the comment edit screen

You can take reference from below code. It will provide an option to update user id of comment (https://prnt.sc/s57q4f). paste below code in active theme’s functions.php file.I have tested and it is working for me. let me know if it works for you. # comment user id update metabox function action_add_meta_boxes_comment( $comment ) { ?> … Read more