<!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">         </div>
</span><span class="cx">         </form>';
</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 = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
</span><span class="cx">         else
</span><span class="cx">                 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
</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 <li>).
</span><span class="cx"> * @param string $after Text to output after the link (defaults to </li>).
</span><ins>+ * @param boolean $echo Default to echo and not return the link.
</ins><span class="cx"> */
</span><del>-function wp_register( $before = '<li>', $after = '</li>' ) {
</del><ins>+function wp_register( $before = '<li>', $after = '</li>', $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 . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $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) && isset( $cache[ $key ] ) ) {
-                        echo $cache[ $key ];
-                        return;
</del><ins>+                if ( is_array($cache) && 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 '<table id="wp-calendar">
</del><ins>+        $calendar_output .= '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
</ins><span class="cx">         <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
</span><span class="cx">         <thead>
</span><span class="cx">         <tr>';
</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->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
</span><span class="cx">                 $wd = esc_attr($wd);
</span><del>-                echo "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
</del><ins>+                $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
</ins><span class="cx">         }
</span><del>-
-        echo '
</del><ins>+        
+        $calendar_output .= '
</ins><span class="cx">         </tr>
</span><span class="cx">         </thead>
</span><span class="cx">
</span><span class="lines">@@ -1098,24 +1112,20 @@
</span><span class="cx">         <tr>';
</span><span class="cx">
</span><span class="cx">         if ( $previous ) {
</span><del>-                echo "\n\t\t".'<td colspan="3" id="prev"><a href="' .
-                get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
-                        date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
</del><ins>+                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
</ins><span class="cx">         } else {
</span><del>-                echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
</del><ins>+                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        echo "\n\t\t".'<td class="pad">&nbsp;</td>';
</del><ins>+        $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
</ins><span class="cx">
</span><span class="cx">         if ( $next ) {
</span><del>-                echo "\n\t\t".'<td colspan="3" id="next"><a href="' .
-                get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month) ,
-                        date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
</del><ins>+                $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
</ins><span class="cx">         } else {
</span><del>-                echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
</del><ins>+                $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        echo '
</del><ins>+        $calendar_output .= '
</ins><span class="cx">         </tr>
</span><span class="cx">         </tfoot>
</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 "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
</del><ins>+                $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
</ins><span class="cx">
</span><span class="cx">         $daysinmonth = intval(date('t', $unixmonth));
</span><span class="cx">         for ( $day = 1; $day <= $daysinmonth; ++$day ) {
</span><span class="cx">                 if ( isset($newrow) && $newrow )
</span><del>-                        echo "\n\t</tr>\n\t<tr>\n\t\t";
</del><ins>+                        $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
</ins><span class="cx">                 $newrow = false;
</span><span class="cx">
</span><span class="cx">                 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
</span><del>-                        echo '<td id="today">';
</del><ins>+                        $calendar_output .= '<td id="today">';
</ins><span class="cx">                 else
</span><del>-                        echo '<td>';
</del><ins>+                        $calendar_output .= '<td>';
</ins><span class="cx">
</span><span class="cx">                 if ( in_array($day, $daywithpost) ) // any posts today?
</span><del>-                                echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
</del><ins>+                                $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
</ins><span class="cx">                 else
</span><del>-                        echo $day;
-                echo '</td>';
</del><ins>+                        $calendar_output .= $day;
+                $calendar_output .= '</td>';
</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 && $pad != 7 )
</span><del>-                echo "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
</del><ins>+                $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
</ins><span class="cx">
</span><del>-        echo "\n\t</tr>\n\t</tbody>\n\t</table>";
</del><ins>+        $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
</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>