<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lester Chan's WordPress Plugins &#187; widget</title>
	<atom:link href="http://lesterchan.net/wordpress/tag/widget/feed/" rel="self" type="application/rss+xml" />
	<link>http://lesterchan.net/wordpress</link>
	<description>Lester Chan's WordPress Plugins Development Blog</description>
	<lastBuildDate>Sat, 07 Jan 2012 03:01:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>New WP_Widget Class In WordPress 2.8</title>
		<link>http://lesterchan.net/wordpress/2009/03/17/new-wp_widget-class-in-wordpress-28/</link>
		<comments>http://lesterchan.net/wordpress/2009/03/17/new-wp_widget-class-in-wordpress-28/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 05:30:41 +0000</pubDate>
		<dc:creator>Lester Chan</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[2.8]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://lesterchan.net/wordpress/?p=252</guid>
		<description><![CDATA[In WordPress 2.8, there is a new WP_Widget class, which personally I like it very much as now the multi-instances of widgets is handled by WordPress, all you need to do is just to extends the WP_Widget class and overwrite &#8230; <a href="http://lesterchan.net/wordpress/2009/03/17/new-wp_widget-class-in-wordpress-28/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In WordPress 2.8, there is a new WP_Widget class, which personally I like it very much as now the multi-instances of widgets is handled by WordPress, all you need to do is just to extends the WP_Widget class and overwrite 3 of the functions namely widgets(), update() and form();</p>
<p>Below is a sample code taken from my WP-Polls that displays Polls Widget. It is tested and it works perfectly. Hope it is useful for plugin authors.</p>
<pre lang="php" line="1">
<?php
### Class: WP-Polls Widget
 class WP_Widget_Polls extends WP_Widget {
	// Constructor
	function WP_Widget_Polls() {
		$widget_ops = array('description' => __('Put a poll that you have added in WP-Polls on your sidebar', 'wp-polls'));
		$this->WP_Widget('polls', __('Polls'), $widget_ops);
	}

	// Display Widget
	function widget($args, $instance) {
		extract($args);
		$title = esc_attr($instance['title']);
		$poll_id = intval($instance['poll_id']);
		$display_pollarchive = intval($instance['display_pollarchive']);
		echo $before_widget.$before_title.$title.$after_title;
		get_poll($poll_id);
		if($display_pollarchive) {
			display_polls_archive_link();
		}
		echo $after_widget;
	}

	// When Widget Control Form Is Posted
	function update($new_instance, $old_instance) {
		if (!isset($new_instance['submit'])) {
			return false;
		}
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['poll_id'] = intval($new_instance['poll_id']);
		$instance['display_pollarchive'] = intval($new_instance['display_pollarchive']);
		return $instance;
	}

	// DIsplay Widget Control Form
	function form($instance) {
		global $wpdb;
		$instance = wp_parse_args((array) $instance, array('title' => __('Polls', 'wp-polls'), 'poll_id' => 0, 'display_pollarchive' => 1));
		$title = esc_attr($instance['title']);
		$poll_id = intval($instance['poll_id']);
		$display_pollarchive = intval($instance['display_pollarchive']);
?>

			<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-polls'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>

			<label for="<?php echo $this->get_field_id('display_pollarchive'); ?>"><?php _e('Display Polls Archive Link Below Poll?', 'wp-polls'); ?>
<select name="<?php echo $this->get_field_name('display_pollarchive'); ?>" id="<?php echo $this->get_field_id('display_pollarchive'); ?>" class="widefat">
<option value="0"<?php selected(0, $display_pollarchive); ?>><?php _e('No', 'wp-polls'); ?></option>
<option value="1"<?php selected(1, $display_pollarchive); ?>><?php _e('Yes', 'wp-polls'); ?></option>
</select>

			</label>

			<label for="<?php echo $this->get_field_id('poll_id'); ?>"><?php _e('Poll To Display:', 'wp-polls'); ?>
<select name="<?php echo $this->get_field_name('poll_id'); ?>" id="<?php echo $this->get_field_id('poll_id'); ?>" class="widefat">
<option value="-1"<?php selected(-1, $poll_id); ?>><?php _e('Do NOT Display Poll (Disable)', 'wp-polls'); ?></option>
<option value="-2"<?php selected(-2, $poll_id); ?>><?php _e('Display Random Poll', 'wp-polls'); ?></option>
<option value="0"<?php selected(0, $poll_id); ?>><?php _e('Display Latest Poll', 'wp-polls'); ?></option>
</select>

			</label>
<input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
<?php
	}
}

### Function: Init WP-Polls Widget
add_action('widgets_init', 'widget_polls_init');
function widget_polls_init() {
	register_widget('WP_Widget_Polls');
}
?>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lesterchan.net/wordpress/2009/03/17/new-wp_widget-class-in-wordpress-28/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Dashboard Widget (Without Controls) Sample Plugin</title>
		<link>http://lesterchan.net/wordpress/2008/03/19/dashboard-widget-without-controls-sample-plugin/</link>
		<comments>http://lesterchan.net/wordpress/2008/03/19/dashboard-widget-without-controls-sample-plugin/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 17:46:58 +0000</pubDate>
		<dc:creator>Lester Chan</dc:creator>
				<category><![CDATA[Sample Plugins]]></category>
		<category><![CDATA[2.5]]></category>
		<category><![CDATA[dashboard]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://lesterchan.net/wordpress/?p=158</guid>
		<description><![CDATA[WordPress 2.5 has the ability to customize your administration dashboard with the help of widgets. After poking around WordPress 2.5 codes, I have come out with this Dashboard Widget Sample Plugin. BUT do note that this plugin does not include &#8230; <a href="http://lesterchan.net/wordpress/2008/03/19/dashboard-widget-without-controls-sample-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>WordPress 2.5 has the ability to customize your administration dashboard with the help of widgets.</p>
<p>After poking around WordPress 2.5 codes, I have come out with this Dashboard Widget Sample Plugin. BUT do note that this plugin does not include Dashboard Widget Controls. If I have the time, I will add that in or perhaps I will create another plugin called &#8220;Dashboard Widget (With Controls) Sample Plugin&#8221;.</p>
<p>To get a clearer picture of what this sample plugin does, here is a <a href="http://files.lesterchan.net/viewing/screenshots/dashboard_widget_sample.png/">screenshot of the Dashboard Widget (Without Controls) Sample</a> in action.</p>
<p>Here comes the code:</p>
<pre lang="php" line="1">
<?php
/*
Plugin Name: Dashboard Widget (Without Controls) Sample
Plugin URI: http://lesterchan.net
Description: A sample on how to add widgets on your dashboard easily.
Version: 0.01
Author: Lester 'GaMerZ' Chan
Author URI: http://lesterchan.net
*/

/*

Replace all instances of PLUGINNAME with your nice plugin name something like "polls" or "ratings (without the quotes)

*/

### Function: Register Dashboard Widget
add_action('wp_dashboard_setup', 'PLUGINNAME_register_dashboard_widget');
function PLUGINNAME_register_dashboard_widget() {
	wp_register_sidebar_widget('dashboard_PLUGINNAME', __('Sample Dashboard Widget', 'PLUGINNAME'), 'dashboard_PLUGINNAME',
		array(
		'all_link' => 'Full URL For "See All" link', // Example: 'index.php?page=wp-useronline/wp-useronline.php'
		'feed_link' => 'Full URL For "RSS" link', // Example: 'index.php?page=wp-useronline/wp-useronline-rss.php'
		'width' => 'half', // OR 'fourth', 'third', 'half', 'full' (Default: 'half')
		'height' => 'single', // OR 'single', 'double' (Default: 'single')
		)
	);
}

### Function: Add Dashboard Widget
add_filter('wp_dashboard_widgets', 'PLUGINNAME_add_dashboard_widget');
function PLUGINNAME_add_dashboard_widget($widgets) {
	global $wp_registered_widgets;
	if (!isset($wp_registered_widgets['dashboard_PLUGINNAME'])) {
		return $widgets;
	}
	array_splice($widgets, sizeof($widgets)-1, 0, 'dashboard_PLUGINNAME');
	return $widgets;
}

### Function: Print Dashboard Widget
function dashboard_PLUGINNAME($sidebar_args) {
	global $wpdb;
	extract($sidebar_args, EXTR_SKIP);
	echo $before_widget;
	echo $before_title;
	echo $widget_name;
	echo $after_title;
	echo 'YOUR CONTENT GOES IN HERE';
	echo $after_widget;
}
?>
</pre>
<p>You can also download the file by clicking the link below:<br />
Note: There is a file embedded within this post, please visit this post to download the file.</p>
<p>Hope this helps some of you guys. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://lesterchan.net/wordpress/2008/03/19/dashboard-widget-without-controls-sample-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Database Caching 1/15 queries in 0.011 seconds using memcached
Object Caching 334/358 objects using xcache
Content Delivery Network via cdn.lesterchan.net

Served from: lesterchan.net @ 2012-02-12 07:31:29 -->
