Make WordPress Core

Changeset 60954

Timestamp:
10/17/2025 03:03:09 PM (5 weeks ago)
Author:
johnjamesjacoby
Message:

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.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r60717 r60954  
    10051005    $network_id = (int) $network_id;
    10061006
     1007    /**
     1008     * Fires before a network is populated.
     1009     *
     1010     * @since 6.9.0
     1011     *
     1012     * @param int    $network_id        ID of network to populate.
     1013     * @param string $domain            The domain name for the network.
     1014     * @param string $email             Email address for the network administrator.
     1015     * @param string $site_name         The name of the network.
     1016     * @param string $path              The path to append to the network's domain name.
     1017     * @param bool   $subdomain_install Whether the network is a subdomain installation or a subdirectory installation.
     1018     */
     1019    do_action( 'before_populate_network', $network_id, $domain, $email, $site_name, $path, $subdomain_install );
     1020
    10071021    $errors = new WP_Error();
    10081022    if ( '' === $domain ) {
     
    11241138        flush_rewrite_rules();
    11251139
     1140        /**
     1141         * Fires after a network is created when converting a single site to multisite.
     1142         *
     1143         * @since 6.9.0
     1144         *
     1145         * @param int    $network_id        ID of network created.
     1146         * @param string $domain            The domain name for the network.
     1147         * @param string $email             Email address for the network administrator.
     1148         * @param string $site_name         The name of the network.
     1149         * @param string $path              The path to append to the network's domain name.
     1150         * @param bool   $subdomain_install Whether the network is a subdomain installation or a subdirectory installation.
     1151         */
     1152        do_action( 'after_upgrade_to_multisite', $network_id, $domain, $email, $site_name, $path, $subdomain_install );
     1153
    11261154        if ( ! $subdomain_install ) {
    11271155            return true;
     
    11691197        }
    11701198    }
     1199
     1200    /**
     1201     * Fires after a network is fully populated.
     1202     *
     1203     * @since 6.9.0
     1204     *
     1205     * @param int    $network_id        ID of network created.
     1206     * @param string $domain            The domain name for the network.
     1207     * @param string $email             Email address for the network administrator.
     1208     * @param string $site_name         The name of the network.
     1209     * @param string $path              The path to append to the network's domain name.
     1210     * @param bool   $subdomain_install Whether the network is a subdomain installation or a subdirectory installation.
     1211     */
     1212    do_action( 'after_populate_network', $network_id, $domain, $email, $site_name, $path, $subdomain_install );
    11711213
    11721214    return true;
Note: See TracChangeset for help on using the changeset viewer.