/wp-admin/load-scripts.php

  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( dirname( __FILE__ ) ) . '/' ); 
  13.  
  14. define( 'WPINC', 'wp-includes' ); 
  15.  
  16. $load = $_GET['load']; 
  17. if ( is_array( $load ) ) 
  18. $load = implode( '', $load ); 
  19.  
  20. $load = preg_replace( '/[^a-z0-9, _-]+/i', '', $load ); 
  21. $load = array_unique( explode( ', ', $load ) ); 
  22.  
  23. if ( empty($load) ) 
  24. exit; 
  25.  
  26. require( ABSPATH . 'wp-admin/includes/noop.php' ); 
  27. require( ABSPATH . WPINC . '/script-loader.php' ); 
  28. require( ABSPATH . WPINC . '/version.php' ); 
  29.  
  30. $compress = ( isset($_GET['c']) && $_GET['c'] ); 
  31. $force_gzip = ( $compress && 'gzip' == $_GET['c'] ); 
  32. $expires_offset = 31536000; // 1 year 
  33. $out = ''; 
  34.  
  35. $wp_scripts = new WP_Scripts(); 
  36. wp_default_scripts($wp_scripts); 
  37.  
  38. if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) { 
  39. $protocol = $_SERVER['SERVER_PROTOCOL']; 
  40. if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) { 
  41. $protocol = 'HTTP/1.0'; 
  42. header( "$protocol 304 Not Modified" ); 
  43. exit(); 
  44.  
  45. foreach ( $load as $handle ) { 
  46. if ( !array_key_exists($handle, $wp_scripts->registered) ) 
  47. continue; 
  48.  
  49. $path = ABSPATH . $wp_scripts->registered[$handle]->src; 
  50. $out .= get_file($path) . "\n"; 
  51.  
  52. header("Etag: $wp_version"); 
  53. header('Content-Type: application/javascript; charset=UTF-8'); 
  54. header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT'); 
  55. header("Cache-Control: public, max-age=$expires_offset"); 
  56.  
  57. if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { 
  58. header('Vary: Accept-Encoding'); // Handle proxies 
  59. if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { 
  60. header('Content-Encoding: deflate'); 
  61. $out = gzdeflate( $out, 3 ); 
  62. } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) { 
  63. header('Content-Encoding: gzip'); 
  64. $out = gzencode( $out, 3 ); 
  65.  
  66. echo $out; 
  67. exit; 
.