Check if user is admin by user ID

You worded it as you want to check if user has administrator role. It is considered more proper to check for capability, relevant to specific action. In practice this is usually expressed as current_user_can( ‘manage_options’ ) for current user. For arbitrary user it would be user_can( $user_id, ‘manage_options’ ). Of course this is capability that … Read more

Automatically delete inactive users after 2 months

Your query is wrong because your third argument to TIMESTAMPDIFF is incorrect. You should be using meta_value instead of SELECT meta_value. SELECT user_id FROM wp_usermeta WHERE meta_key = ‘wp_wp_kc_last_active_time’ AND TIMESTAMPDIFF( second, now(), TIMESTAMP(meta_value) ) > 5184000; Try that and see if the results start looking correct. I just checked over the mySQL Date Function … Read more

What’s the difference between the capability remove_users and delete_users?

The difference is really no difference in regular (single install) WordPress. It’s in a multisite install (network) where there is a difference. In multisite, only a Super Admin (who can manage everything on the network) has delete_users capability, while an “admin” (who would own/manage a single site) can remove_users from their site, but cannot delete … Read more

List users by last name in WP_User_Query

There is a better way to do this as of WordPress version 3.7. Use the WordPress property meta_key to select the last name property and then orderby => meta_value with an ascending order. <?php $args = array( ‘meta_key’ => ‘last_name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’ ); $user_query = new WP_User_Query( $args ); if ( … Read more

How to Display a List of Users Who Have Made at Least 1 Post?

You need to set the who parameter in get_users <?php $blogusers = get_users( ‘orderby=post_count&who=authors’ ); foreach ( $blogusers as $user ) { echo ‘<li>’ . esc_html( $user->display_name ) . ‘</li>’; } ?> EDIT Seems I was to fast answering. The code in your question and in my answer is the start to what you want … Read more

Is there a way to merge two users?

Generally speaking I agree with most of the other answers but, if for some reason you really had to merge two accounts here is how that could work. Merging User-B into User-A Reassign all of User-B’s content to User-A Determine the highest privilege of User-B If higher than the privileges of User-A elevate User-A’s privileges … Read more