WordPress.org

Ready to get started?Download WordPress

Forums

wpMandrill
Adapting wp_new_user_notification (8 posts)

  1. Diomed1780
    Member
    Posted 1 year ago #

    I've been experimenting with Mandrill and very pleased with the ability it gives to avoid the relatively low limits my web host places on outgoing e-mails, so hoping to make good use of it.

    One specific query about adding a filter. In Loren's excellent blog 'Own Your WordPress Email with Mandrill' he gives the example of a filter to change the subject of wp_wp_new_user_notification. Previously I have had a custom function adapting the standard wp_new_user_notification as shown in the WordPress Codex, with a much prettier and more informative version of the email that goes out to a new user. This is now not working and the new user notification reverts to the standard WordPress notifications.

    Once I try to adapt using a Mandrill payload filter, building on Loren's example, the immediate issue is that there are two parts of this function - a message ($message) that goes to the admins to alert them to the new user, and one (also $message) that goes to the new user, with their username, password, plus the text that I have added. Using the payload filter and adding a custom $message['subject'] or $message['html'] affects BOTH messages, so that they are identical.

    I have a function that I wrote to send out mail on publication of a post of a certain category, and that works OK. So in general I think I'll be fine with functions and filters - it's this new user notification that I'm scratching my head about.

    http://wordpress.org/plugins/wpmandrill/

  2. MC_Will
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Diomed1780,

    The $message parameter has the whole payload that will be sent to Mandrill and there must be a way, by checking its values, to tell one from the other.

    Your mission, should you choose to accept it, involves to find that way (probably... by checking the To: address?)

    This message will not self destruct in five seconds (you know, so others can take advantage of it).

  3. Diomed1780
    Member
    Posted 1 year ago #

    Hi, I've been thinking and have been playing around with something like this:

    function filterWelcomeSubject($message)
    {
    if(in_array('wp_wp_new_user_notification', $message['tags']['automatic']) && ( strpos ($message['to'],'admin@xyz.com') !== false ))
    {...

    The idea being, as you suggested, that I try to write a filter for the e-mail that goes to the admin, and one for the mail that goes to any other address. It isn't yet working - ie it reverts to the standard WordPress filters - and I think my problem must lie in the fact that I am checking for a string in $message['to']. I think I need to call up the 'to' address differently - could you offer me some guidance, please?

  4. MC_Will
    Member
    Plugin Author

    Posted 1 year ago #

    Hey Diomed1780,

    When in doubt, print_r it to a log file.

    The $message variable has the same structure than the one used in the Mandrill Send API Call:
    https://mandrillapp.com/api/docs/messages.JSON.html#method=send

    That said, try using $message['to']['email'] instead.

  5. Diomed1780
    Member
    Posted 1 year ago #

    Hello Will,

    Have tried altering the code to

    function filterWelcomeSubject($message)
    {
    if(in_array('wp_wp_new_user_notification', $message['tags']['automatic']) && ( strpos ($message['to']['email'],'admin@xyz.com') !== false ))
    {...

    Have also tried a number of other permutations, but no joy so far. Also tried setting up a separate 'if' condition to test the recipient's address inside the first condition. The e-mails are received by the new user, and by the admin, but the format reverts to the standard WP notifications, which is what I have adapted in the past, and I would still wish to adapt, to be more welcoming to the new user.

    Hey ho, will think about it further in the morning.

  6. Diomed1780
    Member
    Posted 1 year ago #

    OK, I have a working solution, though it's not ideal and if anyone can develop on it to produce a better way, then I would be happy to hear.

    My problem was that once I tried to adapt using a Mandrill payload filter, there are two parts of the wp_new_user_notification - a message ($message) that goes to the admins to alert them to the new user, and one (also $message) that goes to the new user, with their username, password, plus the text that I have added. Using the payload filter and adding a custom $message['subject'] or $message['html'] affects BOTH messages, so that they are identical. If I don't adapt the $message, then it reverts to the standard WordPress new user notification messages.

    My quick-and-dirty solution (not that I arrived at it so quickly) - and I realise it is not the approved way - was to hack the function in the pluggable.php file. Thus, when it reverts to the 'standard' WordPress messages, it produces my customised versions.

  7. MC_Will
    Member
    Plugin Author

    Posted 12 months ago #

    Hi Diomed1780,

    That's not the right way to do that. Can you get in touch with me at will at malchimp, please?

  8. bellasys
    Member
    Posted 10 months ago #

    I don't have a working solution yet. But I will be creating one considering that I have a custom membership site launching by the 7th of November which handles all of the above items and I've chosen Mandrill as my T-Mail service.

    I have recently set up a server running Debian 7, Nginx 1.2, MySQL 5.5 and PHP 5.4 with WP 3.6.1 and WishlistMember 2.7. I've successfully set up Mandrill with SPF and DKIM running on the primary domain. Not going to share the url until it goes live.

    I have a free membership level and people who Sign Up get registered in WP and also get a confirmation mail of their opt-in which I send via Mandrill. Only after confirming do they get processed on the Marketing List. This means effectively that (let's say) MailChimp does not perform the Confirmed Opt-In, and technically none of these people count as confirmed opt-ins according to MC, but this works for my clients for now. That's because the only movement expected with these lists is to become managed completely in-house if the business grows large enough, or to remain on MailChimp. The technicality of confirmed opt-in will only become an issue if moving to another provider...

    A client getting added to free membership part facilitates many other features, in fact, even if someone purchases a product before Signing Up they are still processed in this way. This adds a step to the product purchase flow, but it's all behind the scenes, and it's worth it. This way, everyone who is interested in connecting with the site (whether paid or free) counts as a member, and all the functions and features are integrated.

    Technically I do not need to send username and password to a client due to the fact that I have developed technology to handle all this server-side.

    However, the same steps are conducted whether they're being handled client-side or server side; and this means I will be creating a solution and Integrating Mandrill either through the wpMandrill plugin as I currently have it set, or perhaps using the zip files and opting for straight #includes.

    At this point not sure which will be best considering the custom WP Theme coding and Custom Plugins I've written to produce the business logic, but either way I will contribute to this thread in the next few weeks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic