Make WordPress Core


Ignore:
Timestamp:
02/10/2010 06:37:14 PM (17 years ago)
Author:
ryan
Message:

Add an echo arg to some general template functions. Props ShaneF. fixes #11842

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r12982 r13048  
    112112 *
    113113 * @since 2.7.0
    114  */
    115 function get_search_form() {
     114 * @param boolean $echo Default to echo and not return the form.
     115 */
     116function get_search_form($echo = true) {
    116117        do_action( 'get_search_form' );
    117118
     
    129130        </form>';
    130131
    131         echo apply_filters('get_search_form', $form);
     132        if ( $echo )
     133                echo apply_filters('get_search_form', $form);
     134        else
     135                return apply_filters('get_search_form', $form);
    132136}
    133137
     
    142146 *
    143147 * @param string $redirect Optional path to redirect to on login/logout.
    144  */
    145 function wp_loginout($redirect = '') {
     148 * @param boolean $echo Default to echo and not return the link.
     149 */
     150function wp_loginout($redirect = '', $echo = true) {
    146151        if ( ! is_user_logged_in() )
    147152                $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
    148153        else
    149154                $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
    150 
    151         echo apply_filters('loginout', $link);
     155       
     156        if ( $echo )
     157                echo apply_filters('loginout', $link);
     158        else
     159                return apply_filters('loginout', $link);
    152160}
    153161
     
    281289 * @param string $before Text to output before the link (defaults to <li>).
    282290 * @param string $after Text to output after the link (defaults to </li>).
    283  */
    284 function wp_register( $before = '<li>', $after = '</li>' ) {
     291 * @param boolean $echo Default to echo and not return the link.
     292 */
     293function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
    285294
    286295        if ( ! is_user_logged_in() ) {
     
    292301                $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
    293302        }
    294 
    295         echo apply_filters('register', $link);
     303       
     304        if ( $echo )
     305                echo apply_filters('register', $link);
     306        else
     307                return apply_filters('register', $link);
    296308}
    297309
     
    10021014 *
    10031015 * @param bool $initial Optional, default is true. Use initial calendar names.
    1004  */
    1005 function get_calendar($initial = true) {
     1016 * @param bool $echo Optional, default is true. Set to false for return.
     1017 */
     1018function get_calendar($initial = true, $echo = true) {
    10061019        global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    10071020
     
    10091022        $key = md5( $m . $monthnum . $year );
    10101023        if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
    1011                 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
    1012                         echo $cache[ $key ];
    1013                         return;
     1024                if ( is_array($cache) && isset( $cache[ $key ] ) ) {           
     1025                        if ( $echo )
     1026                                echo apply_filters( 'get_calendar',  $cache[$key] );
     1027                        else
     1028                                return apply_filters( 'get_calendar',  $cache[$key] ); 
    10141029                }
    10151030        }
     
    10281043        }
    10291044
    1030         ob_start();
    10311045        if ( isset($_GET['w']) )
    10321046                $w = ''.intval($_GET['w']);
     
    10741088        /* translators: Calendar caption: 1: month name, 2: 4-digit year */
    10751089        $calendar_caption = _x('%1$s %2$s', 'calendar caption');
    1076         echo '<table id="wp-calendar">
     1090        $calendar_output .= '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
    10771091        <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    10781092        <thead>
     
    10881102                $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    10891103                $wd = esc_attr($wd);
    1090                 echo "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
    1091         }
    1092 
    1093         echo '
     1104                $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
     1105        }
     1106       
     1107        $calendar_output .= '
    10941108        </tr>
    10951109        </thead>
     
    10991113
    11001114        if ( $previous ) {
    1101                 echo "\n\t\t".'<td colspan="3" id="prev"><a href="' .
    1102                 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
    1103                         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>';
     1115                $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>';
    11041116        } else {
    1105                 echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    1106         }
    1107 
    1108         echo "\n\t\t".'<td class="pad">&nbsp;</td>';
     1117                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
     1118        }
     1119
     1120        $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
    11091121
    11101122        if ( $next ) {
    1111                 echo "\n\t\t".'<td colspan="3" id="next"><a href="' .
    1112                 get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month) ,
    1113                         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>';
     1123                $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>';
    11141124        } else {
    1115                 echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    1116         }
    1117 
    1118         echo '
     1125                $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
     1126        }
     1127
     1128        $calendar_output .= '
    11191129        </tr>
    11201130        </tfoot>
     
    11681178        $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    11691179        if ( 0 != $pad )
    1170                 echo "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
     1180                $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    11711181
    11721182        $daysinmonth = intval(date('t', $unixmonth));
    11731183        for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    11741184                if ( isset($newrow) && $newrow )
    1175                         echo "\n\t</tr>\n\t<tr>\n\t\t";
     1185                        $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    11761186                $newrow = false;
    11771187
    11781188                if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
    1179                         echo '<td id="today">';
     1189                        $calendar_output .= '<td id="today">';
    11801190                else
    1181                         echo '<td>';
     1191                        $calendar_output .= '<td>';
    11821192
    11831193                if ( in_array($day, $daywithpost) ) // any posts today?
    1184                                 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
     1194                                $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
    11851195                else
    1186                         echo $day;
    1187                 echo '</td>';
     1196                        $calendar_output .= $day;
     1197                $calendar_output .= '</td>';
    11881198
    11891199                if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
     
    11931203        $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    11941204        if ( $pad != 0 && $pad != 7 )
    1195                 echo "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    1196 
    1197         echo "\n\t</tr>\n\t</tbody>\n\t</table>";
    1198 
    1199         $output = ob_get_contents();
    1200         ob_end_clean();
    1201         echo $output;
     1205                $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
     1206
     1207        $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
     1208
    12021209        $cache[ $key ] = $output;
    12031210        wp_cache_set( 'get_calendar', $cache, 'calendar' );
     1211
     1212        if ( $echo )
     1213                echo apply_filters( 'get_calendar',  $calendar_output );
     1214        else
     1215                return apply_filters( 'get_calendar',  $calendar_output );
     1216
    12041217}
    12051218
Note: See TracChangeset for help on using the changeset viewer.