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

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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

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.