Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress 5.1.1 Email Token to Display a Members Avatar


  • mohamedbakry83
    Participant

    @mohamedbakry83

    I’d like to be able to include a clickable avatar of a member in the emails that are sent out instead of just an html link to their profile. Many community websites, online dating sites, etc., do this. For example, would be cool when a new member sends a friend request. Right now when a member friends another the default Buddypress email template includes a clickable link to visit the member’s profile ( {{initiator.name}} ). I think it would be sweet if there was a token ( e.g., {{initiator.avatar}} ) to use to give us the option to add the avatar.

    or is there any way to do that in my site

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

  • shanebp
    Moderator

    @shanebp

    From the codex:

    Add Email Token


    mohamedbakry83
    Participant

    @mohamedbakry83

    thanks for your comment,
    i would like to create an email notification for a new user message or new friendship request embedded with profile avatar not just profile name

    Hi @mohamedbakry83,

    In this case you’ll need to copy the email template into a /buddypress/assets/email/single-bp-email.php file of your active theme and edit it from theme to include a new template tag.

    something like:

    <?php mohamedbakry83_output_avatar(); ?>

    Then in a bp-custom.php file, you’ll need to include new function for this template tag:

    
    function mohamedbakry83_output_avatar() {
      $token = '{{recipient.avatar}}';
      printf( '<img src="%s">', $token );
    }
    

    In this file, you’ll need to use & adapt the filter @shanebp pasted in his first reply making sure to check $formatted_tokens['friend-requests.url'] & $formatted_tokens['initiator.id'] are set and then set the recipient.avatar token like this :

    $formatted_tokens['recipient.avatar'] = bp_core_fetch_avatar(
      array(
        'object'  => 'user',
        'item_id' => $formatted_tokens['initiator.id'],
        'html'    => false,
      )
    );

    This is for the friendship request email. But you should be able to do it for any email type with this example.


    mohamedbakry83
    Participant

    @mohamedbakry83

    many thanks bro, i will test it

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