PageRenderTime 115ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/admin.php

https://bitbucket.org/julianelve/vendor-wordpress
PHP | 232 lines | 153 code | 49 blank | 30 comment | 68 complexity | c7180435c0aaa4d8d743a823d709dcc8 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  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(stripslashes($_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_reset_vars(array('profile', 'redirect', 'redirect_url', 'a', 'text', 'trackback', 'pingback'));
  66. wp_enqueue_script( 'common' );
  67. $editing = false;
  68. if ( isset($_GET['page']) ) {
  69. $plugin_page = stripslashes($_GET['page']);
  70. $plugin_page = plugin_basename($plugin_page);
  71. }
  72. if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
  73. $typenow = $_REQUEST['post_type'];
  74. else
  75. $typenow = '';
  76. if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
  77. $taxnow = $_REQUEST['taxonomy'];
  78. else
  79. $taxnow = '';
  80. if ( WP_NETWORK_ADMIN )
  81. require(ABSPATH . 'wp-admin/network/menu.php');
  82. elseif ( WP_USER_ADMIN )
  83. require(ABSPATH . 'wp-admin/user/menu.php');
  84. else
  85. require(ABSPATH . 'wp-admin/menu.php');
  86. if ( current_user_can( 'manage_options' ) )
  87. @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
  88. do_action('admin_init');
  89. if ( isset($plugin_page) ) {
  90. if ( !empty($typenow) )
  91. $the_parent = $pagenow . '?post_type=' . $typenow;
  92. else
  93. $the_parent = $pagenow;
  94. if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
  95. $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
  96. // backwards compatibility for plugins using add_management_page
  97. if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) {
  98. // There could be plugin specific params on the URL, so we need the whole query string
  99. if ( !empty($_SERVER[ 'QUERY_STRING' ]) )
  100. $query_string = $_SERVER[ 'QUERY_STRING' ];
  101. else
  102. $query_string = 'page=' . $plugin_page;
  103. wp_redirect( admin_url('tools.php?' . $query_string) );
  104. exit;
  105. }
  106. }
  107. unset($the_parent);
  108. }
  109. $hook_suffix = '';
  110. if ( isset($page_hook) )
  111. $hook_suffix = $page_hook;
  112. else if ( isset($plugin_page) )
  113. $hook_suffix = $plugin_page;
  114. else if ( isset($pagenow) )
  115. $hook_suffix = $pagenow;
  116. set_current_screen();
  117. // Handle plugin admin pages.
  118. if ( isset($plugin_page) ) {
  119. if ( $page_hook ) {
  120. do_action('load-' . $page_hook);
  121. if (! isset($_GET['noheader']))
  122. require_once(ABSPATH . 'wp-admin/admin-header.php');
  123. do_action($page_hook);
  124. } else {
  125. if ( validate_file($plugin_page) )
  126. wp_die(__('Invalid plugin page'));
  127. 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") ) )
  128. wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));
  129. do_action('load-' . $plugin_page);
  130. if ( !isset($_GET['noheader']))
  131. require_once(ABSPATH . 'wp-admin/admin-header.php');
  132. if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") )
  133. include(WPMU_PLUGIN_DIR . "/$plugin_page");
  134. else
  135. include(WP_PLUGIN_DIR . "/$plugin_page");
  136. }
  137. include(ABSPATH . 'wp-admin/admin-footer.php');
  138. exit();
  139. } else if (isset($_GET['import'])) {
  140. $importer = $_GET['import'];
  141. if ( ! current_user_can('import') )
  142. wp_die(__('You are not allowed to import.'));
  143. if ( validate_file($importer) ) {
  144. wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
  145. exit;
  146. }
  147. if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) {
  148. wp_redirect( admin_url( 'import.php?invalid=' . $importer ) );
  149. exit;
  150. }
  151. do_action( 'load-importer-' . $importer );
  152. $parent_file = 'tools.php';
  153. $submenu_file = 'import.php';
  154. $title = __('Import');
  155. if (! isset($_GET['noheader']))
  156. require_once(ABSPATH . 'wp-admin/admin-header.php');
  157. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  158. define('WP_IMPORTING', true);
  159. if ( apply_filters( 'force_filtered_html_on_import', false ) )
  160. kses_init_filters(); // Always filter imported data with kses on multisite.
  161. call_user_func($wp_importers[$importer][2]);
  162. include(ABSPATH . 'wp-admin/admin-footer.php');
  163. // Make sure rules are flushed
  164. flush_rewrite_rules(false);
  165. exit();
  166. } else {
  167. do_action("load-$pagenow");
  168. // Backwards compatibility with old load-page-new.php, load-page.php,
  169. // and load-categories.php actions.
  170. if ( $typenow == 'page' ) {
  171. if ( $pagenow == 'post-new.php' )
  172. do_action( 'load-page-new.php' );
  173. elseif ( $pagenow == 'post.php' )
  174. do_action( 'load-page.php' );
  175. } elseif ( $pagenow == 'edit-tags.php' ) {
  176. if ( $taxnow == 'category' )
  177. do_action( 'load-categories.php' );
  178. elseif ( $taxnow == 'link_category' )
  179. do_action( 'load-edit-link-categories.php' );
  180. }
  181. }
  182. if ( !empty($_REQUEST['action']) )
  183. do_action('admin_action_' . $_REQUEST['action']);