forked from WPChill/download-monitor
/
installer-functions.php
95 lines (74 loc) · 1.92 KB
/
installer-functions.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
/**
* Plugin activation hook.
* When site is multisite and plugin is network activated, installer will run for each blog
*
* @param bool $network_wide
*/
function __download_monitor_install( $network_wide = false ) {
// Load installer functions
require_once plugin_dir_path( DLM_PLUGIN_FILE_INSTALLER ) . 'includes/class-dlm-installer.php';
// DLM Installer
$installer = new DLM_Installer();
// check if
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
// check if it's multisite
if ( is_multisite() && true == $network_wide ) {
// get websites
$sites = wp_get_sites();
// loop
if ( count( $sites ) > 0 ) {
foreach ( $sites as $site ) {
// switch to blog
switch_to_blog( $site['blog_id'] );
// run installer on blog
$installer->install();
// restore current blog
restore_current_blog();
}
}
} else {
// no multisite so do normal install
$installer->install();
}
}
/**
* Run installer for new blogs on multisite when plugin is network activated
*
* @param $blog_id
* @param $user_id
* @param $domain
* @param $path
* @param $site_id
* @param $meta
*/
function __download_monitor_mu_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
// check if plugin is network activated
if ( is_plugin_active_for_network( 'download-monitor/download-monitor.php' ) ) {
// DLM Installer
$installer = new DLM_Installer();
// switch to new blog
switch_to_blog( $blog_id );
// run installer on blog
$installer->install();
// restore current blog
restore_current_blog();
}
}
/**
* Delete DLM log table on multisite when blog is deleted
*
* @param $tables
*
* @return array
*/
function __download_monitor_mu_delete_blog( $tables ) {
global $wpdb;
$tables[] = $wpdb->prefix . 'download_log';
return $tables;
}