<?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>Helion-Prime Solutions blog &#187; cms</title>
	<atom:link href="http://blogs.helion-prime.com/tag/cms/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.helion-prime.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 26 Aug 2010 13:02:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple wordpress sidebar widget step-by-step development</title>
		<link>http://blogs.helion-prime.com/2008/04/14/simple-wordpress-sidebar-widget-step-by-step-development.html</link>
		<comments>http://blogs.helion-prime.com/2008/04/14/simple-wordpress-sidebar-widget-step-by-step-development.html#comments</comments>
		<pubDate>Mon, 14 Apr 2008 16:04:39 +0000</pubDate>
		<dc:creator>henadiy.atroshko</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=9</guid>
		<description><![CDATA[sidebar and widgets
Sidebar – is an area that take place on the left or on the right from main area. Usually on sidebar placed blog common or quick access elements. This elements called widgets.
Common examples:   authors, tags, categories, etc.
In the world of WordPress widget is a plugin subtype. That is activation/deactivation of widgets [...]]]></description>
			<content:encoded><![CDATA[<h2>sidebar and widgets</h2>
<p>Sidebar – is an area that take place on the left or on the right from main area. Usually on sidebar placed blog common or quick access elements. This elements called widgets.<br />
Common examples:   authors, tags, categories, etc.</p>
<p>In the world of WordPress widget is a plugin subtype. That is activation/deactivation of widgets realized thru the control panel of plug-ins.</p>
<p>Status control of widgets managed  in the  Design/Widgets panel. There you can add/remove widgets from/to sidebar and change their parameters.</p>
<h2>1. How to add new widget</h2>
<p>Since widget is plug-in it is behavior like common plug-in in WordPress. In other words it is php-script which placed in directory/subdirectories  “/wp-content/plugins”. For correct information representation widget(plug-in) should has header like above:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/*<br />
Plugin Name: Simple Wordpress Sidebar Widget<br />
Plugin URI: http://open.helion-prime.com/Simple-Wordpress-Sidebar-Widget<br />
Description: Simple wordpress sidebar widget.<br />
Version: 1.0<br />
Author: Helion-Prime Solutions Ltd.<br />
Author URI: http://helion-prime.com/<br />
*/</span></div></td></tr></tbody></table></div>
<p>&#8216;Plugin Name&#8217; field described symbolic plug-in name in the system.<br />
&#8216;Plugin URI &#8216; contains link to plug-in description.<br />
&#8216;description&#8217;  description.<br />
&#8216;version&#8217; version<br />
&#8216;Author&#8217; author name<br />
&#8216;Author URI&#8217; uniform resource identifier</p>
<p>In the upshot in order to add new widget to the system we should:<br />
create file “simple-sidebar-widget.php”<br />
add to file described header<br />
copy file to directory “/wp-content/plugins”</p>
<p>Then in the plug-in control panel we have new plug-in with our name:<br />
&#8216;Simple Wordpress Sidebar Widget&#8217;</p>
<p>simple-sidebar-widget.php</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">/*<br />
Plugin Name: Simple Sidebar Widget<br />
Plugin URI: http://open.helion-prime.com/Simple-Wordpress-Sidebar-Widget<br />
Description: Simple wordpress sidebar widget.<br />
Version: 1.0<br />
Author: Helion-Prime Solutions Ltd.<br />
Author URI: http://helion-prime.com/<br />
*/</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<h2>2. Plug-in registration</h2>
<p>In the first step we have added simplest plug-in (but not widget yet)<br />
In order to transform it to the widget, we should register it.</p>
<p>Code for sidebar registration:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_content_gen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_register<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;register_sidebar_widget<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'simple_sidebar_widget_content_gen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple_sidebar_widget_register'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>To work widget should contain at least 2 functions:<br />
*initialization (here simple_sidebar_widget_register)<br />
*content generation (here simple_sidebar_widget_content_gen)</p>
<p>To get control in the our code we should create hook on some event. We have 2 events to select from. In our case I have selected &#8216;init event&#8217; (raised when system loaded and initialized).<br />
Hook created with help of  add_action function, as parameter to it passed &#8216;name of event&#8217; (init) and name of handler function (simple_sidebar_widget_register).</p>
<p>If event raised function simple_sidebar_widget_register receive control and perform following actions:<br />
*check possibility to create widget with help of  accessibility of widget registration function – function_exists(&#8216;register_sidebar_widget&#8217;).<br />
* if required function is accessible it register widget</p>
<p>As you see register_sidebar_widget function receive 2 parameters:<br />
first contain localized name of widget in the widget control panel.<br />
second link to functionality of content-generator (&#8217;simple_sidebar_widget_content_gen&#8217;).</p>
<p>Now we have full-fledged widget that can be viewed in the widget control panel, it can be added to sidebar (don&#8217;t forget to activate it in the plug-in control panel).</p>
<h2>3. Representation</h2>
<p>If you add our widget to the sidebar it will not show anything. To find any result you should add function of content generation in the following way:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_content_gen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$widget_content</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is simple sidebar widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$widget_content</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>First thing that we do is from array of arguments of function that extract variables we create set of variables.</p>
<p>Mainly it is special variables that should be  used. Then we create content of widget: in fixed order we output values of special(which contain basic widget markup) and defined variables.</p>
<p>Now we can see our widget on sidebar.</p>
<h2>4. Widget setup</h2>
<p>If you want to have possibility to setup widget you should change code to the following:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">function simple_sidebar_widget_control_gen($widget_content, $show_content) {<br />
&lt;p&gt;<br />
&nbsp; &nbsp;&lt;label for=&quot;widget-content&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content:'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &lt;input class=&quot;widefat&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;id=&quot;widget-content&quot; name=&quot;widget-content&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> attribute_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;<br />
&nbsp; &nbsp; &nbsp; /&gt;<br />
&nbsp; &nbsp;&lt;/label&gt;<br />
&lt;/p&gt;<br />
&lt;p&gt;<br />
&nbsp; &nbsp;&lt;label for=&quot;show-content&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;input class=&quot;checkbox&quot; type=&quot;checkbox&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;id=&quot;show-content&quot; name=&quot;show-content&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$show_content</span> ? <span style="color: #0000ff;">'checked=&quot;checked&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; /&gt;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Show content.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp;&lt;/label&gt;<br />
&lt;/p&gt;<br />
&lt;input type=&quot;hidden&quot;<br />
&nbsp; &nbsp; &nbsp; id=&quot;simple-sidebar-widget-submit&quot; name=&quot;simple-sidebar-widget-submit&quot;<br />
&nbsp; &nbsp; &nbsp; value=&quot;1&quot;/&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_control<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newoptions</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'simple-sidebar-widget-submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$newoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$newoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$newoptions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newoptions</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple_sidebar_widget'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;simple_sidebar_widget_control_gen<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_content_gen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$show_content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$widget_content</span> <span style="color: #339933;">=</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ?<br />
&nbsp; &nbsp; &nbsp; __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is simple sidebar widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$show_content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&amp;lt;p&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$widget_content</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_register<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;register_sidebar_widget<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'simple_sidebar_widget_content_gen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;register_widget_control<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'simple_sidebar_widget_control'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>What changed in our code:</strong></p>
<p>In function &#8217;simple_sidebar_widget_register&#8217; one invocation added (&#8216;register_widget_control&#8217;), it register function which catch widget configuration change event (&#8217;simple_sidebar_widget_control&#8217;).</p>
<p>In the generator of widget content additional code added that receives current configuration of widget get_option(&#8217;simple_sidebar_widget&#8217;).<br />
Here parameter &#8217;simple_sidebar_widget&#8217; is identifier of parameters set that used in our widget.<br />
Then into variables $show_content and $widget_content extracted current values of parameters.</p>
<p>As I already noted for event processing of configuration changes we should add appropriate event-handler function (&#8217;simple_sidebar_widget_control&#8217;). In this function we extract parameters from request  and analyze changes, also this function create content of configuration form (this functionality moved to &#8217;simple_sidebar_widget_control_gen&#8217;).</p>
<p>After we added above code in the parameters of widget we have 2 fields.<br />
One field contains content that should be outputted.<br />
Second field is a switch which allow/forbid output of content.</p>
<p>In closing I want to note that widgets work only with themes that support sidebar.<br />
Described methodology work for WordPress >=2.5, although  it is almost the same for previous versions.</p>
<p><strong>related links:</strong><br />
plug-in development &#8211; http://codex.wordpress.org/Writing_a_Plugin<br />
list of actions &#8211; http://codex.wordpress.org/Plugin_API/Action_Reference<br />
localization: http://codex.wordpress.org/Translating_WordPress</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2008/04/14/simple-wordpress-sidebar-widget-step-by-step-development.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
