Automatic Email Address Protection PHP / JavaScript

Date: 27th October 2008 at 7:44 pm | Filed under: development, scripts | Author: Sam Burdge

It is important to protect email addresses on websites from being harvested by spambots.

"Email spambots collect e-mail addresses from the Internet in order to build mailing lists for sending unsolicited e-mail, also known as spam. Such spambots are web crawlers that can gather e-mail addresses from Web sites, newsgroups, special-interest group (SIG) postings, and chat-room conversations. Because e-mail addresses have a distinctive format, spambots are easy to write. A number of legislators in the U.S. are reported to be devising laws that would outlaw the spambot." – Wikipedia

This is my method for automatically detecting email addresses and replacing them with a javascript that will disguise them from spambots. The script works in two stages one in javascript and the other in php.

First the javascript function that outputs the mailto link:

function sb_email(user,site){
document.write('<a href=\"mailto:' + user + '@' + site + '\">');
document.write(user + '@' + site + '<\/a>');
}

The function has 2 parameters "user" and "site", which are the two parts of the email address either side of the "@". This function can be called like so:

sb_email('joe','bloggs.com');

The second part is the php functions that recognise email addresses and replace them with the javascript function to disguise them:

//function to output the js
function create_js ($matches){
$parts = explode ('@', substr ($matches[0], 1));
if(substr($parts[1],-1)=='.'){$parts[1]=substr($parts[1],0,-1); $parts[2]='.';}
$str = $matches[1].'<script language="JavaScript" type="text/javascript">';
$str .= 'sb_email("'.$parts[0].'", "'.$parts[1].'");';
$str .= '</script>'.$parts[2];
return $str;
}
$js_callback = "create_js ";
 
//function to recognise emails
function email_protect($text){
global $js_callback;
$replace = '/([> ])[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}/i';
$output = preg_replace_callback($replace, $js_callback, $text);
return $output;
}

The email_protect php function can be called on any text string like so:

echo email_protect($text);

It will automatically replace any email addresses in the text with the javascript, therefore hiding them from spambots.

Leave a Comment

WordPress - Change Default Email Address Plugin

Date: 20th February 2008 at 12:04 am | Filed under: development, plugins, wordpress | Author: Sam Burdge

This WordPress plugin changes the default email address that all notifications sent from your blog are addressed from. The default address for all emails sent by your blog is currently wordpress@ yoursite.com.

I had seen some tutorials / forum entries previously where people suggested editing the core WordPress file 'pluggable.php' to overide this default. This method does work, however you would have to repeat the hack every time you upgrade to a new version of WordPress so it is not an ideal solution.

Faced with this problem for a site I was working on recently, I wrote this basic plugin which allows you to configure your own email address in the format: Your Name <yourname@yoursite.com>.

Installation:

  1. Upload the file wp_change_default_email.php to your wp-content/plugins folder
  2. Activate the plugin from the Plugins page in WordPress

Usage:

  1. In the Plugins page in WordPress click the edit button next to the plugin in the list.
  2. Scroll down until you see a note saying 'Configure it'
  3. Enter your name and email as shown
  4. If you don't enter a new address the default 'wordpress@' will remain

Download:


5 Responses to “WordPress - Change Default Email Address Plugin”

  • Comment by Shane
    Date: February 29th, 2008 at 8:33 am

    Works great - thank you!

  • Comment by Change Default Email Address » Wordpress Plugins
    Date: July 9th, 2008 at 6:56 am

    [...] Version: 0.1 - License: n/a - Author: Sam Burge - Plugin Page - » Download [...]

  • Comment by Shane
    Date: August 25th, 2008 at 10:27 pm

    Is there a newer version than 0.1? I upgraded to WordPress 2.6.1 and the Plugins area is telling me that there is a new version, but the new version links to:
    GALLERY LIGHTBOX PLUGIN
    http://wordpress.org/extend/plugins/wp-25-gallery-lightbox-plugin/

    Also, just an FYI, version 0.1 now conflicts with the Subscribe2 plugin.

  • Comment by Greg
    Date: September 17th, 2008 at 8:06 pm

    Very handy little plug-in, works like a charm, thanks.

    I’m experiencing a little weirdness, though. I downloaded it from your site. When I install it, it works fine but I get an alert telling me there’s a new version 1.3 (the code says “Version 0.1″) and the link to get the new version points at http://wordpress.org/extend/plugins/wp-25-gallery-lightbox-plugin/ which is clearly wrong. The “Upgrade automatically” option doesn’t work either, with the error mentioning wp-25-gallery.

    Since it works, the only reason I care is I don’t want the little orange flag over “Plugins” in my dashboard, but seems like something you’d want to know.

  • Comment by huski
    Date: October 23rd, 2008 at 10:19 am

    wordpress 2.5
    not working for me, i made the two changes , name and email to the php file, verified the changes were saved in the php file, but it continues to send wordpress and wordpress@domain

    ????

