Top

Wordpress Plugin Template

January 27, 2009

I know that when I started coding Wordpress Plugins, I had a rough time getting started. So, after spending a lot of time building them from the ground up, I eventually developed a plugin template that I start all of my plugins from.

So, after building a number of plugins from it, and “perfecting” it (read: adding time saving features, because I’m lazy and don’t like to re-write code) I’ve decided to release it to the Wordpress community so that other plugin authors don’t have to start from scratch anymore either.

Is it perfect? No – no template is. Does it speed up my plugin coding time? You bet it does!

Note: This code isn’t guaranteed in any way. This is what I use, and it saves me time but is by no means complete. (that’s why it’s a template) Use this code at your discretion, and understand that I’m in no way telling you that it will work for you, heh

That said, if it does help you, let me know, and if you feel so inclined, post about Pressography on your blog!

Download the template here (I’ve saved it as a .txt file, you’ll need to re-name it to .php)

And I also did a walkthrough video of an earlier version to show you why I included the code that I did. Check it out:


(If you can’t read the code, try full screen)

And if you’ve looked at the template I linked to above, and compared it to the video, you’ll notice that I’ve made a few changes since I did the video – I added a few more Find & Replace tokens (like {widget_slug}) to make things that much easier and faster.

Happy coding!

Update: 1/28/09 – I updated the plugin to include the action link, as explained here: http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/
Thanks to Sudar in his comment, below!

Because this plugin/widget is provided free of charge, I simply ask you to link back to Pressography.com in a post on your blog, or from one of your sites. It doesn't need to be anything fancy - just a note saying that you're using it, and whether or not you like it. However, there is no requirement that you do this, you're free to use the plugin regardless.

Comments

23 Responses to “Wordpress Plugin Template”

  1. johnbillion on February 13th, 2009 7:59 pm

    Hi Jason,

    This is a great way of reducing the time it takes to start a new plugin. I’ve got an improvement to suggest. You should replace:

    if (!defined(‘PLUGIN_URL’))
    define(‘PLUGIN_URL’, WP_CONTENT_URL . ‘/plugins/’);
    if (!defined(‘PLUGIN_PATH’))
    define(‘PLUGIN_PATH’, WP_CONTENT_DIR . ‘/plugins/’);

    with:

    if ( !defined( ‘WP_PLUGIN_URL’ ) )
    define( ‘WP_PLUGIN_URL’, WP_CONTENT_URL. ‘/plugins’ );
    if ( !defined( ‘WP_PLUGIN_DIR’ ) )
    define( ‘WP_PLUGIN_DIR’, WP_CONTENT_DIR . ‘/plugins’ );

    as these are the correct constant names (see WordPress Codex – Determining Plugin and Content Directories for reference.)

    You should also look into using WordPress nonces in your plugins for improved security. They’re crazy easy to use once you know how.

    Comment Tags: improvement, plugin, suggestion

Got something to say?





Tags:
Separate individual tags by commas
Bottom