Fire Studios

Archive

Contact

Categories

  • Coding
    • CSS
    • HTML/Javascript
    • PHP
  • Design
  • Freebies
  • General
  • Internet
  • Interviews
  • Plugins
  • Podcasts
  • Reviews
  • Screencasts
  • Tutorial
  • Weekday Tips
  • Wordpress

Podcast

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!';
}

?>

Reader's Thoughts

  • Ayo Adigun

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

  • Martin Bean

    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

    Thanks!

  • Jeff Starr

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

  • Fire G

    Thanks for the kind words guys!

  • Kyle

    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

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

  • Flex developr

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

  • Peter Kahoun

    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

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

  • iPod Nano

    Great article! I’m loving your website;

  • Peter Kahoun

    @Fire_G: I mean http://cz.php.net/manual/en/language.oop5.basic.php example #2.

  • JaneRadriges

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

  • aliplanning

    Thank you to share

  • GarykPatton

    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

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

    roseville teeth whitening

  • KonstantinMiller

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

  • SinySnomy

    Great post!

  • Anna-Alfonso

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

  • Pharmc16

    Very nice site!

  • Rock Tops Granite

    Cool blog!

    Rock Tops Granite

  • nemo

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

Your Thoughts?

 

This is that small text that tells you not to steal our stuff, but we don't really care too much.