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

Comment Tags: Bug Fix | plugin | suggestion | improvement

23 Responses to “Wordpress Plugin Template”

  1. Hans Bakker on November 5th, 2009 6:20 pm

    nm, I figured it out looks like it was working just bad code at the function level which was tripping it up. I like this template a lot.

  2. Hans Bakker on November 5th, 2009 5:34 pm

    where would I put a register_activation_hook

    I tried putting the following in the contruct with no luck

    register_activation_hook(__FILE__,$this->mycoolplugin_install());

  3. Jay on November 3rd, 2009 10:48 pm

    Whats the best way to get the options set in the admin and use the sting values in an external PHP file. E.g. If I was going to have an option like “title” and I wanted to use the value for “title” in a different script apart from wordpress. Basically so these options can be set using the wordpress admin / plugin options, and they will take effect on the other script?

  4. Eric Martin on September 10th, 2009 3:59 pm

    Jason,

    Thanks for the template. I used it as a base for my latest WP plugin, WP-Paginate [1].

    I made some changes and wanted to know if it was alright with you if I offered a modified version of your template from my blog. I would, of course, provide attribution to your original.

    Let me know either way. [2]

    Thanks,
    Eric

    [1] http://wordpress.org/extend/plugins/wp-paginate/
    [2] http://www.ericmmartin.com/contact/

  5. Jon Pruett on June 14th, 2009 11:37 pm

    I’m loving the template – only an hour or so worth of hacking and I have a fully functional admin screen saving and retrieving options. This is a big step in the right direction for my first plugin. Thanks!!

    I do have a question / request – are you going to update the template to handle the new widget API in WP version 2.8?

    Thanks again,
    - Jon

  6. Jason on June 5th, 2009 5:40 pm

    @Andrea – Fixed :) I thought I’d updated the .txt file, turns out I simply uploaded the .php file – hah! I made some more updates based on my own usage of the template, too.

    Comment Tags: Bug Fix
  7. Andrea on May 28th, 2009 3:56 am

    @Stefano Aglietti – Same issue here.

    If I’ve understood, this template is outdated. Even after 3 month from johnbillion’s advice, is still using the wrong constants. so, perhaps, we should work on our own template or found one more reliable somewhere on the web ;)

  8. kamal on May 25th, 2009 6:21 am

    Thannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnks for sharing your knowledj.
    Your Angel.

  9. Stanley @ WP Post Thumbnail on March 11th, 2009 4:22 am

    Hi Jason,

    This is a good thread and I hope it can be a start to some great discussion and input.

    The first step is usually the toughest for someone learning plugin programming. I remember I had trouble taking some written plugins apart. Then figuring out how bits and pieces come together for a WP plugin. It took quite a while before I start writing a line of code for my plugin.

    With each major WordPress update, there’ll be changes to plugin codes. It’ll be great if you can keep this plugin template frequently updated.

    Thanks for this article.

  10. Stephen Rider on March 4th, 2009 9:05 am

    Oh, and johnbillion is correct — you’re better off using the standard WP constants — WP_PLUGIN_URL and WP_PLUGIN_DIR.

  11. Stephen Rider on March 4th, 2009 8:52 am

    RE the Action links, my article is a bit outdated. As of WP 2.7, you can hook the filter on plugin_action_links_{plugin_basename} and it will just run for the one plugin row instead of every one. That way you don’t have to do the “is this the right line?” check each time.

    As for the footer attribution — I don’t see why it’s redundant. If the title of your plugin’s admin page has a header of “Plugin XYZ Settings”, then yes, it’s redundant, but I’ve always felt that plugins settings pages should be designed to look as though they’re part of core — i.e. it shouldn’t scream “I’m a plugin!”. If you do it that way, there’s nothing redundant in a small statement at the bottom saying “this functionality is being created by XYZ Plugin”.

    Overall, the template is a very nice idea. Good work. :-)

  12. Stefano Aglietti on February 24th, 2009 5:18 am

    Opps sorry i pasted to much code in the comment before :)

  13. Stefano Aglietti on February 24th, 2009 5:17 am

    How come that on 2.7.1 i get:

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘register_widgets’ was given in /home/.jimmie/steveagl/wordpress-it.it/wp-includes/plugin.php on line 339

    and when i access option page:

    *

    Bacheca
    Bacheca
    o Bacheca
    o Woopra Analytics
    o Statistiche Akismet
    *

    *

    Articoli
    Articoli
    o Modifica
    o Aggiungi nuovo
    o Tag
    o Categorie
    o Gestisci i tag
    o Modifica di massa sui Tags
    o Auto Tags
    *

    Media
    Media
    o Libreria
    o Aggiungi nuovo
    *

    Link
    Link
    o Modifica
    o Aggiungi nuovo
    o Categorie dei link
    *

    Pagine
    Pagine
    o Modifica
    o Aggiungi nuova
    *

    Commenti 0
    *

    *

    Aspetto
    Aspetto
    o Temi
    o Widget
    o Editor
    *

    Plugin 0
    Plugin 0
    o Installati
    o Aggiungi nuovo
    o Editor
    o Configurazione Akismet
    *

    Utenti
    Utenti
    o Autori & utenti
    o Aggiungi nuovo
    o Il tuo profilo
    *

    Strumenti
    Strumenti
    o Strumenti
    o Importa
    o Esporta
    o Aggiorna
    o Backup
    *

    Impostazioni
    Impostazioni
    o Generale
    o Scrittura
    o Revisions
    o Lettura
    o Discussione
    o Media
    o Privacy
    o Permalink
    o Varie
    o TG Most Commented Posts
    o Fuso Orario
    o FeedBurner
    o Maintenance Mode
    o Woopra Settings
    o Simple Tags
    o XML-Sitemap
    *

    *

    cformsII
    cformsII
    o Form Settings
    o Global Settings
    o Styling
    o Help!
    *

    Downloads
    Downloads
    o Manage Downloads
    o Add File
    o Download Options
    o Download Templates
    o Uninstall WP-DownloadManager

    Aiuto
    Documentazione in italiano (In inglese)
    Forum di supporto in italiano (In inglese)
    Aiuto

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘admin_options_page’ was given in /home/.jimmie/steveagl/wordpress-it.it/wp-includes/plugin.php on line 339

  14. TAT (Affiliate Secrets) on February 21st, 2009 5:18 am

    I’ve tried a lot of plugins and themes in my blog. Most are great but some are *^$()^^!.

    You may see the plugins and theme I used in my blog

  15. TAT (Affiliate Secrets) on February 21st, 2009 5:16 am

    I’ve tried a lot of templates and plugins. Most are great but some are &%$*)!

    In my blog, you may see some plugin and template I used. You might leave your comments or condemn there :(

  16. 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
  17. Sudar on January 28th, 2009 2:46 am

    @Jason – Thanks for considering my request :)

  18. Jason on January 28th, 2009 12:57 am

    @Sudar -
    Great idea – I’ll add the action link soon, but I’m not sure how I feel about the footer link… it seems a bit redundant, only displaying it when they’re on your options pages, and a little spammy to put it site-wide (unless your plugin does truely change WP site-wide) so I think I’ll leave that up to the individual plugin authors.

    I don’t want to be the guy to start the trend of every plugin getting credit in the footer ;)

  19. Sudar on January 27th, 2009 10:54 pm

    Thanks for sharing the template. It will really save a couple of minutes while creating a new Plugin.

    How about adding functions to display action links and footer links. Details at http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/ and http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/

  20. Whirled Wind » Blog Archive » Lovin’ the Open Source on June 15th, 2009 12:02 am

    [...] templates, and started to get a little cross eyed. Then I ran across the plugin template on Pressography – and the excellent video tutorial that goes along with it. Confidence begins to [...]

  21. All my bookmarks ever | Daniel John Gayle on May 29th, 2009 6:57 pm

    [...] Wordpress Plugin Template : Pressography [...]

  22. WordPress ???? at Becomin' Charles on March 9th, 2009 8:21 am

    [...] WordPress?????? [...]

  23. Wordpress Plugin/Widget Template | David Bisset: Web Designer, Coder, Wordpress Guru on January 29th, 2009 10:37 am

    [...] is more of a bookmark then anything else, since I have yet to try this. But this Wordpress Plugin Template seems very interesting and useful for those who want to learn to create Wordpress plugins. Not sure [...]

Got something to say?





Tags:
Separate individual tags by commas
Bottom