-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
multisite-enhancements.php
executable file
·188 lines (168 loc) · 5.51 KB
/
multisite-enhancements.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Plugin Name: Multisite Enhancements
* Description: Enhance Multisite for Network Admins with different topics
* Plugin URI: https://github.com/bueltge/WordPress-Multisite-Enhancements
* Version: 1.7.1
* Author: Frank Bültge
* Author URI: https://bueltge.de
* License: GPLv2+
* License URI: LICENSE
* Requires PHP: 7.2
* Text Domain: multisite-enhancements
* Domain Path: /languages
* Network: true
*
* @package multisite-enhancement
*/
if ( function_exists( 'add_action' ) ) {
add_action( 'plugins_loaded', array( Multisite_Enhancements::get_object(), 'load' ) );
}
/**
* Class Multisite_Enhancements.
* Plugin wrapper to list as plugin in WordPress environment and load all necessary files.
*/
class Multisite_Enhancements {
/**
* The class object.
*
* @var array
*/
private static $class_objects = array();
/**
* Load translation file.
*
* @since 2016-10-23
*/
public function load_translation() {
load_plugin_textdomain(
'multisite-enhancements',
false,
basename( __DIR__ ) . '/languages/'
);
}
/**
* Autoload and init used functions.
*
* @since 0.0.1
*/
public function load() {
define( 'MULTISITE_ENHANCEMENT_BASE', __DIR__ . '/src' );
if ( function_exists( 'is_multisite' ) && ! is_multisite() ) {
add_filter( 'admin_notices', array( $this, 'error_msg_no_multisite' ) );
return;
}
$this->load_translation();
require_once __DIR__ . '/vendor/autoload.php';
add_action( 'init', array( self::set_object( new Multisite_Enhancements\Settings() ), 'init' ) );
$modules = array(
'add-favicon' => array( 'init' => array( Multisite_Enhancements\Add_Admin_Favicon::class, 'init' ) ),
'remove-logo' => array( 'init' => array( Multisite_Enhancements\Add_Admin_Favicon::class, 'init' ) ),
'add-blog-id' => array( 'init' => array( Multisite_Enhancements\Add_Blog_Id::class, 'init' ) ),
'add-css' => array( 'init' => array( Multisite_Enhancements\Add_Css::class, 'init' ) ),
'add-plugin-list' => array( 'init' => array( Multisite_Enhancements\Add_Plugin_List::class, 'init' ) ),
'add-site-status' => array( 'init' => array( Multisite_Enhancements\Add_Site_Status_Labels::class, 'init' ) ),
'add-ssl-identifier' => array(
'admin_init' => array( Multisite_Enhancements\Add_Ssh_Identifier::class, 'init' ),
),
'add-theme-list' => array( 'init' => array( Multisite_Enhancements\Add_Theme_List::class, 'init' ) ),
'add-manage-comments' => array(
'init' => array( Multisite_Enhancements\Admin_Bar_Tweaks::class, 'init' ),
),
'change-footer' => array( 'init' => array( Multisite_Enhancements\Change_Footer_Text::class, 'init' ) ),
'filtering-themes' => array( 'admin_init' => array( Multisite_Enhancements\Filtering_Themes::class, 'init' ) ),
'add-new-plugin' => array( 'init' => array( Multisite_Enhancements\Multisite_Add_New_Plugin::class, 'init' ) ),
'add-user-last-login' => array(
'init' => array( Multisite_Enhancements\Add_User_Last_Login::class, 'init' ),
),
);
foreach ( $modules as $id => $hooks ) {
if ( Multisite_Enhancements\Settings::is_feature_enabled( $id ) ) {
foreach ( $hooks as $hook_name => $callback ) {
if ( is_string( $callback[0] ) && class_exists( $callback[0] ) ) {
$callback[0] = self::set_object( new $callback[0]() );
}
if ( ! has_action( $hook_name, $callback ) ) {
add_action( $hook_name, $callback );
}
}
}
}
}
/**
* Load objects for all plugin classes, default for this class.
*
* @param string $class_name FQN of the class to get object from.
* @return object|null $class_object
* @since 0.0.1
*/
public static function get_object( string $class_name = '' ): ?object {
if ( '' === $class_name ) {
$class_name = __CLASS__;
}
if ( isset( self::$class_objects[ $class_name ] ) ) {
return self::$class_objects[ $class_name ];
}
if ( __CLASS__ === $class_name ) {
self::set_object( new self() );
return self::get_object( __CLASS__ );
}
return null;
}
/**
* Store objects for all plugin classes, default for this class.
*
* @param object $class_object The object to store.
* @return object
*/
public static function set_object( object $class_object ): object {
$class_name = get_class( $class_object );
if ( isset( self::$class_objects[ $class_name ] ) ) {
return self::$class_objects[ $class_name ];
}
self::$class_objects[ $class_name ] = $class_object;
return self::get_object( $class_name );
}
/**
* Display an Admin Notice if multisite is not active.
*
* @since 0.0.1
*/
public function error_msg_no_multisite() {
deactivate_plugins( plugin_basename( __FILE__ ) );
?>
<div class="error">
<p>
<?php
esc_html_e(
'The plugin only works in a multisite installation. See how to install a multisite network:',
'multisite-enhancements'
);
?>
<a href="https://developer.wordpress.org/advanced-administration/multisite/create-network/" title="
<?php
esc_html_e(
'WordPress Codex: Create a network',
'multisite-enhancements'
);
?>
">
<?php esc_html_e( 'WordPress Codex: Create a network', 'multisite-enhancements' ); ?>
</a>
</p>
</div>
<div class="updated notice">
<p>
<?php
echo wp_kses(
__( 'Plugin <strong>deactivated</strong>.', 'multisite-enhancements' ),
array(
'strong' => array(),
)
);
?>
</p>
</div>
<?php
}
} // end class