Warning: This function has been deprecated. Use size_format() instead.

wp_convert_bytes_to_hr() WordPress Function

The wp_convert_bytes_to_hr() function converts a given number of bytes to a human-readable format. The function accepts an integer value representing the number of bytes, and returns a string containing the formatted value.

wp_convert_bytes_to_hr( int $bytes ) #

Converts an integer byte value to a shorthand byte value.


Description

Top ↑

See also


Top ↑

Parameters

$bytes

(int)(Required)An integer byte value.


Top ↑

Return

(string) A shorthand byte value.


Top ↑

Source

File: wp-includes/deprecated.php

function wp_convert_bytes_to_hr( $bytes ) {
	_deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' );

	$units = array( 0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );
	$log   = log( $bytes, KB_IN_BYTES );
	$power = (int) $log;
	$size  = KB_IN_BYTES ** ( $log - $power );

	if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) {
		$unit = $units[ $power ];
	} else {
		$size = $bytes;
		$unit = $units[0];
	}

	return $size . $unit;
}


Top ↑

Changelog

Changelog
VersionDescription
3.6.0Use size_format()
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More