]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/admin.php
WordPress 3.6.1-scripts
[autoinstalls/wordpress.git] / wp-admin / admin.php
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  */
14 if ( ! defined('WP_ADMIN') )
15         define('WP_ADMIN', true);
16
17 if ( ! defined('WP_NETWORK_ADMIN') )
18         define('WP_NETWORK_ADMIN', false);
19
20 if ( ! defined('WP_USER_ADMIN') )
21         define('WP_USER_ADMIN', false);
22
23 if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) {
24         define('WP_BLOG_ADMIN', true);
25 }
26
27 if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') )
28         define('WP_LOAD_IMPORTERS', true);
29
30 require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
31
32 nocache_headers();
33
34 if ( get_option('db_upgraded') ) {
35         flush_rewrite_rules();
36         update_option( 'db_upgraded',  false );
37
38         /**
39          * Runs on the next page load after successful upgrade
40          *
41          * @since 2.8
42          */
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'] ) ) ) );
47                 exit;
48         } elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
49                 /**
50                  * On really small MU installs run the upgrader every time,
51                  * else run it less often to reduce load.
52                  *
53                  * @since 2.8.4b
54                  */
55                 $c = get_blog_count();
56                 // If 50 or fewer sites, run every time. Else, run "about ten percent" of the time. Shh, don't check that math.
57                 if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
58                         require_once( ABSPATH . WPINC . '/http.php' );
59                         $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) );
60                         do_action( 'after_mu_upgrade', $response );
61                         unset($response);
62                 }
63                 unset($c);
64         }
65 }
66
67 require_once(ABSPATH . 'wp-admin/includes/admin.php');
68
69 auth_redirect();
70
71 // Schedule trash collection
72 if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') )
73         wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
74
75 set_screen_options();
76
77 $date_format = get_option('date_format');
78 $time_format = get_option('time_format');
79
80 wp_enqueue_script( 'common' );
81
82 $editing = false;
83
84 if ( isset($_GET['page']) ) {
85         $plugin_page = wp_unslash( $_GET['page'] );
86         $plugin_page = plugin_basename($plugin_page);
87 }
88
89 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
90         $typenow = $_REQUEST['post_type'];
91 else
92         $typenow = '';
93
94 if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
95         $taxnow = $_REQUEST['taxonomy'];
96 else
97         $taxnow = '';
98
99 if ( WP_NETWORK_ADMIN )
100         require(ABSPATH . 'wp-admin/network/menu.php');
101 elseif ( WP_USER_ADMIN )
102         require(ABSPATH . 'wp-admin/user/menu.php');
103 else
104         require(ABSPATH . 'wp-admin/menu.php');
105
106 if ( current_user_can( 'manage_options' ) )
107         @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
108
109 do_action('admin_init');
110
111 if ( isset($plugin_page) ) {
112         if ( !empty($typenow) )
113                 $the_parent = $pagenow . '?post_type=' . $typenow;
114         else
115                 $the_parent = $pagenow;
116         if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
117                 $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
118                 // backwards compatibility for plugins using add_management_page
119                 if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
120                         // There could be plugin specific params on the URL, so we need the whole query string
121                         if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
122                                 $query_string = $_SERVER[ 'QUERY_STRING' ];
123                         else
124                                 $query_string = 'page=' . $plugin_page;
125                         wp_redirect( admin_url('tools.php?' . $query_string) );
126                         exit;
127                 }
128         }
129         unset($the_parent);
130 }
131
132 $hook_suffix = '';
133 if ( isset($page_hook) )
134         $hook_suffix = $page_hook;
135 else if ( isset($plugin_page) )
136         $hook_suffix = $plugin_page;
137 else if ( isset($pagenow) )
138         $hook_suffix = $pagenow;
139
140 set_current_screen();
141
142 // Handle plugin admin pages.
143 if ( isset($plugin_page) ) {
144         if ( $page_hook ) {
145                 do_action('load-' . $page_hook);
146                 if (! isset($_GET['noheader']))
147                         require_once(ABSPATH . 'wp-admin/admin-header.php');
148
149                 do_action($page_hook);
150         } else {
151                 if ( validate_file($plugin_page) )
152                         wp_die(__('Invalid plugin page'));
153
154                 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") ) )
155                         wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
156
157                 do_action('load-' . $plugin_page);
158
159                 if ( !isset($_GET['noheader']))
160                         require_once(ABSPATH . 'wp-admin/admin-header.php');
161
162                 if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
163                         include(WPMU_PLUGIN_DIR . "/$plugin_page");
164                 else
165                         include(WP_PLUGIN_DIR . "/$plugin_page");
166         }
167
168         include(ABSPATH . 'wp-admin/admin-footer.php');
169
170         exit();
171 } else if (isset($_GET['import'])) {
172
173         $importer = $_GET['import'];
174
175         if ( ! current_user_can('import') )
176                 wp_die(__('You are not allowed to import.'));
177
178         if ( validate_file($importer) ) {
179                 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
180                 exit;
181         }
182
183         if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) {
184                 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
185                 exit;
186         }
187
188         do_action( 'load-importer-' . $importer );
189
190         $parent_file = 'tools.php';
191         $submenu_file = 'import.php';
192         $title = __('Import');
193
194         if (! isset($_GET['noheader']))
195                 require_once(ABSPATH . 'wp-admin/admin-header.php');
196
197         require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
198
199         define('WP_IMPORTING', true);
200
201         if ( apply_filters( 'force_filtered_html_on_import', false ) )
202                 kses_init_filters();  // Always filter imported data with kses on multisite.
203
204         call_user_func($wp_importers[$importer][2]);
205
206         include(ABSPATH . 'wp-admin/admin-footer.php');
207
208         // Make sure rules are flushed
209         flush_rewrite_rules(false);
210
211         exit();
212 } else {
213         do_action("load-$pagenow");
214         // Backwards compatibility with old load-page-new.php, load-page.php,
215         // and load-categories.php actions.
216         if ( $typenow == 'page' ) {
217                 if ( $pagenow == 'post-new.php' )
218                         do_action( 'load-page-new.php' );
219                 elseif ( $pagenow == 'post.php' )
220                         do_action( 'load-page.php' );
221         }  elseif ( $pagenow == 'edit-tags.php' ) {
222                 if ( $taxnow == 'category' )
223                         do_action( 'load-categories.php' );
224                 elseif ( $taxnow == 'link_category' )
225                         do_action( 'load-edit-link-categories.php' );
226         }
227 }
228
229 if ( !empty($_REQUEST['action']) )
230         do_action('admin_action_' . $_REQUEST['action']);