[ Index ]

PHP Cross Reference of WordPress

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  if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
  52      header( "$protocol 304 Not Modified" );
  53      exit;
  54  }
  55  
  56  foreach ( $load as $handle ) {
  57      if ( ! array_key_exists( $handle, $wp_styles->registered ) ) {
  58          continue;
  59      }
  60  
  61      $style = $wp_styles->registered[ $handle ];
  62  
  63      if ( empty( $style->src ) ) {
  64          continue;
  65      }
  66  
  67      $path = ABSPATH . $style->src;
  68  
  69      if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
  70          // All default styles have fully independent RTL files.
  71          $path = str_replace( '.min.css', '-rtl.min.css', $path );
  72      }
  73  
  74      $content = get_file( $path ) . "\n";
  75  
  76      if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) {
  77          $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
  78          $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
  79          $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
  80          $out    .= $content;
  81      } else {
  82          $out .= str_replace( '../images/', 'images/', $content );
  83      }
  84  }
  85  
  86  header( "Etag: $wp_version" );
  87  header( 'Content-Type: text/css; charset=UTF-8' );
  88  header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
  89  header( "Cache-Control: public, max-age=$expires_offset" );
  90  
  91  echo $out;
  92  exit;


Generated: Mon Jun 27 01:00:02 2022 Cross-referenced by PHPXref 0.7.1