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