最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How Can I Display the Last Modified Date for User Profiles on WordPress?

programmeradmin1浏览0评论

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;
}
发布评论

评论列表(0)

  1. 暂无评论