load-styles.php (2457B)
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 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); 17 18 require ABSPATH . 'wp-admin/includes/noop.php'; 19 require ABSPATH . WPINC . '/theme.php'; 20 require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php'; 21 require ABSPATH . WPINC . '/script-loader.php'; 22 require ABSPATH . WPINC . '/version.php'; 23 24 $protocol = $_SERVER['SERVER_PROTOCOL']; 25 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ), 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 $rtl = ( isset( $_GET['dir'] ) && 'rtl' === $_GET['dir'] ); 44 $expires_offset = 31536000; // 1 year. 45 $out = ''; 46 47 $wp_styles = new WP_Styles(); 48 wp_default_styles( $wp_styles ); 49 50 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) { 51 header( "$protocol 304 Not Modified" ); 52 exit; 53 } 54 55 foreach ( $load as $handle ) { 56 if ( ! array_key_exists( $handle, $wp_styles->registered ) ) { 57 continue; 58 } 59 60 $style = $wp_styles->registered[ $handle ]; 61 62 if ( empty( $style->src ) ) { 63 continue; 64 } 65 66 $path = ABSPATH . $style->src; 67 68 if ( $rtl && ! empty( $style->extra['rtl'] ) ) { 69 // All default styles have fully independent RTL files. 70 $path = str_replace( '.min.css', '-rtl.min.css', $path ); 71 } 72 73 $content = get_file( $path ) . "\n"; 74 75 if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) { 76 $content = str_replace( '../images/', '../' . WPINC . '/images/', $content ); 77 $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content ); 78 $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content ); 79 $out .= $content; 80 } else { 81 $out .= str_replace( '../images/', 'images/', $content ); 82 } 83 } 84 85 header( "Etag: $wp_version" ); 86 header( 'Content-Type: text/css; charset=UTF-8' ); 87 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' ); 88 header( "Cache-Control: public, max-age=$expires_offset" ); 89 90 echo $out; 91 exit;