My First Plugin!

May 15, 2012

So I finally wrote a WordPress plugin for release to the WordPress community.

I’ve been wanting to do this for a while, but haven’t been presented with a great circumstance to write one.  In my opinion software should make our lives easier or solve a problem for us, and I finally came across a problem that needed solving.

I’ve had more than one client complain that password protected posts on their site don’t have a logout button and can be accessed long after the password was provided.  The reason for this is the cookie that is created by javascript for that password will exist for 10 days, which with sensitive information is much too long. Although it is not recommended that you use a simple WordPress protected post to share any really valuable information, it is a much cheap and quicker way to present content to users whom you chose to have access to see it.

The concept and logic behind the plugin is simple, if a password protected post is open, add a button which will delete the cookie for that password.

Using WordPress’ native code that writes the original cookie, I have it set to make that cookie expire immediately (well 10 days in the past actually).  I simply call to an AJAX function which destroys the cookie more or less.  The javascript is hooked on through `wp_enqueue_scripts` and the actions are added approriately.  The AJAX function is registered so both logged in and non-logged in WordPress users can use the button.

It really is a neat little plugin, but it was a great learning experience. For more information check out the Protected Posts Logout Button plugin page

Comments are closed.

« Back to Blog