Skip to content

Instantly share code, notes, and snippets.

@ironprogrammer
Last active May 2, 2024 00:10
Show Gist options
  • Save ironprogrammer/d184896e7c74fb214a6caba27d1a8f03 to your computer and use it in GitHub Desktop.
Save ironprogrammer/d184896e7c74fb214a6caba27d1a8f03 to your computer and use it in GitHub Desktop.
Trac 59251 testing
<?php
/**
* Tests result of disk_free_space, used in /wp-admin/includes/class-wp-site-health.php.
*
* See https://core.trac.wordpress.org/ticket/59251.
*
* - Place file in /wp-content/mu-plugins/ and go to /wp-admin/. Result displayed as notice.
* - Remove file when testing is complete.
*
* You can disable disk_free_space() by adding the following to php.ini and restarting PHP:
* disable_functions = disk_free_space
*/
add_action( 'admin_notices', 'test_disk_free_space' );
function test_disk_free_space() {
$path = WP_CONTENT_DIR . '/upgrade/';
$available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( $path ) : false;
?>
<div class="notice notice-info is-dismissible">
<h2>check-disk-space.php result:</h2>
<pre><?php
var_export( [
'path' => $path,
'is_link' => is_link( $path ),
'function_exists' => function_exists( 'disk_free_space' ),
'isInternal' => function_exists( 'disk_free_space' ) ? ( new ReflectionFunction( 'disk_free_space' ) )->isInternal() : 'n/a',
'available_space' => $available_space
] );
?></pre>
</div>
<?php
}
// Override disk_free_space when disabled in php.ini. Uncomment to test.
// if ( ! function_exists( 'disk_free_space' ) ) {
// function disk_free_space() {
// return 20 * MB_IN_BYTES - 1; // Triggers critical space warning.
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment