[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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


Generated : Tue Apr 23 08:20:01 2024 Cross-referenced by PHPXref