WordPress.org

Make WordPress Core

Ticket #14170: 14170.4.diff

File 14170.4.diff, 2.2 KB (added by scribu, 8 years ago)

Handle network activation via filters

  • wp-includes/ms-default-filters.php

     
    2222
    2323// Blogs
    2424add_filter( 'wpmu_validate_blog_signup', 'signup_nonce_check' );
    25 add_action( 'wpmu_new_blog', 'wpmu_activate_network_plugins', 9 );
    2625add_action( 'wpmu_new_blog', 'wpmu_log_new_registrations', 10, 2 );
    2726add_action( 'wpmu_new_blog', 'newblog_notify_siteadmin', 10, 2 );
    2827
    2928// Register Nonce
    3029add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
    3130
     31// Plugins
     32add_action( 'wpmu_new_blog', 'wpmu_activate_network_plugins', 9 );
     33add_action( 'activated_plugin', 'wpmu_handle_network_activation', 9 );
     34add_action( 'deactivated_plugin', 'wpmu_handle_network_activation', 9 );
     35
    3236// Template
    3337add_action( 'template_redirect', 'maybe_redirect_404' );
    3438add_filter( 'allowed_redirect_hosts', 'redirect_this_site' );
  • wp-includes/ms-functions.php

     
    12441244        restore_current_blog();
    12451245}
    12461246
     1247/**
     1248 * Fires the activation hook for each active site in a network
     1249 * when a network activation occurs
     1250 *
     1251 * @since 3.1.0
     1252 *
     1253 * @param string $plugin The plugin being network-activated
     1254 */
     1255function wpmu_handle_network_activation( $plugin ) {
     1256        if ( !is_plugin_active_for_network( $plugin ) )
     1257                return;
     1258
     1259        global $wpdb;
     1260
     1261        $active_blogs = $wpdb->get_col( "
     1262                SELECT blog_id
     1263                FROM $wpdb->blogs
     1264                WHERE site_id = '{$wpdb->siteid}'
     1265                AND deleted = 0
     1266        " );
     1267
     1268        list( $action ) = explode( '_', current_filter(), 2 );
     1269
     1270        $action = str_replace( 'activated', 'activate', $action );
     1271
     1272        foreach ( $active_blogs as $blog_id ) {
     1273                switch_to_blog( $blog_id );
     1274
     1275                if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) )
     1276                        continue;
     1277
     1278                do_action( $action . '_' . $plugin, false );
     1279                do_action( $action . '_plugin', $plugin, false );
     1280        }
     1281
     1282        restore_current_blog();
     1283}
     1284
    12471285function wpmu_log_new_registrations( $blog_id, $user_id ) {
    12481286        global $wpdb;
    12491287        $user = new WP_User( (int) $user_id );