Importing Existing Users with Passwords

You can use wp_insert_user. Since your old database has passwords in base64, you can easily get the original password string using base64_decode. $new_user_data = array( ‘user_pass’ => ‘password’,//pass your decoded password string ‘user_login’ => ‘username’,//pass your username ‘user_email’ => ’email’, ‘first_name’ => ‘firstname’, ‘last_name’ => ‘lastname’, ‘role’ => ‘author’//if you want to specify a different … Read more

Delete user from frontend

Taken directly form the wp_delete_user documentation: if(is_user_logged_in() && !empty($_GET[‘DeleteMyAccount’])) { add_action(‘init’, ‘remove_logged_in_user’); } function remove_logged_in_user() { require_once(ABSPATH.’wp-admin/includes/user.php’ ); $current_user = wp_get_current_user(); wp_delete_user( $current_user->ID ); } Things to note: Your code didn’t check if the user was logged in or not by the time you’re printing the remove user link, the init action has already happened … Read more

Total Word Count For Posts And Comments By One Author

Run a couple of queries and a code snippet to calculate the word count for the post content, comments content and tag names on each post. // This query will return the number of words in the post content $post_qry=”SELECT LENGTH(post_content) – LENGTH(REPLACE(post_content, ‘ ‘, ”))+1 from wp_posts where ID=”.$post_id; // This query will return … Read more

Get user’s most published categories

This can be done easily with $wpdb, here’s my approach: function GetTop2CategoryByUser($user_id, $taxonomy){ global $wpdb; $results=$wpdb->get_results( $wpdb->prepare( ” SELECT tt.term_id as category, COUNT(p.ID) as count FROM $wpdb->posts p JOIN $wpdb->term_relationships tr ON p.ID = tr.object_id JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id AND (tt.taxonomy = %s AND tt.term_taxonomy_id != 1) WHERE p.post_author = %s GROUP … Read more

Set Display Name to first and last name (phpmyadmin SQL Query)

I know this is an old question, but for anyone still looking how to achieve this, the following query should do the job: UPDATE wp_users INNER JOIN wp_usermeta AS fn_meta ON wp_users.ID = fn_meta.user_id AND fn_meta.meta_key = ‘first_name’ INNER JOIN wp_usermeta AS ln_meta ON wp_users.ID = ln_meta.user_id AND ln_meta.meta_key = ‘last_name’ SET wp_users.display_name = CONCAT(fn_meta.meta_value, … Read more

Get users only if Gravatar is specified

Gravatar by design doesn’t require the downstream system to be aware if there is a match. The image (if any) is determined and served on request, only hash needs to be provided. It’s impossible to “guess” from email or its hash if it has an avatar. That can only be resolved by request to the … Read more

How to add edit users capability to a custom role?

In the particular case that you were working on a multisite installation. Did you try to also add the ‘manage_network_users’ capability? function edit_shop_manager() { // Get custom role $shop_manager = get_role(‘shop_manager’); $shop_manager->add_cap(‘create_users’); $shop_manager->add_cap(‘edit_users’); $shop_manager->add_cap(‘manage_network_users’); $shop_manager->add_cap(‘delete_users’); $shop_manager->add_cap(‘list_users’); $shop_manager->add_cap(‘remove_users’); $shop_manager->add_cap(‘promote_users’); } add_action( ‘init’, ‘edit_shop_manager’ );