[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> admin.php (source)

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


Generated : Thu Oct 30 08:20:06 2025 Cross-referenced by PHPXref