-
Notifications
You must be signed in to change notification settings - Fork 0
/
multisite-labels.php
56 lines (43 loc) · 1.1 KB
/
multisite-labels.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
<?php
/**
* Plugin Name: Multisite labels
* Description: Assign labels to WP Multisite websites. Useful for keeping them apart in multilingual environments.
*
* Plugin URI: https://github.com/trendwerk/multisite-labels/
*
* Author: Trendwerk
* Author URI: https://github.com/trendwerk
*
* Version: 1.0.1
*/
if( ! is_multisite() )
return;
class Multisite_Labels {
function __construct() {
add_action( 'get_blogs_of_user', array( $this, 'change' ) );
}
/**
* Change the label of the blog
*/
function change( $blogs ) {
if( 0 == count( $blogs ) )
return $blogs;
foreach( $blogs as &$blog ) {
$hash = md5( time() );
if( $hash === get_blog_option( $blog->userblog_id, 'admin_label', $hash ) ) {
/**
* Allow superadmins to setup an admin label
*/
switch_to_blog( $blog->userblog_id );
update_option( 'admin_label', '' );
restore_current_blog();
} else if( $admin_label = get_blog_option( $blog->userblog_id, 'admin_label' ) ) {
/**
* Set the admin label
*/
$blog->blogname = $admin_label;
}
}
return $blogs;
}
} new Multisite_Labels;