Today, We want to share with you WordPress set and get User last login Date and time.In this post we will show you How to Store Users Last Login Time in WordPress Datatbse, hear for How to Capture Users Last Login Date and Time in WordPress we will give you demo and example for implement.In this post, we will learn about How to get last login Access Date and time in wordpress with an example.
WordPress set and get User last login Date and time
There are the Following The simple About WordPress set/get User last login Datetime Full Information With Example and source code.
As I will cover this Post with live Working example to develop how to display last login time in php, so the php last login date and time script for this example is following below.
WordPress Set user last login time
Set User Last Login Date And Time In WordPress Without Plugin
add_action('wp_login', 'set_last_login'); //function for setting the last signin function set_last_login($login) { $user = get_userdatabylogin($login); $current_login_time = get_user_meta( $user->ID , 'current_login', true); //add or update the last login value for logged in user if(!empty($current_login_time)){ update_usermeta( $user->ID, 'last_login', $current_login_time ); update_usermeta( $user->ID, 'current_login', current_time('mysql') ); }else { update_usermeta( $user->ID, 'current_login', current_time('mysql') ); update_usermeta( $user->ID, 'last_login', current_time('mysql') ); } } function get_last_login($user_id) { $user_last_login = get_user_meta($user_id, 'last_login', true); $custom_date_format = get_option('date_format') . ' ' . get_option('time_format'); if(wp_is_mobile()) { $user_last_signin = date("M j, y, g:i a", strtotime($user_last_login)); }else { $user_last_signin = mysql2date($custom_date_format, $user_last_login, false); } return $user_last_signin; }
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about WordPress set/get User last login Datetime.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.