-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-notifications.php
286 lines (242 loc) · 7.77 KB
/
update-notifications.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/**
* Plugin Name: WPMU DEV Dashboard
* Plugin URI: https://wpmudev.com/project/wpmu-dev-dashboard/
* Description: Brings the powers of WPMU DEV directly to you. It will revolutionize how you use WordPress. Activate now!
* Author: WPMU DEV
* Version: 4.11.0
* Author URI: https://wpmudev.com/
* Text Domain: wpmudev
* Domain Path: includes/languages/
* Network: true
* WDP ID: 119
*
* @package WPMUDEV_Dashboard
*/
/*
Copyright 2007-2018 Incsub (http://incsub.com)
Author - Aaron Edwards
Contributors - Philipp Stracker, Victor Ivanov, Vladislav Bailovic, Jeffri H, Marko Miljus
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* The main Dashboard class that behaves as an interface to the other Dashboard
* classes.
*/
class WPMUDEV_Dashboard {
/**
* The current plugin version. Must match the plugin header.
*
* @var string (Version number)
*/
public static $version = '4.11.0';
/**
* The current SUI version.
*
* @var string (SUI Version number)
*
* Required for the body class on admin pages
* Use sui followed by version number
* Use dash instead of dots as number seperator
*/
public static $sui_version = 'sui-2-9-6';
/**
* Holds the API module.
* Handles all the remote calls to the WPMUDEV Server.
*
* @var WPMUDEV_Dashboard_Api
* @since 4.0.0
*/
public static $api = null;
/**
* Holds the Remote module.
* Handles all the Hub calls from the WPMUDEV Servers.
*
* @var WPMUDEV_Dashboard_Remote
* @since 4.0.0
*/
public static $remote = null;
/**
* Holds the Site/Settings module.
* Handles all local things like storing/fetching settings.
*
* @var WPMUDEV_Dashboard_Site
* @since 4.0.0
*/
public static $site = null;
/**
* Holds the UI module.
* Handles all the UI tasks, like displaying a specific Dashboard page.
*
* @var WPMUDEV_Dashboard_Ui
* @since 4.0.0
*/
public static $ui = null;
/**
* Holds the Upgrader module.
* Handles all upgrade/installation relevant tasks.
*
* @var WPMUDEV_Dashboard_Upgrader
* @since 4.1.0
*/
public static $upgrader = null;
/**
* Holds the Notification module.
* Handles all the dashboard notifications.
*
* @var WPMUDEV_Dashboard_Notice
* @since 4.0.0
*/
public static $notice = null;
/**
* Creates and returns the WPMUDEV Dashboard object.
* We'll have only one of those ;)
*
* Important: This function must be called BEFORE the plugins_loaded hook!
*
* @since 4.0.0
* @return WPMUDEV_Dashboard
*/
public static function instance() {
static $inst = null;
if ( null === $inst ) {
$inst = new WPMUDEV_Dashboard();
}
return $inst;
}
/**
* The singleton constructor will initialize the modules.
*
* Important: This function must be called BEFORE the plugins_loaded hook!
*
* @since 1.0.0
*/
private function __construct() {
require_once 'shared-ui/plugin-ui.php';
require_once 'includes/class-wpmudev-dashboard-site.php';
require_once 'includes/class-wpmudev-dashboard-api.php';
require_once 'includes/class-wpmudev-dashboard-remote.php';
require_once 'includes/class-wpmudev-dashboard-ui.php';
require_once 'includes/class-wpmudev-dashboard-upgrader.php';
require_once 'includes/class-wpmudev-dashboard-notice.php';
self::$site = new WPMUDEV_Dashboard_Site( __FILE__ );
self::$api = new WPMUDEV_Dashboard_Api();
self::$remote = new WPMUDEV_Dashboard_Remote();
self::$notice = new WPMUDEV_Dashboard_Message();
self::$upgrader = new WPMUDEV_Dashboard_Upgrader();
/*
* The UI module sets up all the WP hooks when it is created.
* So it should stay the last module to create, so it can access the
* other modules already in the constructor.
*/
self::$ui = new WPMUDEV_Dashboard_Ui();
// Register the plugin activation hook.
register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) );
// Register the plugin deactivation hook.
register_deactivation_hook( __FILE__, array( $this, 'deactivate_plugin' ) );
// Register the plugin uninstall hook.
register_uninstall_hook( __FILE__, array( 'WPMUDEV_Dashboard', 'uninstall_plugin' ) );
// Get db version.
$version = self::$site->get_option( 'version', true, '1.0' );
// If existing version is not same, upgrade.
if ( ! empty( $version ) && version_compare( $version, self::$version, '<' ) ) {
$this->upgrade_plugin( $version );
}
/**
* Custom code can be executed after Dashboard is initialized with the
* default settings.
*
* @since 4.0.0
* @var WPMUDEV_Dashboard The initialized dashboard object.
*/
do_action( 'wpmudev_dashboard_init', $this );
}
/**
* Run code on plugin activation.
*
* @since 1.0.0
* @internal Action hook
*/
public function activate_plugin() {
global $current_user;
// Make sure all Dashboard settings exist in the DB.
self::$site->init_options();
// Reset the admin-user when plugin is activated.
if ( $current_user && $current_user->ID ) {
self::$site->set_option( 'limit_to_user', $current_user->ID );
} else {
self::$site->set_option( 'limit_to_user', '' );
}
// On next page load we want to redirect user to login page.
self::$site->set_option( 'redirected_v4', 0 );
// Set plugin version on activation.
self::$site->set_option( 'version', self::$version );
// Force refresh of all data when plugin is activated.
self::$site->set_option( 'refresh_profile_flag', 1 );
// This needs to trigger after init to prevent Call to undefined function wp_get_current_user() errors.
add_action( 'shutdown', array( self::$api, 'refresh_projects_data' ) );
self::$site->schedule_shutdown_refresh();
}
/**
* Run code on plugin deactivation.
*
* @since 4.1.1
* @internal Action hook
*/
public function deactivate_plugin() {
// On next page load we want to redirect user to login page.
self::$site->set_option( 'redirected_v4', 0 );
}
/**
* Run code on plugin uninstall.
*
* @since 4.5
* @internal Action hook
*/
public static function uninstall_plugin() {
// On next page load we want to redirect user to login page.
self::$site->logout( false );
// TODO Delete all options from DB.
}
/**
* Run code on plugin version upgrade.
*
* @param string $version Old version.
*
* @since 4.11
*
* @return void
*/
private function upgrade_plugin( $version ) {
// Set new version.
self::$site->set_option( 'version', self::$version );
// Show upgrade highlights modal.
self::$site->set_option( 'highlights_dismissed', false );
/**
* Action hook to execute upgrade functions.
*
* @param string $version Old version.
* @param string $new_version New version.
*
* @since 4.11
*/
do_action( 'wpmudev_dashboard_version_upgrade', $version, self::$version );
}
};
// Initialize the WPMUDEV Dashboard.
WPMUDEV_Dashboard::instance();
if ( ! class_exists( 'WPMUDEV_Update_Notifications' ) ) {
/**
* Dummy class for backwards compatibility to stone-age.
*/
class WPMUDEV_Update_Notifications {};
}