Make WordPress Core

Ticket #11842: 11842.3.diff

File 11842.3.diff, 7.3 KB (added by ShaneF, 15 years ago)

added code from '#10575'

  • general-template.php

     
    111111 * search. To give a few examples of what it can be used for.
    112112 *
    113113 * @since 2.7.0
     114 * @param boolean $echo Default to echo and not return the form.
    114115 */
    115 function get_search_form() {
     116function get_search_form($echo = true) {
    116117        do_action( 'get_search_form' );
    117118
    118119        $search_form_template = locate_template(array('searchform.php'));
     
    128129        </div>
    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
    134138/**
     
    141145 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
    142146 *
    143147 * @param string $redirect Optional path to redirect to on login/logout.
     148 * @param boolean $echo Default to echo and not return the link.
    144149 */
    145 function wp_loginout($redirect = '') {
     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
    154162/**
     
    228236 *
    229237 * @param string $before Text to output before the link (defaults to <li>).
    230238 * @param string $after Text to output after the link (defaults to </li>).
     239 * @param boolean $echo Default to echo and not return the link.
    231240 */
    232 function wp_register( $before = '<li>', $after = '</li>' ) {
     241function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
    233242
    234243        if ( ! is_user_logged_in() ) {
    235244                if ( get_option('users_can_register') )
     
    239248        } else {
    240249                $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
    241250        }
    242 
    243         echo apply_filters('register', $link);
     251       
     252        if ( $echo )
     253                echo apply_filters('register', $link);
     254        else
     255                return apply_filters('register', $link);
    244256}
    245257
    246258/**
     
    949961 * @since 1.0.0
    950962 *
    951963 * @param bool $initial Optional, default is true. Use initial calendar names.
     964 * @param bool $echo Optional, default is true. Set to false for return.
    952965 */
    953 function get_calendar($initial = true) {
     966function get_calendar($initial = true, $echo = true) {
    954967        global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    955968
    956969        $cache = array();
     
    975988                }
    976989        }
    977990
    978         ob_start();
    979991        if ( isset($_GET['w']) )
    980992                $w = ''.intval($_GET['w']);
    981993
     
    10211033
    10221034        /* translators: Calendar caption: 1: month name, 2: 4-digit year */
    10231035        $calendar_caption = _x('%1$s %2$s', 'calendar caption');
    1024         echo '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
     1036        $calendar_output .= '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
    10251037        <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    10261038        <thead>
    10271039        <tr>';
     
    10351047        foreach ( $myweek as $wd ) {
    10361048                $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    10371049                $wd = esc_attr($wd);
    1038                 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
     1050                $calendar_output .= "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
    10391051        }
    10401052
    1041         echo '
     1053        $calendar_output .= '
    10421054        </tr>
    10431055        </thead>
    10441056
     
    10461058        <tr>';
    10471059
    10481060        if ( $previous ) {
    1049                 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
     1061                $calendar_output .= "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
    10501062                get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
    10511063                        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>';
    10521064        } else {
    1053                 echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
     1065                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    10541066        }
    10551067
    1056         echo "\n\t\t".'<td class="pad">&nbsp;</td>';
     1068        $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
    10571069
    10581070        if ( $next ) {
    1059                 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
     1071                $calendar_output .= "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
    10601072                get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month) ,
    10611073                        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>';
    10621074        } else {
    1063                 echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
     1075                $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    10641076        }
    10651077
    1066         echo '
     1078        $calendar_output .= '
    10671079        </tr>
    10681080        </tfoot>
    10691081
     
    11151127        // See how much we should pad in the beginning
    11161128        $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    11171129        if ( 0 != $pad )
    1118                 echo "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
     1130                $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    11191131
    11201132        $daysinmonth = intval(date('t', $unixmonth));
    11211133        for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    11221134                if ( isset($newrow) && $newrow )
    1123                         echo "\n\t</tr>\n\t<tr>\n\t\t";
     1135                        $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    11241136                $newrow = false;
    11251137
    11261138                if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
    1127                         echo '<td id="today">';
     1139                        $calendar_output .= '<td id="today">';
    11281140                else
    1129                         echo '<td>';
     1141                        $calendar_output .= '<td>';
    11301142
    11311143                if ( in_array($day, $daywithpost) ) // any posts today?
    1132                                 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
     1144                                $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
    11331145                else
    1134                         echo $day;
    1135                 echo '</td>';
     1146                        $calendar_output .= $day;
     1147                $calendar_output .= '</td>';
    11361148
    11371149                if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
    11381150                        $newrow = true;
     
    11401152
    11411153        $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    11421154        if ( $pad != 0 && $pad != 7 )
    1143                 echo "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
     1155                $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    11441156
    1145         echo "\n\t</tr>\n\t</tbody>\n\t</table>";
     1157        $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    11461158
    1147         $output = ob_get_contents();
    1148         ob_end_clean();
    1149         echo $output;
    11501159        $cache[ $key ] = $output;
    11511160        wp_cache_set( 'get_calendar', $cache, 'calendar' );
     1161
     1162        if ( $echo )
     1163                echo apply_filters( 'get_calendar',  $calendar_output );
     1164        else
     1165                return apply_filters( 'get_calendar',  $calendar_output );
     1166
    11521167}
    11531168
    11541169/**