Skip to content

Instantly share code, notes, and snippets.

@widoz
Last active July 18, 2017 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save widoz/f5f879709388b7ac0d41 to your computer and use it in GitHub Desktop.
Save widoz/f5f879709388b7ac0d41 to your computer and use it in GitHub Desktop.
Media Functions
<?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;
} );
<?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