Skip to:
Content
Pages
Categories
Search
Top
Bottom

display member updated date?

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

  • somethingelse
    Participant

    @somethingelse

    last login date isn’t sufficient… btw. they have to log in to access files and other info, which doesn’t always mean they updated their profile or payments


    Henry Wright
    Moderator

    @henrywright

    Hi @somethingelse

    Have you ever thought about a custom solution using user meta? Something like:

    // Hook this to a particular action.
    update_user_meta( get_current_user_id(), 'active', current_time( 'mysql' ) );

    Then you’d get that for display using something like this:

    // $last_active will be a date-time string.
    $last_active = get_user_meta( get_current_user_id(), 'active', true );

    Refs:
    https://codex.wordpress.org/Function_Reference/get_user_meta
    https://codex.wordpress.org/Function_Reference/update_user_meta


    shanebp
    Moderator

    @shanebp

    There are per-user entries in the bp_activity database table for type > update_profile and date_recorded.
    Here a function for retrieving that info on a per-user basis.
    Put it in bp-custom.php or your theme functions.php

    function last_profile_update( $user_id ) {
      global $wpdb; 
    	
      $last_update = $wpdb->get_var( "SELECT date_recorded FROM {$wpdb->prefix}bp_activity WHERE user_id = $user_id AND type = 'updated_profile' ORDER BY date_recorded DESC LIMIT 1" );
    	
      echo 'last profile update: ' . $last_update;
    }

    Use it wherever you want like so: last_profile_update( 1 );


    Henry Wright
    Moderator

    @henrywright

    @shanebp is it worth escaping $user_id in the SQL statement? think you can use the prepare() method for that?


    shanebp
    Moderator

    @shanebp

    Using prepare would be easy and fine.
    But if it’s only being used internally, is there really any need ?
    I assume she’ll only use it on the front-end with a is_super_admin check before calling.
    And using it in a wp-admin > users column shouldn’t be a problem.

    But you’re right, using prepare is the best practice.
    And no, I’m not going to update it, lol.


    Henry Wright
    Moderator

    @henrywright

    I was thinking the same (i.e. just used internally). It’s when you start doing things like last_profile_update( $_GET['user_id'] ) you have to worry lol. I suppose it’s worth it for the record…? here goes…

    $last_update = $wpdb->get_var( $wpdb->prepare( 
    	"
    		SELECT date_recorded 
    		FROM {$wpdb->prefix}bp_activity 
    		WHERE user_id = %d 
                    AND type = 'updated_profile' 
                    ORDER BY date_recorded DESC 
                    LIMIT 1 
    	", 
    	$user_id
    ) );

    somethingelse
    Participant

    @somethingelse

    thank you for the assistance…
    curious – what would be the point of checking for is_super_admin? i do want it to display on the public-facing side of things, not just for me.

    i admit to NOT being a programmer… so particularly appreciate the details of nuances. Does ” doing things like last_profile_update( $_GET[‘user_id’] ) ” put my site at risk somehow?

    i haven’t quite got it working yet, but this really helped get me on the right track.


    Henry Wright
    Moderator

    @henrywright

    last_profile_update( $_GET['user_id'] ) is only a bad thing if you don’t escape $user_id in the SQL statement provided by @shanebp. That’s because $_GET['user_id'] could be tainted as it is received from the browser. In your case, you won’t be doing that. You’ll be providing the user ID yourself so using @shanebp’s SQL should be absolutely fine. If you were to accept the user ID from the browser, or from a user submission then that’s when you should use the prepare method (see my SQL above).

    Hope that helps?


    somethingelse
    Participant

    @somethingelse

    ahh… thank you. helps increase my education 🙂 so i understand why NOT to do something.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘display member updated date?’ is closed to new replies.
Skip to toolbar