ID.php
12 years ago
actions.php
12 years ago
alternate-text.php
12 years ago
available-sizes.php
12 years ago
caption.php
12 years ago
description.php
12 years ago
dimensions.php
12 years ago
exif-data.php
12 years ago
file-name.php
12 years ago
file-size.php
12 years ago
full-path.php
12 years ago
height.php
12 years ago
mime-type.php
12 years ago
width.php
12 years ago
available-sizes.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * CPAC_Column_Media_Available_Sizes |
| 5 | * |
| 6 | * @since 2.0.0 |
| 7 | */ |
| 8 | class CPAC_Column_Media_Available_Sizes extends CPAC_Column { |
| 9 | |
| 10 | function __construct( $storage_model ) { |
| 11 | |
| 12 | // define properties |
| 13 | $this->properties['type'] = 'column-available_sizes'; |
| 14 | $this->properties['label'] = __( 'Available Sizes', 'cpac' ); |
| 15 | |
| 16 | // call contruct |
| 17 | parent::__construct( $storage_model ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @see CPAC_Column::get_value() |
| 22 | * @since 2.0.0 |
| 23 | */ |
| 24 | function get_value( $id ) { |
| 25 | $paths = array(); |
| 26 | |
| 27 | $meta = get_post_meta( $id, '_wp_attachment_metadata', true ); |
| 28 | |
| 29 | if ( ! isset( $meta['sizes'] ) ) |
| 30 | return false; |
| 31 | |
| 32 | // available sizes |
| 33 | if ( $intersect = array_intersect( array_keys( $meta['sizes'] ), get_intermediate_image_sizes() ) ) { |
| 34 | |
| 35 | $url = wp_get_attachment_url( $id ); |
| 36 | $filename = basename( $url ); |
| 37 | $paths[] = "<a title='{$filename}' href='{$url}'>" . __( 'full size', 'cpac' ) . "</a>"; |
| 38 | |
| 39 | foreach ( $intersect as $size ) { |
| 40 | $src = wp_get_attachment_image_src( $id, $size ); |
| 41 | |
| 42 | if ( ! empty( $src[0] ) ) { |
| 43 | $filename = basename( $src[0] ); |
| 44 | $paths[] = "<a title='{$filename}' href='{$src[0]}' class='available'>{$size}</a>"; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | global $_wp_additional_image_sizes; |
| 50 | unset( $_wp_additional_image_sizes['post-thumbnail'] ); |
| 51 | |
| 52 | // image does not have these additional sizes rendered yet |
| 53 | if ( $missing = array_diff( array_keys( $_wp_additional_image_sizes), array_keys( $meta['sizes'] ) ) ) { |
| 54 | foreach ( $missing as $size ) { |
| 55 | $paths[] = "<span title='Missing size: Try regenerate thumbnails with the plugin: Force Regenerate Thumbnails' href='javascript:;' class='not-available'>{$size}</span>"; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return "<div class='sizes'>" . implode( '<span class="cpac-divider"></span>', $paths ) . "</div>"; |
| 60 | } |
| 61 | } |