Comment puis-je changer le modèle d'e-mail pour un nouvel utilisateur
3 réponses
- votes
-
- 2018-01-02
Pour les utilisateurs de 2018et suivants:
La réponse de David Gardfonctionnetoujours,maiselleest ancienneet ilexiste unenouvellefaçonmeilleure/pluspropre de lefaire (plusbesoin deplugin).
Depuis WordPress 4.9.0,ilexiste denouveauxfiltres que vouspouvez utiliserpourpersonnaliser lese-mails d'inscription:
- wp_new_user_notification_email -personnaliser l'e-mailenvoyé à l'utilisateur
- wp_new_user_notification_email_admin -personnaliser l'e-mailenvoyé à l'administrateur
Exemple d'utilisation d'une-mailenvoyé à l'administrateur (vouspouvez le coller dans le functions.php de votrethème):
add_filter( 'wp_new_user_notification_email_admin', 'custom_wp_new_user_notification_email', 10, 3 ); function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) { $wp_new_user_notification_email['subject'] = sprintf( '[%s] New user %s registered.', $blogname, $user->user_login ); $wp_new_user_notification_email['message'] = sprintf( "%s ( %s ) has registerd to your blog %s.", $user->user_login, $user->user_email, $blogname ); return $wp_new_user_notification_email; }
For 2018 and onwards users:
David Gard's answer still works but is old and there's a new better/cleaner way to do this (no need for a plugin anymore).
Since WordPress 4.9.0 there are new filters you can use to customise registration emails:
- wp_new_user_notification_email - customise email sent to User
- wp_new_user_notification_email_admin - customise email sent to Admin
Usage example on email sent to Admin (you can paste this in your theme's functions.php ):
add_filter( 'wp_new_user_notification_email_admin', 'custom_wp_new_user_notification_email', 10, 3 ); function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) { $wp_new_user_notification_email['subject'] = sprintf( '[%s] New user %s registered.', $blogname, $user->user_login ); $wp_new_user_notification_email['message'] = sprintf( "%s ( %s ) has registerd to your blog %s.", $user->user_login, $user->user_email, $blogname ); return $wp_new_user_notification_email; }
-
- 2015-02-06
Lenouvele-mail denotification utilisateurest crééet envoyépar lafonction
wp_new_user_notification()
,qui setrouve dans wp-includes/plugable.phpIln'y apas de hook defiltre dans cettefonction qui vouspermettra demanipuler la sortie de l'email,mais vouspouvezbien sûr écrasern'importe quellefonctionenfichable via unplugin.
<₹ Remarque
- Vousne pouvez écraser lesfonctionsenfichables qu'àpartir d'unplugin,pas de votrethème.Voiricipourplus de détails sur lesfonctionsenfichableset une liste complète de celles disponibles - http://codex.wordpress .org/Pluggable_Functions
Ce code créera leplugin qui sera utilisé à laplace de celui de wp-includes/plugable.php (enregistrez-le dans sonproprefichier dans wp-content/plugins/).
Jene l'aipaspersonnalisépour vous,mais cela devrait vousmettre sur labonne voie.
<?php /** * Plugin Name: Custom new user notification email * Description: Overwrites the pluggable 'wp_new_user_notification()' plugin to allow the sending of a custom email * Author: David Gard * Version: 1.0 */ if ( !function_exists('wp_new_user_notification') ) : /** * Pluggable - Email login credentials to a newly-registered user * * A new user registration notification is also sent to admin email. * * @since 2.0.0 * * @param int $user_id User ID. * @param string $plaintext_pass Optional. The user's plaintext password. Default empty. */ 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); $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"; @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); } endif;
The new user notification email is created and sent by the function
wp_new_user_notification()
, found in wp-includes/plugable.phpThere is no filter hook within this funciton that will allow you to manipulate the output of the email, however you can of course overwrite any pluggable function via a plugin.
Note - You can only overwrite pluggable functions from within a plugin, not from within your theme.
See here for more details on pluggable functions and a full list of those available - http://codex.wordpress.org/Pluggable_Functions
This code will create the plugin which will be used instead of the one in wp-includes/plugable.php (save it in its own file in wp-content/plugins/).
I haven't customised it for you, but this should get you on your way.
<?php /** * Plugin Name: Custom new user notification email * Description: Overwrites the pluggable 'wp_new_user_notification()' plugin to allow the sending of a custom email * Author: David Gard * Version: 1.0 */ if ( !function_exists('wp_new_user_notification') ) : /** * Pluggable - Email login credentials to a newly-registered user * * A new user registration notification is also sent to admin email. * * @since 2.0.0 * * @param int $user_id User ID. * @param string $plaintext_pass Optional. The user's plaintext password. Default empty. */ 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); $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"; @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); } endif;
-
- 2017-08-30
Si vousfaites référence à une configurationmultisite,celle-ciest configurable via unmodèle quiestmisen place dans labase de données sous 2 sections:
E-mail debienvenue
et
E-mail debienvenue de l'utilisateur
http://yoursite/wp-admin/network/settings.php
Vouspouvez lepersonnaliser à votreguise.
If you are referring to a multisite setup, this is configurable through a template that is set up in the database under 2 sections:
Welcome Email
and
Welcome User Email
http://yoursite/wp-admin/network/settings.php
You can customize it to your liking.
Lorsquej'ajoute unnouveau client,l'e-mailestenvoyé aunouvel utilisateur dans ceformat:
Maintenant,je veux changer ceformat comme ceci:
J'aiessayé cecirépondez mais celane fonctionnepas.
Commentpuis-jefaire cela?