This website uses cookies to allow us to see how the site is used. If you continue to use this site, we assume that you are okay with this. If you want to use the sites without cookies, please see our privacy policy.

Have all WordPress user data emailed to site owner on registration

Some sites will have additional user data in the registration form, when users register the site owner is notified by email. Now rather than just getting notified by WordPress that a new user has registered why not have all WordPress user data emailed to site owner on registration, here’s a function that does just that.

function new_user_registered($user_id) {
    global $wpdb;
    $admin_email = get_bloginfo('admin_email');

    if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles
        $to = $admin_email;
        $subject = 'Yay! You have a new registered user.';
        $message = "The user has registered with the following user meta data:\n";
        foreach($_POST as $key => $value){
            $message .= $key . ': '. $value . '\n';
        }
        wp_mail( $to, $subject, $message);
    }
}
add_action( 'user_register', 'new_user_registered');

function yoursite_wp_mail_from($content_type) {
  return 'changethis@mydomain.com';
}
add_filter('wp_mail_from','yoursite_wp_mail_from');

function yoursite_wp_mail_from_name($name) {
  return 'From a Nice Name';
}
add_filter('wp_mail_from_name','yoursite_wp_mail_from_name');

About

A geek who likes to code and be nice ^_^

4 thoughts on “Have all WordPress user data emailed to site owner on registration

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.