Leave a Comment

WP Instructions Plugin

Date: 19th February 2008 at 10:07 pm | Filed under: development, plugins, wordpress | Author: Sam Burdge

As someone who regularly sets up WordPress sites for clients, often with bespoke themes and various plugins installed, I find it useful and helpful to include basic instructions for them. I used to send a text document to them by email when I handed the site over, but more recently have been including an instructions page as a tab in WordPress.

This plugin allows you to create a custom instructions page for a wordpress blog. Especially useful for those setting up WordPress sites for other people. You can use it to provide instructions for use of specific plugins etc.

Installation:

  1. Upload the wp_instructions folder to your wp-content/plugins folder.
  2. Activate the plugin from the Plugins page.

Usage:

To create your custom instructions simply edit the instructions.txt file in the wp_instructions folder. You can use html if you want. Numbered lists are a good format for giving step-by -step instructions.

Handy Tip:

As pointed out by David A (See comments for this post) you can use WordPress to create an instructions page and save it as private. You can then copy and paste the code from the code view of the WP text editor into the plugin's instructions.txt file, thus creating an html formatted instructions page without having to write any html yourself.

Download:


20 Responses to “WP Instructions Plugin”

  • Comment by Sam Burdge
    Date: March 2nd, 2008 at 5:19 pm

    Hi all,
    Just a quick note to users of this plugin - the plugin is currently set so that all user levels are able to view the instructions. If you wish to change this so that only users of a certain level (i.e Authors or administrators) are able to view the instructions you can change the following line in the plugin's code:

    add_menu_page('WP Instructions', 'Instructions', 1, __FILE__, 'wp_instructions_page');

    Replace the number 1 with the number that relates to the user level you want. For more info about user levels please visit this page on the wordpress site Levels and Users for WordPress.

    Also for non-english users you can always replace the word 'Instructions' with the translation in your own language.

    I hope these tips come in handy.

    Sam

  • Comment by Ken savage
    Date: March 4th, 2008 at 3:58 pm

    Hey Sam, nice plugins. thx for sharing.

    Woould you be willing to share the instruction you give out for new people accessing wordpress? I'm turning over a new site to another group in my company and this would save me a few hours of writing and creating screen shots.

  • Comment by David
    Date: March 4th, 2008 at 10:58 pm

    The download is an empty file!?!?

  • Comment by Sam Burdge
    Date: March 9th, 2008 at 1:54 pm

    Hi Ken,
    All of the instructions I have written are generally to do with using specific plugins like Podpress or ANIga. They would probably not be that useful to you. You could always take some of the instructions from the wordpress.org site and summarise them.
    Sam

  • Comment by Sam Burdge
    Date: March 10th, 2008 at 10:01 pm

    Hi David
    This problem (in IE only) should be solved now. Appologies for the inconvenience.
    Sam

  • Comment by David A
    Date: March 18th, 2008 at 3:18 pm

    Hi, nice idea! However, I'm wondering if it can be modified to pull a specific page from Wordpress instead of using a text file. That way you could use WP's page editor to edit up your instructions with formatting.

    So far, it appears that if you were to create a page template with no header, sidebar, footer- just the page content code, then create a page in WP, make it private, and use that blank page template, it should work fine as a replacement for Instructions.txt under your plugin (provided the path is changed in the plugin).

    You'd probably need to use pretty permalinks to keep the path stable, or provide a selector within the plugin page to pick the right page, but otherwise it should work fine? Does this sound workable/useful, or have I strayed too far from the path (again) ? :)

  • Comment by Sam Burdge
    Date: March 19th, 2008 at 7:31 pm

    Hi David,
    Thats an interesting thought. I will think about integrating such a feature for a future release of the plugin.
    Sam

  • Comment by David A
    Date: March 20th, 2008 at 3:59 pm

    Hi again, I discovered that by using WP to create a Private page of instructions, you can copy and paste from the Code view into the Instructions.txt, and it displays perfectly.

    You will still likely need to upload the text file into the plugin folder (your server directories, like mine, are probably not writeable for security reasons), but at least you can use WP to write and maintain the instructions.

    Thanks again for such a great idea, and donation incoming!

    David
    p.s. The captcha system is giving me a headache, three tries and no luck so far. I'm triplechecking before submitting, and it sure LOOKS right…

  • Comment by Sam Burdge
    Date: March 23rd, 2008 at 5:35 pm

    Hi David
    Thanks. I'm glad you found it so useful.
    Sam

  • Comment by Weathervane
    Date: March 25th, 2008 at 10:01 pm

    I can't find a download link for any of your plugins. Am I missing something?

  • Comment by Sam Burdge
    Date: March 26th, 2008 at 10:57 pm

    @Weathervane: Hi, erm… the big button that says 'download file' under the heading 'Download:' at the bottom of each plugin post!

  • Comment by Kevin
    Date: April 8th, 2008 at 12:46 pm

    The plugin doesn't work op wp 2.5 :(

  • Comment by Sam Burdge
    Date: April 12th, 2008 at 10:48 pm

    @Kevin: I have tested it on WP 2.5 and it works fine for me. Have you tried re-installing the plugin?

  • Comment by Leon
    Date: April 14th, 2008 at 1:07 pm

    Hi Sam

    Nice plugin. Was looking for something like this. The WP admin plugin manager states that there is a 1.0 version, but the HTML link refers to your flash clock plugin. Maybe you can fix this?

  • Comment by Christopher
    Date: April 15th, 2008 at 2:44 pm

    Just installed it and I think it is a great little plugin - really useful, many thanks for your hard work.

    It did not seem to like it that I have not installed WordPress in the root (blog homepage is in different directory from where WordPress is installed), so had to edit the plugin to point it at the right directory for the text file.

    I also just noticed that WordPress is suggesting an update but linking to wp-digi-clock-plugin-01beta

  • Comment by Christopher
    Date: April 15th, 2008 at 2:50 pm

    Sorry, could have been more useful if I had included my edit.

    Changed get_bloginfo(’url’) for get_bloginfo(’wpurl’)

  • Comment by Casey
    Date: May 30th, 2008 at 5:49 pm

    I keep downloading and upgrading, but it keeps telling me that a new version is available. The zip I download produces a folder name wp_instructions_01, with another wp_instructions folder within. No matter which folder I put up there, the plugins page says there’s a newer version available.

    could you please check to see if the package is correct? I’m using 2.5.1. I read that your plugin was compatible with 2.5x…. please advise if this isn’t true, thanks!

  • Comment by WP Help : Pressing Pixels | A Wordpress Magazine
    Date: June 4th, 2008 at 10:10 pm

    [...] I came across a plugin that did this but is was not easily updatable and had some issues with a couple of installations. So I’ve improved on it and here is WP Help inspired by Sam Burdge’s wp-instructions. [...]

  • Comment by Laran Evans
    Date: July 19th, 2008 at 5:21 am

    Hey Sam. Neat plugin.

    I did run into some issues due to the use of the fopen function.

    I wrote a plugin that generates a table of contents for content.

    Someone contacted me today saying that they wanted to integrate the table of contents with your instructions plugin. So I did. I also fixed the fopen bug.

    So, here’s a link to the integrated code (just the .php file, not instructions.txt) along with two screenshots. One screenshot is when my table of contents plugin is activated. The other is when it’s de-activated.

    http://tinyurl.com/5n3qj6

    Now I’m going to go check out the WP Help plugin :)

    Enjoy!

  • Comment by Laran Evans
    Date: July 19th, 2008 at 5:23 am

    I forgot to give the url of my plugin. Here it is:

    http://wordpress.org/extend/plugins/wordpress-table-of-contents/

