Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#37866 closed enhancement (fixed)

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

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

Description

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 10 years ago.
37866.2.diff (741 bytes ) - added by flixos90 9 years ago.
37866.3.diff (1.9 KB ) - added by flixos90 9 years ago.

Download all attachments as: .zip

Change History (11)

@flixos90
10 years ago

#1 @flixos90
10 years ago

  • Keywords has-patch added

37866.diff introduces the new parameter.

#2 @flixos90
10 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.


10 years ago

#4 @flixos90
10 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
9 years ago

  • Keywords commit added; 2nd-opinion removed
  • Milestone Awaiting Review4.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?

@flixos90
9 years ago

#6 @flixos90
9 years ago

  • Owner set to flixos90
  • Status newassigned

37866.2.diff adjusts the docblock to be more precise.

@flixos90
9 years ago

#7 @flixos90
9 years ago

  • Keywords has-unit-tests added

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

#8 @flixos90
9 years ago

  • Resolutionfixed
  • Status assignedclosed

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.