Last active
July 18, 2017 22:03
-
-
Save widoz/f5f879709388b7ac0d41 to your computer and use it in GitHub Desktop.
Media Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add Extra Image sizes | |
* | |
* Add extra image size to chosen select | |
* | |
* @param array $list The list of the default wordpress image sizes | |
* @return array $list The filtered image sizes | |
*/ | |
add_filter( 'image_size_names_choose', function( $list ) { | |
$_images = get_intermediate_image_sizes(); | |
if ( empty( $_images ) ) { | |
return $list; | |
} | |
foreach ( $_images as $index => $item ) { | |
$list[ sanitize_key( $item ) ] = ucwords( preg_replace( '/[^a-z0-9]/', ' ', $item ) ); | |
} | |
return $list; | |
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add Media Column | |
* | |
* @param array $columns The media table list columns | |
* | |
* @return array $columns The filtered columns | |
*/ | |
add_filter( 'manage_media_columns', function ( $columns ) { | |
$columns['size'] = __( 'Size' ); | |
return $columns; | |
} ); | |
/** | |
* Add Size | |
* | |
* @param string $column_name The current media table column | |
* @param int $post_id The current media post ID | |
* | |
* @return void | |
*/ | |
add_action( 'manage_media_custom_column', function ( $column_name, $post_id ) { | |
if ( 'size' === $column_name ) { | |
echo size_format( filesize( get_attached_file( $post_id ) ) ); | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment