Make WordPress Core

Opened 13 years ago

Closed 13 months ago

Last modified 12 months ago

#27289 closed enhancement (fixed)

Add populate_network action

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

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 8 years ago.
First patch with new hooks
27289-2.patch​ (6.6 KB ) - added by johnjamesjacoby 15 months ago.
Refreshed for 6.9

Download all attachments as: .zip

Change History (17)

#1 @wonderboymusic
12 years ago

  • Keywords needs-patch added
  • Milestone Awaiting Review → 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
11 years ago

  • Keywords reporter-feedback added

@Mista-Flo
8 years ago

First patch with new hooks

#6 @Mista-Flo
8 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
2 years ago

  • Keywords needs-refresh added; reporter-feedback bulk-reopened removed
  • Milestone → 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
2 years 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.


21 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
21 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.


20 months ago
#11

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

#12 @johnjamesjacoby
15 months ago

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

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


14 months ago

#14 @spacedmonkey
13 months ago

  • Keywords commit added

@johnjamesjacoby The patch looks good. Adding commit.

#15 @rollybueno
13 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
13 months ago

  • Resolution → fixed
  • Status assigned → 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
12 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.