amy
11/5/2017 - 4:14 AM

Change Columns Media Manager

List filenames, add PDF file type

// Add the column
function filename_column( $cols ) {
        $cols["filename"] = "Filename";
        return $cols;
}
// Display filenames
function filename_value( $column_name, $id ) {
    $meta = wp_get_attachment_metadata($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' ); 
// Add PDF Support to WordPress Media Manager
function modify_post_mime_types( $post_mime_types ) {
	// select the mime type, here: 'application/pdf'
	// then we define an array with the label values

	$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
	
	// then we return the $post_mime_types variable
	return $post_mime_types;
}
// Add Filter Hook
add_filter( 'post_mime_types', 'modify_post_mime_types' );

// For other types, go here and search for get_allow: http://core.trac.wordpress.org/browser/tags/3.5.2/wp-includes/functions.php#L0