PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/admin.php

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