-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-ms-site-quota.php
110 lines (93 loc) · 2.51 KB
/
wp-ms-site-quota.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
Plugin Name: WP MS Disk Quota Column
Description: Adds a "Disk Quota" column on the WP Sites network dashboard page.
Author: r-a-y
Author URI: http://profiles.wordpress.org/r-a-y
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
add_action( 'plugins_loaded', array( 'Ray_MS_Site_Quota_Column', 'init' ) );
class Ray_MS_Site_Quota_Column {
/**
* Internal name used to register our disk quota column.
*
* @var string
*/
public $column_name = 'quota';
/**
* Static init method.
*/
public static function init() {
return new self();
}
/**
* Constructor.
*/
protected function __construct() {
if ( ! is_admin() ) {
return;
}
add_action( 'admin_head-sites.php', array( $this, 'setup_hooks' ) );
}
/**
* Callback method used to setup hooks.
*
* Fired on the 'admin_head-sites.php' hook so our plugin only runs inside
* the WP Sites dashboard.
*/
public function setup_hooks() {
// time to register some hooks!
add_filter( 'wpmu_blogs_columns', array( $this, 'register_column' ) );
add_action( 'manage_sites_custom_column', array( $this, 'setup_column' ), 10, 2 );
// might as well inject some CSS while we're here!
?>
<style type="text/css">
</style>
<?php
}
/**
* Register our custom quota column.
*
* @param array $retval Current registered columns.
* @return array
*/
public function register_column( $retval ) {
$retval[$this->column_name] = __( 'Disk Quota', 'wp-ms-site-quota' );
return $retval;
}
/**
* Output our custom quota column content.
*
* @param string $column_name The registered column name that the list table is currently on.
* @param int $user_id The blog ID associated with the current blog row.
*/
public function setup_column( $column_name, $blog_id ) {
if ( $this->column_name !== $column_name ) {
return;
}
switch_to_blog( $blog_id );
// You might recognize this from wp_dashboard_quota().
$quota = get_space_allowed();
$used = get_space_used();
if ( $used > $quota ) {
$percentused = '100';
} else {
$percentused = ( $used / $quota ) * 100;
}
$text = sprintf(
/* translators: 1: number of megabytes, 2: percentage */
__( '%1$s MB / %2$s MB (%3$s%%)' ),
number_format_i18n( round( $used, 2 ), 2 ),
number_format_i18n( $quota, 2 ),
number_format( $percentused )
);
printf(
'<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
esc_url( admin_url( 'upload.php' ) ),
__( 'Manage Uploads' ),
$text
);
restore_current_blog();
}
}