| 1 |
<?php |
| 2 |
/** |
| 3 |
* Defines activation functions, which are run when the Plugin is activated. |
| 4 |
* |
| 5 |
* @package WP_To_Buffer |
| 6 |
* @author WP Zinc |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Runs the installation and update routines when the plugin is activated. |
| 11 |
* |
| 12 |
* @since 3.0.0 |
| 13 |
* |
| 14 |
* @param bool $network_wide Is network wide activation. |
| 15 |
*/ |
| 16 |
function wp_to_buffer_activate( $network_wide ) { |
| 17 |
|
| 18 |
// Initialise Plugin. |
| 19 |
$wp_to_buffer = WP_To_Buffer::get_instance(); |
| 20 |
$wp_to_buffer->initialize(); |
| 21 |
|
| 22 |
// Check if we are on a multisite install, activating network wide, or a single install. |
| 23 |
if ( ! is_multisite() || ! $network_wide ) { |
| 24 |
// Single Site activation. |
| 25 |
$wp_to_buffer->get_class( 'install' )->install(); |
| 26 |
} else { |
| 27 |
// Multisite network wide activation. |
| 28 |
$sites = get_sites( |
| 29 |
array( |
| 30 |
'number' => 0, |
| 31 |
) |
| 32 |
); |
| 33 |
foreach ( $sites as $site ) { |
| 34 |
switch_to_blog( (int) $site->blog_id ); |
| 35 |
$wp_to_buffer->get_class( 'install' )->install(); |
| 36 |
restore_current_blog(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Runs the installation and update routines when the plugin is activated |
| 44 |
* on a WPMU site. |
| 45 |
* |
| 46 |
* @since 3.0.0 |
| 47 |
* |
| 48 |
* @param mixed $site_or_blog_id WP_Site or Blog ID. |
| 49 |
*/ |
| 50 |
function wp_to_buffer_activate_new_site( $site_or_blog_id ) { |
| 51 |
|
| 52 |
// Check if $site_or_blog_id is a WP_Site or a blog ID. |
| 53 |
if ( is_a( $site_or_blog_id, 'WP_Site' ) ) { |
| 54 |
$site_or_blog_id = $site_or_blog_id->blog_id; |
| 55 |
} |
| 56 |
|
| 57 |
// Initialise Plugin. |
| 58 |
$wp_to_buffer = WP_To_Buffer::get_instance(); |
| 59 |
$wp_to_buffer->initialize(); |
| 60 |
|
| 61 |
// Run installation routine. |
| 62 |
switch_to_blog( $site_or_blog_id ); |
| 63 |
$wp_to_buffer->get_class( 'install' )->install(); |
| 64 |
restore_current_blog(); |
| 65 |
|
| 66 |
} |
| 67 |
|