Execute a function when admin changes the user role

You can use the set_user_role hook, that will only fire when the user role changes: add_action( ‘set_user_role’, function( $user_id, $role, $old_roles ) { // Your code … }, 10, 3 ); If you want to restrict this to a profile update, you can use: add_action( ‘set_user_role’, function( $user_id ) { add_action( ‘profile_update’, function( $user_id ) … Read more

Change the author slug from nickname to ID

Surprised to see this unanswered for this long. This is pretty simple to do with a simple block of code: function set_my_nice_name() { global $wpdb; $user_table = $wpdb->prefix . ‘users’; $wpdb->query(“UPDATE $user_table SET `user_nicename`=`ID`”); } add_action(‘init’, ‘set_my_nice_name’); This works because the visible portion of an author slug (or profile slug in BuddyPress) uses the user_nicename … Read more

alphabetically order role drop-down selection in dashboard

Almost the same approach One Trick Pony has chosen, but I am using translated names and uasort() (to preserve the keys): add_filter( ‘editable_roles’, ‘t5_sort_editable_roles’ ); /** * Array of roles. * * @wp-hook editable_roles * @param array $roles * @return array */ function t5_sort_editable_roles( $roles ) { uasort( $roles, ‘t5_uasort_editable_roles’ ); return $roles; } /** … Read more

How can 2 blogs share the same users

I think you want to install your second site on the same database but with a different table prefix, e.g. $table_prefix = “qa_”; in wp-config.php You are then able to define a custom user and/or user_meta table by adding the following lines to wp-config.php define(‘CUSTOM_USER_TABLE’, [orig_table_prefix].’my_users’); define(‘CUSTOM_USER_META_TABLE’, [orig_table_prefix].’my_usermeta’); Source: http://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables I have read somewhere before … Read more

Ban a user and end their session

Use wp_logout(). It calls wp_clear_auth_cookie() and invalidates the current log-in information immediately. Sample code, not tested: add_action( ‘init’, ‘log_out_banned_user’ ); function log_out_banned_user() { if ( ! is_user_logged_in() ) return; $user = wp_get_current_user(); if ( ! get_user_option( ‘rc_banned’, $user->ID, false ) ) return; wp_logout(); wp_redirect( home_url( “https://wordpress.stackexchange.com/” ) ); exit; }

Email user when password is reset by admin

Here’s one way to add this feature using the following flowline : The admin updates the user option page: -> edit_user_profile_update or personal_options_update hooks activated -> edit_user() function is called -> wp_update_user() function is called within edit_user() -> wp_insert_user() function is called within wp_update_user() -> profile_update hook activated within wp_insert_user() for user updates, not user … Read more