• Resolved southcast

    (@southcast)


    in my wordpress based site, I have got a couple of users with two kinds of levels (editor and author ) and in order to keep track of their attendance, I need a simple widget on my dashboard ( something like one illustrated below ), which could tell me which of the users are logged in or not alongwith the last time the user logged in in human time.

    JOHN DOE : ONLINE [ Last login – 3 days ago ]
    JANE DOE : OFFLINE [ Last login – 260 days ago ]
    ANOTHER JOHN : ONLINE [ Last login – 2 hours ago ]

    Earlier I searched in google and www.ads-software.com and went through numerous posts in order to find a solution. They all seem pretty similar to what I need but not specific. Is there a way this could be accomplished without a plugin.

Viewing 1 replies (of 1 total)
  • Thread Starter southcast

    (@southcast)

    I had this sorted earlier, thought will just leave an answer here for someone looking to do something similar. Well the code below is rough and is just an example so you will need to modify according to your need. The code will give you the status of the users online-offline.

    <?php if ( is_user_logged_in() ) {
          $current_user = wp_get_current_user();
          if ( 19 == $current_user->ID ) {
          echo 'JOHN - ONLINE';
          } else {
          echo 'JOHN - OFFLINE';
          }
      }
    ?>

    To show the time of the last login needs a little more tweaks. First paste this function to your functions.php

    function your_last_login($login) {
        global $user_ID;
        $user = get_userdatabylogin($login);
        update_usermeta($user->ID, 'last_login', current_time('mysql'));
    }
    add_action('wp_login','your_last_login');
    function get_last_login($user_id) {
        $last_login = get_user_meta($user_id, 'last_login', true);
        $date_format = get_option('date_format') . ' ' . get_option('time_format');
        $the_last_login = mysql2date($date_format, $last_login, false);
        echo $the_last_login;
    }

    and then use this on your template file to get the last login details.

    <?php
             global $userdata;
             get_currentuserinfo();
             echo  'Last Login:';
             get_last_login($userdata->ID);
    ?>

    If you want you can make a tiny plugin out of this.
    Cheers !

Viewing 1 replies (of 1 total)
  • The topic ‘display online status of users in the wordpress admin dashboard’ is closed to new replies.