Arrow

Posts on this site are never sponsored.

Stop receiving access cheques from your credit card company

Every month, mbna (MasterCard) sends me access cheques, hoping that I will pay off balances from other cards or am strapped for cash and will have other uses for them. Usually I just recycle these cheques. However, the latest batch arrived with a fridge magnet:

MBNA magnet for access cheques

I can’t even recycle the magnet (got any ideas?). Therefore, in the interest of efficiency and the environment, I stopped this once and for all. Just because you have a credit card, doesn’t mean you should be receiving anything other than your regular statements (which, for most cards, you can now receive via e-mail).

You too can call the number on the back of your credit card, speak to a customer service representative, and ask them to remove you from all direct mail and phone marketing programs.

Temporarily redirect site visitors with .htaccess

Even if you follow the good practice of first making changes to a development server, you still need to implement your site upgrades or code tweaks on a live site. During your implementation time, you probably don’t want people to visit your site so that they don’t see revealing errors or cause some data damage.

A quick solution is to make a simple “please come back shortly” page (let’s call it temp_upgrade.htm) and redirect all site visitors to that page until you’re ready. The redirect part can be handled by a text file named .htaccess, placed in the root directory of your site. If you are using a content management system, this file probably already exists. .htaccess has all sorts of powerful uses for authentication, error responses, URLs, and caching.

For this solution, we will alter URLs via a rewrite rule at the top of your .htaccess file. Supposing that your IP address is 65.98.113.34 (find yours by going to whatismyip.com):

RewriteEngine On
RewriteCond %{REQUEST_URI} !(temp_upgrade\.htm)
RewriteCond %{REMOTE_ADDR} !(65\.98\.113\.34)
RewriteRule ^(.*)$ temp_upgrade\.htm [L]

The first line enables the rewriting engine (if it is not already enabled). The second line applies the rule for all pages on your site except for the “please come back shortly” page, and the third line applies the rule for anybody who visits your site except for you. The fourth line is the actual rule, which redirects all site visits to the desired page.

