Skip to:
Content
Pages
Categories
Search
Top
Bottom

Overridding Email Tokens


  • binaryfabric
    Participant

    @binaryfabric

    Hi,

    Im using bp_send_email() to send custom email to people would fill out a form. I followed this tutorial(https://codex.buddypress.org/emails/custom-emails/) and everything seems for fine except one thing.

    I cannot over ride the salutation, more specificly {{recipient.name}}, I understand that the function takes this info directly from the WP_USER object, and it seems to be the display name.

    I tried doing many things, the problem is that people who are sent email are not always current users of the site, and i do not want to have to create a whole new email system for just a few emails.

    So what I am trying to do and send an WP_USER object to bp_send_email(), and everything works find, again accept the {{recipient.name}}.

    Here is the following code:

    $user = new WP_User(0);
    $user->display_name = "display_name";
    $user->first_name = "first_name";
    $user->last_name = "last_name";
    $user->user_nicename = "user_nicename";
    $user->user_email = "user@email.com";
    $user->nickname = "nickname";
    	
    bp_send_email('email_taximony', $user, $args);

    I also tried setting recipient.name in the args with no luck.

    Thanks,

Viewing 7 replies - 1 through 7 (of 7 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Please check this link http://buddypress.wp-a2z.org/oik_api/bp_email_recipientget_name/ and here you will find this filter:

    return apply_filters( 'bp_email_recipient_get_name', $this->name, $this );

    Hopefully, it will help you.

    Thanks


    shanebp
    Moderator

    @shanebp

    @prashantvatsh – thanks for the rely.
    Please use the code button when sharing code.


    binaryfabric
    Participant

    @binaryfabric

    Thank you I will look into that.


    binaryfabric
    Participant

    @binaryfabric

    I belive the “issue” is here:

    class-bp-email-recipient.php:104 
    $wp_name = wp_specialchars_decode( bp_core_get_user_displayname( $this->user_object->ID ), ENT_QUOTES );

    Even though we have a WP_USER object we still try and go and retrieve the user from the DB by user ID.

    Anyway to get around this/have this changed/submit a request?

    Thanks


    Prashant Singh
    Participant

    @prashantvatsh

    I feel your request is very much of your own and there is nothing wrong to fetch users name using this function bp_core_get_user_displayname. You can still request them, also have you tried the filter I have provided?


    binaryfabric
    Participant

    @binaryfabric

    That might be your opinion, but I going to disagree. Why make a round trip to the DB if you already have the info in your object?

    As for your filter, I have checked it out, but decided to go a different route that made a little more sense to me, then having to override more templates.

    I already override: single-bp-email.php so in the template itself I just replace the function bp_email_the_salutation() with my own function. I added some logic as needed, and now it works OK.

    I say OK because I am still unable to override {{recipient.name}}. I supply bp_send_email() with a WP_USER, and it’s a little frustrating that it does not take the info from the object.

    Thanks for the direction though, you have helped me come to a solution that is sufficient for now.


    Prashant Singh
    Participant

    @prashantvatsh

    ok, great 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar