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


Generated : Sat Jun 6 08:20:01 2020 Cross-referenced by PHPXref