Make WordPress Core


Ignore:
Timestamp:
06/29/2014 11:12:34 PM (10 years ago)
Author:
wonderboymusic
Message:

Add a function, get_comments_number_text(), that returns instead of echoing. comments_number() wraps it.

Props kapeels, nbachiyski.
Fixes #10177.

File:
1 edited

Legend:

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

    r28824 r28912  
    714714 */
    715715function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
    716     if ( !empty( $deprecated ) )
     716    if ( ! empty( $deprecated ) ) {
    717717        _deprecated_argument( __FUNCTION__, '1.3' );
    718 
     718    }
     719    echo get_comments_number_text( $zero, $one, $more );
     720}
     721
     722/**
     723 * Display the language string for the number of comments the current post has.
     724 *
     725 * @since 4.0.0
     726 *
     727 * @param string $zero Optional. Text for no comments. Default false.
     728 * @param string $one  Optional. Text for one comment. Default false.
     729 * @param string $more Optional. Text for more than one comment. Default false.
     730 */
     731function get_comments_number_text( $zero = false, $one = false, $more = false ) {
    719732    $number = get_comments_number();
    720733
    721     if ( $number > 1 )
    722         $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
    723     elseif ( $number == 0 )
    724         $output = ( false === $zero ) ? __('No Comments') : $zero;
    725     else // must be one
    726         $output = ( false === $one ) ? __('1 Comment') : $one;
    727 
     734    if ( $number > 1 ) {
     735        $output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Comments' ) : $more );
     736    } elseif ( $number == 0 ) {
     737        $output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
     738    } else { // must be one
     739        $output = ( false === $one ) ? __( '1 Comment' ) : $one;
     740    }
    728741    /**
    729742     * Filter the comments count for display.
     
    737750     * @param int    $number The number of post comments.
    738751     */
    739     echo apply_filters( 'comments_number', $output, $number );
     752    return apply_filters( 'comments_number', $output, $number );
    740753}
    741754
Note: See TracChangeset for help on using the changeset viewer.