Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

php - How to display current and old information for WordPress in Email message

I'm currently programming a service that sends out an Email, when an user updates his/her profile. This information will be displayed as a Discord Message (integration via Zapier). My question, my current setup only displays the old information, how can I get the newest & older version being sent out?. If I apply the same code at my profile page I do get the 'latest' version.

So the problem I currently have: $discord_username is the previous data, instead of the up to date variant. The $user_info_old / $user_info_old->discord_id is empty, and if I print_r($olduserdata) then I just get a 1 back.

The how can I get the current information for $user_info->discord_id and the previous data for $user_info->discord_id? This is my current setup. Not the nicest, but it does the job for 90%.

function user_profile_update( $user_id, $olduserdata ) {
    $site_url = get_bloginfo('wpurl');
    $active_memberships = wc_memberships_get_user_memberships( $user_info, $args );
    $user_info = get_userdata( $user_id );
    $user_info_old = get_userdata( $olduserdata );
    $discord_username = $user_info->discord_id;
    
    if ($active_memberships && $discord_username) {
      $namemembership = $active_memberships[0]->plan->name;
      $user_regdate = date( 'm/d/Y h:s', strtotime( $user_info->user_registered ) );
      $to = '[email protected]'; 
      $subject = $user_info->discord_id;
      $message = "**Name: **".$user_info->user_firstname." ".$user_info->user_lastname. "
**Email Address: **" .$user_info->user_email. "
**Membership: **".$namemembership."
**Registered: **".$user_regdate." UTC
".$user_info_old->discord_id."Please make sure to add correct permission and remove verified tag. 
Discord ID:```".$user_info->discord_id."
```".$user_info_old->discord_id."```";
      wp_mail( $to, $subject, $message);
    } 
    clean_user_cache( $user_info );
}

Update I've tried various caching methods, but nothing sofar. + as a bonus: the message tends to display twice. Is this function/hook being called twice normally?

question from:https://stackoverflow.com/questions/65891002/how-to-display-current-and-old-information-for-wordpress-in-email-message

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...