<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[17738] trunk/wp-content/themes/twentyeleven: In Twenty Eleven:
  Register the widget from functions.php.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17738">17738</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-04-28 09:47:30 +0000 (Thu, 28 Apr 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>In Twenty Eleven: Register the widget from functions.php. Kill create_function. Attach twentyeleven_widgets_init() to widgets_init, rather than init. Eliminate use of the $post global in the widget. see <a href="http://trac.wordpress.org/ticket/17198">#17198</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpcontentthemestwentyelevenfunctionsphp">trunk/wp-content/themes/twentyeleven/functions.php</a></li>
<li><a href="#trunkwpcontentthemestwentyelevenincwidgetsphp">trunk/wp-content/themes/twentyeleven/inc/widgets.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpcontentthemestwentyelevenfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentyeleven/functions.php (17737 => 17738)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyeleven/functions.php        2011-04-28 09:32:34 UTC (rev 17737)
+++ trunk/wp-content/themes/twentyeleven/functions.php        2011-04-28 09:47:30 UTC (rev 17738)
</span><span class="lines">@@ -366,9 +366,14 @@
</span><span class="cx"> add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Register widgetized area and update sidebar with default widgets
</del><ins>+ * Register our sidebars and widgetized areas. Also register the default Epherma widget.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_widgets_init() {
</span><ins>+
+        register_widget( 'Twenty_Eleven_Ephemera_Widget' );
+
</ins><span class="cx">         register_sidebar( array(
</span><span class="cx">                 'name' =&gt; __( 'Main Sidebar', 'twentyeleven' ),
</span><span class="cx">                 'id' =&gt; 'sidebar-1',
</span><span class="lines">@@ -418,7 +423,7 @@
</span><span class="cx">                 'after_title' =&gt; '&lt;/h1&gt;',
</span><span class="cx">         ) );
</span><span class="cx"> }
</span><del>-add_action( 'init', 'twentyeleven_widgets_init' );
</del><ins>+add_action( 'widgets_init', 'twentyeleven_widgets_init' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Display navigation to next/previous pages when applicable
</span></span></pre></div>
<a id="trunkwpcontentthemestwentyelevenincwidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentyeleven/inc/widgets.php (17737 => 17738)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyeleven/inc/widgets.php        2011-04-28 09:32:34 UTC (rev 17737)
+++ trunk/wp-content/themes/twentyeleven/inc/widgets.php        2011-04-28 09:47:30 UTC (rev 17738)
</span><span class="lines">@@ -78,13 +78,11 @@
</span><span class="cx">                 echo $title; // Can set this with a widget option, or omit altogether
</span><span class="cx">                 echo $after_title;
</span><span class="cx"> 
</span><del>-                global $post;
-
</del><span class="cx">                 ?&gt;
</span><span class="cx">                 &lt;ol&gt;
</span><span class="cx">                 &lt;?php while ( $ephemera-&gt;have_posts() ) : $ephemera-&gt;the_post(); ?&gt;
</span><span class="cx"> 
</span><del>-                        &lt;?php if ( 'link' != get_post_format( $post-&gt;ID ) ) : ?&gt;
</del><ins>+                        &lt;?php if ( 'link' != get_post_format() ) : ?&gt;
</ins><span class="cx"> 
</span><span class="cx">                         &lt;li class=&quot;entry-title&quot;&gt;
</span><span class="cx">                                 &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?&gt;&quot; rel=&quot;bookmark&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
</span><span class="lines">@@ -116,7 +114,7 @@
</span><span class="cx"> 
</span><span class="cx">                 echo $after_widget;
</span><span class="cx"> 
</span><del>-                // Reset the global $the_post as this query will have stomped on it
</del><ins>+                // Reset the post globals as this query will have stomped on it
</ins><span class="cx">                 wp_reset_postdata();
</span><span class="cx"> 
</span><span class="cx">                 // end check for ephemeral posts
</span><span class="lines">@@ -161,6 +159,4 @@
</span><span class="cx">                         &lt;input id=&quot;&lt;?php echo esc_attr( $this-&gt;get_field_id( 'number' ) ); ?&gt;&quot; name=&quot;&lt;?php echo esc_attr( $this-&gt;get_field_name( 'number' ) ); ?&gt;&quot; type=&quot;text&quot; value=&quot;&lt;?php echo esc_attr( $number ); ?&gt;&quot; size=&quot;3&quot; /&gt;&lt;/p&gt;
</span><span class="cx">                 &lt;?php
</span><span class="cx">         }
</span><del>-}
-
-add_action( 'widgets_init', create_function( '', &quot;register_widget( 'Twenty_Eleven_Ephemera_Widget' );&quot; ) );
</del><span class="cx">\ No newline at end of file
</span><ins>+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>