wp_loginaction-hookWP 1.5.0

Fires after a user has successfully logged in.

Usage

add_action( 'wp_login', 'wp_kama_login_action', 10, 2 );

/**
 * Function for `wp_login` action-hook.
 * 
 * @param string  $user_login Username.
 * @param WP_User $user       WP_User object of the logged-in user.
 *
 * @return void
 */
function wp_kama_login_action( $user_login, $user ){
	// action...
}
$user_login(string)
The username (login).
$user(WP_User)
The logged-in user object.

Examples

#1 Record the time when a user logs in

## Record the time when the user visits their profile
add_action( 'wp_login', 'write_time_when_user_logged_in', 10, 2 );
function write_time_when_user_logged_in( $user_login, $user ){
	// Write to the meta-fields
	update_user_meta( $user->ID, 'last_login_time', time() );

	// Or write the timestamp to an unused column in the wp_users table
	// global $wpdb;
	// $wpdb->query("UPDATE $wpdb->users SET user_status = ". time() ." WHERE ID = $user->ID LIMIT 1");
}

Changelog

Since 1.5.0 Introduced.

Where the hook is called

wp_signon()
wp_login
wp-includes/user.php 138
do_action( 'wp_login', $user->user_login, $user );

Where the hook is used in WordPress

Usage not found.