Created
January 9, 2020 11:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the awsome support, it works like a charm.
Greetings from Germany!
-Paul