[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Fri Oct 25 08:20:01 2019 Cross-referenced by PHPXref 0.7