Skip to:
Content
Pages
Categories
Search
Top
Bottom

User Last Login

Viewing 6 replies - 1 through 6 (of 6 total)

  • Robin W
    Moderator

    @robin-w

    suspect this is what you need – untested !!

    $user_id = bbp_get_displayed_user_id() ;
    $last_login = get_user_meta($user_id, 'last_login', true);

    so if you go down the route you have, you’d add a second shortcode

    function rew_lastlogin () {
    	$user_id = bbp_get_displayed_user_id() ;
    	$last_login = get_user_meta($user_id, 'last_login', true);
        $the_login_date = date_i18n(get_option('date_format'), $last_login);
       return $the_login_date; 
    }
    
    add_shortcode('bbp_lastlogin','rew_lastlogin');

    and then use

    <?php echo ‘Last seen: ‘. do_shortcode(‘[bbp_lastlogin]’) .’ ago’; ?>


    thinkercorner11
    Participant

    @thinkercorner11

    Thanks for the fast reply, but unfortunately it didn’t work. It’s still showing my last login date everywhere. I have tried to look what login date will show, when I am not logged in, but it is showing the same, so I think it has something to do, that it is showing the admin last login (not the one of the current logged in user). One possibility also could be that some code of the theme is overriding the functions of bbPress, so I will ask the developer if there is any theme related code to get the user id.


    thinkercorner11
    Participant

    @thinkercorner11

    Hmm, he said there is no function, which is overriding these functions, but he send me this code:

    function wpb_lastlogin() { 
        $last_login = get_user_meta(bbp_get_displayed_user_field( 'ID' ), 'last_login', true);
        if ($last_login) {
            $the_login_date = date_i18n(get_option('date_format'), $last_login);
        } else {
            $the_login_date = 'The user is not logged in yet.';
        }
        return $the_login_date; 
    }

    But still not working. It also could be that I messed up the integration process a bit, because I used a plugin to save the last login in the admin panel, and after this I was trying to use the snippet. Is there a way to reset the last login metadata?


    Robin W
    Moderator

    @robin-w

    that’s basically a rewrite of my code, so suggest that you have a problem somewhere.

    You are putting this code in your functions file – yes ?

    in which case can you show the actual code including the function/lines before it and after it


    thinkercorner11
    Participant

    @thinkercorner11

    I fixed it 🙂 . Sorry, there was no problem with your code, or the code from the developer of the theme, there was a problem with a other plugin. I use the WordFence Security plugin, which also saves the last login metadata, but in a I different place, so I have deleted the first part of the snippet (which is saving the last login metadata) and changed

    $last_login = get_user_meta($user_id, ‘last_login’, true);

    to

    $last_login = get_user_meta( $user_id, ‘wfls-last-login’, true);

    So thanks for the help, looks like the problem is solved.


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar