<?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>Jonas Nordström&#187; jonasnordstrom.se</title> <atom:link href="http://jonasnordstrom.se/tag/tutorial/feed/" rel="self" type="application/rss+xml" /><link>http://jonasnordstrom.se</link> <description>Teknik och media</description> <lastBuildDate>Wed, 08 Sep 2010 04:55:08 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=abc</generator> <item><title>Skapa enkel widget i WordPress</title><link>http://jonasnordstrom.se/skapa-enkel-widget-i-wordpress/</link> <comments>http://jonasnordstrom.se/skapa-enkel-widget-i-wordpress/#comments</comments> <pubDate>Mon, 12 Oct 2009 22:27:17 +0000</pubDate> <dc:creator>jonas</dc:creator> <category><![CDATA[Teknik]]></category> <category><![CDATA[wordpress]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[tutorial]]></category> <category><![CDATA[widget]]></category> <category><![CDATA[yo]]></category><guid
isPermaLink="false">http://jonasnordstrom.se/?p=195</guid> <description><![CDATA[Det är enkelt att göra en widget i WordPress. Man kan givetvis göra den hur avancerad som helst, men själva grunden är enkel och jag ska visa hur det går till. Du vet säkert att en widget är en plugin-liknande funktion som man kan placera någonstans på sin WordPress-sajt, ofta hamnar den i sidomenyn. Vanliga [...]]]></description> <content:encoded><![CDATA[<p>Det är enkelt att göra en widget i WordPress. Man kan givetvis göra den hur avancerad som helst, men själva grunden är enkel och jag ska visa hur det går till.</p><p>Du vet säkert att en widget är en plugin-liknande funktion som man kan placera någonstans på sin WordPress-sajt, ofta hamnar den i sidomenyn. Vanliga exempel är &#8221;Arkiv&#8221;, &#8221;Taggmoln&#8221; eller &#8221;Senaste flickr-bilderna&#8221;.</p><p>Det fungerar så att man i ett tema har definierat ett antal utrymmen där man kan placera widgets, dessa utrymmen kallas för &#8221;sidebars&#8221;. Sidebars kan man placera i sidomenyn, footern eller egentligen var som helst i temat. I varje &#8221;sidebar&#8221; kan sen sajt-administratören dra in en eller flera widgets.<br
/> Hos mig ser det ut så här, under &#8221;Utseende&#8221; -> &#8221;Widgets&#8221;.<br
/><div
id="attachment_199" class="wp-caption alignnone" style="width: 580px"><a
href="http://jonasnordstrom.se/wp-content/uploads/2009/10/Bild-7.png"><img
src="http://jonasnordstrom.se/wp-content/uploads/2009/10/Bild-7-580x342.png" alt="Widgets i WordPress dashboard" title="widgets" width="580" height="342" class="size-medium wp-image-199" /></a><p
class="wp-caption-text">Widgets i WordPress dashboard</p></div></p><p>Från och med WordPress 2.8 har det blivit lättare att <a
href="http://codex.wordpress.org/Widgets_API">skapa egna widgets</a>. Man utgår från basklassen WP_Widget och implementerar en del av metoderna.<br
/> De här metoderna måste man implementera:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> My_Widget <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> My_Widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// widget actual processes</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// outputs the content of the widget</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// processes widget options to be saved</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// outputs the options form on admin</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
register_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My_Widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Jag tänkte bygga en widget som visar min senaste status-uppdatering från sajten <a
href="http://yo.se">Yo!</a>. Genom att logga in på yo.se och gå till URL:en <a
href="http://yo.se/widget/">http://yo.se/widget/</a>, får man en HTML-snutt som egentligen gör hela jobbet åt oss när det gäller att visa senaste status. den ser ut så här:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;yo-widget&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_yo_windyjonas&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://windyjonas.yo.se/&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Jonas Nordström&quot;</span><span style="color: #339933;">&gt;</span>Windyjonas<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>h1<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://yo.se/widget/1/w.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
    _yo<span style="color: #339933;">.</span>username <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;windyjonas&quot;</span><span style="color: #339933;">;</span>
    _yo<span style="color: #339933;">.</span>hostname <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://yo.se&quot;</span><span style="color: #339933;">;</span>
    _yo<span style="color: #339933;">.</span>style <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://yo.se/widget/1/w.css&quot;</span><span style="color: #339933;">;</span>
    _yo<span style="color: #339933;">.</span>init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div><p>Det allra enklaste hade förstås varit att klippa in den här koden i en text-widget, men då hade det här inte blivit ett exempel på hur man skapar en WordPress-widget, så vi struntar i det och går vidare <img
