Skip to content

Commit 518cd65

Browse files
committed
Script Loader: Remove the unused compression test.
The compression test ran on admin screens until it stored its result in the `can_compress_scripts` option, but that result has had no effect since PHP compression was removed from `load-scripts.php` and `load-styles.php` in r43580, and the last code reading it was removed in r64485. The test also failed with a 400 error when `admin_url()` was filtered to add a query string, as translation plugins do, since it appended a second `?` to the AJAX URL. Users without `manage_options` were sent the test on every admin page, since the AJAX handler rejected their requests and the option was never set. Rather than fixing the URL, the test is removed. The `compression_test()` and `wp_ajax_wp_compression_test()` functions are deprecated as no-ops so that existing callers do not cause fatal errors, and the `wp-compression-test` AJAX action is no longer registered. On single sites, the option is already deleted on a database upgrade since it is in the list of unused options. On multisite it is a network option, so it is no longer primed and is now deleted by `upgrade_network()`, with the database version bumped for that step. Developed in WordPress#14412. Follow-up to r10357, r43580, r64485. Props azaozz, juzar, tofandel, szepeviktor, irozum, oglekler, peterwilsoncc, westonruter. See #57548, #63017. Fixes #58302, #65750, #65980. git-svn-id: https://develop.svn.wordpress.org/trunk@64486 602fd350-edb4-49c9-b593-d223f7449a82
1 parent acf82f5 commit 518cd65

12 files changed

Lines changed: 93 additions & 374 deletions

File tree

‎src/wp-admin/admin-ajax.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
$core_actions_get = array(
4848
'fetch-list',
4949
'ajax-tag-search',
50-
'wp-compression-test',
5150
'imgedit-preview',
5251
'oembed-cache',
5352
'autocomplete-user',

‎src/wp-admin/admin-footer.php‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@
104104
*/
105105
do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
106106

107-
// get_site_option() won't exist when auto upgrading from <= 2.7.
108-
if ( function_exists( 'get_site_option' )
109-
&& false === get_site_option( 'can_compress_scripts' )
110-
) {
111-
compression_test();
112-
}
113-
114107
?>
115108

116109
<div class="clear"></div></div><!-- wpwrap -->

‎src/wp-admin/includes/ajax-actions.php‎

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -177,76 +177,6 @@ function wp_ajax_ajax_tag_search() {
177177
wp_die();
178178
}
179179

180-
/**
181-
* Handles compression testing via AJAX.
182-
*
183-
* @since 3.1.0
184-
*/
185-
function wp_ajax_wp_compression_test() {
186-
if ( ! current_user_can( 'manage_options' ) ) {
187-
wp_die( -1 );
188-
}
189-
190-
if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) {
191-
// Use `update_option()` on single site to mark the option for autoloading.
192-
if ( is_multisite() ) {
193-
update_site_option( 'can_compress_scripts', 0 );
194-
} else {
195-
update_option( 'can_compress_scripts', 0, true );
196-
}
197-
wp_die( 0 );
198-
}
199-
200-
if ( isset( $_GET['test'] ) ) {
201-
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
202-
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
203-
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
204-
header( 'Content-Type: application/javascript; charset=UTF-8' );
205-
$force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP );
206-
$test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
207-
208-
if ( '1' === $_GET['test'] ) {
209-
echo $test_str;
210-
wp_die();
211-
} elseif ( '2' === $_GET['test'] ) {
212-
if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
213-
wp_die( -1 );
214-
}
215-
216-
if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
217-
header( 'Content-Encoding: deflate' );
218-
$output = gzdeflate( $test_str, 1 );
219-
} elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) {
220-
header( 'Content-Encoding: gzip' );
221-
$output = gzencode( $test_str, 1 );
222-
} else {
223-
wp_die( -1 );
224-
}
225-
226-
echo $output;
227-
wp_die();
228-
} elseif ( 'no' === $_GET['test'] ) {
229-
check_ajax_referer( 'update_can_compress_scripts' );
230-
// Use `update_option()` on single site to mark the option for autoloading.
231-
if ( is_multisite() ) {
232-
update_site_option( 'can_compress_scripts', 0 );
233-
} else {
234-
update_option( 'can_compress_scripts', 0, true );
235-
}
236-
} elseif ( 'yes' === $_GET['test'] ) {
237-
check_ajax_referer( 'update_can_compress_scripts' );
238-
// Use `update_option()` on single site to mark the option for autoloading.
239-
if ( is_multisite() ) {
240-
update_site_option( 'can_compress_scripts', 1 );
241-
} else {
242-
update_option( 'can_compress_scripts', 1, true );
243-
}
244-
}
245-
}
246-
247-
wp_die( 0 );
248-
}
249-
250180
/**
251181
* Handles image editor previews via AJAX.
252182
*

‎src/wp-admin/includes/deprecated.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,3 +1600,27 @@ function image_attachment_fields_to_save( $post, $attachment ) {
16001600
function delete_users_add_js() {
16011601
_deprecated_function( __FUNCTION__, '7.1.0' );
16021602
}
1603+
1604+
/**
1605+
* Was used to output JavaScript that tested whether compressing scripts from PHP works.
1606+
*
1607+
* The scripts and styles have not been compressed from PHP since 4.9.9, so the result
1608+
* of the test went unused.
1609+
*
1610+
* @since 2.8.0
1611+
* @deprecated 7.2.0
1612+
*/
1613+
function compression_test() {
1614+
_deprecated_function( __FUNCTION__, '7.2.0' );
1615+
}
1616+
1617+
/**
1618+
* Was used to handle the compression test via AJAX.
1619+
*
1620+
* @since 3.1.0
1621+
* @deprecated 7.2.0
1622+
*/
1623+
function wp_ajax_wp_compression_test() {
1624+
_deprecated_function( __FUNCTION__, '7.2.0' );
1625+
wp_die( 0 );
1626+
}

