[wp-trac] [WordPress Trac] #40901: get_comments_number_text() third argument parsing weirdly

WordPress Trac noreply at wordpress.org
Thu Jun 1 13:43:44 UTC 2017


#40901: get_comments_number_text() third argument parsing weirdly
--------------------------+-----------------------------
 Reporter:  eclare        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  4.7.5
 Severity:  normal        |   Keywords:
  Focuses:  template      |
--------------------------+-----------------------------
 `comments_number()` is a wrapper for echoing `get_comments_number_text()`.

 Reference: https://codex.wordpress.org/Function_Reference/comments_number

 The 3rd parameter's description: Text to display when there is more than
 one comment. % is replaced by the number of comments, so '% so far' is
 displayed as "5 so far" when there are five comments.

 This doesn't seem to work as expected. In particular, the parser doesn't
 look just for '%' but also for strings with spaces in front or behind this
 sign, after which it processes it in a illogical way.

 For example, this code

 {{{
 <? _e('Read on', 'anytextdomain');
 comments_number(' and add the first comment', ' and see the first
 comment', ' % so far'); ?>
 ...
 }}}

 results in: `Read on 2 komentarze...` ("komentarze is a Polish translation
 of "comments", which is ok). Where's the "so far" string?

 Now another example with text before the % sign:

 {{{
 <? _e('Read on', 'anytextdomain');
 comments_number(' and add the first comment', ' and see the first
 comment', ' and view % comments'); ?>
 ...
 }}}

 The result is bizarre: `Read on2 komentarze...`

 With some testing it seems that some strings passed as the 3rd argument
 are being kept, but it's totally illogical and requires review. If this is
 somehow intended, it should be explained in the Codex. So far, even the
 Codex example doesn't work as intended. I also checked that I'm not using
 any `comments_num*` filters.

 Workaround: use `get_comments_number()` with conditional code.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40901>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list