Home / Archive / MemberPress: Send “Profile Updated” Admin Notification When MemberPress Account Is Updated
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Send “Profile Updated” Admin Notification When MemberPress Account Is Updated

Similar to the code snippet here: https://library.wpcode.com/snippet/m5ye1wj2/, this code sends a notification to the admin when a user modifies information on their MemberPress Account page.

In the example code, the following lines were used to retrieve specific user data and create the arguments to display that data:

$user_name = $user_info->display_name;
$user_email = $user_info->user_email;

These arguments are added to the message to display retrieved user data in the e-mail body:

$message = "Profile of $user_name , $user_email has been updated!";

Following this logic, you can also add other arguments and update the message you wish to receive.

In addition, the code can be modified to send this notification to any other e-mail. To do this, the code needs to be updated on the following line:

wp_mail( '[email protected]', $subject, $message);

Here, users can add any e-mail address they want instead of [email protected]

Code Preview
php
<?php
function user_profile_update($user) {
  $site_url = get_bloginfo('wpurl');
  $user_info = get_userdata($user->ID);
  $user_name = $user_info->display_name; //Retrieves user's full name
  $user_email = $user_info->user_email; //Retrieves user's e-mail address
  $subject = "Profile Updated: ".$site_url."";
  $message = "Profile of $user_name , $user_email has been updated!"; //Displays retrieved user data in the message
  wp_mail(get_option('admin_email'), $subject, $message);
}
add_action('mepr-save-account', 'user_profile_update');

Comments

Add a Comment