3 * WordPress Administration Bootstrap
6 * @subpackage Administration
10 * In WordPress Administration Screens
14 if ( ! defined( 'WP_ADMIN' ) ) {
15 define( 'WP_ADMIN', true );
18 if ( ! defined('WP_NETWORK_ADMIN') )
19 define('WP_NETWORK_ADMIN', false);
21 if ( ! defined('WP_USER_ADMIN') )
22 define('WP_USER_ADMIN', false);
24 if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) {
25 define('WP_BLOG_ADMIN', true);
28 if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') )
29 define('WP_LOAD_IMPORTERS', true);
31 require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
35 if ( get_option('db_upgraded') ) {
36 flush_rewrite_rules();
37 update_option( 'db_upgraded', false );
40 * Fires on the next page load after a successful DB upgrade.
44 do_action( 'after_db_upgrade' );
45 } elseif ( get_option('db_version') != $wp_db_version && empty($_POST) ) {
46 if ( !is_multisite() ) {
47 wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
51 * Filter whether to attempt to perform the multisite DB upgrade routine.
53 * In single site, the user would be redirected to wp-admin/upgrade.php.
54 * In multisite, the DB upgrade routine is automatically fired, but only
55 * when this filter returns true.
57 * If the network is 50 sites or less, it will run every time. Otherwise,
58 * it will throttle itself to reduce load.
62 * @param bool true Whether to perform the Multisite upgrade routine. Default true.
64 } elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
65 $c = get_blog_count();
68 * If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load:
69 * attempt to do no more than threshold value, with some +/- allowed.
71 if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
72 require_once( ABSPATH . WPINC . '/http.php' );
73 $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) );
74 /** This action is documented in wp-admin/network/upgrade.php */
75 do_action( 'after_mu_upgrade', $response );
82 require_once(ABSPATH . 'wp-admin/includes/admin.php');
86 // Schedule trash collection
87 if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() )
88 wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
92 $date_format = get_option('date_format');
93 $time_format = get_option('time_format');
95 wp_enqueue_script( 'common' );
101 * $pagenow is set in vars.php
102 * $wp_importers is sometimes set in wp-admin/includes/import.php
103 * The remaining variables are imported as globals elsewhere, declared as globals here
105 * @global string $pagenow
106 * @global array $wp_importers
107 * @global string $hook_suffix
108 * @global string $plugin_page
109 * @global string $typenow
110 * @global string $taxnow
112 global $pagenow, $wp_importers, $hook_suffix, $plugin_page, $typenow, $taxnow;
118 if ( isset($_GET['page']) ) {
119 $plugin_page = wp_unslash( $_GET['page'] );
120 $plugin_page = plugin_basename($plugin_page);
123 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
124 $typenow = $_REQUEST['post_type'];
128 if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
129 $taxnow = $_REQUEST['taxonomy'];
133 if ( WP_NETWORK_ADMIN )
134 require(ABSPATH . 'wp-admin/network/menu.php');
135 elseif ( WP_USER_ADMIN )
136 require(ABSPATH . 'wp-admin/user/menu.php');
138 require(ABSPATH . 'wp-admin/menu.php');
140 if ( current_user_can( 'manage_options' ) ) {
142 * Filter the maximum memory limit available for administration screens.
144 * This only applies to administrators, who may require more memory for tasks like updates.
145 * Memory limits when processing images (uploaded or edited by users of any role) are
146 * handled separately.
148 * The WP_MAX_MEMORY_LIMIT constant specifically defines the maximum memory limit available
149 * when in the administration back-end. The default is 256M, or 256 megabytes of memory.
153 * @param string 'WP_MAX_MEMORY_LIMIT' The maximum WordPress memory limit. Default 256M.
155 @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
159 * Fires as an admin screen or script is being initialized.
161 * Note, this does not just run on user-facing admin screens.
162 * It runs on admin-ajax.php and admin-post.php as well.
164 * This is roughly analgous to the more general 'init' hook, which fires earlier.
168 do_action( 'admin_init' );
170 if ( isset($plugin_page) ) {
171 if ( !empty($typenow) )
172 $the_parent = $pagenow . '?post_type=' . $typenow;
174 $the_parent = $pagenow;
175 if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
176 $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
178 // Backwards compatibility for plugins using add_management_page().
179 if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
180 // There could be plugin specific params on the URL, so we need the whole query string
181 if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
182 $query_string = $_SERVER[ 'QUERY_STRING' ];
184 $query_string = 'page=' . $plugin_page;
185 wp_redirect( admin_url('tools.php?' . $query_string) );
193 if ( isset( $page_hook ) ) {
194 $hook_suffix = $page_hook;
195 } elseif ( isset( $plugin_page ) ) {
196 $hook_suffix = $plugin_page;
197 } elseif ( isset( $pagenow ) ) {
198 $hook_suffix = $pagenow;
201 set_current_screen();
203 // Handle plugin admin pages.
204 if ( isset($plugin_page) ) {
207 * Fires before a particular screen is loaded.
209 * The load-* hook fires in a number of contexts. This hook is for plugin screens
210 * where a callback is provided when the screen is registered.
212 * The dynamic portion of the hook name, `$page_hook`, refers to a mixture of plugin
213 * page information including:
214 * 1. The page type. If the plugin page is registered as a submenu page, such as for
215 * Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'.
216 * 2. A separator of '_page_'.
217 * 3. The plugin basename minus the file extension.
219 * Together, the three parts form the `$page_hook`. Citing the example above,
220 * the hook name used would be 'load-settings_page_pluginbasename'.
222 * @see get_plugin_page_hook()
226 do_action( 'load-' . $page_hook );
227 if (! isset($_GET['noheader']))
228 require_once(ABSPATH . 'wp-admin/admin-header.php');
231 * Used to call the registered callback for a plugin screen.
236 do_action( $page_hook );
238 if ( validate_file($plugin_page) )
239 wp_die(__('Invalid plugin page'));
241 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") ) )
242 wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
245 * Fires before a particular screen is loaded.
247 * The load-* hook fires in a number of contexts. This hook is for plugin screens
248 * where the file to load is directly included, rather than the use of a function.
250 * The dynamic portion of the hook name, `$plugin_page`, refers to the plugin basename.
252 * @see plugin_basename()
256 do_action( 'load-' . $plugin_page );
258 if ( !isset($_GET['noheader']))
259 require_once(ABSPATH . 'wp-admin/admin-header.php');
261 if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
262 include(WPMU_PLUGIN_DIR . "/$plugin_page");
264 include(WP_PLUGIN_DIR . "/$plugin_page");
267 include(ABSPATH . 'wp-admin/admin-footer.php');
270 } elseif ( isset( $_GET['import'] ) ) {
272 $importer = $_GET['import'];
274 if ( ! current_user_can('import') )
275 wp_die(__('You are not allowed to import.'));
277 if ( validate_file($importer) ) {
278 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
282 if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) {
283 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
288 * Fires before an importer screen is loaded.
290 * The dynamic portion of the hook name, `$importer`, refers to the importer slug.
294 do_action( 'load-importer-' . $importer );
296 $parent_file = 'tools.php';
297 $submenu_file = 'import.php';
298 $title = __('Import');
300 if (! isset($_GET['noheader']))
301 require_once(ABSPATH . 'wp-admin/admin-header.php');
303 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
305 define('WP_IMPORTING', true);
308 * Whether to filter imported data through kses on import.
310 * Multisite uses this hook to filter all data through kses by default,
311 * as a super administrator may be assisting an untrusted user.
315 * @param bool false Whether to force data to be filtered through kses. Default false.
317 if ( apply_filters( 'force_filtered_html_on_import', false ) ) {
318 kses_init_filters(); // Always filter imported data with kses on multisite.
321 call_user_func($wp_importers[$importer][2]);
323 include(ABSPATH . 'wp-admin/admin-footer.php');
325 // Make sure rules are flushed
326 flush_rewrite_rules(false);
331 * Fires before a particular screen is loaded.
333 * The load-* hook fires in a number of contexts. This hook is for core screens.
335 * The dynamic portion of the hook name, `$pagenow`, is a global variable
336 * referring to the filename of the current page, such as 'admin.php',
337 * 'post-new.php' etc. A complete hook for the latter would be
338 * 'load-post-new.php'.
342 do_action( 'load-' . $pagenow );
345 * The following hooks are fired to ensure backward compatibility.
346 * In all other cases, 'load-' . $pagenow should be used instead.
348 if ( $typenow == 'page' ) {
349 if ( $pagenow == 'post-new.php' )
350 do_action( 'load-page-new.php' );
351 elseif ( $pagenow == 'post.php' )
352 do_action( 'load-page.php' );
353 } elseif ( $pagenow == 'edit-tags.php' ) {
354 if ( $taxnow == 'category' )
355 do_action( 'load-categories.php' );
356 elseif ( $taxnow == 'link_category' )
357 do_action( 'load-edit-link-categories.php' );
361 if ( ! empty( $_REQUEST['action'] ) ) {
363 * Fires when an 'action' request variable is sent.
365 * The dynamic portion of the hook name, `$_REQUEST['action']`,
366 * refers to the action derived from the `GET` or `POST` request.
370 do_action( 'admin_action_' . $_REQUEST['action'] );