Make WordPress Core

Opened 8 years ago

Closed 6 months ago

Last modified 6 months ago

#41627 closed feature request (wontfix)

Additional parameter for multisite activation

Reported by: tazotodua's profile tazotodua Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8.1
Component: Plugins Keywords: close
Focuses: administration, multisite Cc:

Description

It could be good, if there was something additional parameter, which made
'register_activation_hook' function to be executed per individual sub-sites, while activating it from Network dashboard.

that is good, because i.e. in activation hook, we want sometimes to create tables, add options ( and etc) per each sub-site.

Change History (4)

#1 @SergeyBiryukov
8 years ago

  • Component changed from General to Plugins
  • Focuses administration multisite added

#2 @nikunj8866
6 months ago

  • Keywords close added

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

#3 @nikunj8866
6 months ago

  • Resolution set to invalid
  • Status changed from new to closed

#4 @peterwilsoncc
6 months ago

  • Milestone Awaiting Review deleted
  • Resolution changed from invalid to wontfix
Note: See TracTickets for help on using tickets.