Make WordPress Core

Ticket #17763: 17763.2.diff

File 17763.2.diff, 6.1 KB (added by voldemortensen, 10 years ago)
  • src/wp-includes/comment-template.php

     
    711711 * @param string $one        Optional. Text for one comment. Default false.
    712712 * @param string $more       Optional. Text for more than one comment. Default false.
    713713 * @param string $deprecated Not used.
    714  */
    715 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
     714 * @param bool $echo         Whether to echo or just return the string. Default true.
     715*/
     716function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $echo = true ) {
    716717        if ( ! empty( $deprecated ) ) {
    717718                _deprecated_argument( __FUNCTION__, '1.3' );
    718719        }
    719         echo get_comments_number_text( $zero, $one, $more );
     720
     721        if ($echo) {
     722                echo get_comments_number_text( $zero, $one, $more );
     723        } else {
     724                return get_comments_number_text( $zero, $one, $more );
     725        }
    720726}
    721727
    722728/**
     
    12041204}
    12051205
    12061206/**
    1207  * Displays the link to the comments popup window for the current post ID.
     1207 * Retrieves the link to the comments popup window for the current post ID.
    12081208 *
    12091209 * Is not meant to be displayed on single posts and pages. Should be used
    12101210 * on the lists of posts
     
    12121212 * @global string $wpcommentspopupfile  The URL to use for the popup window.
    12131213 * @global int    $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
    12141214 *
    1215  * @since 0.71
     1215 * @since 4.1
    12161216 *
    1217  * @param string $zero      Optional. String to display when no comments. Default false.
    1218  * @param string $one       Optional. String to display when only one comment is available.
    1219  *                          Default false.
    1220  * @param string $more      Optional. String to display when there are more than one comment.
    1221  *                          Default false.
    1222  * @param string $css_class Optional. CSS class to use for comments. Default empty.
    1223  * @param string $none      Optional. String to display when comments have been turned off.
    1224  *                          Default false.
    1225  * @return null Returns null on single posts and pages.
     1217 * @param bool|string $zero      Optional. String to display when no comments. Default false.
     1218 * @param bool|string $one       Optional. String to display when only one comment is available.
     1219 *                               Default false.
     1220 * @param bool|string $more      Optional. String to display when there are more than one comment.
     1221 *                               Default false.
     1222 * @param string $css_class      Optional. CSS class to use for comments. Default empty.
     1223 * @param bool|string $none      Optional. String to display when comments have been turned off.
     1224 *                               Default false.
     1225 * @return string
    12261226 */
    1227 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
     1227function get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
    12281228        global $wpcommentspopupfile, $wpcommentsjavascript;
    12291229
    12301230        $id = get_the_ID();
     
    12361236
    12371237        $number = get_comments_number( $id );
    12381238
    1239         if ( 0 == $number && !comments_open() && !pings_open() ) {
    1240                 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
    1241                 return;
     1239        if ( 0 == $number && ! comments_open() && ! pings_open() ) {
     1240                return '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
    12421241        }
    12431242
    12441243        if ( post_password_required() ) {
     
    12461245                return;
    12471246        }
    12481247
    1249         echo '<a href="';
     1248        $output = '';
     1249
     1250        $output .= '<a href="';
    12501251        if ( $wpcommentsjavascript ) {
    12511252                if ( empty( $wpcommentspopupfile ) )
    12521253                        $home = home_url();
    12531254                else
    12541255                        $home = get_option('siteurl');
    1255                 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
    1256                 echo '" onclick="wpopen(this.href); return false"';
     1256                $output .= $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
     1257                $output .= '" onclick="wpopen(this.href); return false"';
    12571258        } else { // if comments_popup_script() is not in the template, display simple comment link
    1258                 if ( 0 == $number )
    1259                         echo get_permalink() . '#respond';
    1260                 else
    1261                         comments_link();
    1262                 echo '"';
     1259                if ( 0 == $number ) {
     1260                        $output .= get_permalink() . '#respond';
     1261                } else {
     1262                        $output .= get_comments_link();
     1263                        $output .= '"';
     1264                }
    12631265        }
    12641266
    1265         if ( !empty( $css_class ) ) {
    1266                 echo ' class="'.$css_class.'" ';
     1267        if ( ! empty( $css_class ) ) {
     1268                $output .= ' class="'.$css_class.'" ';
    12671269        }
    12681270        $title = the_title_attribute( array('echo' => 0 ) );
    12691271
     
    12751277         *
    12761278         * @param string $attributes The comments popup link attributes. Default empty.
    12771279         */
    1278         echo apply_filters( 'comments_popup_link_attributes', $attributes );
     1280        $output .= apply_filters( 'comments_popup_link_attributes', $attributes );
    12791281
    1280         echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
    1281         comments_number( $zero, $one, $more );
    1282         echo '</a>';
     1282        $output .= ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
     1283        $output .= comments_number( $zero, $one, $more, '', false );
     1284        $output .= '</a>';
     1285        return $output;
    12831286}
    12841287
    12851288/**
     1289 * Displays the link to the comments popup window for the current post ID.
     1290 *
     1291 * Is not meant to be displayed on single posts and pages. Should be used on the
     1292 * lists of posts.
     1293 *
     1294 * @since 0.71
     1295 *
     1296 * @param bool|string $zero   The string to display when no comments.
     1297 * @param bool|string $one    The string to display when only one comment is available.
     1298 * @param bool|string $more   The string to display when there are more than one comment.
     1299 * @param string $css_class   The CSS class to use for comments.
     1300 * @param bool|string $none   The string to display when comments have been turned off.
     1301 */
     1302function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
     1303        echo get_comments_popup_link($zero, $one, $more, $css_class, $none);
     1304}
     1305
     1306/**
    12861307 * Retrieve HTML content for reply to comment link.
    12871308 *
    12881309 * @since 2.7.0