PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/admin.php

https://gitlab.com/WPonEB/WPonEB
PHP | 363 lines | 166 code | 55 blank | 142 comment | 64 complexity | 0402ac65e6e367dddea2d155d869ed7b MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress Administration Bootstrap
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * In WordPress Administration Screens
  10. *
  11. * @since 2.3.2
  12. */
  13. if ( ! defined( 'WP_ADMIN' ) ) {
  14. define( 'WP_ADMIN', true );
  15. }
  16. if ( ! defined('WP_NETWORK_ADMIN') )
  17. define('WP_NETWORK_ADMIN', false);
  18. if ( ! defined('WP_USER_ADMIN') )
  19. define('WP_USER_ADMIN', false);
  20. if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) {
  21. define('WP_BLOG_ADMIN', true);
  22. }
  23. if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') )
  24. define('WP_LOAD_IMPORTERS', true);
  25. require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
  26. nocache_headers();
  27. if ( get_option('db_upgraded') ) {
  28. flush_rewrite_rules();
  29. update_option( 'db_upgraded', false );
  30. /**
  31. * Fires on the next page load after a successful DB upgrade.
  32. *
  33. * @since 2.8.0
  34. */
  35. do_action( 'after_db_upgrade' );
  36. } elseif ( get_option('db_version') != $wp_db_version && empty($_POST) ) {
  37. if ( !is_multisite() ) {
  38. wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
  39. exit;
  40. /**
  41. * Filters whether to attempt to perform the multisite DB upgrade routine.
  42. *
  43. * In single site, the user would be redirected to wp-admin/upgrade.php.
  44. * In multisite, the DB upgrade routine is automatically fired, but only
  45. * when this filter returns true.
  46. *
  47. * If the network is 50 sites or less, it will run every time. Otherwise,
  48. * it will throttle itself to reduce load.
  49. *
  50. * @since 3.0.0
  51. *
  52. * @param bool $do_mu_upgrade Whether to perform the Multisite upgrade routine. Default true.
  53. */
  54. } elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
  55. $c = get_blog_count();
  56. /*
  57. * If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load:
  58. * attempt to do no more than threshold value, with some +/- allowed.
  59. */
  60. if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
  61. require_once( ABSPATH . WPINC . '/http.php' );
  62. $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) );
  63. /** This action is documented in wp-admin/network/upgrade.php */
  64. do_action( 'after_mu_upgrade', $response );
  65. unset($response);
  66. }
  67. unset($c);
  68. }
  69. }
  70. require_once(ABSPATH . 'wp-admin/includes/admin.php');
  71. auth_redirect();
  72. // Schedule trash collection
  73. if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() )
  74. wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
  75. // Schedule Transient cleanup.
  76. if ( ! wp_next_scheduled( 'delete_expired_transients' ) && ! wp_installing() ) {
  77. wp_schedule_event( time(), 'daily', 'delete_expired_transients' );
  78. }
  79. set_screen_options();
  80. $date_format = __( 'F j, Y' );
  81. $time_format = __( 'g:i a' );
  82. wp_enqueue_script( 'common' );
  83. /**
  84. * $pagenow is set in vars.php
  85. * $wp_importers is sometimes set in wp-admin/includes/import.php
  86. * The remaining variables are imported as globals elsewhere, declared as globals here
  87. *
  88. * @global string $pagenow
  89. * @global array $wp_importers
  90. * @global string $hook_suffix
  91. * @global string $plugin_page
  92. * @global string $typenow
  93. * @global string $taxnow
  94. */
  95. global $pagenow, $wp_importers, $hook_suffix, $plugin_page, $typenow, $taxnow;
  96. $page_hook = null;
  97. $editing = false;
  98. if ( isset($_GET['page']) ) {
  99. $plugin_page = wp_unslash( $_GET['page'] );
  100. $plugin_page = plugin_basename($plugin_page);
  101. }
  102. if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
  103. $typenow = $_REQUEST['post_type'];
  104. else
  105. $typenow = '';
  106. if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
  107. $taxnow = $_REQUEST['taxonomy'];
  108. else
  109. $taxnow = '';
  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. if ( current_user_can( 'manage_options' ) ) {
  117. wp_raise_memory_limit( 'admin' );
  118. }
  119. /**
  120. * Fires as an admin screen or script is being initialized.
  121. *
  122. * Note, this does not just run on user-facing admin screens.
  123. * It runs on admin-ajax.php and admin-post.php as well.
  124. *
  125. * This is roughly analogous to the more general {@see 'init'} hook, which fires earlier.
  126. *
  127. * @since 2.5.0
  128. */
  129. do_action( 'admin_init' );
  130. if ( isset($plugin_page) ) {
  131. if ( !empty($typenow) )
  132. $the_parent = $pagenow . '?post_type=' . $typenow;
  133. else
  134. $the_parent = $pagenow;
  135. if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
  136. $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
  137. // Back-compat for plugins using add_management_page().
  138. if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
  139. // There could be plugin specific params on the URL, so we need the whole query string
  140. if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
  141. $query_string = $_SERVER[ 'QUERY_STRING' ];
  142. else
  143. $query_string = 'page=' . $plugin_page;
  144. wp_redirect( admin_url('tools.php?' . $query_string) );
  145. exit;
  146. }
  147. }
  148. unset($the_parent);
  149. }
  150. $hook_suffix = '';
  151. if ( isset( $page_hook ) ) {
  152. $hook_suffix = $page_hook;
  153. } elseif ( isset( $plugin_page ) ) {
  154. $hook_suffix = $plugin_page;
  155. } elseif ( isset( $pagenow ) ) {
  156. $hook_suffix = $pagenow;
  157. }
  158. set_current_screen();
  159. // Handle plugin admin pages.
  160. if ( isset($plugin_page) ) {
  161. if ( $page_hook ) {
  162. /**
  163. * Fires before a particular screen is loaded.
  164. *
  165. * The load-* hook fires in a number of contexts. This hook is for plugin screens
  166. * where a callback is provided when the screen is registered.
  167. *
  168. * The dynamic portion of the hook name, `$page_hook`, refers to a mixture of plugin
  169. * page information including:
  170. * 1. The page type. If the plugin page is registered as a submenu page, such as for
  171. * Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'.
  172. * 2. A separator of '_page_'.
  173. * 3. The plugin basename minus the file extension.
  174. *
  175. * Together, the three parts form the `$page_hook`. Citing the example above,
  176. * the hook name used would be 'load-settings_page_pluginbasename'.
  177. *
  178. * @see get_plugin_page_hook()
  179. *
  180. * @since 2.1.0
  181. */
  182. do_action( "load-{$page_hook}" );
  183. if (! isset($_GET['noheader']))
  184. require_once(ABSPATH . 'wp-admin/admin-header.php');
  185. /**
  186. * Used to call the registered callback for a plugin screen.
  187. *
  188. * @ignore
  189. * @since 1.5.0
  190. */
  191. do_action( $page_hook );
  192. } else {
  193. if ( validate_file( $plugin_page ) ) {
  194. wp_die( __( 'Invalid plugin page.' ) );
  195. }
  196. 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") ) )
  197. wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
  198. /**
  199. * Fires before a particular screen is loaded.
  200. *
  201. * The load-* hook fires in a number of contexts. This hook is for plugin screens
  202. * where the file to load is directly included, rather than the use of a function.
  203. *
  204. * The dynamic portion of the hook name, `$plugin_page`, refers to the plugin basename.
  205. *
  206. * @see plugin_basename()
  207. *
  208. * @since 1.5.0
  209. */
  210. do_action( "load-{$plugin_page}" );
  211. if ( !isset($_GET['noheader']))
  212. require_once(ABSPATH . 'wp-admin/admin-header.php');
  213. if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
  214. include(WPMU_PLUGIN_DIR . "/$plugin_page");
  215. else
  216. include(WP_PLUGIN_DIR . "/$plugin_page");
  217. }
  218. include(ABSPATH . 'wp-admin/admin-footer.php');
  219. exit();
  220. } elseif ( isset( $_GET['import'] ) ) {
  221. $importer = $_GET['import'];
  222. if ( ! current_user_can( 'import' ) ) {
  223. wp_die( __( 'Sorry, you are not allowed to import content.' ) );
  224. }
  225. if ( validate_file($importer) ) {
  226. wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
  227. exit;
  228. }
  229. if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) {
  230. wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
  231. exit;
  232. }
  233. /**
  234. * Fires before an importer screen is loaded.
  235. *
  236. * The dynamic portion of the hook name, `$importer`, refers to the importer slug.
  237. *
  238. * @since 3.5.0
  239. */
  240. do_action( "load-importer-{$importer}" );
  241. $parent_file = 'tools.php';
  242. $submenu_file = 'import.php';
  243. $title = __('Import');
  244. if (! isset($_GET['noheader']))
  245. require_once(ABSPATH . 'wp-admin/admin-header.php');
  246. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  247. define('WP_IMPORTING', true);
  248. /**
  249. * Whether to filter imported data through kses on import.
  250. *
  251. * Multisite uses this hook to filter all data through kses by default,
  252. * as a super administrator may be assisting an untrusted user.
  253. *
  254. * @since 3.1.0
  255. *
  256. * @param bool $force Whether to force data to be filtered through kses. Default false.
  257. */
  258. if ( apply_filters( 'force_filtered_html_on_import', false ) ) {
  259. kses_init_filters(); // Always filter imported data with kses on multisite.
  260. }
  261. call_user_func($wp_importers[$importer][2]);
  262. include(ABSPATH . 'wp-admin/admin-footer.php');
  263. // Make sure rules are flushed
  264. flush_rewrite_rules(false);
  265. exit();
  266. } else {
  267. /**
  268. * Fires before a particular screen is loaded.
  269. *
  270. * The load-* hook fires in a number of contexts. This hook is for core screens.
  271. *
  272. * The dynamic portion of the hook name, `$pagenow`, is a global variable
  273. * referring to the filename of the current page, such as 'admin.php',
  274. * 'post-new.php' etc. A complete hook for the latter would be
  275. * 'load-post-new.php'.
  276. *
  277. * @since 2.1.0
  278. */
  279. do_action( "load-{$pagenow}" );
  280. /*
  281. * The following hooks are fired to ensure backward compatibility.
  282. * In all other cases, 'load-' . $pagenow should be used instead.
  283. */
  284. if ( $typenow == 'page' ) {
  285. if ( $pagenow == 'post-new.php' )
  286. do_action( 'load-page-new.php' );
  287. elseif ( $pagenow == 'post.php' )
  288. do_action( 'load-page.php' );
  289. } elseif ( $pagenow == 'edit-tags.php' ) {
  290. if ( $taxnow == 'category' )
  291. do_action( 'load-categories.php' );
  292. elseif ( $taxnow == 'link_category' )
  293. do_action( 'load-edit-link-categories.php' );
  294. } elseif( 'term.php' === $pagenow ) {
  295. do_action( 'load-edit-tags.php' );
  296. }
  297. }
  298. if ( ! empty( $_REQUEST['action'] ) ) {
  299. /**
  300. * Fires when an 'action' request variable is sent.
  301. *
  302. * The dynamic portion of the hook name, `$_REQUEST['action']`,
  303. * refers to the action derived from the `GET` or `POST` request.
  304. *
  305. * @since 2.6.0
  306. */
  307. do_action( 'admin_action_' . $_REQUEST['action'] );
  308. }