The MU forums have moved to WordPress.org

Howto: Modify text in e-mail to new user (11 posts)

  1. jeffstack
    Member
    Posted 16 years ago #

    I have a wordpress MU install locked down using Angsuman’s Authenticated WordPress Plugin.

    I then add users manually via the Site Admin - Users tab and the add user option.

    When I do it this way my users receive and email titled:
    Your username and password
    and the body includes:
    Username: username
    Password: generated password
    http://blog.domain.com/wp-login.php

    I want to add a more descriptive text to the above e-mail. However I can not seem to find the relevant .php file anywhere.

    If I automatically create a user via creating a new blog I can specify the text of the e-mail via the Site Admin - Options panel under the "Welcome Email" heading.

    This e-mail only goes to blog owners. I want to be able to send a similar e-mail to invited users.

  2. drmike
    Member
    Posted 16 years ago #

    it's wp-includes/wpmu-functions.php That's where all of the user and blog creation gets done.

  3. jeffstack
    Member
    Posted 16 years ago #

    Thanks,

    That is what I thought. The problem is that the text does not seem to be attached.

    I assume the relevant sections is:

    }

    function wpmu_welcome_user_notification($user_id, $password, $meta = '') {
    global $current_site;

    $welcome_email = __( "Dear User,

    Your new account is setup.

    You can log in with the following information:
    Username: USERNAME
    Password: PASSWORD

    Thanks!

    --The WordPress Team

    SITE_NAME" );

    $user = new WP_User($user_id);

    $welcome_email = apply_filters( "update_welcome_user_email", $welcome_email, $user_id, $password, $meta);
    $welcome_email = str_replace( "SITE_NAME", $current_site->site_name, $welcome_email );
    $welcome_email = str_replace( "USERNAME", $user->user_login, $welcome_email );
    $welcome_email = str_replace( "PASSWORD", $password, $welcome_email );

    $admin_email = get_site_option( "admin_email" );
    if( $admin_email == '' )
    $admin_email = 'support@' . $_SERVER[ 'SERVER_NAME' ];
    $message_headers = "MIME-Version: 1.0\n" . "From: " . get_site_option( "site_name" ) . " <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    $message = $welcome_email;
    if( empty( $current_site->site_name ) )
    $current_site->site_name = "WordPress MU";
    $subject = sprintf(__('New %1$s User: %2$s'), $current_site->site_name, $user->user_login);
    wp_mail($user->user_email, $subject, $message, $message_headers);
    }

    However, even with no modifications all that is emailed is:

    Username: username
    Password: generated password
    http://blog.domain.com/wp-login.php

    There are no comments at all.

    Any suggestions?

  4. zappoman
    Member
    Posted 16 years ago #

    First of all, there is an admin control panel setting to change this text WITHOUT any code mods. The code is there only if it fails to read from the options.

    You should find this option if you log in as a site admin and go the SiteAdmin, Options. It's the third option from the top... "Welcome Email".

  5. jeffstack
    Member
    Posted 16 years ago #

    Thanks zappoman but that is incorrect. Yes that is the welcome e-mail that is sent out for new BLOG owners (ie. you create a blog and this email is sent to the new owner of that blog). It is not the email that is sent when you create a new user without a blog (ie. a subscriber only) via the Site Admin panel and the "Add User" option under the users tab. As described in the 1st post all those new users get is their username, generated password and login page. There is no explanation of why they were invited to join, ect.

    Looking in wpmu-functions.php it appears that the section of code I highlighted in my above post is the relevant section but changes made to the code are not represented in changes in the sent e-mail. They still only contain username, generated password and login page.

    I agree that there should be a built in section in the control panel where you can change the contents of this e-mail but it has not been coded yet.

    Does anyone else have any suggestions?

  6. zappoman
    Member
    Posted 16 years ago #

    Jeff, sorry, I totally misread your post. I am sorry.

    If I come up from air on my current project I'll hunt around for you... (and me, since I want to make sure the correct invite mail goes out if I use this feature to).

    I suspect that you generally in the right area. I guess my approach would be to start with the admin panel and trace from there.

  7. jaredbangs
    Member
    Posted 16 years ago #

    Jeff, I don't have the code handy right now, but I suspect there are some plugin hooks that will allow you to modify the content of that message at the appropriate place. I would say that this would be the desirable method of achieving this goal.

    Even if there are no plugin actions/filters that are exactly where you might want them, there's always filters on the wp_mail function that will allow you to do just about anything you need to for e-mails.

    Finally, (if you don't want to go the plugin route for some reason) there was one time where I did some MU development work for a company that wanted to make extensive changes to text throughout WPMU (e-mails and otherwise), and I ended up doing it using poEdit and the alternate language features built in, but instead of translating from English to another language you can replace the text parts that you want to alter. It isn't the desirable way to do it thought, since those language files would need to be updated for each new version. (This may not apply to your situation, but just thought I'd throw it out there).

  8. zappoman
    Member
    Posted 16 years ago #

    Jared,

    I like the suggestions... I've been wondering about this idea of using localization tricks to replace strings... the one thing I've wondered about is whether that approach is very "future proof"... it seems like the strings could get changed in a future version and your lookups would no longer work.

    What is the appropriate design pattern on this?

    Submit a patch to tracs/Donncha with an improved filter or a new admin UI?
    Or work around it with a plugin?
    Or work around it with a localization fix?

    I had a similar dilemma with a small bug(?) where a filter wasn't being used (theme directory replacement) and I ended up using a plugin that installed a php ob_start() hook to workaround the bug.

    What does the community suggest?

  9. jaredbangs
    Member
    Posted 16 years ago #

    I'd suggest that the best approach for this particular issue is a plugin with an admin UI (site admin only) that would help the user manage the substitution without dealing with code.

    You're correct (I believe) in that localization is usually not the right approach to customization, for the primary reason you listed. I only did it one time where they wanted a MAJOR rebranding of the system; get this: they didn't want to use the term "blog" *anywhere* in the system :( I would never, ever recommend editing the core files, so localization seemed to be the only option in that case.

    In this case, there will ideally be specific plugin hooks (filters / actions) but even if not, it can be handled by filtering the mail message and a little regex replacement magic. :) Recent versions (using phpmailer) make it much easier to manage mail functionality in WP.

    I do a lot of plugin development, but I haven't really gone so far as to look into submitting patches yet, so I don't know what the standard operating procedure is on this project about that yet. Off hand I would guess that generally the best approach (especially for something like this) would be to try and do it in a plugin if at all possible, and then float it to the community to see if it has broad enough application to be considered for adoption into the core (many things won't).

  10. berserc
    Member
    Posted 16 years ago #

    The code is in /wp-includes/pluggable.php

  11. boonika
    Member
    Posted 15 years ago #

    Same problem here. New blog owners only get this as a message body:

    Username: username
    Password: generated password
    http://blog.domain.com/wp-login.php

About this Topic

  • Started 16 years ago by jeffstack
  • Latest reply from boonika