Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#37865 closed enhancement (fixed)

Allow using the `$network_id` parameter of `get_blog_count()` again

Reported by: flixos90's profile flixos90 Owned by: flixos90's profile flixos90
Milestone: 4.8 Priority: normal
Severity: normal Version: 3.7
Component: Networks and Sites Keywords: has-patch commit has-unit-tests
Focuses: multisite Cc:


The $network_id parameter of get_blog_count() has not been used since 3.1, and was officially deprecated in 25113. When looking at the history, it appears that this was done to be able to fully rely on get_site_option() which does not support passing a network ID.

However, now we have get_network_option() which _does_ support a network ID, so I think we should un-deprecate this parameter and make use of it again (is that possible?).

Attachments (3)

37865.diff (930 bytes) - added by flixos90 8 years ago.
37865.2.diff (958 bytes) - added by flixos90 7 years ago.
37865.3.diff (4.0 KB) - added by flixos90 7 years ago.

Download all attachments as: .zip

Change History (10)

8 years ago

#1 @flixos90
8 years ago

  • Keywords has-patch added; needs-patch removed

37865.diff makes use of the parameter again, by leveraging the power of get_network_option(). In the DocBlock, I also added notices for both the 3.7 change (previously missing) and the new change.

#2 @flixos90
8 years ago

  • Keywords 2nd-opinion added

An alternative approach could be:

  • introduce get_network_site_count( $network = null ) (returns the value of the network option blog_count)
  • introduce get_global_site_count() (returns the sum of get_network_site_count() for all networks)
  • deprecate get_blog_count() and recommend get_network_site_count() as replacement
  • replace Core usages of get_blog_count() with either get_network_site_count() or get_global_site_count() (depending on context)

Related to this ticket: #37866

#3 @jeremyfelt
8 years ago

  • Keywords 2nd-opinion removed
  • Milestone changed from Awaiting Review to Future Release

Nice one. It's fun to see the history on the deprecation.

I think the approach in 37865.diff makes sense for the time being. Since we aren't actually adding any new functionality, we should stick with the same name (get_blog_count()). In the future, if we think of something super interesting to do with a new version of the function, we may want to explore a get_site_count().

get_global_site_count() could be interesting once we have a better idea of what global options look like.

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.

8 years ago

7 years ago

#5 @flixos90
7 years ago

  • Keywords commit added
  • Milestone changed from Future Release to 4.8
  • Owner set to flixos90
  • Status changed from new to assigned

37865.2.diff adjusts the version number and the docblock to be more precise (see for a related comment).

7 years ago

#6 @flixos90
7 years ago

  • Keywords has-unit-tests added

37865.3.diff adds a unit test for the new parameter. Another (rather unstable) unit test was adjusted in order to work with an additional network being registered in wpSetUpBeforeClass().

#7 @flixos90
7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 40370:

Multisite: Support the $network_id parameter of get_blog_count().

The get_blog_count() function used to support an $id parameter for the network ID prior to WordPress 3.1. This parameter has not been used since the introduction of get_site_option() and was later deprecated in [25113]. With get_network_option() however it is possible to support the parameter again, now properly renamed as $network_id.

A unit test has for the parameter has been added as well. Another unit test in the same class was adjusted to work properly with multiple networks existing.

Fixes #37865.

Note: See TracTickets for help on using tickets.