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' );
23define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
24
25require ABSPATH . 'wp-admin/includes/noop.php';
26require ABSPATH . WPINC . '/theme.php';
27require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php';
28require ABSPATH . WPINC . '/global-styles-and-settings.php';
29require ABSPATH . WPINC . '/script-loader.php';
30require ABSPATH . WPINC . '/version.php';
31
32$protocol = $_SERVER['SERVER_PROTOCOL'];
33if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
34 $protocol = 'HTTP/1.0';
35}
36
37$load = $_GET['load'];
38if ( is_array( $load ) ) {
39 ksort( $load );
40 $load = implode( '', $load );
41}
42
43$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
44$load = array_unique( explode( ',', $load ) );
45
46if ( empty( $load ) ) {
47 header( "$protocol 400 Bad Request" );
48 exit;
49}
50
51$rtl = ( isset( $_GET['dir'] ) && 'rtl' === $_GET['dir'] );
52$expires_offset = 31536000; // 1 year.
53$out = '';
54
55$wp_styles = new WP_Styles();
56wp_default_styles( $wp_styles );
57
58$etag = $wp_styles->get_etag( $load );
59
60if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
61 header( "$protocol 304 Not Modified" );
62 exit;
63}
64
65foreach ( $load as $handle ) {
66 if ( ! array_key_exists( $handle, $wp_styles->registered ) ) {
67 continue;
68 }
69
70 $style = $wp_styles->registered[ $handle ];
71
72 if ( empty( $style->src ) ) {
73 continue;
74 }
75
76 $path = ABSPATH . $style->src;
77
78 if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
79 // All default styles have fully independent RTL files.
80 $path = str_replace( '.min.css', '-rtl.min.css', $path );
81 }
82
83 $content = get_file( $path ) . "\n";
84
85 // Note: str_starts_with() is not used here, as wp-includes/compat.php is not loaded in this file.
86 if ( 0 === strpos( $style->src, '/' . WPINC . '/css/' ) ) {
87 $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
88 $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
89 $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
90 $out .= $content;
91 } else {
92 $out .= str_replace( '../images/', 'images/', $content );
93 }
94}
95
96header( "Etag: $etag" );
97header( 'Content-Type: text/css; charset=UTF-8' );
98header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
99header( "Cache-Control: public, max-age=$expires_offset" );
100
101echo $out;
102exit;
103