Skip to content

Commit 5c86c77

Browse files
authored
Version 1.3.2 (#341)
1 parent 39333bb commit 5c86c77

File tree

5 files changed

+139
-6
lines changed

5 files changed

+139
-6
lines changed

docs/plugin/readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Tags: health check
33
Contributors: wordpressdotorg, westi, pento, Clorith
44
Requires at least: 4.0
55
Tested up to: 5.2
6-
Stable tag: 1.3.1
6+
Stable tag: 1.3.2
77
License: GPLv2
88
License URI: https://www.gnu.org/licenses/gpl-2.0.html
99

@@ -39,6 +39,10 @@ Are you unfamiliar with how to clear your cookies? No worries, you may also clos
3939

4040
== Changelog ==
4141

42+
= v1.3.2 =
43+
* Add polyfill for directory size calculations for sites running WordPress versions older than 5.2.0
44+
* Fix link for the extended PHP information
45+
4246
= v1.3.1 =
4347
* Include missing dependency for JavaScript files, first introduced in WordPress 5.2
4448

src/health-check.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Plugin URI: https://wordpress.org/plugins/health-check/
1010
* Description: Checks the health of your WordPress install.
1111
* Author: The WordPress.org community
12-
* Version: 1.3.1
12+
* Version: 1.3.2
1313
* Author URI: https://wordpress.org/plugins/health-check/
1414
* Text Domain: health-check
1515
*/
@@ -35,7 +35,7 @@
3535
define( 'HEALTH_CHECK_MYSQL_REC_VERSION', '5.6' );
3636

3737
// Set the plugin version.
38-
define( 'HEALTH_CHECK_PLUGIN_VERSION', '1.3.1' );
38+
define( 'HEALTH_CHECK_PLUGIN_VERSION', '1.3.2' );
3939

4040
// Set the absolute path for the plugin.
4141
define( 'HEALTH_CHECK_PLUGIN_DIRECTORY', plugin_dir_path( __FILE__ ) );

src/includes/class-health-check-debug-data.php

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,50 @@ public static function get_database_size() {
11231123
return (int) $size;
11241124
}
11251125

1126+
public static function ajax_get_sizes() {
1127+
check_ajax_referer( 'health-check-site-status-result' );
1128+
1129+
if ( ! current_user_can( 'install_plugins' ) || is_multisite() ) {
1130+
wp_send_json_error();
1131+
}
1132+
1133+
$sizes_data = Health_Check_Debug_Data::get_sizes();
1134+
$all_sizes = array( 'raw' => 0 );
1135+
1136+
foreach ( $sizes_data as $name => $value ) {
1137+
$name = sanitize_text_field( $name );
1138+
$data = array();
1139+
1140+
if ( isset( $value['size'] ) ) {
1141+
if ( is_string( $value['size'] ) ) {
1142+
$data['size'] = sanitize_text_field( $value['size'] );
1143+
} else {
1144+
$data['size'] = (int) $value['size'];
1145+
}
1146+
}
1147+
1148+
if ( isset( $value['debug'] ) ) {
1149+
if ( is_string( $value['debug'] ) ) {
1150+
$data['debug'] = sanitize_text_field( $value['debug'] );
1151+
} else {
1152+
$data['debug'] = (int) $value['debug'];
1153+
}
1154+
}
1155+
1156+
if ( ! empty( $value['raw'] ) ) {
1157+
$data['raw'] = (int) $value['raw'];
1158+
}
1159+
1160+
$all_sizes[ $name ] = $data;
1161+
}
1162+
1163+
if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
1164+
wp_send_json_error( $all_sizes );
1165+
}
1166+
1167+
wp_send_json_success( $all_sizes );
1168+
}
1169+
11261170
/**
11271171
* Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
11281172
* Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
@@ -1156,6 +1200,15 @@ public static function get_sizes() {
11561200
$max_execution_time -= 2;
11571201
}
11581202

1203+
if ( ! defined( 'WP_START_TIMESTAMP' ) ) {
1204+
global $timestart;
1205+
if ( version_compare( phpversion(), '5.4.0', '>=' ) && isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ) {
1206+
define( 'WP_START_TIMESTAMP', $_SERVER['REQUEST_TIME_FLOAT'] );
1207+
} else {
1208+
define( 'WP_START_TIMESTAMP', $timestart );
1209+
}
1210+
}
1211+
11591212
// Go through the various installation directories and calculate their sizes.
11601213
// No trailing slashes.
11611214
$paths = array(
@@ -1182,9 +1235,17 @@ public static function get_sizes() {
11821235

11831236
if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
11841237
if ( 'wordpress_size' === $name ) {
1185-
$dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1238+
if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '<' ) ) {
1239+
$dir_size = Health_Check_Debug_Data::recurse_dirsize( $path, $exclude, $max_execution_time );
1240+
} else {
1241+
$dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1242+
}
11861243
} else {
1187-
$dir_size = recurse_dirsize( $path, null, $max_execution_time );
1244+
if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '<' ) ) {
1245+
$dir_size = Health_Check_Debug_Data::recurse_dirsize( $path, null, $max_execution_time );
1246+
} else {
1247+
$dir_size = recurse_dirsize( $path, null, $max_execution_time );
1248+
}
11881249
}
11891250
}
11901251

@@ -1248,4 +1309,71 @@ public static function get_sizes() {
12481309

12491310
return $all_sizes;
12501311
}
1312+
1313+
/**
1314+
* Fallback function for directory size calculation on sites running WordPress <5.2
1315+
*
1316+
* @param string $directory Full path of a directory.
1317+
* @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths.
1318+
* Expected without trailing slash(es).
1319+
* @param int $max_execution_time Maximum time to run before giving up. In seconds.
1320+
* The timeout is global and is measured from the moment WordPress started to load.
1321+
* @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
1322+
*/
1323+
static function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
1324+
$size = 0;
1325+
1326+
$directory = untrailingslashit( $directory );
1327+
1328+
if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
1329+
return false;
1330+
}
1331+
1332+
if (
1333+
( is_string( $exclude ) && $directory === $exclude ) ||
1334+
( is_array( $exclude ) && in_array( $directory, $exclude, true ) )
1335+
) {
1336+
return false;
1337+
}
1338+
1339+
if ( null === $max_execution_time ) {
1340+
// Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
1341+
if ( function_exists( 'ini_get' ) ) {
1342+
$max_execution_time = ini_get( 'max_execution_time' );
1343+
} else {
1344+
// Disable...
1345+
$max_execution_time = 0;
1346+
}
1347+
1348+
// Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value.
1349+
if ( $max_execution_time > 10 ) {
1350+
$max_execution_time -= 1;
1351+
}
1352+
}
1353+
1354+
$handle = opendir( $directory );
1355+
if ( $handle ) {
1356+
while ( ( $file = readdir( $handle ) ) !== false ) {
1357+
$path = $directory . '/' . $file;
1358+
if ( '.' != $file && '..' != $file ) {
1359+
if ( is_file( $path ) ) {
1360+
$size += filesize( $path );
1361+
} elseif ( is_dir( $path ) ) {
1362+
$handlesize = Health_Check_Debug_Data::recurse_dirsize( $path, $exclude, $max_execution_time );
1363+
if ( $handlesize > 0 ) {
1364+
$size += $handlesize;
1365+
}
1366+
}
1367+
1368+
if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
1369+
// Time exceeded. Give up instead of risking a fatal timeout.
1370+
$size = null;
1371+
break;
1372+
}
1373+
}
1374+
}
1375+
closedir( $handle );
1376+
}
1377+
return $size;
1378+
}
12511379
}

