From 21864a98d075e23d694479ca4ccc49a8671026cd Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 29 Jun 2014 23:13:15 +0000 Subject: [PATCH] Add a function, `get_comments_number_text()`, that returns instead of echoing. `comments_number()` wraps it. Props kapeels, nbachiyski. Fixes #10177. Built from https://develop.svn.wordpress.org/trunk@28912 git-svn-id: http://core.svn.wordpress.org/trunk@28711 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index b3b1e2e781..bb7c3afadd 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -713,18 +713,31 @@ function get_comments_number( $post_id = 0 ) { * @param string $deprecated Not used. */ function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { - if ( !empty( $deprecated ) ) + if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '1.3' ); + } + echo get_comments_number_text( $zero, $one, $more ); +} +/** + * Display the language string for the number of comments the current post has. + * + * @since 4.0.0 + * + * @param string $zero Optional. Text for no comments. Default false. + * @param string $one Optional. Text for one comment. Default false. + * @param string $more Optional. Text for more than one comment. Default false. + */ +function get_comments_number_text( $zero = false, $one = false, $more = false ) { $number = get_comments_number(); - if ( $number > 1 ) - $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); - elseif ( $number == 0 ) - $output = ( false === $zero ) ? __('No Comments') : $zero; - else // must be one - $output = ( false === $one ) ? __('1 Comment') : $one; - + if ( $number > 1 ) { + $output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Comments' ) : $more ); + } elseif ( $number == 0 ) { + $output = ( false === $zero ) ? __( 'No Comments' ) : $zero; + } else { // must be one + $output = ( false === $one ) ? __( '1 Comment' ) : $one; + } /** * Filter the comments count for display. * @@ -736,7 +749,7 @@ function comments_number( $zero = false, $one = false, $more = false, $deprecate * is equal to 0, 1, or 1+. * @param int $number The number of post comments. */ - echo apply_filters( 'comments_number', $output, $number ); + return apply_filters( 'comments_number', $output, $number ); } /**