PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/wp-admin/admin.php

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