Parental Control for WordPress

Parental Control is a WordPress plugin aimed at supporting freedom of expression by allowing a blog administrator to control what content is displayed to a casual reader and what is not. It consists of a profanity filter with a customizable word list, a mechanism to suppress displaying posts from a selectable ‘adults only’ category, and supporting functions to allow easy on/off switching by blog readers.

Quick download: Parental Control 1.0.23 Beta.

Note: This is a Beta release. It means that while this software has been found to work in a limited use, it has not yet been tested widely enough to be considered stable. USE AT YOUR OWN RISK.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Compatibility

Parental Control 1.0.23 Beta is compatible with the latest releases of WordPress’ 2.2 trunk and with WordPress’ 2.3 trunk from version 2.3 RC 1 upwards. 2.3 trunk versions prior to RC 1 aren’t supported.

The Purpose And Background

Parental Control is based on the idea that by giving readers the freedom to choose whether or not they wish to see potentially offensive content, the author is freed from worrying about publishing such content and thus his freedom of expression is improved.

In my personal blog I occasionally write about topics which could be rated ‘adult’, or not suitable for children. In addition to and apart from such posts, the language I use often contains words or expressions which some people may find offensive. Since my blog is relatively well-ranked by Google, lately I’ve found myself contemplating my use of language more and more often. I hate the restricting feeling this imposes on my writing, but on the other hand I do appreciate the importance of not violating easily offended minds, particulary those of children, who might end up in my blog when googling for something completely innocent.

I dislike the practice of blocking website users at the gates, warning them of possibly offensive content; why not simply make such content accessible through the warning page, while still letting non-offensive content be viewed freely, without forcing users to first go through the warnings? It’s not a radical, new idea; many web 2.0 services use it, and yet I couldn’t find any ready implementations for WordPress, my blog engine of choice.

So I began to develop one myself: a plugin, which would automatically censor out some of the content from readers who have not specifically opted to be able to read such content. The plugin would allow me to write anything I happen to feel like writing, without having to worry about the possibility of offending people who enter my site quite randomly.

What It’s Not

Although setting up your blog properly, as described below, makes using the switch somewhat cumbersome and thereby more difficult for very young users, Parental Control is not a surefire way to keep your children safe from adult content. You should not let your children read a blog containing highly disturbing material unsupervised, even if the blog does have Parental Control. That is because Parental Control relies heavily on your users’ honesty about themselves.

Disabling Parental Control and thus exposing offensive content is, end the end, simply a matter of clicking a link on your blog. If an underaged user decides to disregard your warnings and expose themselves to nasty content, Parental Control does not and can not stop them from doing so. You should therefore make your warning page (see below) such that after reading it, the user knows what they’ll get when switching Parental Control off. Thereafter, if they’re adults, the decision is theirs to make and if they’re not, they should know that the material is not suitable for them.

