Skip to content

Instantly share code, notes, and snippets.

@benmay
Created December 7, 2013 09:58
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 benmay/7839222 to your computer and use it in GitHub Desktop.
Save benmay/7839222 to your computer and use it in GitHub Desktop.
Adds the ID col
<?php
Class MediaUploaderTweak {
static function run() {
add_filter( 'manage_media_columns', array( 'MediaUploaderTweak', 'cols' ), 1 );
add_action( 'manage_media_custom_column', array( 'MediaUploaderTweak', 'col' ), 1, 2 );
add_action( 'admin_head-upload.php', array( 'MediaUploaderTweak', 'admin_head' ) );
}
// Does some basic re-ordering and adds new column.
static function cols( $defaults ) {
// Define new array to store columns
// (need to merge the ID in after the icon.
$new_array = array();
$new_array[ 'cb' ] = $defaults[ 'cb' ];
$new_array[ 'icon' ] = $defaults[ 'icon' ];
$new_array[ 'attachment_id' ] = __( 'ID' );
// Remove these two as we've added in manually.
unset( $defaults[ 'cb' ] );
unset( $defaults[ 'icon' ] );
// Merge anything in else that may exist.
return array_merge( $new_array, $defaults );
}
// If correct, adds the ID
static function col( $column_name, $id ) {
if ( $column_name === 'attachment_id' ) {
echo $id;
}
}
// Sets the width on the col
static function admin_head() {
echo '<style type="text/css"> #attachment_id {width: 40px; } </style>';
}
}
MediaUploaderTweak::run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment