My First WordPress Plugin – WP-AntiSpambot

I’ve been making WordPress sites and plugin functionality for some time now, but have yet to make anything to release to the public.  I’ve been thinking about making something to submit to the WordPress plugin repo for some time and finally figured out I would do it.  I just wanted to see the process and get something up there, so I started out very simple.

I decided I’d create a plugin using the built-in WordPress antispambot() function.  This function will take a plain text email address and encode it into HTML entities so spambots can’t read it.  I don’t know how, but I didn’t actually know about this function until about a a month or two ago.  I figured I’d create a shortcode that takes advantage of this function in the WordPress editor.  You just have to wrap up your email address the shortcode as shown here to make your email address hidden to spammers (remove the spaces, of course).

[ email ]yourname@yoursite.com[ /email ]

I say the plugin is simple.  How simple you ask?  Well, it’s only four lines of code, save comments:

function df_antispambot_shortcode( $atts, $content = null ) {
 return '<a href=mailto:' . antispambot( $content ) . '>' . antispambot( $content ) . '</a>';
}
add_shortcode( 'email', 'df_antispambot_shortcode');

Yep, pretty simple.

I end up making some future improvements.  I had a suggestion to parse the editor to detect emails and automatically add antispambot.  I also could add a TinyMCE button to create the shortcode.  Maybe we’ll see these in future versions.

The submittal process to the WordPress plugin repo was pretty simple and straightforward.  How long does it take to get a plugin approved in the WordPress repo?  I submitted the plugin on February 28th and it was approved on March 6th.  Not too bad.  I encourage anyone to try your hand at a plugin.  It’s a fun experience.

Download my WP-AntiSpambot plugin here »

1 Comment

  1. Thanks! you just save me an hour of template creation

Leave a Reply

Your email address will not be published.

*

© 2017 Dustin Filippini

Theme by Anders NorenUp ↑