<!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>[13048] trunk/wp-includes/general-template.php:
  Add an echo arg to some general template functions.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13048">13048</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-10 18:37:14 +0000 (Wed, 10 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add an echo arg to some general template functions. Props ShaneF. fixes <a href="http://trac.wordpress.org/ticket/11842">#11842</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesgeneraltemplatephp">trunk/wp-includes/general-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesgeneraltemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/general-template.php (13047 => 13048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/general-template.php        2010-02-10 17:50:26 UTC (rev 13047)
+++ trunk/wp-includes/general-template.php        2010-02-10 18:37:14 UTC (rev 13048)
</span><span class="lines">@@ -111,8 +111,9 @@
</span><span class="cx">  * search. To give a few examples of what it can be used for.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.7.0
</span><ins>+ * @param boolean $echo Default to echo and not return the form.
</ins><span class="cx">  */
</span><del>-function get_search_form() {
</del><ins>+function get_search_form($echo = true) {
</ins><span class="cx">         do_action( 'get_search_form' );
</span><span class="cx"> 
</span><span class="cx">         $search_form_template = locate_template(array('searchform.php'));
</span><span class="lines">@@ -128,7 +129,10 @@
</span><span class="cx">         &lt;/div&gt;
</span><span class="cx">         &lt;/form&gt;';
</span><span class="cx"> 
</span><del>-        echo apply_filters('get_search_form', $form);
</del><ins>+        if ( $echo )
+                echo apply_filters('get_search_form', $form);
+        else
+                return apply_filters('get_search_form', $form);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -141,14 +145,18 @@
</span><span class="cx">  * @uses apply_filters() Calls 'loginout' hook on HTML link content.
</span><span class="cx">  *
</span><span class="cx">  * @param string $redirect Optional path to redirect to on login/logout.
</span><ins>+ * @param boolean $echo Default to echo and not return the link.
</ins><span class="cx">  */
</span><del>-function wp_loginout($redirect = '') {
</del><ins>+function wp_loginout($redirect = '', $echo = true) {
</ins><span class="cx">         if ( ! is_user_logged_in() )
</span><span class="cx">                 $link = '&lt;a href=&quot;' . esc_url( wp_login_url($redirect) ) . '&quot;&gt;' . __('Log in') . '&lt;/a&gt;';
</span><span class="cx">         else
</span><span class="cx">                 $link = '&lt;a href=&quot;' . esc_url( wp_logout_url($redirect) ) . '&quot;&gt;' . __('Log out') . '&lt;/a&gt;';
</span><del>-
-        echo apply_filters('loginout', $link);
</del><ins>+        
+        if ( $echo )
+                echo apply_filters('loginout', $link);
+        else
+                return apply_filters('loginout', $link);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -280,8 +288,9 @@
</span><span class="cx">  *
</span><span class="cx">  * @param string $before Text to output before the link (defaults to &lt;li&gt;).
</span><span class="cx">  * @param string $after Text to output after the link (defaults to &lt;/li&gt;).
</span><ins>+ * @param boolean $echo Default to echo and not return the link.
</ins><span class="cx">  */
</span><del>-function wp_register( $before = '&lt;li&gt;', $after = '&lt;/li&gt;' ) {
</del><ins>+function wp_register( $before = '&lt;li&gt;', $after = '&lt;/li&gt;', $echo = true ) {
</ins><span class="cx"> 
</span><span class="cx">         if ( ! is_user_logged_in() ) {
</span><span class="cx">                 if ( get_option('users_can_register') )
</span><span class="lines">@@ -291,8 +300,11 @@
</span><span class="cx">         } else {
</span><span class="cx">                 $link = $before . '&lt;a href=&quot;' . admin_url() . '&quot;&gt;' . __('Site Admin') . '&lt;/a&gt;' . $after;
</span><span class="cx">         }
</span><del>-
-        echo apply_filters('register', $link);
</del><ins>+        
+        if ( $echo )
+                echo apply_filters('register', $link);
+        else
+                return apply_filters('register', $link);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1001,16 +1013,19 @@
</span><span class="cx">  * @since 1.0.0
</span><span class="cx">  *
</span><span class="cx">  * @param bool $initial Optional, default is true. Use initial calendar names.
</span><ins>+ * @param bool $echo Optional, default is true. Set to false for return.
</ins><span class="cx">  */
</span><del>-function get_calendar($initial = true) {
</del><ins>+function get_calendar($initial = true, $echo = true) {
</ins><span class="cx">         global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
</span><span class="cx"> 
</span><span class="cx">         $cache = array();
</span><span class="cx">         $key = md5( $m . $monthnum . $year );
</span><span class="cx">         if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
</span><del>-                if ( is_array($cache) &amp;&amp; isset( $cache[ $key ] ) ) {
-                        echo $cache[ $key ];
-                        return;
</del><ins>+                if ( is_array($cache) &amp;&amp; isset( $cache[ $key ] ) ) {                
+                        if ( $echo )
+                                echo apply_filters( 'get_calendar',  $cache[$key] );
+                        else
+                                return apply_filters( 'get_calendar',  $cache[$key] );        
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1027,7 +1042,6 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        ob_start();
</del><span class="cx">         if ( isset($_GET['w']) )
</span><span class="cx">                 $w = ''.intval($_GET['w']);
</span><span class="cx"> 
</span><span class="lines">@@ -1073,7 +1087,7 @@
</span><span class="cx"> 
</span><span class="cx">         /* translators: Calendar caption: 1: month name, 2: 4-digit year */
</span><span class="cx">         $calendar_caption = _x('%1$s %2$s', 'calendar caption');
</span><del>-        echo '&lt;table id=&quot;wp-calendar&quot;&gt;
</del><ins>+        $calendar_output .= '&lt;table id=&quot;wp-calendar&quot; summary=&quot;' . esc_attr__('Calendar') . '&quot;&gt;
</ins><span class="cx">         &lt;caption&gt;' . sprintf($calendar_caption, $wp_locale-&gt;get_month($thismonth), date('Y', $unixmonth)) . '&lt;/caption&gt;
</span><span class="cx">         &lt;thead&gt;
</span><span class="cx">         &lt;tr&gt;';
</span><span class="lines">@@ -1087,10 +1101,10 @@
</span><span class="cx">         foreach ( $myweek as $wd ) {
</span><span class="cx">                 $day_name = (true == $initial) ? $wp_locale-&gt;get_weekday_initial($wd) : $wp_locale-&gt;get_weekday_abbrev($wd);
</span><span class="cx">                 $wd = esc_attr($wd);
</span><del>-                echo &quot;\n\t\t&lt;th scope=\&quot;col\&quot; title=\&quot;$wd\&quot;&gt;$day_name&lt;/th&gt;&quot;;
</del><ins>+                $calendar_output .= &quot;\n\t\t&lt;th scope=\&quot;col\&quot; title=\&quot;$wd\&quot;&gt;$day_name&lt;/th&gt;&quot;;
</ins><span class="cx">         }
</span><del>-
-        echo '
</del><ins>+        
+        $calendar_output .= '
</ins><span class="cx">         &lt;/tr&gt;
</span><span class="cx">         &lt;/thead&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -1098,24 +1112,20 @@
</span><span class="cx">         &lt;tr&gt;';
</span><span class="cx"> 
</span><span class="cx">         if ( $previous ) {
</span><del>-                echo &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;prev&quot;&gt;&lt;a href=&quot;' .
-                get_month_link($previous-&gt;year, $previous-&gt;month) . '&quot; title=&quot;' . sprintf(__('View posts for %1$s %2$s'), $wp_locale-&gt;get_month($previous-&gt;month),
-                        date('Y', mktime(0, 0 , 0, $previous-&gt;month, 1, $previous-&gt;year))) . '&quot;&gt;&amp;laquo; ' . $wp_locale-&gt;get_month_abbrev($wp_locale-&gt;get_month($previous-&gt;month)) . '&lt;/a&gt;&lt;/td&gt;';
</del><ins>+                $calendar_output .= &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;prev&quot;&gt;&lt;a href=&quot;' . get_month_link($previous-&gt;year, $previous-&gt;month) . '&quot; title=&quot;' . sprintf(__('View posts for %1$s %2$s'), $wp_locale-&gt;get_month($previous-&gt;month), date('Y', mktime(0, 0 , 0, $previous-&gt;month, 1, $previous-&gt;year))) . '&quot;&gt;&amp;laquo; ' . $wp_locale-&gt;get_month_abbrev($wp_locale-&gt;get_month($previous-&gt;month)) . '&lt;/a&gt;&lt;/td&gt;';
</ins><span class="cx">         } else {
</span><del>-                echo &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;prev&quot; class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</del><ins>+                $calendar_output .= &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;prev&quot; class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        echo &quot;\n\t\t&quot;.'&lt;td class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</del><ins>+        $calendar_output .= &quot;\n\t\t&quot;.'&lt;td class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</ins><span class="cx"> 
</span><span class="cx">         if ( $next ) {
</span><del>-                echo &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;next&quot;&gt;&lt;a href=&quot;' .
-                get_month_link($next-&gt;year, $next-&gt;month) . '&quot; title=&quot;' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale-&gt;get_month($next-&gt;month) ,
-                        date('Y', mktime(0, 0 , 0, $next-&gt;month, 1, $next-&gt;year))) ) . '&quot;&gt;' . $wp_locale-&gt;get_month_abbrev($wp_locale-&gt;get_month($next-&gt;month)) . ' &amp;raquo;&lt;/a&gt;&lt;/td&gt;';
</del><ins>+                $calendar_output .= &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;next&quot;&gt;&lt;a href=&quot;' . get_month_link($next-&gt;year, $next-&gt;month) . '&quot; title=&quot;' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale-&gt;get_month($next-&gt;month), date('Y', mktime(0, 0 , 0, $next-&gt;month, 1, $next-&gt;year))) ) . '&quot;&gt;' . $wp_locale-&gt;get_month_abbrev($wp_locale-&gt;get_month($next-&gt;month)) . ' &amp;raquo;&lt;/a&gt;&lt;/td&gt;';
</ins><span class="cx">         } else {
</span><del>-                echo &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;next&quot; class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</del><ins>+                $calendar_output .= &quot;\n\t\t&quot;.'&lt;td colspan=&quot;3&quot; id=&quot;next&quot; class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        echo '
</del><ins>+        $calendar_output .= '
</ins><span class="cx">         &lt;/tr&gt;
</span><span class="cx">         &lt;/tfoot&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -1167,24 +1177,24 @@
</span><span class="cx">         // See how much we should pad in the beginning
</span><span class="cx">         $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
</span><span class="cx">         if ( 0 != $pad )
</span><del>-                echo &quot;\n\t\t&quot;.'&lt;td colspan=&quot;'. esc_attr($pad) .'&quot; class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</del><ins>+                $calendar_output .= &quot;\n\t\t&quot;.'&lt;td colspan=&quot;'. esc_attr($pad) .'&quot; class=&quot;pad&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</ins><span class="cx"> 
</span><span class="cx">         $daysinmonth = intval(date('t', $unixmonth));
</span><span class="cx">         for ( $day = 1; $day &lt;= $daysinmonth; ++$day ) {
</span><span class="cx">                 if ( isset($newrow) &amp;&amp; $newrow )
</span><del>-                        echo &quot;\n\t&lt;/tr&gt;\n\t&lt;tr&gt;\n\t\t&quot;;
</del><ins>+                        $calendar_output .= &quot;\n\t&lt;/tr&gt;\n\t&lt;tr&gt;\n\t\t&quot;;
</ins><span class="cx">                 $newrow = false;
</span><span class="cx"> 
</span><span class="cx">                 if ( $day == gmdate('j', current_time('timestamp')) &amp;&amp; $thismonth == gmdate('m', current_time('timestamp')) &amp;&amp; $thisyear == gmdate('Y', current_time('timestamp')) )
</span><del>-                        echo '&lt;td id=&quot;today&quot;&gt;';
</del><ins>+                        $calendar_output .= '&lt;td id=&quot;today&quot;&gt;';
</ins><span class="cx">                 else
</span><del>-                        echo '&lt;td&gt;';
</del><ins>+                        $calendar_output .= '&lt;td&gt;';
</ins><span class="cx"> 
</span><span class="cx">                 if ( in_array($day, $daywithpost) ) // any posts today?
</span><del>-                                echo '&lt;a href=&quot;' . get_day_link($thisyear, $thismonth, $day) . &quot;\&quot; title=\&quot;&quot; . esc_attr($ak_titles_for_day[$day]) . &quot;\&quot;&gt;$day&lt;/a&gt;&quot;;
</del><ins>+                                $calendar_output .= '&lt;a href=&quot;' . get_day_link($thisyear, $thismonth, $day) . &quot;\&quot; title=\&quot;&quot; . esc_attr($ak_titles_for_day[$day]) . &quot;\&quot;&gt;$day&lt;/a&gt;&quot;;
</ins><span class="cx">                 else
</span><del>-                        echo $day;
-                echo '&lt;/td&gt;';
</del><ins>+                        $calendar_output .= $day;
+                $calendar_output .= '&lt;/td&gt;';
</ins><span class="cx"> 
</span><span class="cx">                 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
</span><span class="cx">                         $newrow = true;
</span><span class="lines">@@ -1192,15 +1202,18 @@
</span><span class="cx"> 
</span><span class="cx">         $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
</span><span class="cx">         if ( $pad != 0 &amp;&amp; $pad != 7 )
</span><del>-                echo &quot;\n\t\t&quot;.'&lt;td class=&quot;pad&quot; colspan=&quot;'. esc_attr($pad) .'&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</del><ins>+                $calendar_output .= &quot;\n\t\t&quot;.'&lt;td class=&quot;pad&quot; colspan=&quot;'. esc_attr($pad) .'&quot;&gt;&amp;nbsp;&lt;/td&gt;';
</ins><span class="cx"> 
</span><del>-        echo &quot;\n\t&lt;/tr&gt;\n\t&lt;/tbody&gt;\n\t&lt;/table&gt;&quot;;
</del><ins>+        $calendar_output .= &quot;\n\t&lt;/tr&gt;\n\t&lt;/tbody&gt;\n\t&lt;/table&gt;&quot;;
</ins><span class="cx"> 
</span><del>-        $output = ob_get_contents();
-        ob_end_clean();
-        echo $output;
</del><span class="cx">         $cache[ $key ] = $output;
</span><span class="cx">         wp_cache_set( 'get_calendar', $cache, 'calendar' );
</span><ins>+
+        if ( $echo )
+                echo apply_filters( 'get_calendar',  $calendar_output );
+        else
+                return apply_filters( 'get_calendar',  $calendar_output );
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>