Therefore, you can work on your site, viewing and testing it as per normal, while everybody else will be redirected somewhere else. When you’re ready to reveal your site again, either remove those lines from the .htaccess file or comment them out — add a hash (#) at the beginning of each line — so that you’ll have a model there for next time.

Note that this solution has a drawback in that if you share a network with other computers that have the same IP address as you, those computers will still be able to access your site. You can mitigate this in many ways (among other things, adding password protection and temporarily moving the site’s files), but that’s a whole other discussion.

WordPress redirect to a thank you page or message after commenting

By default, after someone leaves a comment on a WordPress blog, they are redirected back to the same page, to the section on that page where their comment has been posted. The after-commenting URL usually looks something like this: http://www.yoursite.com/2008/08/yourpost#comment-comment_385

Suppose you use the commenting feature as a “contact me” function on one or more of your pages. In this case, you do not display the comments on the page; therefore, after someone has submitted the so-called comment, by default they are redirected to the same page with no confirmation that their message has been received.

You can customize the redirect in two ways:

  • Use a hidden variable named “redirect_to” in the comment form with the value being the URL to redirect to.
  • Write a plugin that uses the comment_post_redirect hook.

We will focus on the second option, as it is arguably more scalable and powerful (because you can potentially add complex rules and manage this in one place).

In our example, you can use a plugin to append a “thankyou” parameter to the URL, which the post or page template would recognize and display a relevant message:

Thank you message after a comment has been submitted

The plugin component would look something like this:

<?php
/*
Plugin Name: Redirect to a thank you message
Plugin URI: http://www.theblog.ca/wordpress-redirect-comment
Description: Redirect the user to the same page but display some confirmation that their message has been received
Author: Peter Keung
Version: 0.1
Author URI: http://www.theblog.ca/
*/

$rty_ids = array();
// List the post or page IDs that should get this treatment
// We suppose here that you want this to apply to the pages with the IDs 23 and 26
$rty_ids[23] = '';
$rty_ids[26] = '';

// Set this to true to affect all posts
$rty_all = false;

function rty_comment_redirect ($location, $comment)
{
    global $_POST, $rty_ids;

    // Leave out the "redirect_to" condition if you want to ignore what was posted in the form
    if( empty( $_POST['redirect_to'] ) && ( $rty_all || isset( $rty_ids[$comment->comment_post_ID] ) ) )
    {
        
        if( get_option('permalink_structure') == '' )
        {
            // If your URL looks like "?p=8" then we need an ampersand
            $rty_parameter_syntax = '&';
        }
        else
        {
            $rty_parameter_syntax = '?';
        }
        
        // Append a "thank you" parameter so the post or page template can display the appropriate message
        // Alternatively, you can put a specific page to redirect to
        // Or, you can check the value of the other properties of the $comment object to do something else
        // The $comment object contains: comment_ID, comment_post_ID, comment_author, comment_author_email, 
        // comment_author_url, comment_author_IP, comment_date, comment_date_gmt, 
        // comment_content, comment_karma, comment_approved (1 for approved; 0 for moderation queue; spam for spam), 
        // comment_agent, comment_type, comment_parent, user_id

        $location = get_permalink($comment->comment_post_ID) . $rty_parameter_syntax . 'thankyou';

        return $location;
    }
    
    // Use the normal redirect location if our conditions don't match
    else
    {
        return $location;
    }
}

add_action('comment_post_redirect', 'rty_comment_redirect', 15, 2);
?>

Then, somewhere in your “Single post” or “Page” template is the thank you message that displays when needed:

        <?php if( isset( $_GET['thankyou'] ) ) { ?>
		<div class="thankyou" style="border: 1px solid red; padding: 20px;">
			<p>Thanks for your comment!</p>
		</div>
        <?php } ?>

If you’re adventurous, you can tweak the plugin to add rules so that different comment forms behave differently — some might display a thank you message on the same page; some might redirect to completely different pages; and the message could be different depending on whether the comment was approved, held for moderation, or marked as spam.

Canadian VOIP phone number: les.net and Gizmo

Update: I’m now using voip.ms and have reviewed it here

I needed an economical, flexible incoming phone number (below I explain why I don’t really need an outgoing solution) for my web development business. By “flexible” I mean that it had to come with the option to ring either a normal phone or a software phone on my laptop, since I am constantly changing locations during the week.

Thanks to John, I was referred to les.net and Gizmo5.

Basically, les.net provides me with the phone number only and charges either a flat rate of $8.88 per month or $3.50 per month plus $0.011 per minute (essentially pay as you go). I chose the latter plan since it means that I can receive 489 minutes of calls per month before the flat rate becomes a better value.

Gizmo5 is the free software that serves as the actual phone on my laptop, utilizing Voice Over IP to transmit the audio. (Of course, for this to work, I need to be connected to the Internet.)

Incoming call on Gizmo5

The les.net number was quick to set up, there is no setup fee, I can pay monthly via PayPal, it worked immediately, and I can constantly change, via the web interface, where the number forwards to (normal phone or software phone on my laptop; adventurous people can get a physical VOIP phone).

Change where the les.net phone number routes to

It took me a bit of time to figure out the correct settings for forwarding my les.net number to my Gizmo5 account, so here’s a screenshot of my settings for anybody who is going down this route:

Settings for forwarding les.net number to Gizmo

(Note that the Peer Address is what is referred to as a SIP number, which is provided for free when you get a Gizmo5 account and can be found in your Gizmo5 profile.)

On the Gizmo5 side of things, I get a voicemail box, the messages are e-mailed to me in .wav format, and there’s caller ID, all for free.

Because of the magicJack, Skype, and Jajah, I haven’t had the need to explore making outgoing calls from the les.net number, since they all enable me to make free or cheap outgoing calls that originate from other numbers. However, apparently Gizmo5 can make calls that originate from my les.net phone number for about two cents a minute.

So far, I can say that both les.net and Gizmo5 work great, and call quality is comparable to a normal phone as long as I’m using a broadband Internet connection. The cost is a fraction of the cost of a normal phone service, with the added benefit that the phone number can follow me wherever I bring my laptop.

If you are going to try this out, be prepared to learn some new terms such as SIP and DID. Therefore, if you’re interested in exploring the Voice Over IP route, note that there is also the option of paying a bit more to get a more guaranteed, complete solution to handle the geeky bits and to provide you with a robust back-end that ensures good call quality.

Version 2.2.0: Peter’s Collaboration E-mails for WordPress

Here’s a plugin I wrote to take advantage of the pending review feature available in WordPress 2.3 and higher. Note that the latest version of this plugin requires WordPress 3.0 and higher.

With the default pending review feature, you can have “Contributor” users who can write posts. However, these posts are not published until an “Editor” or “Administrator” user comes along and approves the post. What this plugin does is send e-mails at three steps:

  1. When a Contributor user submits an article for review: The plugin e-mails a list of moderators of your choice, letting them know that there is a post ready for review, and giving them a link to edit the post.
  2. When a post is approved: The original Contributor user gets an e-mail saying that their post has been approved and who it was approved by. If the post was directly published, the author is given a link to read the post as the whole world sees it. If the post is scheduled to be published, the author is informed of the time that their post will go live. When the post does go live, the author will get another e-mail informing him / her of that.
  3. When a post’s status is changed back to “draft” from “pending”: The original Contributor user gets an e-mail saying that their post has been reverted back to a draft, along with a link to edit and re-submit the post.

You can assign specific moderators (these must be Administrator or Editor users) to specific Contributor users:

The management screen for configuring moderators

When used with Peter’s Post Notes on WordPress 2.7 and higher, users can leave notes to accompany the e-mails for each step in the workflow.

Get the plugin

Without further ado:

Download Version 2.2.0 of Peter’s Collaboration E-mails for WordPress [July 27, 2016: Replace use of deprecated get_currentuserinfo function. (Thanks Kyle!)]

February 15, 2010: Enhanced version 1.3.3 by François Elie: Adds the ability to define moderators by page; and tree-based page/category moderator fallback logic (by François Elie)

Translations

The following translations are included with the plugin download. Note that version 1.5.0 of the plugin included a lot of new (and untranslated) strings. Please send me any updated or new translation files!

  • Castilian Spanish translation by Guillermo and Luis
  • Italian translation by Massimo Santi
  • French translation by Romain
  • Japanese translation by Kazuhiro Terada and Hijili Kosugi
  • Brazilian Portuguese translation by Murillo Ferrari
  • Romanian translation by Gabriel Berzescu
  • Polish translation by Michal Rozmiarek
  • German translation by Rian Klijn
  • Dutch translation by Rene and Dennis Koot
  • Russian translation by Doktor Bro
  • Turkish translation by Can Kaya
  • Catalan translation by Aleix
  • Danish translation by Tom
  • Indonesian translation by Syamsul Alam
  • Czech translation by Michal Kuk
  • Irish translation by Jordan Silaen

Download an old WordPress MU version (not updated since version 1.3.0 of the plugin) here.

Version 2.2.0 [July 27, 2016: Replace use of deprecated get_currentuserinfo function. (Thanks Kyle!)]

Version 2.1.0 [February 12, 2016: Do not e-mail private notes -- new with Peter's Post Notes 1.6.0 and up.]

Version 2.0.0 [Optional message to thank the author for their submission. Also: fixed the scheduled post timestamp. (Thanks Luis González Jaime!)]

Version 1.9.3 [October 7, 2013: Minor button styling improvements. (Thanks daymobrew!) Also: support PHP 5 static function calls, bumping WordPress requirement to 3.2+.]

Version 1.9.2 [March 29, 2013: Bug fix: In some cases, custom taxonomies weren't showing up as an e-mail condition option. (Thanks boxcarpress and jswan2!)]

Version 1.9.1 [January 29, 2013: Fix bug from previous release that broke front-end post submissions.]

Version 1.9.0 [January 23, 2013: Allow editing of plugin settings via the WordPress admin interface so that settings persist after upgrades.]

Version 1.8.2 [January 13, 2013: Fix e-mail text about the author of a post if it has been set by another user. (Thanks Alexander!) Allow editors to manage collaboration e-mail settings in WordPress 3.5+ (required capability is now "manage_categories" instead of "manage_links").]

Version 1.8.1 [October 8, 2012: Rewrite function that gets post type moderators to support collaborators with more restricted permissions. (Thanks Harold!)]

Version 1.8.0 [October 5, 2012: Added approver_user_id custom field upon pending-to-publish and pending-to-future transitions. (Thanks Chris Andrews!)]

Version 1.7.1 [October 3, 2012: Minor fixes for translations. (Thanks Hijili Kosugi!)]

Version 1.7.0 [September 22, 2012: Added e-mails at the "private-to-published" transition (enabled by default), and if a post is edited AND commented using the Peter's Post Notes plugin by another user (thanks Erik!) (disabled by default).]

Version 1.6.2 [September 22, 2011: Minor code edit for WordPress 3.3 compatibility.]

Version 1.6.1 [August 13, 2011: Minor code cleanup to remove unnecessary error notices.]

Version 1.6.0 [June 19, 2011: Added ability to specify contributor and moderator roles for sites with custom roles and capabilities.]

Version 1.5.0 [November 27, 2010: Support for custom post types and taxonomies.]

Version 1.4.0 [September 2, 2010: Added ability to specify contributor and moderator roles for sites with custom roles and capabilities.]

Version 1.3.5 [April 25, 2010: E-mails are now all encoded in UTF-8.]

Version 1.3.4 [January 11, 2010: Plugin now removes its database tables when it is uninstalled, instead of when it is deactivated. This prevents the collaboration rules from being deleted when upgrading WordPress automatically.]

Version 1.3.3 [September 22, 2009: Maintenance release to remove unnecessary code calls and increase security.]

Version 1.3.2 [June 27, 2009: Minor fixes for translations.]

Version 1.3.1 [June 19, 2009: Updated plugin for WordPress 2.8.]

Version 1.3.0 [February 16, 2009: Added e-mails at the "pending-to-future" and "future-to-publish" transitions.]

Version 1.2.2 [February 6, 2009: Added backwards translation support for WordPress 2.5.]

Version 1.2.1 [January 3, 2009: Added .po and .mo files for translators.]

Version 1.2.0 [December 10, 2008: Added another e-mail trigger: when a pending post's status is changed back to a draft. Also added interoperability with Peter's Post Notes (for WordPress 2.7 and up) so that users can leave descriptive notes at each step in the workflow.]

Version 1.1.0 [September 18, 2008: You can specify moderators per post category.]

Version 1.0.1 [August 7, 2008: Database table names no longer use a fixed prefix. They now use whatever your WordPress installation uses ("wp_" by default).]

Version 1.0.0 [July 22, 2008: You can now specify moderators per user.]

Version 0.2.0 [Nov 11, 2007: Two new options: 1) Specify a name and e-mail address to send all e-mails (instead of having the contributor as the sender for pending e-mails and the contributor as the sender for approval e-mails); and 2) Toggle whether to show the contributor, in the approval e-mail, which user approved his / her post.]

Version 0.1.0 [Oct 31, 2007: First version!]

Turkish translation of 0.2.0 by Baris.

Slovakian translation (UTF-8) of 0.1.0 translated by sir.peterson.

Installation

Simply unzip the file peters_collaboration_emails.php to your WordPress plugin directory. Then, activate it in the Plugins menu in the WordPress admin section.

Details about the e-mails sent (who the sender should be; whether the contributor should know who approved his/her post; and so on) are configured by editing the top of the plugin file itself. The default settings should be sufficient for most implementations.

Moderator rules are configured in the Settings > Collaboration e-mails admin menu. Moderators are Administrator or Editor users who should be notified whenever a post is submitted for review. You can create groups of Contributor users and assign different moderators for each group. In other words, different users can be notified based on who wrote a post. You can also assign moderators based on post categories. If a Contributor user belongs to multiple groups and/or a post has multiple categories, all moderators who have been assigned to the relevant groups and categories are e-mailed.

Troubleshooting

Now, whenever you release a plugin the first comments you usually receive are people who have trouble with your plugin. Hopefully I can build a brief troubleshooting section first:

– If you are not receiving any e-mails, make sure that the PHP mail() function is configured properly (ask your web host or if you’re computer-savvy, check it out yourself; or if you have credentials for an SMTP server, install and configure the WP Mail SMTP plugin). If you are trying to send to multiple recipients via SMTP, note that WordPress up to 2.8 has a bug; I described a fix in this post. Also make sure that a Contributor user has actually submitted a post for review.

– If you want to use this plugin with pages, you need to allow the Contributor user to actually create pages (as by default they cannot). Use a plugin such as Capability Manager to add the “edit pages” capability to the Contributor role. With that plugin, you can even create new roles if you’d like.

– If the plugin simply breaks, make sure you are using WordPress 2.5 or higher. Also check the settings near the top of the plugin file (in the WordPress admin section, go to Plugins > Plugin Editor > Peter’s Collaboration E-mails).

– Need help installing the plugin or customizing your installation? Hire my consulting services: peterATmugo.ca!