Wordpress Plugin Templates

7 Feb, 2010  |  Written by  |  under wp news

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 TitlePlugin URI: your-url.com/plugin-name/Description: Your super awesome, catchy, and descriptive descriptionVersion: 1.0.0Author: you!Author URI: your-url.com/*//*Change log1.0.0 – Achievement – AchievementBeta 3 – Achievement – Achievement – AchievementBeta 2 – Achievement – Achievement – Achievement – AchievementBeta 1 – Achievement – AchievementAlpha 1 – used the plugin template from FS*/// some Defaults$var1 = ”;$var2 = ”;$var3 = array();$var4 = ”;// put our defaults in the “wp-options” tableadd_option(“***-var1″, $var1);add_option(“***-var2″, $var2);add_option(“***-var3″, $var3);add_option(“***-var4″, $var4);// start the pluginif ( ! 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 paneladd_action(‘admin_menu’, array(‘SBC_Admin’,'add_config_page’));?>admin-page.php<?php// Update Settingsif ( 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 featurefunction 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!’;}?>

Wordpress Plugin Templates

No Responses so far | Have Your Say!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>