Hacking

Customizing Buddypress / bbPress notification emails

We’re spinning up another buddypress community at work and need to customize many of the outgoing emails. This can be done via filters but is kind of tedious and doesn’t make it easy for non-devs to update the messages later. I found a plugin called Welcome Pack which provides a fairly straightforward interface for customizing some of the Budddypress emails, and have started extending it to encompass all of the outgoing mail we need control over (bbpress, wp core emails).

screenshot-local.wordpress.dev 2014-11-11 16-12-55

Ideally I’d like to add an Admin interface to link up new filter hooks, but for now I’ve just got a filter function you can use in your theme or plugin. It’s very much a work in progress, right now I’m doing a lot of refactoring to make things a little better suited to our use case. I think by the time it’s done it will save us a significant amount of time that I used to spend hunting down and editing email templates.

You can view my fork of the project on github. If this is a project anyone else is interested in, let me know!

Programming

Mysql_Awesome_Query

Hm it’s been a while since I’ve posted, been busy with a lot of boring, non-hacking stuff. Travesty! But here’s something vaguely interesting:

Often when I’m writing a bunch of PHP I want to be able to see the MySQL queries its generating. Usually I just comment out the mysql_query() and replace it with an echo. But sometimes that’s annoying, or I want to check multiple queries at once and don’t feel like switching them back and forth all the time.

I wrote a quick function called mysql_awesome_query(), which will either execute or echo a query depending on whether it’s a SELECT, INSERT, UPDATE, or DELETE/DROP.

//1 is run, 0 is echo sql
$flags = array(
'S'=>1,
'I'=>1,
'U'=>1,
'D'=>1
);


function mysql_awesome_query($sql){
$flags = $GLOBALS['flags'];

if($flags[$sql[0]]==1){
$result = mysql_query($sql);
if(mysql_error()){
return mysql_error();
} else {
return $result;
}
} else {
echo $sql;
return false;
}
}

The $flags global variable is an array of settings for which types of queries to execute, based on the first letter of the query string. MySQL conveniently doesn't have a lot of overlap there.
When mysql_awesome_query() is executed it checks the first letter of the query and if the corresponding array value is 1, it executes it and returns either a result or a mysql error. If it's 0, it simply echos the query so you can review it.

I'm sure there are more elegant ways to do this, but this was quick and dirty and works for my purposes.