[wp-trac] [WordPress Trac] #41627: Additional parameter for multisite activation
WordPress Trac
noreply at wordpress.org
Mon Aug 11 11:53:24 UTC 2025
#41627: Additional parameter for multisite activation
-----------------------------+----------------------------------------
Reporter: tazotodua | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 4.8.1
Severity: normal | Resolution:
Keywords: close | Focuses: administration, multisite
-----------------------------+----------------------------------------
Changes (by nikunj8866):
* keywords: => close
Comment:
@tazotodua You can already handle this in plugins by checking the
{{{$network_wide}}} parameter in the activation callback and looping
through each site when needed, for example:
{{{#!php
<?php
register_activation_hook( __FILE__, 'my_plugin_activate' );
function my_plugin_activate( $network_wide ) {
global $wpdb;
if ( is_multisite() && $network_wide ) {
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
my_plugin_single_site_activate();
restore_current_blog();
}
} else {
my_plugin_single_site_activate();
}
}
function my_plugin_single_site_activate() {
// Create tables, add options, etc.
}
}}}
This covers the use case for running activation logic on each sub-site
during a network activation. If you have a different requirement that this
approach can't solve, please share more details so the ticket can be
reopened.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41627#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list