Created
April 30, 2020 09:23
-
-
Save rajucs/e6adb649df40c54b2415653286e31691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'wp_login', 'track_user_logins', 10, 2 ); | |
| function track_user_logins( $user_login, $user ){ | |
| if( $login_amount = get_user_meta( $user->id, 'login_amount', true ) ){ | |
| // They've Logged In Before, increment existing total by 1 | |
| update_user_meta( $user->id, 'login_amount', ++$login_amount ); | |
| } else { | |
| // First Login, set it to 1 | |
| update_user_meta( $user->id, 'login_amount', 1 ); | |
| } | |
| } | |
| add_shortcode( 'login_content', 'login_content' ); | |
| function login_content( $atts ){ | |
| if( is_user_logged_in() ){ | |
| // Get current total amount of logins (should be at least 1) | |
| $login_amount = get_user_meta( get_current_user_id(), 'login_amount', true ); | |
| // return content based on how many times they've logged in. | |
| if( $login_amount == 1 ){ | |
| return 'Welcome, this is your first time here!'; | |
| } else if( $login_amount == 2 ){ | |
| return 'Welcome back, second timer!'; | |
| } else if( $login_amount == 3 ){ | |
| return 'Welcome back, third timer!'; | |
| } else { | |
| return "Geez, you have logged in a lot, $login_amount times in fact..."; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment