-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
wpmn-loader.php
222 lines (190 loc) · 4.94 KB
/
wpmn-loader.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Plugin loader class
*
* @package WPMN
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: WP Multi-Network
* Description: Provides a Network Management Interface for global administrators in WordPress Multisite installations.
* Plugin URI: https://wordpress.org/plugins/wp-multi-network/
* Author: Triple J Software, Inc.
* Author URI: https://jjj.software
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-multi-network
* Network: true
* Requires at least: 4.9
* Requires PHP: 5.2
* Tested up to: 6.1
* Version: 2.5.2
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Class responsible for initializing and loading plugin functionality.
*
* @since 1.3.0
*/
class WPMN_Loader {
/**
* Plugin main file path.
*
* @since 1.3.0
* @var string
*/
public $file = '';
/**
* Plugin main file path, relative to the plugins directory.
*
* @since 1.3.0
* @var string
*/
public $basename = '';
/**
* URL to the plugin's wp-multi-network subdirectory.
*
* @since 1.3.0
* @var string
*/
public $plugin_url = '';
/**
* Path to the plugin's wp-multi-network subdirectory.
*
* @since 1.3.0
* @var string
*/
public $plugin_dir = '';
/**
* Version to use for the plugin assets.
*
* @since 1.3.0
* @var string
*/
public $asset_version = 202108250001;
/**
* Network admin class instance.
*
* @since 1.3.0
* @var WP_MS_Networks_Admin
*/
public $admin;
/**
* Network capabilities class instance.
*
* @since 2.3.0
* @var WP_MS_Networks_Capabilities
*/
private $capabilities;
/**
* Network admin bar class instance.
*
* @since 2.3.0
* @var WP_MS_Networks_Admin_Bar
*/
private $admin_bar;
/**
* Constructor.
*
* @since 1.3.0
*/
public function __construct() {
$this->constants();
$this->setup_globals();
$this->includes();
}
/**
* Sets up constants used by the plugin if they are not already defined.
*
* @since 1.3.0
*/
private function constants() {
if ( ! defined( 'RESCUE_ORPHANED_BLOGS' ) ) {
define( 'RESCUE_ORPHANED_BLOGS', false );
}
if ( ! defined( 'WPMN_DEPRECATED' ) ) {
define( 'WPMN_DEPRECATED', false );
}
}
/**
* Sets up the global properties used by the plugin.
*
* @since 1.3.0
*/
private function setup_globals() {
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
$this->plugin_dir = plugin_dir_path( $this->file ) . 'wp-multi-network/';
$this->plugin_url = plugin_dir_url( $this->file ) . 'wp-multi-network/';
}
/**
* Includes the required files to run the plugin.
*
* @since 1.3.0
*/
private function includes() {
// Manual localization loading is no longer necessary since WP 4.6.
if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) {
load_plugin_textdomain( 'wp-multi-network' );
}
require $this->plugin_dir . 'includes/compat.php';
require $this->plugin_dir . 'includes/functions.php';
require $this->plugin_dir . 'includes/classes/class-wp-ms-networks-capabilities.php';
if ( is_blog_admin() || is_network_admin() ) {
require $this->plugin_dir . 'includes/metaboxes/move-site.php';
require $this->plugin_dir . 'includes/metaboxes/edit-network.php';
require $this->plugin_dir . 'includes/classes/class-wp-ms-networks-admin.php';
$this->admin = new WP_MS_Networks_Admin();
}
require $this->plugin_dir . 'includes/classes/class-wp-ms-networks-admin-bar.php';
$this->capabilities = new WP_MS_Networks_Capabilities();
$this->capabilities->add_hooks();
$this->admin_bar = new WP_MS_Networks_Admin_Bar();
if ( defined( 'WPMN_DEPRECATED' ) && ( true === WPMN_DEPRECATED ) ) {
require $this->plugin_dir . 'includes/deprecated.php';
}
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require $this->plugin_dir . 'includes/classes/class-wp-ms-network-command.php';
}
// REST endpoint class only load 4.7+.
if ( version_compare( $GLOBALS['wp_version'], '4.7', '>=' ) ) {
require $this->plugin_dir . 'includes/classes/class-wp-ms-rest-networks-controller.php';
}
}
}
/**
* Hooks loader into muplugins_loaded, in order to load early.
*
* @since 1.3.0
*/
function setup_multi_network() {
wpmn();
}
add_action( 'muplugins_loaded', 'setup_multi_network' );
/**
* Hook REST endpoints on rest_api_init
*
* @since 2.3.0
*/
function setup_multi_network_endpoints() {
$controller = new WP_MS_REST_Networks_Controller();
$controller->register_routes();
}
add_action( 'rest_api_init', 'setup_multi_network_endpoints', 99 );
/**
* Returns the main WP Multi Network instance.
*
* It will be instantiated if not available yet.
*
* @since 1.7.0
*
* @return WPMN_Loader WP Multi Network instance to use.
*/
function wpmn() {
static $wpmn = false;
if ( false === $wpmn ) {
$wpmn = new WPMN_Loader();
}
return $wpmn;
}