Users: List A to Z, for Users

There’s the WP_User_Query for that: /** * List all Users * Use as: Template Tag * * @uses WP_User_Query * @return (array) List of user objects */ wpse35713_get_users_list() { $query = new WP_User_Query( array( ‘order’ => ‘ASC’ ,’orderby’ => ‘login’ ) ); $users = $query->get_results(); $html = “<ul><li>”; foreach ( $users as $user ) { … Read more

How to add custom fields to my custom registration form

There’s wp_login_form() for such cases. It offers tons of hooks to extend it. // In your template wp_login_form( array( /* Args: refer to Codex page */ ) ); A more in-depth look at the filters, can be found here @GitHub WP Core source. ‘login_form_top’ – above login-username ‘login_form_middle’ – above login-submit ‘login_form_bottom’ – below login-submit … Read more

How to create a Menu based a username

As said in the comments, this depends on how many users there are and how different those menus are supposed to be. If there are just a few users and you want completely different menus for each of them, you would have to create different menus in the backend and the call them conditionally in … Read more

How to delete all post and attachments of a user when I delete it?

The hook you choose is appropriate, and here is how to use it to delete all posts of all types (posts, pages, links, attachments, etc) of the deleted user: add_action(‘delete_user’, ‘my_delete_user’); function my_delete_user($user_id) { $args = array ( ‘numberposts’ => -1, ‘post_type’ => ‘any’, ‘author’ => $user_id ); // get all posts by this user: … Read more

Query users by capability – uninstall/deactivate callback

It was actually much easier than I originally thought – just doing a WP_User_Query for a meta value (meta arrays are supported as well, like for the other query classes). public function on_deactivate() { $meta_key = ‘tools_page_tsi_per_page’; $query = new WP_User_Query( array( ‘meta_key’ => $meta_key ) ); if ( empty( $query->results ) ) return; foreach … Read more

Highlighting the current users comment

assumes that your theme is using comment_class(); example (to be added to functions.php of your theme): add_filter( ‘comment_class’, ‘comment_class_logged_in_user’ ); function comment_class_logged_in_user( $classes ) { global $comment; if ( $comment->user_id > 0 && is_user_logged_in() ) { global $current_user; get_currentuserinfo(); $logged_in_user = $current_user->ID; if( $comment->user_id == $logged_in_user ) $classes[] = ‘comment-author-logged-in’; } return $classes; } requires … Read more

Average Account Age

WordPress records when a user was registered in the $wpdb->users (usually wp_users) table in the column user_registered. So you can use that to calculate the average account age. There’s no internal function for this, so you’ll have to use $wpdb directly. This stackoverflow answer has some good info about calculating the average of a series … Read more