src='http://jonasnordstrom.se/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Jag kallar widgeten för &#8221;Yo Status&#8221;, så min widgetklass ska få namnet &#8221;Yo_Status_Widget&#8221; och de metoder jag ska implementera blir följaktligen:</p><ul><li><em>Yo_Status_Widget()</em> &#8211; konstruktor</li><li><em>widget()</em> &#8211; funktionen som ska skicka ut widget-koden till webbläsaren</li><li><em>update()</em> &#8211; Det ska gå att konfigurera widgeten. update() ser till så att man kan ändra aliasnamn (yo-användare)</li><li><em>form()</em> &#8211; Skapar formuläret för att ändra aliasnamn</li></ul><h4>Yo_Status_Widget()</h4><p>Skapa ett WP_Widget-objekt med rätt metainfo och options. &#8221;classname&#8221; nedan är alltså css-klassen i det omslutande HTML-elementet.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> Yo_Status_Widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$widget_ops</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classname'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'widget_yo_status'</span><span style="color: #339933;">,</span> 
            <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Display status from Yo! (http://yo.se)'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WP_Widget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yo-status'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Yo Status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$widget_ops</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4>widget()</h4><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">function widget($args, $instance) {
	extract($args, EXTR_SKIP);
&nbsp;
	echo $before_widget;
	$alias = empty($instance['alias']) ? '&amp;nbsp;' :
          apply_filters('widget_alias', $instance['alias']);
   ?&gt;
    &lt;div class=&quot;yo-widget&quot; id=&quot;_yo_<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		  &lt;h1&gt;&lt;a href=&quot;http://<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>.yo.se/&quot;&gt;
                 <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h1&gt;
		  &lt;script src=&quot;http://yo.se/widget/1/w.js&quot; 
                     type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
		  &lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
		    _yo.username = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;;
		    _yo.hostname = &quot;http://yo.se&quot;;
		    _yo.style = &quot;http://yo.se/widget/1/w.css&quot;;
		    _yo.init();
		  &lt;/script&gt;
		&lt;/div&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4>update()</h4><p>Den här funktionen anropas efter att användaren matat in ett yo-alias och klickat på &#8221;Spara&#8221;</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$old_instance</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</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: #000088;">$new_instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Formuläret som möjliggör ändring av yo-användare.</p><h4>form()</h4><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">	function form($instance) {
		$instance = wp_parse_args( (array) $instance, array( 'alias' =&gt; '') );
		$alias = strip_tags($instance['alias']);
?&gt;
		&lt;p&gt;
			&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Alias på yo.se: 
				&lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; 
					name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; 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;">$alias</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
			&lt;/label&gt;
		&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span></pre></div></div><h3>Resultat</h3><p>Till slut bakar jag ihop alltihop till en ny plugin. Det hade i och för sig gått att deklarera hela widgeten i functions.php, men jag föredrar att inte röra temafilerna så mycket.<br
/> Jag gjorde en plugin av alltihop genom att skapa filen /wp-contents/plugins/yo-status/yo-status.php. En del av outputen i widget()-metoden är här utbruten i en egen metod.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">/* 
Plugin Name: Yo Status
Plugin URI: http://jonasnordstrom.se/yo-status-widget 
Description: Display your yo.se status in sidebar
Version: 0.2
Author: Jonas Nordstrom
Author URI: http://jonasnordstrom.se
*/</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'widgets_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'yo_status_load_widgets'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> yo_status_load_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_widget<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Yo_Status_Widget'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> Yo_Status_Widget <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> Yo_Status_Widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$widget_ops</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classname'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'widget_yo_status'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Display status from Yo! (http://yo.se)'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WP_Widget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yo-status'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Yo Status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$widget_ops</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> yo_status<span style="color: #009900;">&#40;</span><span style="color: #000088;">$alias</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;div class=&quot;yo-widget&quot; id=&quot;_yo_<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		  &lt;h1&gt;&lt;a href=&quot;http://<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>.yo.se/&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h1&gt;
		  &lt;script src=&quot;http://yo.se/widget/1/w.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
		  &lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
		    _yo.username = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$alias</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;;
		    _yo.hostname = &quot;http://yo.se&quot;;
		    _yo.style = &quot;http://yo.se/widget/1/w.css&quot;;
		    _yo.init();
		  &lt;/script&gt;
		&lt;/div&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> EXTR_SKIP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$alias</span> <span style="color: #339933;">=</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'&amp;nbsp;'</span> <span style="color: #339933;">:</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget_alias'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yo_status</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$alias</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$old_instance</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</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: #000088;">$new_instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> wp_parse_args<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$instance</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$alias</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Alias på yo.se: &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alias'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; 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;">$alias</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/label&gt;&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Resultatet syns längst ner i högersplaten, eller om jag ändrat något, så såg det en gång ut så här:<br
/><div
id="attachment_201" class="wp-caption alignnone" style="width: 297px"><a
href="http://jonasnordstrom.se/wp-content/uploads/2009/10/Bild-8.png"><img
src="http://jonasnordstrom.se/wp-content/uploads/2009/10/Bild-8.png" alt="Exempel på hur Yo Status kan se ut" title="Yo-status" width="297" height="374" class="size-full wp-image-201" /></a><p
class="wp-caption-text">Exempel på hur Yo Status kan se ut</p></div></p><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://jonasnordstrom.se/skapa-enkel-widget-i-wordpress/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Served from: jonasnordstrom.se @ 2010-09-11 00:05:11 by W3 Total Cache -->