[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  
   3  /*
   4   * The error_reporting() function can be disabled in php.ini. On systems where that is the case,
   5   * it's best to add a dummy function to the wp-config.php file, but as this call to the function
   6   * is run prior to wp-config.php loading, it is wrapped in a function_exists() check.
   7   */
   8  if ( function_exists( 'error_reporting' ) ) {
   9      /*
  10       * Disable error reporting.
  11       *
  12       * Set this to error_reporting( -1 ) for debugging.
  13       */
  14      error_reporting( 0 );
  15  }
  16  
  17  // Set ABSPATH for execution.
  18  if ( ! defined( 'ABSPATH' ) ) {
  19      define( 'ABSPATH', dirname( __DIR__ ) . '/' );
  20  }
  21  
  22  define( 'WPINC', 'wp-includes' );
  23  
  24  $protocol = $_SERVER['SERVER_PROTOCOL'];
  25  if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
  26      $protocol = 'HTTP/1.0';
  27  }
  28  
  29  $load = $_GET['load'];
  30  if ( is_array( $load ) ) {
  31      ksort( $load );
  32      $load = implode( '', $load );
  33  }
  34  
  35  $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  36  $load = array_unique( explode( ',', $load ) );
  37  
  38  if ( empty( $load ) ) {
  39      header( "$protocol 400 Bad Request" );
  40      exit;
  41  }
  42  
  43  require  ABSPATH . 'wp-admin/includes/noop.php';
  44  require ABSPATH . WPINC . '/script-loader.php';
  45  require  ABSPATH . WPINC . '/version.php';
  46  
  47  $expires_offset = 31536000; // 1 year.
  48  $out            = '';
  49  
  50  $wp_scripts = new WP_Scripts();
  51  wp_default_scripts( $wp_scripts );
  52  wp_default_packages_vendor( $wp_scripts );
  53  wp_default_packages_scripts( $wp_scripts );
  54  
  55  $etag = $wp_scripts->get_etag( $load );
  56  
  57  if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
  58      header( "$protocol 304 Not Modified" );
  59      exit;
  60  }
  61  
  62  foreach ( $load as $handle ) {
  63      if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
  64          continue;
  65      }
  66  
  67      $path = ABSPATH . $wp_scripts->registered[ $handle ]->src;
  68      $out .= get_file( $path ) . "\n";
  69  }
  70  
  71  header( "Etag: $etag" );
  72  header( 'Content-Type: application/javascript; charset=UTF-8' );
  73  header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
  74  header( "Cache-Control: public, max-age=$expires_offset" );
  75  
  76  echo $out;
  77  exit;


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref