This allows to change filename, layout, pagination and other stuff for the DKPF plugin. //PDF…
How to add a sortable custom filename column to the WordPress media library admin column
//add a little css if you like
function enym_admin_table_css() {
echo '<style>
p.filename { display: none; }
</style>';
}
add_action('admin_head', 'enym_admin_table_css');
// Add the column
function filename_column( $cols ) {
$cols["filename"] = "Filename";
return $cols;
}
// Display filenames
function filename_value( $column, $post_ID ) {
if ( 'filename' === $column ) {
$meta = wp_get_attachment_metadata( $post_ID );
echo substr( strrchr( $meta['file'], '/' ), 1); // Used a few PHP functions cause 'file' stores local url to file not filename
}
}
// Register the column as sortable & sort by name
function filename_column_sortable( $cols ) {
$cols["filename"] = "name";
return $cols;
}
// Hook actions to admin_init
function hook_new_media_columns() {
add_filter( 'manage_media_columns', 'filename_column' );
add_action( 'manage_media_custom_column', 'filename_value', 10, 2 );
add_filter( 'manage_upload_sortable_columns', 'filename_column_sortable' );
}
add_action( 'admin_init', 'hook_new_media_columns' );
Dieser Beitrag hat 0 Kommentare