Skip to content

Instantly share code, notes, and snippets.

@mwhiteley16
Created February 8, 2018 13:39
Show Gist options
  • Save mwhiteley16/0ee9c5ed0cbd4fcdceb08a186ff093b4 to your computer and use it in GitHub Desktop.
Save mwhiteley16/0ee9c5ed0cbd4fcdceb08a186ff093b4 to your computer and use it in GitHub Desktop.
Count Logins
<?php
// Create simple meta field to count number of logins
add_action( 'wp_login', 'wd_login_counter' );
function wd_login_counter( $username ){
$userdata = get_user_by( 'login', $username );
$login_count = get_user_meta( $userdata->ID, 'wd_login_count', true );
if ( !is_numeric($login_count) ) $login_count = 0;
$login_count = intval($login_count) + 1;
update_user_meta($userdata->ID, 'wd_login_count', $login_count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment