WordPress.org

Make WordPress Core

Opened 2 weeks ago

Last modified 2 days ago

#48772 assigned enhancement

Missing post ID as parameter for get_comments_number_text()

Reported by: Hinjiriyo Owned by: donmhico
Milestone: 5.4 Priority: normal
Severity: normal Version: 4.0
Component: Comments Keywords: dev-feedback has-patch
Focuses: Cc:
PR Number:

Description

There is no way to pass the post ID to get_comments_number_text() to use this function outside the loop.

After all, get_comments_number_text() calls get_comments_number(). The latter function can be used outside the loop because it uses the post ID as an optional parameter.

So, what about rectivating the deprecated fourth parameter of comments_number() to pass the post ID, and extending get_comments_number() by a fourth parameter to pass the post ID, for using both functions outside of loops?

Attachments (2)

48772.diff (1.2 KB) - added by donmhico 8 days ago.
48772.2.diff (2.0 KB) - added by donmhico 8 days ago.
Added unit test.

Download all attachments as: .zip

Change History (7)

@donmhico
8 days ago

@donmhico
8 days ago

Added unit test.

#1 @donmhico
8 days ago

  • Keywords dev-feedback has-patch added

Hello @Hinjiriyo,

Try to test out the patch I submitted above, i'm not sure about reactivating the deprecated param in comments_number() so the changes is just applied to get_comments_number_text() at the moment.

Let's wait for other dev feedback regarding comments_number().

#2 follow-up: @Hinjiriyo
7 days ago

Great! Just a tiny hint:

@param int|WP_Post $post_id

=> I think it is only an int parameter.

#3 in reply to: ↑ 2 @garrett-eclipse
7 days ago

Replying to Hinjiriyo:

Great! Just a tiny hint:

@param int|WP_Post $post_id

=> I think it is only an int parameter.

Reviewing the get_comments_number function which is passed the post_id it support WP_Post;
https://developer.wordpress.org/reference/functions/get_comments_number/

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.


2 days ago

#5 @peterwilsoncc
2 days ago

  • Milestone changed from Awaiting Review to 5.4
  • Owner set to donmhico
  • Status changed from new to assigned
  • Version changed from 5.3 to 4.0

This was discussed during an APAC triage session, @donmhico agreed to look after the ticket so I've assigned it and placed it on the 5.4 milestone.

Note: See TracTickets for help on using tickets.