Leave a Comment

Fighting Spam

Date: 19th December 2007 at 12:32 am | Filed under: blog, wordpress | Author: Sam Burdge

I've been receiving a bit of spam on my blog lately :evil: obviously none of it gets through, but its still annoying having to delete it all. So, I have decided to take measures against it by implementing a few changes on my blog. I have installed the Captcha! plugin which now requires users to manually enter the text they see in the picture before their comment is submitted. I have also activated the Askimet plugin which flags comments as spam based on the askimet database.

Whilst looking at the different ways to fight spam I found this article: The Solution to Blog Spamming, which I found very useful.

Leave a Comment

WP Digi Clock Plugin (1.0) - New Version!

Date: 4th December 2007 at 10:18 pm | Filed under: development, flash, plugins, wordpress | Author: Sam Burdge

This easy to use plugin will embed a flash digital clock into your wordpress blog, either in a post or page, or within your blog's template (in the sidebar / header / footer etc.). The background and font colours are managed via the options menu. The clock can display the time as set on the user's local machine or as set by your web server with an optional offset. It also has options for 12hr and 24hr clock.

Installation:

  1. Download the plugin file here: WP Digi Clock Plugin (1.0)
  2. Upload the wp-digi-clock folder to your wp-content/plugins folder
  3. Activate the plugin from the plugins page
  4. Go to Options -> WP Digi Clock to choose your colour scheme and time format options

Usage:

To embed in a post or page:

type in [ wp_digi_clock ] (removing the spaces) anywhere in a post or page.

to embed in your page template (header, footer, sidebar):

use the function wp_digital_clock($x), with $x being a number or identifier for example:

<h2>TIME</h2>
<li><?php wp_digital_clock('1'); ?></li>

1 Response to “WP Digi Clock Plugin (1.0) - New Version!”

  • Comment by Mat
    Date: June 2nd, 2008 at 7:28 pm

    thanks for making a great clock.

    is there a way to change the font size?
    thanks again!

Leave a Comment