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 */
8if ( 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.
18if ( ! defined( 'ABSPATH' ) ) {
19 define( 'ABSPATH', dirname( __DIR__ ) . '/' );
20}
21
22define( 'WPINC', 'wp-includes' );
23
24$protocol = $_SERVER['SERVER_PROTOCOL'];
25if ( ! 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'];
30if ( 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
38if ( empty( $load ) ) {
39 header( "$protocol 400 Bad Request" );
40 exit;
41}
42
43require ABSPATH . 'wp-admin/includes/noop.php';
44require ABSPATH . WPINC . '/script-loader.php';
45require ABSPATH . WPINC . '/version.php';
46
47$expires_offset = 31536000; // 1 year.
48$out = '';
49
50$wp_scripts = new WP_Scripts();
51wp_default_scripts( $wp_scripts );
52wp_default_packages_vendor( $wp_scripts );
53wp_default_packages_scripts( $wp_scripts );
54
55$etag = $wp_scripts->get_etag( $load );
56
57if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
58 header( "$protocol 304 Not Modified" );
59 exit;
60}
61
62foreach ( $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
71header( "Etag: $etag" );
72header( 'Content-Type: application/javascript; charset=UTF-8' );
73header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
74header( "Cache-Control: public, max-age=$expires_offset" );
75
76echo $out;
77exit;
78