Filter uncanny-toolkit-pro

uo_download_certificates_available_disk_space

Filters the available disk space used for certificate downloads, allowing modification before it's displayed.

add_filter( 'uo_download_certificates_available_disk_space', $callback, 10, 1 );

Description

Filters the minimum available disk space required for certificate downloads. Allows developers to modify the default 2 GB requirement, perhaps to accommodate larger download batches or different server configurations.


Usage

add_filter( 'uo_download_certificates_available_disk_space', 'your_function_name', 10, 1 );

Parameters

$size (mixed)
This parameter represents the available disk space in gigabytes, which defaults to 2 GB if the `disk_free_space` function is not available.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'uo_download_certificates_available_disk_space' filter.
 *
 * This filter allows you to modify the amount of available disk space
 * (in GB) that is considered for downloading certificates.
 *
 * In this example, we'll ensure that at least 1 GB of disk space is available.
 * If the calculated available space is less than 1 GB, we'll adjust it to 1 GB.
 *
 * @param float|int $size The current calculated available disk space in GB.
 * @return float|int The adjusted available disk space in GB.
 */
add_filter( 'uo_download_certificates_available_disk_space', function( $size ) {
    $minimum_required_space_gb = 1; // Minimum 1 GB of disk space required

    // If the calculated size is less than the minimum required, set it to the minimum.
    if ( is_numeric( $size ) && $size < $minimum_required_space_gb ) {
        $size = $minimum_required_space_gb;
    } elseif ( ! is_numeric( $size ) ) {
        // If for some reason $size is not a number (e.g., null or empty from default)
        // and we didn't have a fallback in the original function, ensure we have at least the minimum.
        $size = $minimum_required_space_gb;
    }

    // Return the potentially adjusted size
    return $size;
}, 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/download-certificates-in-bulk.php:1328
src/classes/download-certificates-in-bulk.php:1340

public static function uo_check_disk_space() {
		$size = 2;
		// If function does not exist, assume and return 2 GB
		if ( ! function_exists( 'disk_free_space' ) ) {
			return apply_filters( 'uo_download_certificates_available_disk_space', $size ); // Function does not exist. Bail, return 0 space.
		}

		if ( function_exists( 'disk_free_space' ) ) {
			$size = disk_free_space( WP_CONTENT_DIR );
			if ( ! empty( $size ) ) {
				$size = round( $size / 1024 / 1024 / 1024, 4 );
			}
		}

		$size = empty( $size ) ? 2 : $size; // If function return empty or null, return 2 as default

		return apply_filters( 'uo_download_certificates_available_disk_space', $size ); // Function does not exist. Bail, return 0 space.
	}

Scroll to Top