WordPress.org

Forums

Simple History
[resolved] Log the users "logged in" when remember checked (3 posts)

  1. RR_80
    Member
    Posted 2 years ago #

    Hello,

    first of all thanks for the plugin.

    However it seems that I spotted a bug. I do use the "WP User Control" Plugin to to give the visitor a chance to Login by a widget. Works fine. If i do the login the correct entries into the table wp_simple_history will be inserted. But if the checkbox "Remember User" is checked, the user will be logged in by its next visit automaticaly without an explixite Login. This works most likely by loading a cookie, somehow by using 'wp_validate_auth_cookie(...)'. This action is missed by the Simple History Plugin. I would like to inform my visitors about the changes since the last visit, but this is not possible. You have to login and logout manually to log the login. I am a programmer and tried to fix it by myselfe. But I am not that much familiar with PHP and wordpress (I work professionaly with C++) and was lost by trying to find the correct entrypoint to protocol this action.

    Thanks in advance!

    http://wordpress.org/extend/plugins/simple-history/

  2. RR_80
    Member
    Posted 2 years ago #

    I tried to solve the problem as the following:

    function __construct()
    {
       ...
       add_action('init', 'loginlog_active');
       ...
    }
    function loginlog_active()
    {
       $current_user = wp_get_current_user();
       $current_user_id = $current_user->ID;
       $user_nicename = urlencode($current_user->user_nicename);
       if (isset($current_user_id) && $current_user_id > 0)
       {
          global $wpdb;
          $query_LastLogin = "SELECT (NOW() - MAX(wp_simple_history.date)) / 86400 AS lastLogin FROM wp_simple_history WHERE (action = 'logged in' AND user_id = '$current_user_id');";
          $lastLogin       = $wpdb->get_results($query_LastLogin);
          if (isset($lastLogin[0]->lastLogin) && $lastLogin[0]->lastLogin >= 3.0)
          {
             simple_history_add("action=logged in&object_type=user&object_id=$current_user_id&object_name=$user_nicename");
          }
       }
    }

    Every time the user ist active, the function test if the last login is older than 3 hours. If yes, an new Login-entry will be createt.

  3. RR_80
    Member
    Posted 2 years ago #

    better:

    function loginlog_active()
    {
       $current_user = wp_get_current_user();
       $current_user_id = $current_user->ID;
       $user_nicename = urlencode($current_user->user_nicename);
       if (isset($current_user_id) && $current_user_id > 0)
       {
          global $wpdb;
          $query_LastLogin = "SELECT TIMESTAMPDIFF(MINUTE, MAX(wp_simple_history.date), NOW()) AS lastLogin FROM wp_simple_history WHERE (action = 'logged in' AND user_id = '$current_user_id');";
          $lastLogin       = $wpdb->get_results($query_LastLogin);
          if (isset($lastLogin[0]->lastLogin) && $lastLogin[0]->lastLogin >= (3.0*60.0))
          {
             simple_history_add("action=logged in&object_type=user&object_id=$current_user_id&object_name=$user_nicename");
          }
       }
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.