-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfc-ges-functions.php
195 lines (186 loc) · 7.89 KB
/
bfc-ges-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
add_action( 'bp_email', 'bfc_email_topline', 10, 2);
function bfc_email_topline ($email_type, $bp_email) {
global $topline;
global $bp;
$avatar = bp_core_fetch_avatar( array( 'item_id' => bp_loggedin_user_id(), 'type' => 'thumb', 'width' => '40', 'height' => '40', 'html' => false ));
$name = bp_core_get_userlink(bp_loggedin_user_id());
$tl_start = '<table role="presentation" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td style="vertical-align: middle; text-align: right;font-weight:normal;color:#243242;font-size:14px;">';
$tl_avatar = '</td><td style="vertical-align: middle; padding-left: 12px;"><img src="' . $avatar . '" height="39" width="39" style="border-radius: 20%;max-width: 39px;vertical-align: middle;" />';
$tl_end = '</td></tr></tbody></table>';
$topline = '';
switch ($email_type) {
case "bp-ges-single":
$topline = $tl_start . 'A new forum post from<br>' . $name . $tl_avatar . $tl_end;
break;
case "bp-ges-digest":
$topline = '';
break;
case "group-message-email":
case "messages-unread":
$topline = $tl_start . 'You have a new message from<br>' . $name . $tl_avatar . $tl_end;
break;
case "bbp-new-forum-topic":
$topline = $tl_start . 'A new forum thread by<br>' . $name . $tl_avatar . $tl_end;
break;
case "bbp-new-forum-reply":
$topline = $tl_start . 'A new forum reply from<br>' . $name . $tl_avatar . $tl_end;
break;
case "activity-comment":
$topline = $tl_start . 'A new comment by<br>' . $name . $tl_avatar . $tl_end;
break;
case "activity-comment-author":
$topline = $tl_start . 'A new reply by<br>' . $name . $tl_avatar . $tl_end;
break;
case "activity-at-message":
case "groups-at-message":
$topline = $tl_start . "You've been mentioned by<br>" . $name . $tl_avatar . $tl_end;
break;
case "new-mention":
case "new-mention-group":
$topline = $tl_start . 'You have a new mention by<br>' . $name . $tl_avatar . $tl_end;
break;
case "groups-details-updated":
$topline = $tl_start . 'Group details updated by<br>' . $name . $tl_avatar . $tl_end;
break;
case "groups-invitation":
$topline = $tl_start . 'From ' . $name . $tl_avatar . $tl_end;
break;
case "groups-member-promoted":
$topline = 'Congratulations!';
break;
case "groups-membership-request":
$topline = $tl_start . 'A new member request from<br>' . $name . $tl_avatar . $tl_end;
break;
case "groups-membership-request-accepted":
case "groups-membership-request-rejected":
$topline = $tl_start . 'From the group steward<br>' . $name . $tl_avatar . $tl_end;
break;
case "settings-verify-email-change":
$topline = $tl_start . 'For your security'. $tl_end;
break;
case "bp-ges-notice":
$topline = $tl_start . 'From your group steward<br>' . $name . $tl_avatar . $tl_end;
break;
case "bp-ges-welcome":
$topline = 'Welcome to the group!';
break;
case "settings-password-changed":
$topline = 'Confirming your password change';
break;
case "invites-member-invite":
case "invite-anyone-invitation":
$topline = $tl_start . "You've been invited to join " . bp_get_option( 'blogname' ) . 'by<br>' . $name . $tl_avatar . $tl_end;
break;
case "content-moderation-email":
case "user-moderation-email":
$topline = ' ';
break;
case "zoom-scheduled-meeting-email":
$topline = $tl_start . 'Zoom meeting scheduled by<br>' . $name . $tl_avatar . $tl_end;
break;
case "zoom-scheduled-webinar-email":
$topline = $tl_start . 'Zoom webinar scheduled by<br>' . $name . $tl_avatar . $tl_end;
break;
case "core-user-registration":
case "core-user-registration-with-blog":
$topline = "You're registered!<br>Activate now to complete your access.";
break;
case "friends-request":
$topline = $tl_start . $name . '<br>requests your friendship' . $tl_avatar . $tl_end;
break;
case "friends-request-accepted":
$topline = $tl_start . $name . '<br>accepted your request' . $tl_avatar . $tl_end;
default:
break;
}
}
add_filter( 'bp_email_set_tokens', 'bfc_set_tokens', 100, 3 );
function bfc_set_tokens ($formatted_tokens, $tokens, $bp_email) {
$email_type = $bp_email->get('type');
$um_start = '<div style="font-family: charter, Georgia, Cambria, \'Times New Roman\', Times, serif; color: #243242; font-size: 18px">';
$um_end = '</div>';
$to = $bp_email->get('to');
$toBPER = $to[0];
$wp_user = $toBPER->get_user();
$recipient_id = $wp_user->ID;
$tokens['email.prefs'] = bp_core_get_user_domain($recipient_id).'settings/notifications/';
switch ($email_type) {
case "bp-ges-single":
$recent_posts = wp_get_recent_posts(array ('numberposts'=> '1', 'post_type' => array('topic','reply')));
$the_post = $recent_posts[0];
$post_type = $the_post['post_type'];
$post_id = $the_post['ID'];
$reply_name = '<a href="' . bbp_get_reply_url( $post_id ) . '">this new reply:</a>';
$topic_id = ($post_type == 'reply') ? bbp_get_reply_topic_id ($post_id) : $post_id;
$topic_name ='<a href="' . bbp_get_topic_permalink( $topic_id ) . '">'. bbp_get_topic_title( $topic_id ) . '</a>';
$forum_id = bbp_get_topic_forum_id($topic_id);
$forum_title = bfc_get_forum_title($forum_id) ;
$forum_link = esc_url( bbp_get_forum_permalink( $forum_id )) ;
$group_link = substr($forum_link, 0, strpos($forum_link, "forum/"));
$group_name = '<a href="' . $group_link . '">' . $forum_title . '</a>';
$tokens['ges.subject'] = bp_core_get_user_displayname( bp_loggedin_user_id() );
if ($post_type == 'reply') {
$tokens['ges.subject'] .= ' replied to "';
} else {
$tokens['ges.subject'] .= ' created "';
}
$tokens['ges.subject'] .= bbp_get_topic_title( $topic_id ). '" in ' . $forum_title;
$intro_close = ($post_type == 'reply') ? $reply_name : 'new thread:';
$tokens['intro'] = $group_name . ' > ' . $topic_name . ' > ' . $intro_close;
$tokens['usermessage'] = $um_start . wp_kses_post($tokens ['usermessage']). $um_end;
return $tokens;
case "messages-unread":
$tokens['usermessage'] = $um_start . wp_kses_post($tokens ['usermessage']). $um_end;
return $tokens;
case "bbp-new-forum-topic":
$tokens['discussion.content'] = $um_start . wp_kses_post($tokens ['discussion.content']). $um_end;
return $tokens;
case "bbp-new-forum-reply":
$tokens['reply.content'] = $um_start . wp_kses_post($tokens ['reply.content']). $um_end;
return $tokens;
case "activity-comment":
case "activity-comment-author":
case "activity-at-message":
case "groups-at-message":
$tokens['usermessage'] = $um_start . wp_kses_post($tokens ['usermessage']). $um_end;
return $tokens;
case "new-mention":
case "new-mention-group":
$tokens['mentioned.content'] = $um_start . wp_kses_post($tokens ['mentioned.content']). $um_end;
return $tokens;
case "group-message-email":
$tokens['message'] = $um_start . wp_kses_post($tokens ['message']). $um_end;
return $tokens;
case "groups-details-updated":
$tokens['changed_text'] = $um_start . wp_kses_post($tokens ['changed_text']). $um_end;
return $tokens;
case "bp-ges-notice":
case "bp-ges-welcome":
$tokens['usermessage'] = $um_start . wp_kses_post($tokens ['usermessage']). $um_end;
return $tokens;
case "invite-anyone-invitation":
$tokens['ia.content'] = $um_start . wp_kses_post($tokens ['ia.content']). $um_end;
return $tokens;
// case "friends-request":
// case "friends-request-accepted":
// case "groups-membership-request-rejected":
// case "groups-membership-request-accepted":
// case "groups-membership-request":
// case "groups-member-promoted":
// case "groups-invitation":
// case "settings-verify-email-change":
// case "invites-member-invite":
// case "zoom-scheduled-meeting-email":
// case "zoom-scheduled-webinar-email":
// case "bp-ges-digest":
// case "settings-password-changed":
// case "content-moderation-email":
// case "user-moderation-email":
// case "core-user-registration":
// case "core-user-registration-with-blog":
default:
return $tokens;
}
}
?>