Make WordPress Core

Opened 9 years ago

Closed 14 months ago

Last modified 14 months ago

#41627 closed feature request (wontfix)

Additional parameter for multisite activation

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

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
9 years ago

  • Component General → Plugins
  • Focuses administration multisite added

#2 @nikunj8866
14 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
14 months ago

  • Resolution → invalid
  • Status new → closed

#4 @peterwilsoncc
14 months ago

  • Milestone Awaiting Review
  • Resolution invalid → wontfix
Note: See TracTickets for help on using tickets.