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

Embed Snippet on Your Site

MemberPress: Send “Profile Updated” Admin Notification

The code changes WordPress's functioning to send notifications to the admin when a user modifies their profile.

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]

The code above works only with the default when the WordPress user profile is updated, but it doesn’t work for the MemberPress-specific data changes when user data is edited on our Account page.

Thus, if the notification needs to be triggered also when users modify data through their Account page, an additional code snippet is needed (both snippets are required): https://library.wpcode.com/snippet/05k4dv6o/

Code Preview
php
<?php
function user_profile_update( $user_id ) {
  $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_bloginfo( 'admin_email' ), $subject, $message );
}
add_action( 'profile_update', 'user_profile_update', 10, 2 );

Comments

Add a Comment