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