3 * WordPress Administration Bootstrap
6 * @subpackage Administration
10 * In WordPress Administration Panels
14 if ( !defined('WP_ADMIN') )
15 define('WP_ADMIN', TRUE);
17 if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') )
18 define('WP_LOAD_IMPORTERS', true);
20 require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
22 if ( get_option('db_upgraded') ) {
23 $wp_rewrite->flush_rules();
24 update_option( 'db_upgraded', false );
27 * Runs on the next page load after successful upgrade
31 do_action('after_db_upgrade');
32 } elseif ( get_option('db_version') != $wp_db_version ) {
33 if ( !is_multisite() ) {
34 wp_redirect(admin_url('upgrade.php?_wp_http_referer=' . urlencode(stripslashes($_SERVER['REQUEST_URI']))));
36 } elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
38 * On really small MU installs run the upgrader every time,
39 * else run it less often to reduce load.
43 $c = get_blog_count();
44 if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
45 require_once( ABSPATH . WPINC . '/http.php' );
46 $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) );
47 do_action( 'after_mu_upgrade', $response );
54 require_once(ABSPATH . 'wp-admin/includes/admin.php');
60 update_category_cache();
62 // Schedule trash collection
63 if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') )
64 wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
68 $date_format = get_option('date_format');
69 $time_format = get_option('time_format');
71 wp_reset_vars(array('profile', 'redirect', 'redirect_url', 'a', 'text', 'trackback', 'pingback'));
73 wp_enqueue_script( 'common' );
74 wp_enqueue_script( 'jquery-color' );
78 if ( isset($_GET['page']) ) {
79 $plugin_page = stripslashes($_GET['page']);
80 $plugin_page = plugin_basename($plugin_page);
83 if ( isset($_GET['post_type']) )
84 $typenow = sanitize_key($_GET['post_type']);
88 if ( isset($_GET['taxonomy']) )
89 $taxnow = sanitize_key($_GET['taxonomy']);
93 require(ABSPATH . 'wp-admin/menu.php');
95 if ( current_user_can( 'manage_options' ) )
96 @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
98 do_action('admin_init');
100 if ( isset($plugin_page) ) {
101 if ( !empty($typenow) )
102 $the_parent = $pagenow . '?post_type=' . $typenow;
104 $the_parent = $pagenow;
105 if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
106 $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
107 // backwards compatibility for plugins using add_management_page
108 if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
109 // There could be plugin specific params on the URL, so we need the whole query string
110 if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
111 $query_string = $_SERVER[ 'QUERY_STRING' ];
113 $query_string = 'page=' . $plugin_page;
114 wp_redirect( 'tools.php?' . $query_string );
122 if ( isset($page_hook) )
123 $hook_suffix = $page_hook;
124 else if ( isset($plugin_page) )
125 $hook_suffix = $plugin_page;
126 else if ( isset($pagenow) )
127 $hook_suffix = $pagenow;
129 set_current_screen();
131 // Handle plugin admin pages.
132 if ( isset($plugin_page) ) {
134 do_action('load-' . $page_hook);
135 if (! isset($_GET['noheader']))
136 require_once(ABSPATH . 'wp-admin/admin-header.php');
138 do_action($page_hook);
140 if ( validate_file($plugin_page) )
141 wp_die(__('Invalid plugin page'));
144 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") ) )
145 wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
147 do_action('load-' . $plugin_page);
149 if ( !isset($_GET['noheader']))
150 require_once(ABSPATH . 'wp-admin/admin-header.php');
152 if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
153 include(WPMU_PLUGIN_DIR . "/$plugin_page");
155 include(WP_PLUGIN_DIR . "/$plugin_page");
158 include(ABSPATH . 'wp-admin/admin-footer.php');
161 } else if (isset($_GET['import'])) {
163 $importer = $_GET['import'];
165 if ( ! current_user_can('import') )
166 wp_die(__('You are not allowed to import.'));
168 if ( validate_file($importer) )
169 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
171 // Allow plugins to define importers as well
172 if ( !isset($wp_importers) || !isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2])) {
173 if (! file_exists(ABSPATH . "wp-admin/import/$importer.php"))
174 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
175 include(ABSPATH . "wp-admin/import/$importer.php");
178 $parent_file = 'tools.php';
179 $submenu_file = 'import.php';
180 $title = __('Import');
182 if (! isset($_GET['noheader']))
183 require_once(ABSPATH . 'wp-admin/admin-header.php');
185 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
187 define('WP_IMPORTING', true);
189 if ( is_multisite() )
190 kses_init_filters(); // Always filter imported data with kses.
192 call_user_func($wp_importers[$importer][2]);
194 include(ABSPATH . 'wp-admin/admin-footer.php');
196 // Make sure rules are flushed
198 $wp_rewrite->flush_rules(false);
202 do_action("load-$pagenow");
203 // Backwards compatibility with old load-page-new.php, load-page.php,
204 // and load-categories.php actions.
205 if ( $typenow == 'page' ) {
206 if ( $pagenow == 'post-new.php' )
207 do_action( 'load-page-new.php' );
208 elseif ( $pagenow == 'post.php' )
209 do_action( 'load-page.php' );
210 } elseif ( $taxnow == 'category' && $pagenow == 'edit-tags.php' ) {
211 do_action( 'load-categories.php' );
215 if ( !empty($_REQUEST['action']) )
216 do_action('admin_action_' . $_REQUEST['action']);