author | ymh <ymh.work@gmail.com> |
Tue, 22 Oct 2019 16:11:46 +0200 | |
changeset 15 | 3d4e9c994f10 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Administration Bootstrap |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* In WordPress Administration Screens |
|
11 |
* |
|
12 |
* @since 2.3.2 |
|
13 |
*/ |
|
5 | 14 |
if ( ! defined( 'WP_ADMIN' ) ) { |
15 |
define( 'WP_ADMIN', true ); |
|
16 |
} |
|
0 | 17 |
|
9 | 18 |
if ( ! defined( 'WP_NETWORK_ADMIN' ) ) { |
19 |
define( 'WP_NETWORK_ADMIN', false ); |
|
20 |
} |
|
0 | 21 |
|
9 | 22 |
if ( ! defined( 'WP_USER_ADMIN' ) ) { |
23 |
define( 'WP_USER_ADMIN', false ); |
|
24 |
} |
|
0 | 25 |
|
26 |
if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) { |
|
9 | 27 |
define( 'WP_BLOG_ADMIN', true ); |
0 | 28 |
} |
29 |
||
9 | 30 |
if ( isset( $_GET['import'] ) && ! defined( 'WP_LOAD_IMPORTERS' ) ) { |
31 |
define( 'WP_LOAD_IMPORTERS', true ); |
|
32 |
} |
|
0 | 33 |
|
9 | 34 |
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); |
0 | 35 |
|
36 |
nocache_headers(); |
|
37 |
||
9 | 38 |
if ( get_option( 'db_upgraded' ) ) { |
0 | 39 |
flush_rewrite_rules(); |
9 | 40 |
update_option( 'db_upgraded', false ); |
0 | 41 |
|
42 |
/** |
|
43 |
* Fires on the next page load after a successful DB upgrade. |
|
44 |
* |
|
45 |
* @since 2.8.0 |
|
46 |
*/ |
|
47 |
do_action( 'after_db_upgrade' ); |
|
9 | 48 |
} elseif ( get_option( 'db_version' ) != $wp_db_version && empty( $_POST ) ) { |
49 |
if ( ! is_multisite() ) { |
|
0 | 50 |
wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); |
51 |
exit; |
|
52 |
||
9 | 53 |
/** |
54 |
* Filters whether to attempt to perform the multisite DB upgrade routine. |
|
55 |
* |
|
56 |
* In single site, the user would be redirected to wp-admin/upgrade.php. |
|
57 |
* In multisite, the DB upgrade routine is automatically fired, but only |
|
58 |
* when this filter returns true. |
|
59 |
* |
|
60 |
* If the network is 50 sites or less, it will run every time. Otherwise, |
|
61 |
* it will throttle itself to reduce load. |
|
62 |
* |
|
63 |
* @since 3.0.0 |
|
64 |
* |
|
65 |
* @param bool $do_mu_upgrade Whether to perform the Multisite upgrade routine. Default true. |
|
66 |
*/ |
|
0 | 67 |
} elseif ( apply_filters( 'do_mu_upgrade', true ) ) { |
68 |
$c = get_blog_count(); |
|
5 | 69 |
|
70 |
/* |
|
71 |
* If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load: |
|
72 |
* attempt to do no more than threshold value, with some +/- allowed. |
|
73 |
*/ |
|
9 | 74 |
if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) == 1 ) ) { |
0 | 75 |
require_once( ABSPATH . WPINC . '/http.php' ); |
9 | 76 |
$response = wp_remote_get( |
77 |
admin_url( 'upgrade.php?step=1' ), |
|
78 |
array( |
|
79 |
'timeout' => 120, |
|
80 |
'httpversion' => '1.1', |
|
81 |
) |
|
82 |
); |
|
5 | 83 |
/** This action is documented in wp-admin/network/upgrade.php */ |
0 | 84 |
do_action( 'after_mu_upgrade', $response ); |
9 | 85 |
unset( $response ); |
0 | 86 |
} |
9 | 87 |
unset( $c ); |
0 | 88 |
} |
89 |
} |
|
90 |
||
9 | 91 |
require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
0 | 92 |
|
93 |
auth_redirect(); |
|
94 |
||
95 |
// Schedule trash collection |
|
9 | 96 |
if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() ) { |
97 |
wp_schedule_event( time(), 'daily', 'wp_scheduled_delete' ); |
|
98 |
} |
|
0 | 99 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
// Schedule Transient cleanup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
if ( ! wp_next_scheduled( 'delete_expired_transients' ) && ! wp_installing() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
wp_schedule_event( time(), 'daily', 'delete_expired_transients' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
|
0 | 105 |
set_screen_options(); |
106 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
$date_format = __( 'F j, Y' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
$time_format = __( 'g:i a' ); |
0 | 109 |
|
110 |
wp_enqueue_script( 'common' ); |
|
111 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
* $pagenow is set in vars.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
* $wp_importers is sometimes set in wp-admin/includes/import.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
* The remaining variables are imported as globals elsewhere, declared as globals here |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* @global string $pagenow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* @global array $wp_importers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* @global string $hook_suffix |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* @global string $plugin_page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* @global string $typenow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* @global string $taxnow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
*/ |
5 | 124 |
global $pagenow, $wp_importers, $hook_suffix, $plugin_page, $typenow, $taxnow; |
125 |
||
126 |
$page_hook = null; |
|
127 |
||
0 | 128 |
$editing = false; |
129 |
||
9 | 130 |
if ( isset( $_GET['page'] ) ) { |
0 | 131 |
$plugin_page = wp_unslash( $_GET['page'] ); |
9 | 132 |
$plugin_page = plugin_basename( $plugin_page ); |
133 |
} |
|
134 |
||
135 |
if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) { |
|
136 |
$typenow = $_REQUEST['post_type']; |
|
137 |
} else { |
|
138 |
$typenow = ''; |
|
0 | 139 |
} |
140 |
||
9 | 141 |
if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) { |
0 | 142 |
$taxnow = $_REQUEST['taxonomy']; |
9 | 143 |
} else { |
0 | 144 |
$taxnow = ''; |
9 | 145 |
} |
0 | 146 |
|
9 | 147 |
if ( WP_NETWORK_ADMIN ) { |
148 |
require( ABSPATH . 'wp-admin/network/menu.php' ); |
|
149 |
} elseif ( WP_USER_ADMIN ) { |
|
150 |
require( ABSPATH . 'wp-admin/user/menu.php' ); |
|
151 |
} else { |
|
152 |
require( ABSPATH . 'wp-admin/menu.php' ); |
|
153 |
} |
|
0 | 154 |
|
155 |
if ( current_user_can( 'manage_options' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
wp_raise_memory_limit( 'admin' ); |
0 | 157 |
} |
158 |
||
159 |
/** |
|
160 |
* Fires as an admin screen or script is being initialized. |
|
161 |
* |
|
162 |
* Note, this does not just run on user-facing admin screens. |
|
163 |
* It runs on admin-ajax.php and admin-post.php as well. |
|
164 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* This is roughly analogous to the more general {@see 'init'} hook, which fires earlier. |
0 | 166 |
* |
167 |
* @since 2.5.0 |
|
168 |
*/ |
|
169 |
do_action( 'admin_init' ); |
|
170 |
||
9 | 171 |
if ( isset( $plugin_page ) ) { |
172 |
if ( ! empty( $typenow ) ) { |
|
0 | 173 |
$the_parent = $pagenow . '?post_type=' . $typenow; |
9 | 174 |
} else { |
0 | 175 |
$the_parent = $pagenow; |
9 | 176 |
} |
177 |
||
178 |
$page_hook = get_plugin_page_hook( $plugin_page, $the_parent ); |
|
179 |
if ( ! $page_hook ) { |
|
180 |
$page_hook = get_plugin_page_hook( $plugin_page, $plugin_page ); |
|
5 | 181 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
// Back-compat for plugins using add_management_page(). |
9 | 183 |
if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook( $plugin_page, 'tools.php' ) ) { |
0 | 184 |
// There could be plugin specific params on the URL, so we need the whole query string |
9 | 185 |
if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { |
186 |
$query_string = $_SERVER['QUERY_STRING']; |
|
187 |
} else { |
|
0 | 188 |
$query_string = 'page=' . $plugin_page; |
9 | 189 |
} |
190 |
wp_redirect( admin_url( 'tools.php?' . $query_string ) ); |
|
0 | 191 |
exit; |
192 |
} |
|
193 |
} |
|
9 | 194 |
unset( $the_parent ); |
0 | 195 |
} |
196 |
||
197 |
$hook_suffix = ''; |
|
5 | 198 |
if ( isset( $page_hook ) ) { |
0 | 199 |
$hook_suffix = $page_hook; |
5 | 200 |
} elseif ( isset( $plugin_page ) ) { |
0 | 201 |
$hook_suffix = $plugin_page; |
5 | 202 |
} elseif ( isset( $pagenow ) ) { |
0 | 203 |
$hook_suffix = $pagenow; |
5 | 204 |
} |
0 | 205 |
|
206 |
set_current_screen(); |
|
207 |
||
208 |
// Handle plugin admin pages. |
|
9 | 209 |
if ( isset( $plugin_page ) ) { |
0 | 210 |
if ( $page_hook ) { |
211 |
/** |
|
212 |
* Fires before a particular screen is loaded. |
|
213 |
* |
|
214 |
* The load-* hook fires in a number of contexts. This hook is for plugin screens |
|
215 |
* where a callback is provided when the screen is registered. |
|
216 |
* |
|
5 | 217 |
* The dynamic portion of the hook name, `$page_hook`, refers to a mixture of plugin |
0 | 218 |
* page information including: |
219 |
* 1. The page type. If the plugin page is registered as a submenu page, such as for |
|
220 |
* Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'. |
|
221 |
* 2. A separator of '_page_'. |
|
222 |
* 3. The plugin basename minus the file extension. |
|
223 |
* |
|
5 | 224 |
* Together, the three parts form the `$page_hook`. Citing the example above, |
0 | 225 |
* the hook name used would be 'load-settings_page_pluginbasename'. |
226 |
* |
|
227 |
* @see get_plugin_page_hook() |
|
228 |
* |
|
229 |
* @since 2.1.0 |
|
230 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
do_action( "load-{$page_hook}" ); |
9 | 232 |
if ( ! isset( $_GET['noheader'] ) ) { |
233 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
234 |
} |
|
0 | 235 |
|
236 |
/** |
|
237 |
* Used to call the registered callback for a plugin screen. |
|
238 |
* |
|
9 | 239 |
* This hook uses a dynamic hook name, `$page_hook`, which refers to a mixture of plugin |
240 |
* page information including: |
|
241 |
* 1. The page type. If the plugin page is registered as a submenu page, such as for |
|
242 |
* Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'. |
|
243 |
* 2. A separator of '_page_'. |
|
244 |
* 3. The plugin basename minus the file extension. |
|
245 |
* |
|
246 |
* Together, the three parts form the `$page_hook`. Citing the example above, |
|
247 |
* the hook name used would be 'settings_page_pluginbasename'. |
|
248 |
* |
|
249 |
* @see get_plugin_page_hook() |
|
250 |
* |
|
0 | 251 |
* @since 1.5.0 |
252 |
*/ |
|
253 |
do_action( $page_hook ); |
|
254 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
if ( validate_file( $plugin_page ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
wp_die( __( 'Invalid plugin page.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
} |
0 | 258 |
|
9 | 259 |
if ( ! ( file_exists( WP_PLUGIN_DIR . "/$plugin_page" ) && is_file( WP_PLUGIN_DIR . "/$plugin_page" ) ) && ! ( file_exists( WPMU_PLUGIN_DIR . "/$plugin_page" ) && is_file( WPMU_PLUGIN_DIR . "/$plugin_page" ) ) ) { |
260 |
wp_die( sprintf( __( 'Cannot load %s.' ), htmlentities( $plugin_page ) ) ); |
|
261 |
} |
|
0 | 262 |
|
263 |
/** |
|
264 |
* Fires before a particular screen is loaded. |
|
265 |
* |
|
266 |
* The load-* hook fires in a number of contexts. This hook is for plugin screens |
|
267 |
* where the file to load is directly included, rather than the use of a function. |
|
268 |
* |
|
5 | 269 |
* The dynamic portion of the hook name, `$plugin_page`, refers to the plugin basename. |
0 | 270 |
* |
271 |
* @see plugin_basename() |
|
272 |
* |
|
273 |
* @since 1.5.0 |
|
274 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
do_action( "load-{$plugin_page}" ); |
0 | 276 |
|
9 | 277 |
if ( ! isset( $_GET['noheader'] ) ) { |
278 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
279 |
} |
|
0 | 280 |
|
9 | 281 |
if ( file_exists( WPMU_PLUGIN_DIR . "/$plugin_page" ) ) { |
282 |
include( WPMU_PLUGIN_DIR . "/$plugin_page" ); |
|
283 |
} else { |
|
284 |
include( WP_PLUGIN_DIR . "/$plugin_page" ); |
|
285 |
} |
|
0 | 286 |
} |
287 |
||
9 | 288 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |
0 | 289 |
|
290 |
exit(); |
|
5 | 291 |
} elseif ( isset( $_GET['import'] ) ) { |
0 | 292 |
|
293 |
$importer = $_GET['import']; |
|
294 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
if ( ! current_user_can( 'import' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
wp_die( __( 'Sorry, you are not allowed to import content.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
} |
0 | 298 |
|
9 | 299 |
if ( validate_file( $importer ) ) { |
0 | 300 |
wp_redirect( admin_url( 'import.php?invalid=' . $importer ) ); |
301 |
exit; |
|
302 |
} |
|
303 |
||
9 | 304 |
if ( ! isset( $wp_importers[ $importer ] ) || ! is_callable( $wp_importers[ $importer ][2] ) ) { |
0 | 305 |
wp_redirect( admin_url( 'import.php?invalid=' . $importer ) ); |
306 |
exit; |
|
307 |
} |
|
308 |
||
309 |
/** |
|
310 |
* Fires before an importer screen is loaded. |
|
311 |
* |
|
5 | 312 |
* The dynamic portion of the hook name, `$importer`, refers to the importer slug. |
0 | 313 |
* |
314 |
* @since 3.5.0 |
|
315 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
do_action( "load-importer-{$importer}" ); |
0 | 317 |
|
9 | 318 |
$parent_file = 'tools.php'; |
0 | 319 |
$submenu_file = 'import.php'; |
9 | 320 |
$title = __( 'Import' ); |
0 | 321 |
|
9 | 322 |
if ( ! isset( $_GET['noheader'] ) ) { |
323 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
324 |
} |
|
0 | 325 |
|
9 | 326 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
0 | 327 |
|
9 | 328 |
define( 'WP_IMPORTING', true ); |
0 | 329 |
|
330 |
/** |
|
331 |
* Whether to filter imported data through kses on import. |
|
332 |
* |
|
333 |
* Multisite uses this hook to filter all data through kses by default, |
|
334 |
* as a super administrator may be assisting an untrusted user. |
|
335 |
* |
|
336 |
* @since 3.1.0 |
|
337 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* @param bool $force Whether to force data to be filtered through kses. Default false. |
0 | 339 |
*/ |
5 | 340 |
if ( apply_filters( 'force_filtered_html_on_import', false ) ) { |
0 | 341 |
kses_init_filters(); // Always filter imported data with kses on multisite. |
5 | 342 |
} |
0 | 343 |
|
9 | 344 |
call_user_func( $wp_importers[ $importer ][2] ); |
0 | 345 |
|
9 | 346 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |
0 | 347 |
|
348 |
// Make sure rules are flushed |
|
9 | 349 |
flush_rewrite_rules( false ); |
0 | 350 |
|
351 |
exit(); |
|
352 |
} else { |
|
353 |
/** |
|
354 |
* Fires before a particular screen is loaded. |
|
355 |
* |
|
356 |
* The load-* hook fires in a number of contexts. This hook is for core screens. |
|
357 |
* |
|
5 | 358 |
* The dynamic portion of the hook name, `$pagenow`, is a global variable |
0 | 359 |
* referring to the filename of the current page, such as 'admin.php', |
5 | 360 |
* 'post-new.php' etc. A complete hook for the latter would be |
361 |
* 'load-post-new.php'. |
|
0 | 362 |
* |
363 |
* @since 2.1.0 |
|
364 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
do_action( "load-{$pagenow}" ); |
5 | 366 |
|
367 |
/* |
|
368 |
* The following hooks are fired to ensure backward compatibility. |
|
369 |
* In all other cases, 'load-' . $pagenow should be used instead. |
|
370 |
*/ |
|
0 | 371 |
if ( $typenow == 'page' ) { |
9 | 372 |
if ( $pagenow == 'post-new.php' ) { |
0 | 373 |
do_action( 'load-page-new.php' ); |
9 | 374 |
} elseif ( $pagenow == 'post.php' ) { |
0 | 375 |
do_action( 'load-page.php' ); |
9 | 376 |
} |
377 |
} elseif ( $pagenow == 'edit-tags.php' ) { |
|
378 |
if ( $taxnow == 'category' ) { |
|
0 | 379 |
do_action( 'load-categories.php' ); |
9 | 380 |
} elseif ( $taxnow == 'link_category' ) { |
0 | 381 |
do_action( 'load-edit-link-categories.php' ); |
9 | 382 |
} |
383 |
} elseif ( 'term.php' === $pagenow ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
do_action( 'load-edit-tags.php' ); |
0 | 385 |
} |
386 |
} |
|
387 |
||
388 |
if ( ! empty( $_REQUEST['action'] ) ) { |
|
9 | 389 |
$action = $_REQUEST['action']; |
390 |
||
0 | 391 |
/** |
392 |
* Fires when an 'action' request variable is sent. |
|
393 |
* |
|
9 | 394 |
* The dynamic portion of the hook name, `$action`, refers to |
395 |
* the action derived from the `GET` or `POST` request. |
|
0 | 396 |
* |
397 |
* @since 2.6.0 |
|
398 |
*/ |
|
9 | 399 |
do_action( "admin_action_{$action}" ); |
0 | 400 |
} |