bp_document_format_size_units( $bytes, bool $post_string = false, string $type = 'bytes' )
Format file size units.
Description
Parameters
- $bytes
-
(Required)
- $post_string
-
(Optional)
Default value: false
- $type
-
(Optional)
Default value: 'bytes'
Return
(string)
Source
File: bp-document/bp-document-functions.php
function bp_document_format_size_units( $bytes, $post_string = false, $type = 'bytes' ) { if ( $bytes > 0 ) { if ( 'GB' === $type && ! $post_string ) { return $bytes / 1073741824; } elseif ( 'MB' === $type && ! $post_string ) { return $bytes / 1048576; } elseif ( 'KB' === $type && ! $post_string ) { return $bytes / 1024; } } if ( $bytes >= 1073741824 ) { $bytes = ( $bytes / 1073741824 ) . ( $post_string ? ' GB' : '' ); } elseif ( $bytes >= 1048576 ) { $bytes = ( $bytes / 1048576 ) . ( $post_string ? ' MB' : '' ); } elseif ( $bytes >= 1024 ) { $bytes = ( $bytes / 1024 ) . ( $post_string ? ' KB' : '' ); } elseif ( $bytes > 1 ) { $bytes = $bytes . ( $post_string ? ' bytes' : '' ); } elseif ( $bytes == 1 ) { $bytes = $bytes . ( $post_string ? ' byte' : '' ); } else { $bytes = '0' . ( $post_string ? ' bytes' : '' ); } return $bytes; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.