• Resolved makmerghen

    (@makmerghen)


    hello
    I used this code to let the logged in user can add new users while he logged in
    add_filter( 'um_registration_for_loggedin_users', '__return_true' );
    and use the next code to fix the un sent email to the new user and to admin

    add_action("um_registration_complete","um_070221_email_notification",1);
    function um_070221_email_notification( $user_id ){
        um_fetch_user( $user_id );
        $email = um_user("user_email");
        UM()->mail()->send( $email, 'welcome_email' );
        
        $emails = um_multi_admin_email();
    	if ( ! empty( $emails ) ) {
    		foreach ( $emails as $email ) {
    			if ( um_user( 'account_status' ) != 'pending' ) {
    				UM()->mail()->send( $email, 'notification_new_user', array( 'admin' => true ) );
    			} else {
    				UM()->mail()->send( $email, 'notification_review', array( 'admin' => true ) );
    			}
    		}
    	}
        
    }

    its look with new update of UM the admin email was work well and thus this code cause to duplicate the sent email to admin where he hot 2 same emails
    would you please help to remove the part of sending admin email from this code
    best regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Please try this:

    add_action("um_registration_complete","um_070221_email_notification",1);
    function um_070221_email_notification( $user_id ){
        um_fetch_user( $user_id );
        $email_admin = um_user("user_email");
        UM()->mail()->send( $email_admin, 'welcome_email' );
        
        $emails = um_multi_admin_email();
    	if ( ! empty( $emails ) ) {
    		foreach ( $emails as $email ) {
    
                            if( $email_admin == $email ) continue; // skip email to avoid duplicate
    
    			if ( um_user( 'account_status' ) != 'pending' ) {
    				UM()->mail()->send( $email, 'notification_new_user', array( 'admin' => true ) );
    			} else {
    				UM()->mail()->send( $email, 'notification_review', array( 'admin' => true ) );
    			}
    		}
    	}
        
    }

    Regards,

    • This reply was modified 3 years, 2 months ago by Champ Camba.
    Thread Starter makmerghen

    (@makmerghen)

    it send also 2 emails to admin

    dear would you please leave the first part of sending email to user
    and remove the second part of sending email to admin I think that will solve the issue

    I tried to do that but because I have no idea about codes it didn’t adjusted to me

    regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Which email notification was sent twice? Is it the welcome email?

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Here’s the code that sends a welcome email for the newly registered user:

    add_action("um_registration_complete","um_070221_email_notification",1);
    function um_070221_email_notification( $user_id ){
        um_fetch_user( $user_id );
        $email_admin = um_user("user_email");
        UM()->mail()->send( $email_admin, 'welcome_email' );
    }

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    regarding your question
    Which email notification was sent twice? Is it the welcome email?

    no the duplicate email was for admin notice for new user

    and after removing the new code above
    everything became normal
    one welcome email to user
    one new user notice email to admin

    thanks a lot and best regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know. I’m marking this as resolved now.

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘duplicated admin email’ is closed to new replies.