[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> load-styles.php (source)

   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   */
   8  if ( 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.
  18  if ( ! defined( 'ABSPATH' ) ) {
  19      define( 'ABSPATH', dirname( __DIR__ ) . '/' );
  20  }
  21  
  22  define( 'WPINC', 'wp-includes' );
  23  define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  24  
  25  require  ABSPATH . 'wp-admin/includes/noop.php';
  26  require ABSPATH . WPINC . '/theme.php';
  27  require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php';
  28  require ABSPATH . WPINC . '/global-styles-and-settings.php';
  29  require ABSPATH . WPINC . '/script-loader.php';
  30  require  ABSPATH . WPINC . '/version.php';
  31  
  32  $protocol = $_SERVER['SERVER_PROTOCOL'];
  33  if ( ! 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'];
  38  if ( 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  
  46  if ( 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();
  56  wp_default_styles( $wp_styles );
  57  
  58  $etag = $wp_styles->get_etag( $load );
  59  
  60  if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
  61      header( "$protocol 304 Not Modified" );
  62      exit;
  63  }
  64  
  65  foreach ( $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  
  96  header( "Etag: $etag" );
  97  header( 'Content-Type: text/css; charset=UTF-8' );
  98  header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
  99  header( "Cache-Control: public, max-age=$expires_offset" );
 100  
 101  echo $out;
 102  exit;


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref