WP_Site_Health::get_test_available_updates_disk_space()publicWP 6.3.0

Tests available disk space for updates.

Method of the class: WP_Site_Health{}

No Hooks.

Return

Array. The test results.

Usage

$WP_Site_Health = new WP_Site_Health();
$WP_Site_Health->get_test_available_updates_disk_space();

Changelog

Since 6.3.0 Introduced.

WP_Site_Health::get_test_available_updates_disk_space() code WP 6.6.2

public function get_test_available_updates_disk_space() {
	$available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;

	$result = array(
		'label'       => __( 'Disk space available to safely perform updates' ),
		'status'      => 'good',
		'badge'       => array(
			'label' => __( 'Security' ),
			'color' => 'blue',
		),
		'description' => sprintf(
			/* translators: %s: Available disk space in MB or GB. */
			'<p>' . __( '%s available disk space was detected, update routines can be performed safely.' ) . '</p>',
			size_format( $available_space )
		),
		'actions'     => '',
		'test'        => 'available_updates_disk_space',
	);

	if ( false === $available_space ) {
		$result['description'] = __( 'Could not determine available disk space for updates.' );
		$result['status']      = 'recommended';
	} elseif ( $available_space < 20 * MB_IN_BYTES ) {
		$result['description'] = sprintf(
			/* translators: %s: Available disk space in MB or GB. */
			__( 'Available disk space is critically low, less than %s available. Proceed with caution, updates may fail.' ),
			size_format( 20 * MB_IN_BYTES )
		);
		$result['status'] = 'critical';
	} elseif ( $available_space < 100 * MB_IN_BYTES ) {
		$result['description'] = sprintf(
			/* translators: %s: Available disk space in MB or GB. */
			__( 'Available disk space is low, less than %s available.' ),
			size_format( 100 * MB_IN_BYTES )
		);
		$result['status'] = 'recommended';
	}

	return $result;
}