Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using XProfile fields in Admin Notification Mail after activation


  • dennis.cabasal
    Participant

    @denniscabasal

    Hi,

    I’m new to buddypress and I was trying to add the xprofile fields to admin email after activation.

    I found this code and I’m desperately trying to figure out how to make it work.

    /*
    Plugin Name: Custom New User Email
    Description: Changes the copy in the email sent out to new users
    */
     
    // Redefine user notification function
    if ( !function_exists('wp_new_user_notification') ) {
        function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
            $user = get_userdata( $user_id );
          
    	// The blogname option is escaped with esc_html on the way into the database in sanitize_option
    	// we want to reverse this for the plain text arena of emails.
    	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    	
    	// find the profile field for referrer
    	//$field1 = xprofile_get_field_data( 'Referrer', $user_id );
            $field1 = xprofile_get_field_data( 'field_id=1', $user_id );
            $field2 = xprofile_get_field_data( 'field_id=2', $user_id );
            $field3 = xprofile_get_field_data( 'field_id=3', $user_id );
    	$field4 = xprofile_get_field_data( 'field_id=4', $user_id );
    	$field5 = xprofile_get_field_data( 'field_id=5', $user_id );
    	$field6 = xprofile_get_field_data( 'field_id=6', $user_id );
    	$field7 = xprofile_get_field_data( 'field_id=32', $user_id );
    	$field8 = xprofile_get_field_data( 'field_id=8', $user_id );
    	$field9 = xprofile_get_field_data( 'field_id=9', $user_id );
    	$field10 = xprofile_get_field_data( 'field_id=10', $user_id );
    	$field11 = xprofile_get_field_data( 'field_id=13', $user_id );
    	$field12 = xprofile_get_field_data( 'field_id=16', $user_id );
    	$field13 = xprofile_get_field_data( 'field_id=25', $user_id );
    
    	$message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
    	$message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
    	$message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n\r\n";
    	$message .= sprintf(__('First Name: %s'), $field1) . "\r\n";
    	$message .= sprintf(__('Last Name: %s'), $field2) . "\r\n";
    	$message .= sprintf(__('Job Title: %s'), $field3) . "\r\n";
    	$message .= sprintf(__('Company: %s'), $field4) . "\r\n";
    	$message .= sprintf(__('Address 1 : %s'), $field5) . "\r\n";
    	$message .= sprintf(__('Address 2 : %s'), $field6) . "\r\n";
    	$message .= sprintf(__('Country	: %s'), $field7) . "\r\n";
    	$message .= sprintf(__('City: %s'), $field8) . "\r\n";
    	$message .= sprintf(__('Zip: %s'), $field9) . "\r\n";
    	$message .= sprintf(__('Phone: %s'), $field10) . "\r\n";
    	$message .= sprintf(__('Fax: %s'), $field11) . "\r\n";
    	$message .= sprintf(__('Relationship: %s'), $field12) . "\r\n";
    	$message .= sprintf(__('Interest: %s'), $field13) . "\r\n";
    
    	@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
    
    	if ( empty($plaintext_pass) )
    		return;
    
    	$message  = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    	$message .= wp_login_url() . "\r\n";
    
    	wp_mail($user->user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
     
         }
    }
     

    Please help.

    Thank you so much

    Dennis

Viewing 6 replies - 1 through 6 (of 6 total)

  • aldorr
    Participant

    @aldorr

    You can try placing this in the functions.php of your Child Theme. Though for buddypress you might want to use bp_get_profile_field_data instead of xprofile_get_field_data.
    I’m trying to do something similar, but the fields are not showing up in my email. I have a feeling the email is getting sent before the database is updated, but for the life of me, I can’t get them… Good luck!


    MorgunovVit
    Participant

    @morgunovvit

    The same question and the same problem!


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Please use this filter apply_filters( ‘wp_new_user_notification_email’, $wp_new_user_notification_email, $user, $blogname ); to change the mail content.

    Thanks


    MorgunovVit
    Participant

    @morgunovvit

    Hi, Prashant!
    Could you describe in more detail why you advise using wp_new_user_notification_email for admin notification?
    And could You give some example?


    MorgunovVit
    Participant

    @morgunovvit

    I’ve tried to use these code:

    function mv_send_additional_emails($user_id){
    $user = get_userdata($user_id);
    $mv_options = get_option('mv_email_admin_option');
    $mv_message = $mv_options? $mv_options['textarea'] : null;
    $cc_mail = $mv_options ? $mv_options['input'] : null;		
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    		
    $message = sprintf(__('New user registred on site %s:'), $blogname) . "<br>\r\n\r\n";
    $message .= sprintf(__('User login: %s'), $user->user_login) . "<br>\r\n\r\n";
    $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n\r\n";
    $message .= sprintf(__('Message text: %s'), $mv_message) . "<br>\r\n\r\n";
    
    /* BuddyPress xprofile */
    $mv_xp_bp_phone =xprofile_get_field_data( 23, $user_id ); // Phone field idd = 23
    $mv_last_name =xprofile_get_field_data( 24, $user_id ); // Last_name field id =24
    
    $message .= sprintf(__('Phone: %s; Last name: %s;' ), $mv_xp_bp_phone, $mv_last_name) . "\r\n";		
    	$headers = array(
    	'From: Sitename <noreply@mc21academy.ru>',
    	'content-type: text/html',
    	'Cc: '
    	);
    // send e-mail to admin
    @wp_mail(get_option('admin_email'), sprintf(__('[%s] New user registered'), $blogname), $message, $headers);}
    	
    add_action('user_register', 'mv_send_additional_emails'); 

    But it didn’t work – the xprofile filds return empty (null).
    But if i try to get xprofile field data for existing user – it works fine
    for example for user id = 1 – xprofile_get_field_data( 23, 1 )) returns: ‘+7 911 810 35 05’!

    I also tried to use another hook: add_filter(‘bp_core_signup_send_validation_email_message’, ‘mv_send_additional_emails’, 10, 3)
    But it doesn’t work too


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    You can also test hook do_action( ‘bp_complete_signup’ ); You can find the hooks related ton registration here buddypress/bp-members/screens/register.php

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar