3 * WordPress Administration Bootstrap
6 * @subpackage Administration
10 * In WordPress Administration Screens
14 if ( ! defined('WP_ADMIN') )
15 define('WP_ADMIN', true);
17 if ( ! defined('WP_NETWORK_ADMIN') )
18 define('WP_NETWORK_ADMIN', false);
20 if ( ! defined('WP_USER_ADMIN') )
21 define('WP_USER_ADMIN', false);
23 if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) {
24 define('WP_BLOG_ADMIN', true);
27 if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') )
28 define('WP_LOAD_IMPORTERS', true);
30 require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
34 if ( get_option('db_upgraded') ) {
35 flush_rewrite_rules();
36 update_option( 'db_upgraded', false );
39 * Fires on the next page load after a successful DB upgrade.
43 do_action( 'after_db_upgrade' );
44 } elseif ( get_option('db_version') != $wp_db_version && empty($_POST) ) {
45 if ( !is_multisite() ) {
46 wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
50 * Filter whether to attempt to perform the multisite DB upgrade routine.
52 * In single site, the user would be redirected to wp-admin/upgrade.php.
53 * In multisite, it is automatically fired, but only when this filter
56 * If the network is 50 sites or less, it will run every time. Otherwise,
57 * it will throttle itself to reduce load.
61 * @param bool true Whether to perform the Multisite upgrade routine. Default true.
63 } elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
64 $c = get_blog_count();
65 // If 50 or fewer sites, run every time. Else, run "about ten percent" of the time. Shh, don't check that math.
66 if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
67 require_once( ABSPATH . WPINC . '/http.php' );
68 $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) );
70 * Fires after the multisite DB upgrade is complete.
74 * @param array|WP_Error $response The upgrade response array or WP_Error on failure.
76 do_action( 'after_mu_upgrade', $response );
83 require_once(ABSPATH . 'wp-admin/includes/admin.php');
87 // Schedule trash collection
88 if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') )
89 wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
93 $date_format = get_option('date_format');
94 $time_format = get_option('time_format');
96 wp_enqueue_script( 'common' );
100 if ( isset($_GET['page']) ) {
101 $plugin_page = wp_unslash( $_GET['page'] );
102 $plugin_page = plugin_basename($plugin_page);
105 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
106 $typenow = $_REQUEST['post_type'];
110 if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
111 $taxnow = $_REQUEST['taxonomy'];
115 if ( WP_NETWORK_ADMIN )
116 require(ABSPATH . 'wp-admin/network/menu.php');
117 elseif ( WP_USER_ADMIN )
118 require(ABSPATH . 'wp-admin/user/menu.php');
120 require(ABSPATH . 'wp-admin/menu.php');
122 if ( current_user_can( 'manage_options' ) ) {
124 * Filter the maximum memory limit available for administration screens.
126 * This only applies to administrators, who may require more memory for tasks like updates.
127 * Memory limits when processing images (uploaded or edited by users of any role) are
128 * handled separately.
130 * The WP_MAX_MEMORY_LIMIT constant specifically defines the maximum memory limit available
131 * when in the administration back-end. The default is 256M, or 256 megabytes of memory.
135 * @param string 'WP_MAX_MEMORY_LIMIT' The maximum WordPress memory limit. Default 256M.
137 @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
141 * Fires as an admin screen or script is being initialized.
143 * Note, this does not just run on user-facing admin screens.
144 * It runs on admin-ajax.php and admin-post.php as well.
146 * This is roughly analgous to the more general 'init' hook, which fires earlier.
150 do_action( 'admin_init' );
152 if ( isset($plugin_page) ) {
153 if ( !empty($typenow) )
154 $the_parent = $pagenow . '?post_type=' . $typenow;
156 $the_parent = $pagenow;
157 if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
158 $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
159 // backwards compatibility for plugins using add_management_page
160 if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
161 // There could be plugin specific params on the URL, so we need the whole query string
162 if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
163 $query_string = $_SERVER[ 'QUERY_STRING' ];
165 $query_string = 'page=' . $plugin_page;
166 wp_redirect( admin_url('tools.php?' . $query_string) );
174 if ( isset($page_hook) )
175 $hook_suffix = $page_hook;
176 else if ( isset($plugin_page) )
177 $hook_suffix = $plugin_page;
178 else if ( isset($pagenow) )
179 $hook_suffix = $pagenow;
181 set_current_screen();
183 // Handle plugin admin pages.
184 if ( isset($plugin_page) ) {
187 * Fires before a particular screen is loaded.
189 * The load-* hook fires in a number of contexts. This hook is for plugin screens
190 * where a callback is provided when the screen is registered.
192 * The dynamic portion of the hook name, $page_hook, refers to a mixture of plugin
193 * page information including:
194 * 1. The page type. If the plugin page is registered as a submenu page, such as for
195 * Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'.
196 * 2. A separator of '_page_'.
197 * 3. The plugin basename minus the file extension.
199 * Together, the three parts form the $page_hook. Citing the example above,
200 * the hook name used would be 'load-settings_page_pluginbasename'.
202 * @see get_plugin_page_hook()
206 do_action( 'load-' . $page_hook );
207 if (! isset($_GET['noheader']))
208 require_once(ABSPATH . 'wp-admin/admin-header.php');
211 * Used to call the registered callback for a plugin screen.
217 do_action( $page_hook );
219 if ( validate_file($plugin_page) )
220 wp_die(__('Invalid plugin page'));
222 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") ) )
223 wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
226 * Fires before a particular screen is loaded.
228 * The load-* hook fires in a number of contexts. This hook is for plugin screens
229 * where the file to load is directly included, rather than the use of a function.
231 * The dynamic portion of the hook name, $plugin_page, refers to the plugin basename.
233 * @see plugin_basename()
237 do_action( 'load-' . $plugin_page );
239 if ( !isset($_GET['noheader']))
240 require_once(ABSPATH . 'wp-admin/admin-header.php');
242 if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
243 include(WPMU_PLUGIN_DIR . "/$plugin_page");
245 include(WP_PLUGIN_DIR . "/$plugin_page");
248 include(ABSPATH . 'wp-admin/admin-footer.php');
251 } else if (isset($_GET['import'])) {
253 $importer = $_GET['import'];
255 if ( ! current_user_can('import') )
256 wp_die(__('You are not allowed to import.'));
258 if ( validate_file($importer) ) {
259 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
263 if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) {
264 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
269 * Fires before an importer screen is loaded.
271 * The dynamic portion of the hook name, $importer, refers to the importer slug.
275 do_action( 'load-importer-' . $importer );
277 $parent_file = 'tools.php';
278 $submenu_file = 'import.php';
279 $title = __('Import');
281 if (! isset($_GET['noheader']))
282 require_once(ABSPATH . 'wp-admin/admin-header.php');
284 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
286 define('WP_IMPORTING', true);
289 * Whether to filter imported data through kses on import.
291 * Multisite uses this hook to filter all data through kses by default,
292 * as a super administrator may be assisting an untrusted user.
296 * @param bool false Whether to force data to be filtered through kses. Default false.
298 if ( apply_filters( 'force_filtered_html_on_import', false ) )
299 kses_init_filters(); // Always filter imported data with kses on multisite.
301 call_user_func($wp_importers[$importer][2]);
303 include(ABSPATH . 'wp-admin/admin-footer.php');
305 // Make sure rules are flushed
306 flush_rewrite_rules(false);
311 * Fires before a particular screen is loaded.
313 * The load-* hook fires in a number of contexts. This hook is for core screens.
315 * The dynamic portion of the hook name, $pagenow, is a global variable
316 * referring to the filename of the current page, such as 'admin.php',
317 * 'post-new.php' etc. A complete hook for the latter would be 'load-post-new.php'.
321 do_action( 'load-' . $pagenow );
322 // Backwards compatibility with old load-page-new.php, load-page.php,
323 // and load-categories.php actions.
324 if ( $typenow == 'page' ) {
325 if ( $pagenow == 'post-new.php' )
326 do_action( 'load-page-new.php' );
327 elseif ( $pagenow == 'post.php' )
328 do_action( 'load-page.php' );
329 } elseif ( $pagenow == 'edit-tags.php' ) {
330 if ( $taxnow == 'category' )
331 do_action( 'load-categories.php' );
332 elseif ( $taxnow == 'link_category' )
333 do_action( 'load-edit-link-categories.php' );
337 if ( ! empty( $_REQUEST['action'] ) ) {
339 * Fires when an 'action' request variable is sent.
341 * The dynamic portion of the hook name, $_REQUEST['action'],
342 * refers to the action derived from the GET or POST request.
346 do_action( 'admin_action_' . $_REQUEST['action'] );