WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#38699 closed task (blessed) (fixed)

Site count incorrect when using wpmu_create_blog() from a different network

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

Description (last modified by johnjamesjacoby)

When using wpmu_create_blog() to create a site on a network ID other than the current, both networks end up with incorrect site counts. The current network gets +1, the other network ID remains the same.

In the event this site is the first site in a new network, no site or user counts are saved in wp_sitemeta.

This is because of a fleet of functions that do not accept a network ID as a parameter. It's also due to a lack of a network "switching" API to flip the $current_site global around when calling them.

The following functions lack proper Network attribution:

  • wp_maybe_update_network_site_counts()
  • wp_maybe_update_network_user_counts()
  • wp_update_network_counts()
  • wp_update_network_user_counts()
  • wp_update_network_site_counts()

See: #37528.

Attachments (1)

38699.diff (1.2 KB) - added by flixos90 2 years ago.

Download all attachments as: .zip

Change History (16)

#1 @johnjamesjacoby
3 years ago

  • Description modified (diff)

Typos.

#2 @flixos90
3 years ago

  • Keywords 2nd-opinion removed
  • Milestone changed from Awaiting Review to 4.8
  • Type changed from defect (bug) to task (blessed)

Let's make this a task to have a better overview on all the tickets that are part of this effort.

Done:

To-Do:

  • wp_update_network_site_counts() (#37528)
  • wp_update_network_user_counts() (#40349)
  • wp_maybe_update_network_site_counts() (#40384)
  • wp_maybe_update_network_user_counts() (#40385)
  • wp_update_network_counts() (#40386)

#3 @flixos90
3 years ago

  • Owner set to flixos90
  • Status changed from new to assigned
Version 0, edited 3 years ago by flixos90 (next)

#4 @flixos90
3 years ago

In 40484:

Multisite: Add $network_id parameter to wp_update_network_site_counts().

Using the new parameter, it is now possible to update the site counts on a network different from the current network.

Props PieWP, johnjamesjacoby.
Fixes #37528. See #38699.

#5 @flixos90
3 years ago

In 40485:

Multisite: Add $network_id parameter to wp_update_network_user_counts().

Using the new parameter, it is now possible to update the user count on a network different from the current one. While the count itself is technically a global user count and not network-wide, it is stored on each individual network, and the new parameter provides more control about where to update the count.

Fixes #40349. See #38699.

#6 @flixos90
3 years ago

In 40486:

Multisite: Add $network_id parameter to wp_update_network_counts().

After the $network_id parameter has been introduced for wp_update_network_site_counts() in [40484] and wp_update_network_user_counts() in [40485], the new parameter can now also be used on the wrapping function.

Fixes #40386. See #38699.

#7 @flixos90
3 years ago

I just opened #40489 in order to add the $network_id parameter to wp_is_large_network() as well. This is required in order to make the parameter work for wp_maybe_update_network_site_counts() and wp_maybe_update_network_user_counts().

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


2 years ago

#9 @flixos90
2 years ago

I'll commit the related #40489, #40384 and #40385 this week, and then we can also fix this ticket easily. Since it's a bug, it should not be a problem getting this in a few days after Beta 1, hopefully on time though.

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


2 years ago

#12 @flixos90
2 years ago

In 40591:

Multisite: Add $network_id parameter to wp_maybe_update_network_site_counts().

This allows calling the function for a specific network correctly, for example after a site has been created for it or been removed from it.

Fixes #40384. See #38699.

#13 @flixos90
2 years ago

In 40593:

Multisite: Add $network_id parameter to wp_maybe_update_network_user_counts().

This allows calling the function for a specific network correctly, for example after a user has been created for it or been removed from it.

Fixes #40385. See #38699.

@flixos90
2 years ago

#14 @flixos90
2 years ago

  • Keywords has-patch has-unit-tests added

38699.diff ensures the site count is updated on the current network and also adds a unit test for it.

#15 @flixos90
2 years ago

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

In 40612:

Multisite: Adjust site count of the correct network after having created a new site.

Prior to this change, after creating a site, the network site count was always refreshed on the current network, regardless of whether the site was created on a different network. With the recent changes, particularly [40591], it is now possible to update the site count for a specific $network_id, so this changeset makes use of the new parameter.

Fixes #38699.

Note: See TracTickets for help on using tickets.