‎src/wp-admin/includes/template.php‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,70 +2544,6 @@ function get_media_states( $post ) {
25442544
return apply_filters( 'display_media_states', $media_states, $post );
25452545
}
25462546

2547-
/**
2548-
* Tests support for compressing JavaScript from PHP.
2549-
*
2550-
* Outputs JavaScript that tests if compression from PHP works as expected
2551-
* and sets an option with the result. Has no effect when the current user
2552-
* is not an administrator. To run the test again the option 'can_compress_scripts'
2553-
* has to be deleted.
2554-
*
2555-
* @since 2.8.0
2556-
*/
2557-
function compression_test() {
2558-
?>
2559-
<script>
2560-
var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>;
2561-
var testCompression = {
2562-
get : function(test) {
2563-
var x;
2564-
if ( window.XMLHttpRequest ) {
2565-
x = new XMLHttpRequest();
2566-
} else {
2567-
try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
2568-
}
2569-
2570-
if (x) {
2571-
x.onreadystatechange = function() {
2572-
var r, h;
2573-
if ( x.readyState == 4 ) {
2574-
r = x.responseText.substr(0, 18);
2575-
h = x.getResponseHeader('Content-Encoding');
2576-
testCompression.check(r, h, test);
2577-
}
2578-
};
2579-
2580-
x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&_ajax_nonce='+compressionNonce+'&'+(new Date()).getTime(), true);
2581-
x.send('');
2582-
}
2583-
},
2584-
2585-
check : function(r, h, test) {
2586-
if ( ! r && ! test )
2587-
this.get(1);
2588-
2589-
if ( 1 == test ) {
2590-
if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
2591-
this.get('no');
2592-
else
2593-
this.get(2);
2594-
2595-
return;
2596-
}
2597-
2598-
if ( 2 == test ) {
2599-
if ( '"wpCompressionTest' === r )
2600-
this.get('yes');
2601-
else
2602-
this.get('no');
2603-
}
2604-
}
2605-
};
2606-
testCompression.check();
2607-
</script>
2608-
<?php
2609-
}
2610-
26112547
/**
26122548
* Echoes a submit button, with provided text and appropriate class(es).
26132549
*

‎src/wp-admin/includes/upgrade.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,12 @@ function upgrade_network() {
26732673
delete_network_option( $network_id, 'site_meta_supported' );
26742674
is_site_meta_supported();
26752675
}
2676+
2677+
// 7.2.0
2678+
if ( $wp_current_db_version < 64486 ) {
2679+
// The compression test that set this option was removed.
2680+
delete_site_option( 'can_compress_scripts' );
2681+
}
26762682
}
26772683

26782684
//

‎src/wp-includes/option.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ function wp_load_core_site_options( $network_id = null ) {
802802
if ( ! is_multisite() || wp_installing() ) {
803803
return;
804804
}
805-
$core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting', 'WPLANG' );
805+
$core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'global_terms_enabled', 'ms_files_rewriting', 'WPLANG' );
806806

807807
wp_prime_network_option_caches( $network_id, $core_options );
808808
}

‎src/wp-includes/version.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @global int $wp_db_version
2525
*/
26-
$wp_db_version = 64402;
26+
$wp_db_version = 64486;
2727

2828
/**
2929
* Holds the TinyMCE version.

‎tests/phpstan/base.neon‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ parameters:
126126
- DOING_AJAX
127127
- DOING_CRON
128128
- EMPTY_TRASH_DAYS
129-
- ENFORCE_GZIP
130129
- FORCE_SSL_LOGIN
131130
- HEADER_IMAGE
132131
- HEADER_IMAGE_HEIGHT

‎tests/phpunit/includes/testcase-ajax.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
2323
protected static $_core_actions_get = array(
2424
'fetch-list',
2525
'ajax-tag-search',
26-
'wp-compression-test',
2726
'imgedit-preview',
2827
'oembed-cache',
2928
'autocomplete-user',

0 commit comments

Comments
 (0)