]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/admin.php
WordPress 3.9
[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          * Fires on the next page load after a successful DB upgrade.
40          *
41          * @since 2.8.0
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
49         /**
50          * Filter whether to attempt to perform the multisite DB upgrade routine.
51          *
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
54          * returns true.
55          *
56          * If the network is 50 sites or less, it will run every time. Otherwise,
57          * it will throttle itself to reduce load.
58          *
59          * @since 3.0.0
60          *
61          * @param bool true Whether to perform the Multisite upgrade routine. Default true.
62          */
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' ) );
69                         /** This action is documented in wp-admin/network/upgrade.php */
70                         do_action( 'after_mu_upgrade', $response );
71                         unset($response);
72                 }
73                 unset($c);
74         }
75 }
76
77 require_once(ABSPATH . 'wp-admin/includes/admin.php');
78
79 auth_redirect();
80
81 // Schedule trash collection
82 if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') )
83         wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
84
85 set_screen_options();
86
87 $date_format = get_option('date_format');
88 $time_format = get_option('time_format');
89
90 wp_enqueue_script( 'common' );
91
92 $editing = false;
93
94 if ( isset($_GET['page']) ) {
95         $plugin_page = wp_unslash( $_GET['page'] );
96         $plugin_page = plugin_basename($plugin_page);
97 }
98
99 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
100         $typenow = $_REQUEST['post_type'];
101 else
102         $typenow = '';
103
104 if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
105         $taxnow = $_REQUEST['taxonomy'];
106 else
107         $taxnow = '';
108
109 if ( WP_NETWORK_ADMIN )
110         require(ABSPATH . 'wp-admin/network/menu.php');
111 elseif ( WP_USER_ADMIN )
112         require(ABSPATH . 'wp-admin/user/menu.php');
113 else
114         require(ABSPATH . 'wp-admin/menu.php');
115
116 if ( current_user_can( 'manage_options' ) ) {
117         /**
118          * Filter the maximum memory limit available for administration screens.
119          *
120          * This only applies to administrators, who may require more memory for tasks like updates.
121          * Memory limits when processing images (uploaded or edited by users of any role) are
122          * handled separately.
123          *
124          * The WP_MAX_MEMORY_LIMIT constant specifically defines the maximum memory limit available
125          * when in the administration back-end. The default is 256M, or 256 megabytes of memory.
126          *
127          * @since 3.0.0
128          *
129          * @param string 'WP_MAX_MEMORY_LIMIT' The maximum WordPress memory limit. Default 256M.
130          */
131         @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
132 }
133
134 /**
135  * Fires as an admin screen or script is being initialized.
136  *
137  * Note, this does not just run on user-facing admin screens.
138  * It runs on admin-ajax.php and admin-post.php as well.
139  *
140  * This is roughly analgous to the more general 'init' hook, which fires earlier.
141  *
142  * @since 2.5.0
143  */
144 do_action( 'admin_init' );
145
146 if ( isset($plugin_page) ) {
147         if ( !empty($typenow) )
148                 $the_parent = $pagenow . '?post_type=' . $typenow;
149         else
150                 $the_parent = $pagenow;
151         if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
152                 $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
153                 // backwards compatibility for plugins using add_management_page
154                 if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
155                         // There could be plugin specific params on the URL, so we need the whole query string
156                         if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
157                                 $query_string = $_SERVER[ 'QUERY_STRING' ];
158                         else
159                                 $query_string = 'page=' . $plugin_page;
160                         wp_redirect( admin_url('tools.php?' . $query_string) );
161                         exit;
162                 }
163         }
164         unset($the_parent);
165 }
166
167 $hook_suffix = '';
168 if ( isset($page_hook) )
169         $hook_suffix = $page_hook;
170 else if ( isset($plugin_page) )
171         $hook_suffix = $plugin_page;
172 else if ( isset($pagenow) )
173         $hook_suffix = $pagenow;
174
175 set_current_screen();
176
177 // Handle plugin admin pages.
178 if ( isset($plugin_page) ) {
179         if ( $page_hook ) {
180                 /**
181                  * Fires before a particular screen is loaded.
182                  *
183                  * The load-* hook fires in a number of contexts. This hook is for plugin screens
184                  * where a callback is provided when the screen is registered.
185                  *
186                  * The dynamic portion of the hook name, $page_hook, refers to a mixture of plugin
187                  * page information including:
188                  * 1. The page type. If the plugin page is registered as a submenu page, such as for
189                  *    Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'.
190                  * 2. A separator of '_page_'.
191                  * 3. The plugin basename minus the file extension.
192                  *
193                  * Together, the three parts form the $page_hook. Citing the example above,
194                  * the hook name used would be 'load-settings_page_pluginbasename'.
195                  *
196                  * @see get_plugin_page_hook()
197                  *
198                  * @since 2.1.0
199                  */
200                 do_action( 'load-' . $page_hook );
201                 if (! isset($_GET['noheader']))
202                         require_once(ABSPATH . 'wp-admin/admin-header.php');
203
204                 /**
205                  * Used to call the registered callback for a plugin screen.
206                  *
207                  * @access private
208                  *
209                  * @since 1.5.0
210                  */
211                 do_action( $page_hook );
212         } else {
213                 if ( validate_file($plugin_page) )
214                         wp_die(__('Invalid plugin page'));
215
216                 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") ) )
217                         wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
218
219                 /**
220                  * Fires before a particular screen is loaded.
221                  *
222                  * The load-* hook fires in a number of contexts. This hook is for plugin screens
223                  * where the file to load is directly included, rather than the use of a function.
224                  *
225                  * The dynamic portion of the hook name, $plugin_page, refers to the plugin basename.
226                  *
227                  * @see plugin_basename()
228                  *
229                  * @since 1.5.0
230                  */
231                 do_action( 'load-' . $plugin_page );
232
233                 if ( !isset($_GET['noheader']))
234                         require_once(ABSPATH . 'wp-admin/admin-header.php');
235
236                 if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
237                         include(WPMU_PLUGIN_DIR . "/$plugin_page");
238                 else
239                         include(WP_PLUGIN_DIR . "/$plugin_page");
240         }
241
242         include(ABSPATH . 'wp-admin/admin-footer.php');
243
244         exit();
245 } else if (isset($_GET['import'])) {
246
247         $importer = $_GET['import'];
248
249         if ( ! current_user_can('import') )
250                 wp_die(__('You are not allowed to import.'));
251
252         if ( validate_file($importer) ) {
253                 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
254                 exit;
255         }
256
257         if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) {
258                 wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
259                 exit;
260         }
261
262         /**
263          * Fires before an importer screen is loaded.
264          *
265          * The dynamic portion of the hook name, $importer, refers to the importer slug.
266          *
267          * @since 3.5.0
268          */
269         do_action( 'load-importer-' . $importer );
270
271         $parent_file = 'tools.php';
272         $submenu_file = 'import.php';
273         $title = __('Import');
274
275         if (! isset($_GET['noheader']))
276                 require_once(ABSPATH . 'wp-admin/admin-header.php');
277
278         require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
279
280         define('WP_IMPORTING', true);
281
282         /**
283          * Whether to filter imported data through kses on import.
284          *
285          * Multisite uses this hook to filter all data through kses by default,
286          * as a super administrator may be assisting an untrusted user.
287          *
288          * @since 3.1.0
289          *
290          * @param bool false Whether to force data to be filtered through kses. Default false.
291          */
292         if ( apply_filters( 'force_filtered_html_on_import', false ) )
293                 kses_init_filters();  // Always filter imported data with kses on multisite.
294
295         call_user_func($wp_importers[$importer][2]);
296
297         include(ABSPATH . 'wp-admin/admin-footer.php');
298
299         // Make sure rules are flushed
300         flush_rewrite_rules(false);
301
302         exit();
303 } else {
304         /**
305          * Fires before a particular screen is loaded.
306          *
307          * The load-* hook fires in a number of contexts. This hook is for core screens.
308          *
309          * The dynamic portion of the hook name, $pagenow, is a global variable
310          * referring to the filename of the current page, such as 'admin.php',
311          * 'post-new.php' etc. A complete hook for the latter would be 'load-post-new.php'.
312          *
313          * @since 2.1.0
314          */
315         do_action( 'load-' . $pagenow );
316         // Backwards compatibility with old load-page-new.php, load-page.php,
317         // and load-categories.php actions.
318         if ( $typenow == 'page' ) {
319                 if ( $pagenow == 'post-new.php' )
320                         do_action( 'load-page-new.php' );
321                 elseif ( $pagenow == 'post.php' )
322                         do_action( 'load-page.php' );
323         }  elseif ( $pagenow == 'edit-tags.php' ) {
324                 if ( $taxnow == 'category' )
325                         do_action( 'load-categories.php' );
326                 elseif ( $taxnow == 'link_category' )
327                         do_action( 'load-edit-link-categories.php' );
328         }
329 }
330
331 if ( ! empty( $_REQUEST['action'] ) ) {
332         /**
333          * Fires when an 'action' request variable is sent.
334          *
335          * The dynamic portion of the hook name, $_REQUEST['action'],
336          * refers to the action derived from the GET or POST request.
337          *
338          * @since 2.6.0
339          */
340         do_action( 'admin_action_' . $_REQUEST['action'] );
341 }