Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wp-user-manager/5a0fb78b8484cac47fee2ca342a2fb6e to your computer and use it in GitHub Desktop.
Save wp-user-manager/5a0fb78b8484cac47fee2ca342a2fb6e to your computer and use it in GitHub Desktop.
WP User Manager - Add all custom field data the user enters on registration to the email sent to the administrator
<?php
add_filter( 'wpum_admin_registration_confirmation_email_headers', function() {
return array('Content-Type: text/html; charset=UTF-8');
});
add_filter('wpum_admin_registration_confirmation_email_message', function( $message, $user ) {
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$message = sprintf( esc_html__( 'You have a new member application for the %s:', 'wp-user-manager' ), $blogname ) . "<br><br>";
$message .= sprintf( esc_html__( 'Username: %s', 'wp-user-manager' ), $user->user_login ) . "<br>";
$message .= sprintf( esc_html__( 'Date Registered: %s', 'wp-user-manager' ), date( "m/d/Y", strtotime( $user->user_registered ) ) ) . "<br>";
$message .= sprintf( esc_html__( 'E-mail: %s', 'wp-user-manager' ), $user->user_email ) . "<br>";
$message .= sprintf( esc_html__( 'First Name: %s', 'wp-user-manager' ), $user->first_name ) . "<br>";
$message .= sprintf( esc_html__( 'Last Name: %s', 'wp-user-manager' ), $user->last_name ) . "<br>";
$message .= sprintf( esc_html__( 'Website: %s', 'wp-user-manager' ), $user->user_url ) . "<br>";
$user_meta = get_user_meta( $user->ID );
$fields = WPUM()->fields->get_fields();
$wpum_fields = array();
foreach ( $fields as $field ) {
$key = $field->meta;
if ( empty( $key ) ) {
continue;
}
$wpum_fields[ $key ] = $field->name;
}
foreach( $user_meta as $user_meta_key => $user_meta_value ) {
if ( 0 !== strpos( $user_meta_key, 'wpum')) {
continue;
}
if ( ! isset( $wpum_fields[ $user_meta_key ] ) ) {
continue;
}
$message .= sprintf( esc_html__( '%s: %s', 'wp-user-manager' ), $wpum_fields[ $user_meta_key ], $user_meta_value[0] ) . "<br>";
}
return $message;
}, 10, 2 );
@PaulGoldschmidt
Copy link

Thanks for the awsome support, it works like a charm.
Greetings from Germany!
-Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment