• Resolved cartoonhank

    (@cartoonhank)


    Hello dear Forminator-Team,

    I have made a user registration form that allows users to register on our website. The newly registered user must then be approved by an admin. Works quite well so far.

    Then I’ve been trying to override the Default New User Notification Email when a news user registers, because WordPress keeps sending the default email, containing my Admin-URL, which User should not receive under any circumstances.

    Neither with the function wp_new_user_notification in the form of a custom plugin nor with the filter wp_new_user_notification_email I can override the default email. Could it be that Forminator uses the function / filter? Or did I overlook something?

    Thank you very much in advance.

    Kind Regards,
    cartoonhank

    • This topic was modified 1 year, 4 months ago by cartoonhank.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @cartoonhank

    Hope you are doing fine.

    There is a code snippet that could help you modify the content of the email. You’ll need to add a must-use plugin to your site’s wp-content/mu-plugins folder as explained in our documentation here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins, then add the following code to the plugin’s php file:

    <?php
    
    add_filter(
    	'forminator_custom_form_user_registration_before_insert',
    	function ( $new_user_data ) {
    		add_action( 'user_register', 'wpmudev_forminator_filter_user_register_email', 10, 2 );
    
    		return $new_user_data;
    	}
    );
    
    
    function wpmudev_forminator_filter_user_register_email( int $user_id, array $userdata ) {
    	remove_action( 'user_register', 'wpmudev_forminator_filter_user_register_email' );
    
    	add_filter(
    		'wp_mail',
    		function ( array $mail_args ) use ( $user_id, $userdata ) {
    			$needle       = 'Account Activated';
    			$filter_email = substr( $mail_args['subject'], - strlen( $needle ) ) === $needle;
    
    			if ( $filter_email ) {
    				$userdata['user_id']  = $user_id;
    				$mail_args['message'] = wpmudev_forminator_registration_email_template( $userdata );
    				$mail_args['headers'] = array( 'Content-Type: text/html; charset=UTF-8' );
    
    				remove_action( 'user_register', 'wpmudev_forminator_filter_user_register_email', 10 );
    			}
    
    			return $mail_args;
    		}
    	);
    }
    
    
    function wpmudev_forminator_registration_email_template( array $user_data = array() ) {
    	if ( empty( $user_data ) ) {
    		return __( 'Hey! You have registered succesfully!' );
    	}
    
    	extract( $user_data );
    
    	$user            = get_user_by( 'id', $user_id );
    	$site_name       = get_bloginfo( 'name' );
    	$home_url        = home_url();
    	$login_page      = wp_login_url();
    	$key             = get_password_reset_key( $user );
    	$pass_reset_link = network_site_url( "wp-login.php?action=rp&key={$key}&login=" . rawurlencode( $user_login ), 'login' );
    
    
    	$tpl = "Dear {$user_login},
    
    <p>Your account on {$site_name} has been activated! Please find your login details below.</p>
    
    
    <p>Login page: {$login_page}</p>
    
    <p>Username: {$user_login} </p>
    
    <p>
    Password: Use the password that you submitted when registering your account, or set a new password at the link below.<br />
    <a href=\"{$pass_reset_link}\">{$pass_reset_link}</a>
    </p>
    
    
    <p>This message was sent from https://yoursite.local</p>";
    
    	do_action( 'retrieve_password_key', $user_login, $key );
    
    	return $tpl;
    }

    You can change the text in the wpmudev_forminator_registration_email_template function starting from this line of code:

    $tpl = "Dear {$user_login},

    Hope this information helps, feel free to reply if you have any additional questions.

    Kind regards

    Luis

    Thread Starter cartoonhank

    (@cartoonhank)

    @wpmudev-support7 thanks for the quick response!

    I’ve tried it and unfortunately it is not working. WordPress keeps sending the standard worpress mail.

    I’ve created a drive folder with the mu-plugin that was edited by me: https://drive.google.com/drive/folders/1ZGj0Ba21CA3M23R-B8cIs7d1gfuF3X-A?usp=sharing



    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @cartoonhank,

    I tested in my system with your given code and it does work out of the box, and the content that you have entered in the custom code is what shows up for me when tested.

    Screenshot at 18:08:46.png

    A minor correction in the code to make the “Kontaktformular” text as an URL would be to remove the double quotes added to the following line in your given code, ie for example:

    	$contact_page    = 'https://page-url/kontakt';

    However, the above shouldn’t be affecting the template. Since you are still getting standard email from WP, most probably there is any other custom code or an existing plugin causing a conflict.

    Would recommend you to run a conflict test and see whether it helps in ruling out what might be causing the issue.

    Please check this flow chart on how to run a conflict test:
    https://wpmudev.com/wp-content/uploads/2015/09/Support-Process-Support-Process.gif

    I hope this helps in moving forward. Please do let us know how that goes.

    Kind Regards,

    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @cartoonhank ,
    ?
    We haven’t heard from you for several days now, so it looks like you no longer need our assistance.
    ?
    Feel free to re-open this topic if needed.
    ?
    Kind regards
    Kasia

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cant override New User Notification E-Mail with filter or function’ is closed to new replies.