display member updated date?
-
i really really need/want to display the “last updated date” on each user profile.
in a perfect world, this would also display in the admin listing…we have a very active membership of 1000+, who have to re-license each year… and regularly update their profiles which have extensive xprofile fields added.
i need an easy way to see when updates were done on both sides.
i am using bp 2.1.1 and xprofile custom fields 2.0.3
with wp 4.0, s2member 141007
-
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
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_metaThere 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.phpfunction 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 );
@shanebp is it worth escaping
$user_id
in the SQL statement? think you can use the prepare() method for that?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.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 ) );
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.
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?
ahh… thank you. helps increase my education 🙂 so i understand why NOT to do something.
- The topic ‘display member updated date?’ is closed to new replies.