Using Growl with Wordpress
Wednesday, May 30th, 2007I read an interesting post by Murph about using Growl, which I’ve been using for a while but never really looked in to how it worked etc. Having recently moved over to a Wordpress based blog, I decided to look at how I could get Growl notifications when a user adds a new comment on the site. This turned out to be very easy, thanks to this article and PHP code which sends the Growl UDP messages for me. All I did was add a simple script helper class to make the implementation in to Wordpress that much easier.
Note: You need to have UDP access from your ISP to your Mac on Port 9887 - I’m working on a TCP version for those who can’t use UDP.
Download & unzip the code in the attached file - I called mine “growl.php” but you can call it what you like. Put it in the wp-includes directory inside your Wordpress blog.
Now edit the file so that the variables GROWL_SERVER, GROWL_SERVER_PASSWORD and GROWL_APP_NAME are relevant to your needs. You’ll also need to add all the notification types you want to include - so that Growl understands the message types. Save the file.
Now you need to edit Wordpress and insert your growl notifications where you want them - I’ve just added a notification when a user adds a comment, but it could be as verbose as whenever a user logins in, registers etc etc. If you want to add a notification for new comments, edit the wp-comments-post.php and find this line:
require( dirname(__FILE__) . '/wp-config.php' );
Then insert a required file under this line - using the correct file name and path if different from mine. Mine looks like this require(dirname(__FILE__) .'/wp-includes/growl.php');
Now find this line $comment_id = wp_new_comment( $commentdata ); and insert the following afterwards (replacing the parameters with your Growl message info).
$growl = new GrowlHelper();
$growl->sendMessage("Comment", "New Blog Comment", $comment_content, 1);
Save the file and add a comment to your blog - you should see the application register in Growl and then a notification that a new comment has been added - sorted!
Enjoy
-Chris-
ref: Download Code
