[wp-trac] [WordPress Trac] #40736: Ensure that `get_blog_count()` and `get_user_count()` return an integer

WordPress Trac noreply at wordpress.org
Tue Jun 10 20:34:26 UTC 2025


#40736: Ensure that `get_blog_count()` and `get_user_count()` return an integer
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Networks and Sites                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  2nd-opinion has-patch has-unit-      |     Focuses:  multisite
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by johnjamesjacoby):

 Replying to [comment:16 johnbillion]:
 > Under what condition can `get_blog_count()` return a non-integer?

 Theoretically:
 1. The `$default_value` return value of `get_network_option()` is `false`
 1. Using the `pre_site_option_blog_count` filter with a non-int
 1. Using the `default_site_option_blog_count` filter with a non-int
 1. Using the `site_option_blog_count` filter with a non-int

 From the original ticket description:
 > the functions only call `get_network_option()` without any typecast.

 Forcing a typecast inside of `get_site_count()` (in the PR) mitigates any
 unexpected return type, at the consequence of the above conditions
 returning `1` for truthy values or `0` for falsey ones.

 No evidence that these filters are being intentionally used to bypass this
 return value being an integer, so the chance of regressions or breakage is
 near-zero.

 Hard to know if anyone is using `get_blog_count()` expecting anything but
 an `int`, but I sure ain't. 😅

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/40736#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list