wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_convert_hr_to_bytes › WordPress Function

Depuis2.3.0
Dépréciéen/a
wp_convert_hr_to_bytes ( $value )
Paramètres:
  • (string) $value A (PHP ini) byte value, either shorthand or ordinary.
    Requis: Oui
Liens:
Retourne:
  • (int) An integer byte value.
Défini(e) dans:
Codex:
Changelog:
  • 4.6.0

Converts a shorthand byte value to an integer byte value.



Source

function wp_convert_hr_to_bytes( $value ) {
	$value = strtolower( trim( $value ) );
	$bytes = (int) $value;

	if ( str_contains( $value, 'g' ) ) {
		$bytes *= GB_IN_BYTES;
	} elseif ( str_contains( $value, 'm' ) ) {
		$bytes *= MB_IN_BYTES;
	} elseif ( str_contains( $value, 'k' ) ) {
		$bytes *= KB_IN_BYTES;
	}

	// Deal with large (float) values which run into the maximum integer size.
	return min( $bytes, PHP_INT_MAX );
}