Installing And Setup

  1. Upload parental-control.php into your plugins folder, then activate it from WordPress’ Plugins menu.
  2. Implement the switch. This is done by editing your template to include the following:

    <?php
    if (function_exists('jupc_switch')) { ?>
    	<?php jupc_switch(); ?>
    <?php } ?>

    When the plugin is activated, this should produce a link which functions as an on/off toggler. Preferably, you should put the link in a place where it won’t be clicked on by accident, as that would defeat the purpose of the plugin.

  3. Set up a post or a page on which you explain your readers where the switch can be found. Be sure to also emphasize its meaning, so that people who are easily offended will know not to use it unless they’re willing to risk being offended. Make a highly visible, permanent link to this post/page in your template, so that it won’t be missed and your rated content go silently unnoticed by all readers from hereon.
  4. Unless you already happen to have a strictly ‘adult’ rated category, you should create a new category (under Manage > Categories) for this purpose. The name of the category doesn’t matter, although using a descriptive name is, of course, good practice.

    Add this category to your ‘adult’ rated posts (i.e. make them belong to this category) from now on. If you have old posts that you think should be rated, add your new category to them also.

  5. Go to Plugins > Parental Control Configuration in your WordPress administration screen to configure the plugin.
    • Select the category you intend to use as your ‘adult’ rated posts’ category. If you only wish to use the profanity filter and not the adult category exclusion, you can select the unnamed category (none).
    • The profanity filter’s text fields can be filled with words you wish to censor from your non- adult rated posts (the ones that are displayed although Parental Control is in effect). The words you enter here will have their middle parts replaced by asterisks. For example, if you enter “damn” (without the quotation marks) into one of the slots, “damn” will be replaced by “d**n” in posts and comments.

      Don’t worry about there not being enough slots for words; saving the settings will give you new empty slots.

      See technical notes about the profanity filter below.

  6. Click Save.
  7. Additionally, you should probably set up your robots.txt to include the following:

    User-agent: *
    Disallow: /*/?kiddie_protect=toggle$
    

    This way, your ‘adult’ rated content and direct links to it should not end up in search engines’ databases. (Note: I’ve not verified whether this works, and I’ve not dealt much with robots exclusions, so I could be wrong about this. If you know better, please leave a comment below.)

Technical Notes

  • The words entered into the profanity filter will be matched as word beginnings. That is, if you choose to censor “damn”, “goddamn” will not be censored, but “damnation” will be (it’ll become “d**nation”). If you wish to censor “goddamn” in addition to “damn”, you should enter both words into the filter, into their own slots.

    Thanks to this feature, there’s no need specify all possible compound and other words with nasty beginnings; specifying the nasty beginning is enough. For example, specifying the f-word will cause the censoring of not only the f-word itself, but f-ed, f-er, f-head and so on.

    There’s a downside: specifying “ass” will result in censoring of not only “ass”, but also “assert”, “assume” and so on. Generally, the shorter the word, the more likely it’ll risk innocent words being censored, so for such profanities, you should only specify compound words, such as “a-hole”. (This feature may be improved in a future version of the plugin.)

    Despite this downside, this feature works quite well at least with the Finnish language, but it should apply to other languages as well. If that isn’t the case with your language, I’d like to hear about it: please leave a comment below.

    For languages where the base of the word may change when conjugating (as is the case with Finnish), you should specify all the different forms of the base word separately. For example, the genetive form of ‘vittu’ (the Finnish f-word) is ‘vitun’, so you should specify both, as the plugin does not know how to conjugate.

    Although the profanity filter does extend to comments, it does not extend to plugins that use their own routines to display comments (such as Get Recent Comments). This means that profanities inside comments will be displayed by these plugins to all users, regardless of their Parental Control selections.

  • Your blog’s feeds will not be censored in any way. It is assumed that those who subscribe to feeds to read a blog regularly, will prefer to receive all content. In the future this feature may be improved so that censored feeds will be provided in addition to uncensored ones, as this increases freedom of choice.
  • The plugin’s functionality relies on being able to set a cookie on the user’s end. After activating the plugin, the filtering is, by default, on, until the user has selected to turn it off. It will not have any actual effect on the content, though, until it has been configured.
  • You can use jupc_on() in your template to test for the user’s Parental Control selection to, for example, emphasize the current state:

    <?php
    if (function_exists('jupc_on')) {
      echo '<li';
      if (jupc_on()) {
        echo ' background-color: red;">';
        echo '<a style="color: white;" href="';
        bloginfo('siteurl');
        echo '/parental-control/">Parental Control is ON</a>';
      } else {
        echo '">';
        echo '<a href="';
        bloginfo('siteurl');
        echo '/parental-control/">Parental Control is OFF</a>';
      }
      echo '</li>';
    }?>

    (This example presumes the existence of a page whose slug is “parental-control”.)

    jupc_on() returns TRUE when the user has selected to turn Parental Control off, and FALSE when the user has selected to turn Parental Control off OR has not yet used the switch.

  • By default, the switch has the id ‘jupcswitch‘ so you can refer to it in your style sheet as #jupcswitch (or a#jupcswitch).

Credits

For the most part, I did not write this plugin from scratch. I picked up, hacked to bits and then put together pieces from a multitude of different plugins made by other people, including Smart Unread Comments by Brett Taylor, WP-Noshit by whoo, Ubernyms by Joel Bennett, Front Page Excluded Categories by Sean O’Steen and Jason York, as well as an unreleased Author Read Comments plugin by Kuraattori. I’m thankful to these people for their code and inspiration.

Feedback

As I mentioned, this is a Beta release, which means that the code may very well contain bugs. I’ve used the plugin successfully in a couple of my own blogs for some time now, but that doesn’t mean it’ll work for you. If it doesn’t, I’d like to hear about it. So if you run into problems with the plugin, please use the comment form below to report them, and I’ll try and do my best resolve them. The purpose of this public Beta release is to find those lurking bugs so that they can be squashed for a full-blown 1.0 release.