load-scripts.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * Disable error reporting.
  4. *
  5. * Set this to error_reporting( -1 ) for debugging.
  6. */
  7. error_reporting( 0 );
  8. // Set ABSPATH for execution.
  9. if ( ! defined( 'ABSPATH' ) ) {
  10. define( 'ABSPATH', dirname( __DIR__ ) . '/' );
  11. }
  12. define( 'WPINC', 'wp-includes' );
  13. $protocol = $_SERVER['SERVER_PROTOCOL'];
  14. if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
  15. $protocol = 'HTTP/1.0';
  16. }
  17. $load = $_GET['load'];
  18. if ( is_array( $load ) ) {
  19. ksort( $load );
  20. $load = implode( '', $load );
  21. }
  22. $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  23. $load = array_unique( explode( ',', $load ) );
  24. if ( empty( $load ) ) {
  25. header( "$protocol 400 Bad Request" );
  26. exit;
  27. }
  28. require ABSPATH . 'wp-admin/includes/noop.php';
  29. require ABSPATH . WPINC . '/script-loader.php';
  30. require ABSPATH . WPINC . '/version.php';
  31. $expires_offset = 31536000; // 1 year.
  32. $out = '';
  33. $wp_scripts = new WP_Scripts();
  34. wp_default_scripts( $wp_scripts );
  35. wp_default_packages_vendor( $wp_scripts );
  36. wp_default_packages_scripts( $wp_scripts );
  37. if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
  38. header( "$protocol 304 Not Modified" );
  39. exit;
  40. }
  41. foreach ( $load as $handle ) {
  42. if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
  43. continue;
  44. }
  45. $path = ABSPATH . $wp_scripts->registered[ $handle ]->src;
  46. $out .= get_file( $path ) . "\n";
  47. }
  48. header( "Etag: $wp_version" );
  49. header( 'Content-Type: application/javascript; charset=UTF-8' );
  50. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
  51. header( "Cache-Control: public, max-age=$expires_offset" );
  52. echo $out;
  53. exit;