Make WordPress Core

Opened 12 years ago

Closed 4 months ago

Last modified 3 months ago

#27289 closed enhancement (fixed)

Add populate_network action

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

Description

At the moment, populate_network_meta is the only hook available to do extra work when a new network is created. However, this is called before the initial site is created when installing the first network. This means it's impossible to do certain things on network creation, such as creating new sites.

(I want to be able to create a new site on network creation so that the network always starts with two sites: the migrated main site and another site.)

Attachments (2)

27289.patch (3.1 KB) - added by Mista-Flo 7 years ago.
First patch with new hooks
27289-2.patch (6.6 KB) - added by johnjamesjacoby 6 months ago.
Refreshed for 6.9

Download all attachments as: .zip

Change History (17)

#1 @wonderboymusic
12 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

#2 @jeremyfelt
12 years ago

I've wanted this too.

There are two scenarios for populate_network(). In the most common, we're moving a single site install to multisite and applying initial configuration. In the other, it is called separately to create a new network. When a new network is created manually, the steps for assigning a main site are skipped and you're on your own to complete the setup tasks that need to run.

Where does the action make sense in this? If it makes sense for both cases, we may need to pass some contextual information. If it only makes sense for initial install, populate_network may not be the right name for the action.

#3 @chriscct7
10 years ago

  • Keywords reporter-feedback added

@Mista-Flo
7 years ago

First patch with new hooks

#6 @Mista-Flo
7 years ago

  • Keywords bulk-reopened has-patch added; needs-patch removed

Hey I have created a patch with three new actions.

One before the beginning of the function,
One when creating a new multisite instance
One when creating a new network (already in a multisite mode)

#7 @desrosj
17 months ago

  • Keywords needs-refresh added; reporter-feedback bulk-reopened removed
  • Milestone set to Awaiting Review

Found this one scrubbing a report of tickets without a milestone.

Is this still something that would be useful? If so, the patch needs to be refreshed for testing and review.

#8 @Mista-Flo
17 months ago

@desrosj Hello, yes I would say it's still useful as Multisite is still lacking attention / some hooks sometimes, so even if it's not popular or drag much attention, it looks like it could help agencies developing complex networks for example.

This ticket was mentioned in PR #8334 on WordPress/wordpress-develop by @sukhendu2002.


12 months ago
#9

  • Keywords has-unit-tests added; needs-refresh removed

This PR adds three new action hooks to the network creation process and related unit tests, allowing developers to extend functionality at key points during network creation:

  • before_populate_network - Fires before any network operations begin, allowing for setup or validation
  • after_upgrade_to_multisite - Fires specifically when upgrading from single site to multisite (network_id = 1)
  • after_populate_network - Fires after network creation is complete, enabling post-creation tasks

Trac ticket: https://core.trac.wordpress.org/ticket/27289
Patch Refresh for: https://core.trac.wordpress.org/attachment/ticket/27289/27289.patch

#10 @sukhendu2002
12 months ago

  • Keywords needs-patch added; has-patch has-unit-tests removed

This ticket was mentioned in PR #8532 on WordPress/wordpress-develop by @sukhendu2002.


11 months ago
#11

  • Keywords has-patch has-unit-tests added; needs-patch removed

#12 @johnjamesjacoby
6 months ago

  • Milestone changed from Awaiting Review to 6.9
  • Owner set to johnjamesjacoby
  • Status changed from new to assigned

@johnjamesjacoby
6 months ago

Refreshed for 6.9

This ticket was mentioned in Slack in #core by welcher. View the logs.


5 months ago

#14 @spacedmonkey
4 months ago

  • Keywords commit added

@johnjamesjacoby The patch looks good. Adding commit.

#15 @rollybueno
4 months ago

Using https://core.trac.wordpress.org/attachment/ticket/27289/27289-2.patch

Since this is just additional hook on populate_network, I tested the unit directly using multisite params:

npm run test:php -- --filter  test_before_populate_network_hook -c tests/phpunit/multisite.xml
npm run test:php -- --filter  test_populate_network_hook_filter -c tests/phpunit/multisite.xml

and the result seems okay:
https://i.imgur.com/ujjAFYG.png

#16 @johnjamesjacoby
4 months ago

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

In 60954:

Networks and Sites: introduce 3 new actions inside the populate_network() function.

  • before_populate_network
  • after_populate_network
  • after_upgrade_to_multisite

These hooks are strategically located to allow the execution of custom code before & after a new multisite network is created, as well as after the first time a single-site installation is upgraded to multisite.

This change also includes a set of unit tests via a new Tests_Multisite_PopulateNetworkHooks class, to confirm that these hooks are executing when and as intended.

Props jeremyfelt, johnjamesjacoby, Mista-Flo, spacedmonkey, sukhendu2002, rmccue, rollybueno.

Fixes #27289.

#17 @desrosj
3 months ago

The miscellaneous developer-focused changes developer note mentioned the new hooks introduced in [60954], but did not cover them in depth: https://make.wordpress.org/core/2025/11/17/miscellaneous-developer-focused-changes-in-6-9/.

Note: See TracTickets for help on using tickets.