ID.php
10 years ago
actions.php
10 years ago
alternate-text.php
10 years ago
attached-to.php
10 years ago
available-sizes.php
10 years ago
caption.php
10 years ago
description.php
10 years ago
dimensions.php
10 years ago
exif-data.php
10 years ago
file-name.php
10 years ago
file-size.php
10 years ago
full-path.php
10 years ago
height.php
10 years ago
mime-type.php
10 years ago
width.php
10 years ago
file-size.php
52 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CPAC_Column_Media_File_Size |
| 4 | * |
| 5 | * @since 2.0 |
| 6 | */ |
| 7 | class CPAC_Column_Media_File_Size extends CPAC_Column { |
| 8 | |
| 9 | /** |
| 10 | * @see CPAC_Column::init() |
| 11 | * @since 2.2.1 |
| 12 | */ |
| 13 | public function init() { |
| 14 | |
| 15 | parent::init(); |
| 16 | |
| 17 | // Properties |
| 18 | $this->properties['type'] = 'column-file_size'; |
| 19 | $this->properties['label'] = __( 'File size', 'codepress-admin-columns' ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @see CPAC_Column::get_value() |
| 24 | * @since 2.0 |
| 25 | */ |
| 26 | function get_value( $id ) { |
| 27 | |
| 28 | $value = ''; |
| 29 | |
| 30 | $file = wp_get_attachment_url( $id ); |
| 31 | $abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file ); |
| 32 | |
| 33 | if ( file_exists( $abs ) ) { |
| 34 | $value = $this->get_readable_filesize( filesize( $abs ) ); |
| 35 | } |
| 36 | |
| 37 | return $value; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Convert file size to readable format |
| 42 | * |
| 43 | * @since 1.4.5 |
| 44 | * |
| 45 | * @param string $size |
| 46 | * @return string Readable filesize |
| 47 | */ |
| 48 | function get_readable_filesize( $size ) { |
| 49 | $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); |
| 50 | return $size ? round( $size/pow( 1024, ( $i = floor( log( $size, 1024 ) ) ) ), 2) . $filesizename[$i] : '0 Bytes'; |
| 51 | } |
| 52 | } |