src/includes/class-health-check.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function init() {
6767
add_action( 'wp_ajax_health-check-files-integrity-check', array( 'Health_Check_Files_Integrity', 'run_files_integrity_check' ) );
6868
add_action( 'wp_ajax_health-check-view-file-diff', array( 'Health_Check_Files_Integrity', 'view_file_diff' ) );
6969
add_action( 'wp_ajax_health-check-mail-check', array( 'Health_Check_Mail_Check', 'run_mail_check' ) );
70+
add_action( 'wp_ajax_health-check-get-sizes', array( 'Health_Check_Debug_Data', 'ajax_get_sizes' ) );
7071

7172
add_filter( 'health_check_tools_tab', array( 'Health_Check_Files_Integrity', 'tools_tab' ) );
7273
add_filter( 'health_check_tools_tab', array( 'Health_Check_Mail_Check', 'tools_tab' ) );

src/pages/debug-data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<?php
114114
printf(
115115
'<a href="%s" class="button button-primary">%s</a>',
116-
esc_url( admin_url( '?page=health-check&tab=phpinfo' ) ),
116+
esc_url( admin_url( 'tools.php?page=health-check&tab=phpinfo' ) ),
117117
esc_html__( 'View extended PHP information', 'health-check' )
118118
);
119119
?>

0 commit comments

Comments
 (0)