bbPress Email notification on post
At Newmedias, we use bbPress and have been using the email notification plugin written by thomasklaiber. It sends an email to those registered for forum notifications every time a post is left on a thread that they had registered for.
I often look at my emails when im away from home on my pda/phone and find it a real pain to have to open the web link in each email to read it. This also means that I can’t download them in my email client for reading later.
My solution to this was blindingly simple,
Put the body of the most recent post into the email itself!
This feature was not available at the time of writing and works very well. The mod is very simple, here’s how i did it.
note: Before doing this to your version of the plugin, make sure that the original author hasn’t added his own version of the same thing!
1) Open notification.php and find the notification_new_post function
2) Paste the following code after the get_topic() call but before the $message=… call
$posts = get_thread($topic_id, 1, 1); $posts = array_reverse($posts); $last = array_pop($posts); $last_text = strip_tags($last->post_text);
3) Overwrite the $message variable to include the new string at the end as follows:
$message = __("There is a new post on: %1\$s \nReply by: %2\$s \n\n%3\$s \n\n%4\$s");
4) Overwrite the sprintf call to the following:
sprintf($message, $topic->topic_title, get_user_name($bb_current_user->ID), get_topic_link($topic_id), $last_text)
(if you are more familiar with php and sprintf then just add the $last_text variable to the end of the list of variables within the existing call)
5) Save, Backup, Upload and test! It should now send the post body with the email
Optionally you can improve the code within this function somewhat…
1) The get_topic call doesn’t need to be in the foreach loop because the topic_id doesn’t change anywhere in the function. Although bbPress uses cacheing, it would still be best practise to move that line and the lines from my step 2 to the line before the foreach loop.
2) Convert the email to HTML by adding the content-type header and setting it to text/html. If you do this then the \n’s will also need to be changed to <br /> and you can optionally remove the strip_tags() from the last line in my step 2
Good luck and let me know about any problems you may have.