Skip to content
Merged
33 changes: 33 additions & 0 deletions tests/integration/tests/test-networkoperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,37 @@ public function test_update_network_clears_cache() {
$this->assertEquals( 'newdomain.com', $updated_network->domain, 'Network should have updated domain without manual cache flush' );
$this->assertEquals( '/newpath/', $updated_network->path, 'Network should have updated path without manual cache flush' );
}

public function test_plugin_auto_activates_on_new_network() {
// Create a test user and grant super admin privileges.
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
grant_super_admin( $user_id );

// Create a test network using add_network().
$network_id = add_network(
array(
'domain' => 'auto-activate-test.com',
'path' => '/',
'site_name' => 'Auto Activate Test',
'network_name' => 'Test Network',
'user_id' => $user_id,
'network_admin_id' => $user_id,
)
);

// Verify network was created successfully.
$this->assertNotWPError( $network_id, 'Network should be created successfully' );
$this->assertIsInt( $network_id, 'Network ID should be an integer' );

// Get the active sitewide plugins for the new network.
$active_plugins = get_network_option( $network_id, 'active_sitewide_plugins', array() );

// Verify the plugin is auto-activated.
$this->assertIsArray( $active_plugins, 'Active sitewide plugins should be an array' );
$this->assertArrayHasKey( 'wp-multi-network/wpmn-loader.php', $active_plugins, 'Plugin should be auto-activated on new network' );
}
}
9 changes: 9 additions & 0 deletions wp-multi-network/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,15 @@ function add_network( $args = array() ) {
// Clean the network cache.
clean_network_cache( $new_network_id );

// Self-activate on new network.
update_network_option(
$new_network_id,
'active_sitewide_plugins',
array(
'wp-multi-network/wpmn-loader.php' => time(),
)
);

/**
* Fires after a new network has been added.
*
Expand Down
Loading