Not so long ago Automatic added the option to register to sites update on wordpress.com by using a checkbox in the comment form. So apparently by ticking the checkbox one should get email updates on every new blog post – which, is a very good idea I might say.
But if you don’t use WordPress.com services and prefer to use your own installation you are in a bit of a problem because (As far as I know) there is no plugin that does that.
In order to achieve this functionality on a customer’s blog I’ve decided to hack one of the common blog updates by mail pluging. I’ve started by using post-notification plugin and looked for a nice addNewUser($mail) function that I can hook into. After 2 hours all I found was that the admin section got a manual subscription field but it posts the results directly to the DB with no specific function.
The next obvious option was Subscribe2 which was much better for my purpose. I found out that this plugin is actually using a Class structure (OO) and has a add($mail) function as part of its function. That was quite relieving Because it made everything much simple.
After finding the function to use all I had to do is add the checkbox in the comments section. I’ve added the next functions in the template function.php using wordpress hooks system.
add_action('comment_form', 'show_registration_checkbox');
function show_registration_checkbox(){?>
<p class="subscribe-to-comments">
<input type="checkbox" name="register" id="register" value="register" style="width: auto;" />
<label for="subscribe"><?php _e('I want to get updates when the blog update','saar');?></label>
</p>
<?}
The first line creates the actual hook to the comments form and set the callback function. the function itself just writes the HTML to the end of the comment form.
The next thing is to listen to a comment post event and again, we can (and always should) use the hook system by defining a listener and creating a callback option to handle the submitted value
add_action('comment_post', 'toto');
function toto()
{
global $mysubscribe2;
if($_POST['register'] == 'register')
$mysubscribe2->add( $_POST['email']);
}
Please note that because Subscribe2 creates an object we need to use that object – hence – the global.






Open Comment Author link in new window
I’ve been searching for a way to open a commenter link on a new window for a long time and with no success. Most of the techniques required me to open one of wordpress core files and alter its functions. Thought it did work, the changes were doom to vanish on the next upgrade.
The correct way to do that is to use the built-in hook system in order to alter the link after it was created.
add_filter('get_comment_author_link', 'authorLinkNew'); function authorLinkNew($result){ return str_replace ('<a', '<a target="_blank" ', $result); }Actually all we do here is search and replace on the anchor element and in that way to add the target blank into the link. It’s actually a bit rough, and there must be a dozen of different ways to do it which are more correct (using php domelement would probably be the best one, Using Regex with preg_replace may be another) but it’s surely the fastest way to do that.
Please note that using another plugin that rewrite links might cause a collision that way, and rewrite this function using a domelement will return better results.