I'm trying to add a "last modified" date to user profiles on WordPress. I'm using the Ultimate Member plugin, so I would prefer to to find a way to save this date to a meta-key that I can pull when I do a search as well.
So far, I this is what I have using a shortcode [wppb-last-updated]
, but it displays the currently logged in user's last modified date. As an admin, I need to see when others have last modified their own information. Any suggestions?
add_filter('wppb_edit_profile_all_changes_saved', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_existing_email', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_invalid_email', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_mismatch_password', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_uncompleted_password', 'wppb_last_updated_save');
function wppb_last_updated_save($content){
$user = wp_get_current_user();
update_user_meta( $user->ID, 'wppb_last_updated', date("d / M / Y") );
return $content;
}
add_shortcode( 'wppb-last-updated', 'wppb_last_updated_print');
function wppb_last_updated_print(){
$user = wp_get_current_user();
$last_updated = get_user_meta($user->ID, 'wppb_last_updated', true );
if ( $last_updated == '' ){
$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
return date( "m/d/Y", strtotime( $registered ) );
}
return $last_updated;
}
EDIT: Is there an alternative method of pulling up the modified date of a user profile via shortcode and parameter anywhere on the site? Something like this?
/**
* Shortcode for Displaying Last Modified Date of User Profile
* Usage: [wppb-last-updated user_id="1"]
*/
add_filter('wppb_edit_profile_all_changes_saved', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_existing_email', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_invalid_email', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_mismatch_password', 'wppb_last_updated_save');
add_filter('wppb_edit_profile_all_changes_saved_except_uncompleted_password', 'wppb_last_updated_save');
function wppb_last_updated_save($content){
$user = $user_id;
update_user_meta( $user->ID, 'wppb_last_updated', date("d / M / Y") );
return $content;
}
add_shortcode( 'wppb-last-updated', 'wppb_last_updated_print');
function wppb_last_updated_print($atts){
$user_id = shortcode_atts( array('user_id' => ''), $atts );
$last_updated = get_user_meta($user->ID, 'wppb_last_updated', true );
if ( $last_updated == '' ){
$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
return date( "m/d/Y", strtotime( $registered ) );
}
return $last_updated;
}