Support » Plugin: BuddyPress Group Email Subscription » Here is a patch fixing some bugs around email customisation

  • naomir

    (@naomir)


    Hi @boonebgorges

    After discussing filters & ways of customising emails with you in another thread https://wordpress.org/support/topic/customising-content-of-emails/, I set about doing some customisations and came up against a few issues. The main one was that you have two variables, $message and $body, and some text was being returned from filters and appended to $message, but then it was $body and not $message that was actually passed to the email function. So the text returned from the filters disappeared. This is a major issue for people wanting to customise.

    Another issue was that the html tags to wrap around the footer text were added before applying the footer filters, so creating a filter removed the html tags and therefore the styling. I guess this could be a desired feature but I wanted to change the text and keep the styling. Also the unsubscribe message at the bottom of the email has no styling. I’ve given it the same styling as the unsubscribe messages for each group, for consistency and to adhere to the convention of making the unsubscribe message smaller and clearly separate from the main message.

    If you had a git repo I would do a pull request but I don’t use SVN and don’t have time to learn it so here is a patch (inline because I don’t see a button here to upload a file).

    — foo 2019-11-10 16:11:17.555166097 +0000
    +++ bp-activity-subscription-digest.php 2019-11-10 16:13:37.117896408 +0000
    @@ -119,14 +119,13 @@
    */
    function bpges_generate_digest( $user_id, $type, $group_activity_ids, $is_preview = false ) {
    $ass_email_css = bpges_digest_css();
    $title = ass_digest_get_title( $type );
    $blogname = get_blog_option( BP_ROOT_BLOG, ‘blogname’ );
    $subject = apply_filters( ‘ass_digest_subject’, “$title [$blogname]”, $blogname, $title, $type );

    – $footer = “\n\n<div class=\”digest-footer\” {$ass_email_css[‘footer’]}>”;
    – $footer .= sprintf( __( “You have received this message because you are subscribed to receive a digest of activity in some of your groups on %s.”, ‘buddypress-group-email-subscription’ ), $blogname );
    + $footer = sprintf( __( “You have received this message because you are subscribed to receive a digest of activity in some of your groups on %s.”, ‘buddypress-group-email-subscription’ ), $blogname );
    $footer = apply_filters( ‘ass_digest_footer’, $footer, $type );
    + $footer = “\n\n<div class=\”digest-footer\” {$ass_email_css[‘footer’]}>$footer</div>”;

    // initialize some strings
    $bp = buddypress();
    @@ -146,7 +145,7 @@
    $group_activity_ids_pristine = $group_activity_ids;

    $header = “<div class=\”digest-header\” {$ass_email_css[‘title’]}>$title ” . __(‘at’, ‘buddypress-group-email-subscription’).” root_domain . “‘>$blogname</div>\n\n”;
    – $message = apply_filters( ‘ass_digest_header’, $header, $title, $ass_email_css[‘title’] );
    + $body = apply_filters( ‘ass_digest_header’, $header, $title, $ass_email_css[‘title’] );

    $sent_activity_ids = array();

    @@ -201,20 +200,19 @@

    // show group summary for digest, and follow help text for weekly summary
    if ( ‘dig’ == $type ) {
    – $message .= apply_filters( ‘ass_digest_summary_full’, __( ‘Group Summary’, ‘buddypress-group-email-subscription’) . “:\n<ul class=\”digest-group-summaries\” {$ass_email_css[‘summary_ul’]}>” . $summary . ““, $ass_email_css[‘summary_ul’], $summary );
    + $body .= apply_filters( ‘ass_digest_summary_full’, __( ‘Group Summary’, ‘buddypress-group-email-subscription’) . “:\n<ul class=\”digest-group-summaries\” {$ass_email_css[‘summary_ul’]}>” . $summary . ““, $ass_email_css[‘summary_ul’], $summary );
    }

    // the meat of the message which we generated above goes here
    – $message .= $activity_message;
    $body .= $activity_message;

    // user is subscribed to “New Topics”
    // add follow help text only if bundled forums are enabled
    if ( ‘sum’ == $type && class_exists( ‘BP_Forums_Component’ ) ) {
    – $message .= apply_filters( ‘ass_summary_follow_topic’, “<div {$ass_email_css[‘follow_topic’]}>” . __( “How to follow a topic: to get email updates for a specific topic, click the topic title – then on the webpage click the <i>Follow this topic</i> button. (If you don’t see the button you need to login first.)”, ‘buddypress-group-email-subscription’ ) . “</div>\n”, $ass_email_css[‘follow_topic’] );
    + $body .= apply_filters( ‘ass_summary_follow_topic’, “<div {$ass_email_css[‘follow_topic’]}>” . __( “How to follow a topic: to get email updates for a specific topic, click the topic title – then on the webpage click the <i>Follow this topic</i> button. (If you don’t see the button you need to login first.)”, ‘buddypress-group-email-subscription’ ) . “</div>\n”, $ass_email_css[‘follow_topic’] );
    }

    – $message .= $footer;
    + $body .= $footer;

    $unsubscribe_message = “\n\n” . sprintf( __( “To disable these notifications per group please login and go to: %s where you can change your email settings for each group.”, ‘buddypress-group-email-subscription’ ), “groups->slug}/\”>” . __( ‘My Groups’, ‘buddypress-group-email-subscription’ ) . “” );

    @@ -223,12 +221,13 @@
    $unsubscribe_message .= “\n\n<br><br>” . __( ‘Disable these notifications for all my groups at once.’, ‘buddypress-group-email-subscription’ ) . ‘‘;
    }

    – $message .= apply_filters( ‘ass_digest_disable_notifications’, $unsubscribe_message, $userdomain . $bp->groups->slug );
    + $unsubscribe_message = apply_filters( ‘ass_digest_disable_notifications’, $unsubscribe_message, $userdomain . $bp->groups->slug );
    + $body .= “<div {$ass_email_css[‘change_email’]}>$unsubscribe_message</div>”;

    – $message .= “</div>”;
    + $body .= “</div>”;

    if ( $is_preview ) {
    – echo $message;
    + echo $body;
    return;
    }

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