Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#37866 closed enhancement (fixed)

Introduce `$network_id` parameter in `get_user_count()`

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


The function get_user_count() currently only supports checking for user count of the current network. Since it is easily possible to retrieve that value for other networks as well using get_network_option() (since 4.4), I think we should support that functionality here as well by introducing an optional $network_id parameter that will default to the current network.

Related: #37865

Attachments (3)

37866.diff (713 bytes) - added by flixos90 8 years ago.
37866.2.diff (741 bytes) - added by flixos90 7 years ago.
37866.3.diff (1.9 KB) - added by flixos90 7 years ago.

Download all attachments as: .zip

Change History (11)

8 years ago

#1 @flixos90
8 years ago

  • Keywords has-patch added

37866.diff introduces the new parameter.

#2 @flixos90
8 years ago

  • Keywords 2nd-opinion added

An alternative approach could be:

  • adjust logic in wp_update_network_user_counts() to count only users in the current network instead of all users
  • introduce get_network_user_count( $network = null ) (returns the value of the network option user_count)
  • introduce get_global_user_count() (returns the sum of get_network_user_count() for all networks)
  • deprecate get_user_count() and recommend get_global_user_count() as replacement
  • replace Core usages of get_user_count() with either get_network_user_count() or get_global_user_count() (depending on context)

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

8 years ago

#4 @flixos90
8 years ago

Since the user count is actually global, but saved as a network option, supporting the $network_id parameter doesn't currently have any actual value. Still, it would allow accessing the option of another network which theoretically might be different. Should we add the parameter (also for parity with get_blog_count() in #37865) or not?

#5 @jeremyfelt
7 years ago

  • Keywords commit added; 2nd-opinion removed
  • Milestone changed from Awaiting Review to 4.8

37866.diff looks good. Would it be helpful to add to the dockblock that this returns the current network's user count by default?

7 years ago

#6 @flixos90
7 years ago

  • Owner set to flixos90
  • Status changed from new to assigned

37866.2.diff adjusts the docblock to be more precise.

7 years ago

#7 @flixos90
7 years ago

  • Keywords has-unit-tests added

37866.3.diff adds a unit test for the new parameter.

#8 @flixos90
7 years ago

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

In 40371:

Multisite: Add $network_id parameter to get_user_count().

The get_user_count() function returns the number of active users on a network, which is stored in a user_count network option. Since get_network_option() supports retrieving options from other networks than the current one, get_user_count() can now make use of that feature.

Fixes #37866.

Note: See TracTickets for help on using tickets.