[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  
   3  /*
   4   * Disable error reporting.
   5   *
   6   * Set this to error_reporting( -1 ) for debugging.
   7   */
   8  error_reporting( 0 );
   9  
  10  // Set ABSPATH for execution.
  11  if ( ! defined( 'ABSPATH' ) ) {
  12      define( 'ABSPATH', dirname( __DIR__ ) . '/' );
  13  }
  14  
  15  define( 'WPINC', 'wp-includes' );
  16  
  17  $protocol = $_SERVER['SERVER_PROTOCOL'];
  18  if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
  19      $protocol = 'HTTP/1.0';
  20  }
  21  
  22  $load = $_GET['load'];
  23  if ( is_array( $load ) ) {
  24      ksort( $load );
  25      $load = implode( '', $load );
  26  }
  27  
  28  $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  29  $load = array_unique( explode( ',', $load ) );
  30  
  31  if ( empty( $load ) ) {
  32      header( "$protocol 400 Bad Request" );
  33      exit;
  34  }
  35  
  36  require  ABSPATH . 'wp-admin/includes/noop.php';
  37  require ABSPATH . WPINC . '/script-loader.php';
  38  require  ABSPATH . WPINC . '/version.php';
  39  
  40  $expires_offset = 31536000; // 1 year.
  41  $out            = '';
  42  
  43  $wp_scripts = new WP_Scripts();
  44  wp_default_scripts( $wp_scripts );
  45  wp_default_packages_vendor( $wp_scripts );
  46  wp_default_packages_scripts( $wp_scripts );
  47  
  48  $etag = "WP:{$wp_version};";
  49  
  50  foreach ( $load as $handle ) {
  51      if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
  52          continue;
  53      }
  54  
  55      $ver   = $wp_scripts->registered[ $handle ]->ver ? $wp_scripts->registered[ $handle ]->ver : $wp_version;
  56      $etag .= "{$handle}:{$ver};";
  57  }
  58  
  59  /*
  60   * This is not intended to be cryptographically secure, just a fast way to get
  61   * a fixed length string based on the script versions. As this file does not
  62   * load the full WordPress environment, it is not possible to use the salted
  63   * wp_hash() function.
  64   */
  65  $etag = 'W/"' . md5( $etag ) . '"';
  66  
  67  if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
  68      header( "$protocol 304 Not Modified" );
  69      exit;
  70  }
  71  
  72  foreach ( $load as $handle ) {
  73      if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
  74          continue;
  75      }
  76  
  77      $path = ABSPATH . $wp_scripts->registered[ $handle ]->src;
  78      $out .= get_file( $path ) . "\n";
  79  }
  80  
  81  header( "Etag: $etag" );
  82  header( 'Content-Type: application/javascript; charset=UTF-8' );
  83  header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
  84  header( "Cache-Control: public, max-age=$expires_offset" );
  85  
  86  echo $out;
  87  exit;


Generated : Thu Apr 25 08:20:02 2024 Cross-referenced by PHPXref