Wordpress Plugin Templates

Wordpress Plugin Templates

Wordpress plugins have become my new addiction in the WP environment, thus I've noticed that I'm using the same few beginning steps every time. This led me to create a template file so that I just open, edit, and continue on my merry way of coding my plugin. I'm posting these templates for free use no matter what you're working on. I'll even be a nice guy and let you repost them as your own.

This template is depreciated. Please use the new ones.

Wordpress Plugin Templates v2

Download the Old Templates

To use, simply replace every "Your_Plugin" with the name of your plugin and replace any "***" with an abbreviation of your plugin.

main.php

<?php
/*
Plugin Name: Your Plugin Title
Plugin URI: http://your-url.com/plugin-name/
Description: Your super awesome, catchy, and descriptive description
Version: 1.0.0
Author: You!
Author URI: http://your-url.com/
*/

/*
Change log

1.0.0
 - Achievement
 - Achievement

Beta 3
 - Achievement
 - Achievement
 - Achievement

Beta 2
 - Achievement
 - Achievement
 - Achievement
 - Achievement

Beta 1
 - Achievement
 - Achievement

Alpha 1
 - Used the plugin template from FS

*/

// Some Defaults
$var1				= '';
$var2				= '';
$var3				= array();
$var4				= '';

// Put our defaults in the "wp-options" table
add_option("***-var1", $var1);
add_option("***-var2", $var2);
add_option("***-var3", $var3);
add_option("***-var4", $var4);

// Start the plugin
if ( ! class_exists( 'Your_Plugin' ) ) {

	class Your_Plugin {

		// prep options page insertion
		function add_config_page() {
			global $wpdb;
			if ( function_exists('add_submenu_page') ) {
				add_options_page('Plugin Title', 'Plugin Name', 10, basename(__FILE__), array('Your_Plugin','config_page'));
				add_filter( 'plugin_action_links', array( 'Your_Plugin', 'filter_plugin_actions' ), 10, 2 );
				add_filter( 'ozh_adminmenu_icon', array( 'Your_Plugin', 'add_ozh_adminmenu_icon' ) );
			}
		}

		// Place in Settings Option List
		function filter_plugin_actions( $links, $file ){
			//Static so we don't call plugin_basename on every plugin row.
			static $this_plugin;
			if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);

			if ( $file == $this_plugin ){
				$settings_link = '<a href="options-general.php?page=main.php">' . __('Settings') . '</a>';
				array_unshift( $links, $settings_link ); // before other links
			}
			return $links;
		}

		function config_page(){
			include('admin-page.php');
		}
	}
}

include('purpose.php');

// insert into admin panel
add_action('admin_menu', array('SBC_Admin','add_config_page'));
?>

admin-page.php

<?php

// Update Settings
if ( isset($_POST['submit']) ) {
	if (!current_user_can('manage_options')) die(__('You cannot edit the search-by-category options.'));
	check_admin_referer('your_plugin-updatesettings');

	// Get our new option values
	$var1					= $_POST['var1'];
	$var2					= $_POST['var2'];
	$var3					= $_POST['var3'];
	$var4					= $_POST['var4'];

	// Fix value of checkboxes
	if(empty($var3)) $var3 = '0';

	// Update the DB with the new option values
	update_option("***-var1", $var1);
	update_option("***-var2", $var2);
	update_option("***-var3", $var3);
	update_option("***-var4", $var4);
}

// Get Current DB Values
$var1					= get_option("***-var1");
$var2					= get_option("***-var2");
$var3					= get_option("***-var3");
$var4					= get_option("***-var4");	

?>

<div class="wrap">
	<h2>Your_Plugin</h2>
	<form action="" method="post" id="your_plugin-config">
		<table class="form-table">
			<?php if (function_exists('wp_nonce_field')) { wp_nonce_field('your_plugin-updatesettings'); } ?>
			<tr>
				<th scope="row" valign="top"><label for="var1">Display text for var1:</label></th>
				<td><input type="text" name="var1" id="var1" class="regular-text" value="<?php echo $var1; ?>"/></td>
			</tr>
			<tr>
				<th scope="row" valign="top"><label for="var2">Display text for var2:</label></th>
				<td><input type="text" name="var2" id="var2" class="regular-text" value="<?php echo $var2; ?>"/></td>
			</tr>
			<tr>
				<th scope="row" valign="top"><label for="var3">Display text for var3:</label></th>
				<td><input type="checkbox" name="var3" id="var3" value="1" <?php if ($var3 == '1') echo 'checked="checked"'; ?> /></td>
			</tr>
			<tr>
				<th scope="row" valign="top"><label for="var4">Display text for var4:</label></th>
				<td><input type="text" name="var4" id="var4" class="regulat-text" value="<?php echo $var4; ?>" /></td>
			</tr>
		</table>
		<br/>
		<span class="submit" style="border: 0;"><input type="submit" name="submit" value="Save Settings" /></span>
	</form>
</div>

purpose.php

<?php
// I suggest creating a new one of these for every major feature

function your_plugin_feature( ) {
	global $wp_query, $post;

	$var1		= get_option("***-var1");
	$var2		= get_option("***-var2");
	$var3		= get_option("***-var3");
	$var4		= get_option("***-var4");

	echo 'Hello World!';
}

?>

Share the Love Share the Love

Add to Reddit Add to StumbleUpon Add to Mixx Add to Delicious Add to designfloat

About the author: Fire G

Hey, I'm the founder of Fire Studios, and thus, have my hands in everything that goes on here at FS. I manage the content, moderate the comments, design everything, code everything, provides a lot of articles, host the official podcast FS-Air, and run/manage most of the other sites in the FI family. Often times I'll come to be working on so many things that I hardly accomplish much, but that's what makes me who I am.

22 Reader Comments

  •  
  • Ayo Adigun
    May 30th

    cool... cant wait to start using these.... thanks

  • Martin Bean
    May 30th

    Wow. Interesting post. We're starting to do a lot of WordPress sites at work now, so this may come in handy in the near future.

  • kucrut
    May 30th

    Thanks!

  • Jeff Starr
    May 30th

    Very cool! ..If only it were that simple! :)

  • Fire G
    May 30th

    Thanks for the kind words guys!

  • Kyle
    May 30th

    I like it! Ive created something similar that I use, but I hadnt gone as far as this. One thing I do include that i don't see here is an activate/deactivate hook and function because I seem to have to create tables on install and remove settings and that kind on deactivation.

  • Fire G
    May 31st

    @Kyle: That's a good idea, I might start adding that to my plugins.

  • Flex developr
    June 1st

    Super!!! Thanks. You very help me )))

  • Peter Kahoun
    June 4th

    There is a few interisting ideas. Some things I would do differently, for example settings-variables (defaults) I would definitely implement as class-variables (otherwise global-ization is needed). Maybe I'll add another feedback after writing another plugin (if it's welcome). Anyway, thanks for sharing.

  • Fire G
    June 4th

    @Peter: I'm writing an updated version now, but what do you mean by Class-variables?

  • iPod Nano
    June 4th

    Great article! I’m loving your website;

  • Peter Kahoun
    June 5th

  • JaneRadriges
    June 13th

    Great post! I'll subscribe right now wth my feedreader software!

  • aliplanning
    June 14th

    Thank you to share

  • GarykPatton
    June 15th

    I have been looking looking around for this kind of information. Will you post some more in future? I'll be grateful if you will.

  • mymmerigree
    June 17th

    Thank you for article. It's very good stuff.
    I enjoy to read fire-studios.com!

    roseville teeth whitening

  • KonstantinMiller
    July 6th

    I think I will try to recommend this post to my friends and family, cuz it's really helpful.

  • SinySnomy
    July 6th

    Great post!

  • Anna-Alfonso
    July 29th

    Sometimes it's really that simple, isn't it? I feel a little stupid for not thinking of this myself/earlier, though.

  • Pharmc16
    September 9th

    Very nice site!

  • Rock Tops Granite
    December 28th

    Cool blog!

    Rock Tops Granite

  • nemo
    February 27th

    Hi ! Great post! I have been looking looking around for this kind of information. Will you post some more in future?

Leave a Reply

Trackbacks/Pings

  1. Wordpress Plugin Templates
  2. Wordpress Plugin Templates | Website Design Blog
  3. Wordpress Plugin Templates « Fire Studios « Netcrema - creme de la social news via digg + delicious + stumpleupon + reddit
  4. 今週の管理人Bookmark (5/24-5/31) - ElectronicBrain is eating BreakFast
  5. Wordpress Plugin Templates « Fire Studios | Webmaster Tools
  6. Wordpress Plugin Templates « Fire Studios
  7. Webmaster Crap » Blog Archive » Wordpress Plugin Templates « Fire Studios
  8. Wordpress Plugins - Wordpress Plugin Templates « Fire Studios
  9. Wordpress Plugin Templates « Fire Studios | thepluginsecrets
  10. Wordpress Plugin Templates « Fire Studios » MyClickSense.com
  11. Twitted by jonasl
  12. Twitted by nourayehia
  13. Wordpress Plugin Templates « Fire Studios | Bloggers Tools
  14. Twitted by ventelations
  15. WordPress プラグイン・テンプレート - ElectronicBrain is eating BreakFast
  16. June 86 Blog » Blog Archive » New bookmarks for 2009.6.1
  17. Wordpress Plugin Templates « Fire Studios | Squico
  18. Twitted by delicious50
  19. Plantillas para desarrollar un plugin desde cero | TodoWordPress
  20. WordPress Articles for June 02 2009 | WPStart.org - WordPress themes, plugins and news
  21. Plantillas para desarrollar plugins para wordpress | gEEK tHE pLANET
  22. Poor Programming Proliferation at compu.terlicio.us
  23. links for 2009-06-04 | Webデザインのリンク集 Webデザインポータルサイト S5-Style
  24. Wordpress Plugin Templates « Fire Studios
  25. Jade the Ripper » WordPressプラグインを作成するためのテンプレートコード